|Home||Switchboard||Unix Administration||Red Hat||TCP/IP Networks||Neoliberalism||Toxic Managers|
May the source be with you, but remember the KISS principle ;-)
Skepticism and critical thinking is not panacea, but can help to understand the world better
|Repartitioning||Grub||Booting into Rescue Mode||Linux Image-based backups and SystemRescueCD||Logical Volume Renaming||How To Manage Your Disk By UUID|
|Linux Multipath||udev||Labeling the partition||Loopback filesystem||Admin Horror Stories||Humor||Etc|
Linux has mind boggling variety of disk mapping schemes. Among them
Logical manager mapping (LVM - mapping)
To label the partition, execute the following as root:
e2label <device> <label>
e2label /dev/sda3 root
To list the label you can use the same utility
# e2label /dev/cciss/c0d0p2 Turbomole
To mount a partition using its label install of device use option -L:
# mount -L Turbomole /Turbomole # df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p8 11904588 3779612 7510492 34% / /dev/cciss/c0d0p7 23809236 438648 22141620 2% /var /dev/cciss/c0d0p5 63484780 5891780 54316144 10% /home /dev/cciss/c0d0p3 63484808 184376 60023576 1% /tmp /dev/cciss/c0d0p1 497829 29387 442740 7% /boot tmpfs 66042700 0 66042700 0% /dev/shm /dev/cciss/c0d0p2 126969692 4627316 115788660 4% /Turbomole
Unfortunately labels for ext2/ext3 filesystem are not visible in df -k listing. That limits the appeal of using disk labels, but still they are a very good way to ensure that all partitions are mounted correctly as they do not depend on the numbering of partitions within disk, which can change.
You can mount partitions using labels and by default RHEL 5.6 is mounting non-LVM partitions this way in /etc/fstab:
# cat /etc/fstab LABEL=/ / ext3 defaults 1 1 /dev/VolGroup00/var /var ext3 defaults 1 2 /dev/VolGroup00/tmp /tmp ext3 defaults 1 2 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 LABEL=SWAP-sda2 swap swap defaults 0 0
Please not that LABEL=/boot means that label is "/boot", not "boot". If you forget about it filesystem will not be mounted on reboot and sysmtem will go into rescue mode. See Troubleshooting Errors in /etc/fstab
While labeling is not required, partition labels can be useful. For example, when adding the partition to /etc/fstab, the label can be listed instead of the partition device name. This proves useful if the partition number is changed from repartitioning the drive or if the partition is moved.
If the e2label command is used with just the partition device name as an argument, the current label for the partition is displayed.
Relabeling of logical volumes on LVM is a different story and there is a different procedure and different command to use. See Logical Volume Renaming
Labeling of logical volumes is good practice as it simplify understanding how the volume is mapped and helps to prevent some errors.
The Linux kernel is a restless beast, and must continally evolve and change. Especially in ways that mystify us poor end lusers. A recent wrinkle, as of kernel version 2.6.20, is changing the /dev names for ATA devices, so that all ATA and SCSI devices are named /dev/sd*. This is a result of using the shiny new libata subsystem. In the olden days PATA (also called IDE) hard drives and ATAPI devices (CD/DVD, tape drives) were /dev/hd*, and SCSI and SATA devices were /dev/sd*.
However, not all Linux distributions default to using libata. *buntu Feisty and Gutsy are all over the map; some versions of them use the new naming convention, some don't, and I haven't figured out which ones, or why. You can see how your own system handles these names with a couple of simple commands. This example from Kubuntu Gutsy shows the old style:$ ls /dev|grep '[s|h]d[a-z]' hda hda1 hda2 hdc hdd sda sda1 sda2 $ mount|grep ^'/dev' /dev/hda1 on / type ext3 (rw,errors=remount-ro) /dev/sda1 on /home type ext3 (rw) /dev/sda2 on /media/sda2 type ext3 (rw) /dev/hda2 on /var type ext3 (rw)
The first command shows all the ATA and SCSI devices detected by your kernel. The second command shows which ones are mounted. On this system there is one PATA hard disk with two partitions (hda), two CD/DVD drives (hdc, hdd), and one SATA disk with two partitions (sda). When I boot into Fedora 8, which defaults to libata, it looks like this:$ ls /dev|grep '[s|h]d[a-z]' sda sda1 sda2 sdb sdb1 sdb2Where are the two CD/DVD drives? These get /dev/sr* names under libata:$ ls /dev|grep sr sr0 sr1
For creating ext3 and xfs file systems, mkfs.ext3 and mkfs.xfs have the -L option to specify the disk label that should be used. For existing file systems, use e2label to label an ext2/ext3 file system. And for xfs file systems, use xfs_admin. Both of these commands can be used with the device to display the existing disk label.
Examples of initializing new file systems with a label:mkfs.ext3 -L ROOT /dev/sda1 mkfs.xfs -L BIGRAID /dev/sde
Examples of e2label and xfs_admin for existing files systems:e2label /dev/sda1 PRIMARY_ROOT e2label /dev/sda1 xfs_admin -L DATA1 /dev/sdf xfs_admin /dev/sdf
labeling swap devices
You can label a swap device by using the mkswap -L label option.mkswap -L SWAP0 /dev/sdb5
Alternative / by-id
Alternatively, you can use the udev by-id specification (look in /dev/disk/by-id). The ID paths are usually pretty long and less meaningful, but they are device specific and won't change as a result of hardware changes. It's probably best to use a disk label as above. However, for vfat/fat file systems disk labels are not available so the by-id specification
should be used./dev/disk/by-id/scsi-3500000e01632b7d0-part2 swap swap defaults 0 0
Examples of Use
Finally, the following are examples of using disk labels in
two key system files, fstab and grub.conf.
Example of /etc/fstab with disk labels:LABEL=ROOT / ext3 defaults 1 1 LABEL=BOOT /boot ext3 defaults 1 2 LABEL=SWAP swap swap defaults 0 0 LABEL=HOME /home ext3 nosuid,auto 1 2
Example of /boot/grub/grub.conf with disk labels:title astrid CentOS primary system root (hd0,0) kernel (hd0,0)/vmlinuz ro root=LABEL=ASTRID_ROOT0 rhgb quiet initrd (hd0,0)/initrd-astrid.img
Linux systems support disk labels via the udev device manager. Using disk labels avoids hard coding device names which can change if there's a change in the hardware configuration (disk added/removed). This will result
in a more robust system.
In case you might not know already, all entries for disks to be mounted at startup are in the file /etc/fstab. What do these labels look like in your fstab? Well, take a look here:
LABEL=/ / ext3 defaults 1 1
Since this is being displayed in your web browser, the extra white spaces won't be showing up. You will see more space between the items above in the actual fstab file. In the old days, in place of the LABEL= entry, there would have been a device path like /dev/hda1. Now though, you can mount via the label and not worry if /dev/hda1 changes to /dev/hdb2 because you plugged in a USB device or something. It mounts by the label assigned to it, instead of the device name.
What's that? How do we manage the label? I am so glad you asked! The answer is simple, but yet it's not. Basically it depends on what file system you formatted the disk with. For the purposes of this article, I will stick with the two most popular (from my travels anyway), and that is ext2 and reiser.
For ext2 file systems, you use the command e2label to view and set the file system label. So, if you want to view the label assigned to the device /dev/hda1, it would look like this:
and on my dev box it returns simply:
because it's the root file system. If we take a look at the entry in my /etc/fstab, the entry to mount it looks like this (just like above):
LABEL=/ / ext3 defaults 1 1
Notice above that the file system is actually ext3, and not ext2. For anyone who doesn't know, ext3 is really ext2 with journaling turned on, so the e2label command applies to it as well. Journaling simply means that the file system logs all changes to a journal before actually committing the changes to the disk. This means that you are much less likely to suffer from disk corruption in the event of a hard stop, power off, etc. The journal can simply be replayed when it comes back up, therefore catching up on any changes that did not get committed. It's a very cool and highly recommended feature, plus who wants to sit through those lengthy fsck sessions?
Back to labels, if you want to set the label, you use the e2label command still, you simply specify the desired disk label after the path. If I were setting the label on the device in question, it would look like this:
e2label /dev/hda1 /
That tells the e2label command to set the label to "/", whereas when that option is left off, it returns the current label. Nifty, huh?
... ... ...
Google matched content
Linux Partition HOWTO - The Linux Documentation Project
RenameUSBDrive - Community Ubuntu Documentation
Parted User's Manual - 2. Using Parted - The GNU Operating System
Re- How to change a partition's label
parted(8)- partition change program - Linux man page
Linux Partition How-To - Labels - Linux Operating System and Linux
Linux Disk Partitioning Guide - Hillsborough Community
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Last modified: March 12, 2019