glabel clarification

Gareth Brown gaz at
Fri Oct 23 15:40:13 UTC 2009

PJ wrote:
> I understood that labeling a disk with glabel would permit the disk to
> be switched to another system and booting from that disk would not
> require other manupulations than adjusting network configuration, samba,
> rc.conf and a few others..
> But what if there is already a disk on the system with the identical
> labels in /dev/label/ ?
> I understood that whatever the actual disk might be (ad4, ad12,
> ad1...)would be irrelevant?
> It would appear that the actual booting goes according to the label; so,
> if there are duplicate labels the boot will not necessarily be from the
> newly installed disk if there is another disk with duplicate glabel labels?
> So doing a glabel seems superfluous...
> What then is the real purpose of glabel, since the boot process seems to
> need a unique identifier?
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"
Basically there is some order required to the whole process and 
labelling is required should you wish to boot from more that just the 
first BIOS disk.

The BIOS will look for disks at certain points on the controller and 
assign device names to each disk based on it's physical position.  The 
GEOM framework adds meta data to an area of the disk that is looked at 
by the kernel at boot.  I've included some of my own documentation on 
how to setup a complex 2 x RAID1 + 1 x RAID10 over 4 disks (2 slices per 
disk).  I know you're not doing anything so complex, but hopefully 
you'll be able to take out the unnecessary step to suit your need.

  GEOM Background

gstripe(8) provides a stripe set or RAID 0
gmirror(8) provides a mirror/duplex or RAID 1
graid3(8) provides a stripe with parity or RAID 3
provider--This GEOM entity appears in /dev. This article shows how to 
create a provider known as /dev/mirror/gm0, which represents the disk 
consumer--This entity receives I/O requests. In the example of a 
mirror/duplex, it is the two physical drives. I use two IDE drives on 
separate cables; they are /dev/ad0 and /dev/ad2.
metadata--When referring to any RAID level, metadata includes the array 
members, their sizes and locations, descriptions of logical disks and 
partitions, and the current state of the disk array.
mirror/duplex--RAID 1 maintains the same data on two separate drives. In 
other words, it mirrors the data on one drive to another drive. If those 
two drives are attached to the same IDE cable, they are a mirror; if 
they are attached to separate cables, they are a duplex. Because a 
single cable introduces a single point of failure, most mirrors are 
actually duplexes.

  Complex GEOM RAID

/Creating a complex 4 disk raid where the OS and swap are duplexed on 
the first slice over the 4 disks; and the 2nd slice of all disks is 
setup as a RAID10 for the data. By analyzing this way, it can be easily 
broken down into it's smaller gmirror/glabel/gsrtipe components if that 
is all that is required. So the dual RAID1 and single RAID10 will look 

    The Aim

      Physical disk providers

da0s1 mirrors with da2s1 for / (1G); /usr (5G) and /var (2G) called 
gmROOT then glabelled ROOT
da1s1 mirrors with da3s1 for swap only and labelled gmSWAP then 
glabelled SWAP
da0s2 mirrors with da2s2 and labelled gmDATA0
da1s2 mirrors with da3s2 and labelled gmDATA1
gmDATA0 and gmDATA1 will be striped and labelled gsDATA and glabelled 
DATA for /home (10G) and /opt (15G)


/ = ROOTa
/usr = ROOTd
/var = ROOTe
/home = DATAd
/opt – DATAe

    Creating a RAID steps

   1. create all slices remembering to leave space between them for the
      disk/slice data - done by creating the first slice larger than it
      needs to be, then creating the second slice, deleting the first
      slice and recreating it from the free space at it's correct size.
   2. create da0s1 partitioning as above; all of da1s1 for swap; and
      da0s2 partitioned as above
   3. install OS onto da0s1. Partitioning as above, installing minimal
      package and developer.
   4. return to config, set root password, then break out (*alt-F4*) to
      add all geom modules to loader.conf: *grep geom
      /boot/defaults/loader.conf >> /boot/loader.conf*
   5. edit /boot/loader.conf so that stripe, mirror and label are set to
      yes and return to the install (*alt-f1*) and exit.
   6. create mirror for root fs on the unused disk: *gmirror label -v -b
      round-robin gmROOT da2s1* /Where gmirror label creates the mirror;
      -v enables verbose mode; -b round-robin chooses a balance
      algorithm (at the moment, round-robin is the algorithm with the
      best performance); ROOT is the name of mirror/duplex (this name
      represents the first GEOM mirror); and /dev/da2s1 represents the
      disk containing the data to mirror./
   7. check it: *gmirror status*
   8. create labels for this mirror: *glabel label -v ROOT mirror/gmROOT*
   9. check it: *glabel status*
  10. copy OS to the new glabelled filesystem: *dd bs=32768
      if=/dev/da0s1 of=/dev/label/ROOT*
  11. create mirror for swap (not essentially necessary but it is
      tidier): *gmirror label -v -b round-robin gmSWAP da1s1 da3s1*
  12. check it: *gmirror status*
  13. create labels for this mirror: *glabel label -v SWAP mirror/gmSWAP*
  14. check it: *glabel status*
  15. create stripe
  16. a *gmirror label -v -b round-robin gmDATA0 da0s2 da2s2*
  17. b *gmirror label -v -b round-robin gmDATA1 da1s2 da3s2*
  18. c *gstripe label -v gsDATA mirror/gmDATA0 mirror/DATA1*
  19. create label for this stripe: *glabel label -v DATA stripe/DATA*
  20. check labels: *glabel status*
  21. mount the mirrored / and edit fstab (this may require an fsck
      first): *mount /dev/label/ROOTa /mnt*
  22. change all fstab device entires to match their equivalent label
      (copy the original first). I.e. /dev/da0s1a to /dev/label/ROOTa
      and /dev/da0s2d to /dev/label/DATAd /When finished, triple-check
      your changes to both /mnt/etc/fstab and /mnt/boot/loader.conf.
      While it is fixable
      it sucks not being able to boot into a new system because of a typo./
  23. halt
  24. swap da0 and da2 around
  25. power up /Boot will show lots of GEOM_MIRROR, GEOM_STRIPE and
      GEOM_LABEL messages for your created GEOM devices/
  26. Insert the original disk into the mirror (remembering the disk
      that was da0 is now going to be da2): *gmirror insert gmROOT
      da2s1; gmirror insert gmDATA0 da2s2*
  27. check mirror: *gmirror status* /Once finished, status will show


# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/label/ROOTa 989M 138M 772M 15% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/label/DATAd 9.7G 22K 8.9G 0% /home
/dev/label/DATAe 15G 4.0K 13G 0% /opt
/dev/label/ROOTd 4.8G 1.3G 3.1G 30% /usr
/dev/label/ROOTe 1.9G 290K 1.8G 0% /var

# swapinfo
Device 1K-blocks Used Avail Capacity
/dev/label/SWAP 8385896 0 8385896 0%

    Replacing a disk

/Lets say da0 dies effecting the mirrors gmROOT and gmDATA0/

   1. remove the disk
   2. tell the mirror to forget the disk: *gmirror forget gmROOT;
      gmirror forget gmDATA0*
   3. insert the new disk
   4. check which scsi the disk is connected to: *camcontrol devlist*
   5. tell the system to rescan the scsi bus the disk is connected to:
      *camcontrol rescan 0*
   6. dump the disk slice-data and geometry from the other disk in the
      mirror: *fdisk /dev/da2 -p >> diskdata*
   7. setup the new disk with the same details: _fdisk -f diskdata
   8. write the MBR: *fdisk -B -b /boot/boot0 /dev/da0*
   9. reinsert the slices into their relevant mirrors: *gmirror insert
      gmROOT da0s1; gmirror insert gmDATA0 da0s2*
  10. check it: *gmirror status*

More information about the freebsd-questions mailing list