- Persistent block device naming
- Contents
- Persistent naming methods
- by-label
- by-uuid
- by-id and by-path
- by-partlabel
- by-partuuid
- Static device names with udev
- Using persistent naming
- fstab
- Kernel parameters
- Ubuntu Documentation
- Using the Partition Editor
- Using the Command line
- Identify your Partition
- Install the Labeling Program
- Unmount the Partition
- Changing the Label
- Filesystems
- FAT16 and FAT32
- Check the current label
- Change the label
- Option 1
- Option 2
- Error message
- Check the current label
- Change the label
- ext2, ext3, and ext4
- Check the current label
- Change the label
- Check the current label
- Change the label
- ReiserFS (v3)
- Change the label
- Check the current label
- Change the label
- Verify the Change
- Other Resources
Persistent block device naming
This article describes how to use persistent names for your block devices. This has been made possible by the introduction of udev and has some advantages over bus-based naming. If your machine has more than one SATA, SCSI or IDE disk controller, the order in which their corresponding device nodes are added is arbitrary. This may result in device names like /dev/sda and /dev/sdb switching around on each boot, culminating in an unbootable system, kernel panic, or a block device disappearing. Persistent naming solves these issues.
Contents
Persistent naming methods
There are four different schemes for persistent naming: by-label, by-uuid, by-id and by-path. For those using disks with GUID Partition Table (GPT), two additional schemes can be used by-partlabel and by-partuuid. You can also use static device names by using Udev.
The directories in /dev/disk/ are created and destroyed dynamically, depending on whether there are devices in them.
The following sections describe what the different persistent naming methods are and how they are used.
The lsblk command can be used for viewing graphically the first persistent schemes:
For those using GPT, use the blkid command instead. The latter is more convenient for scripts, but more difficult to read.
by-label
Almost every file system type can have a label. All your volumes that have one are listed in the /dev/disk/by-label directory.
Most file systems support setting the label upon file system creation, see the man page of the relevant mkfs.* utility. For some file systems it is also possible to change the labels. Following are some methods for changing labels on common file systems:
swap swaplabel -L «new label» /dev/XXX using util-linux ext2/3/4 e2label /dev/XXX «new label» using e2fsprogs btrfs btrfs filesystem label /dev/XXX «new label» using btrfs-progs reiserfs reiserfstune -l «new label» /dev/XXX using reiserfsprogs jfs jfs_tune -L «new label» /dev/XXX using jfsutils xfs xfs_admin -L «new label» /dev/XXX using xfsprogs fat/vfat fatlabel /dev/XXX «new label» using dosfstools mlabel -i /dev/XXX ::»new label» using mtools exfat tune.exfat -L «new label» /dev/XXX using exfatprogs exfatlabel /dev/XXX «new label» using exfatprogs or exfat-utils ntfs ntfslabel /dev/XXX «new label» using ntfs-3g udf udflabel /dev/XXX «new label» using udftools crypto_LUKS (LUKS2 only) cryptsetup config —label=»new label» /dev/XXX using cryptsetup
The label of a device can be obtained with lsblk:
by-uuid
UUID is a mechanism to give each filesystem a unique identifier. These identifiers are generated by filesystem utilities (e.g. mkfs.* ) when the device gets formatted and are designed so that collisions are unlikely. All GNU/Linux filesystems (including swap and LUKS headers of raw encrypted devices) support UUID. FAT, exFAT and NTFS filesystems do not support UUID, but are still listed in /dev/disk/by-uuid/ with a shorter UID (unique identifier):
The UUID of a device can be obtained with lsblk:
The advantage of using the UUID method is that it is much less likely that name collisions occur than with labels. Further, it is generated automatically on creation of the filesystem. It will, for example, stay unique even if the device is plugged into another system (which may perhaps have a device with the same label).
The disadvantage is that UUIDs make long code lines hard to read and break formatting in many configuration files (e.g. fstab or crypttab). Also every time a volume is reformatted a new UUID is generated and configuration files have to get manually adjusted.
by-id and by-path
by-id creates a unique name depending on the hardware serial number, by-path depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to (i.e. pci- for by-path , and ata- for by-id ), so they are linked to the hardware controlling the device. This implies different levels of persistence: the by-path will already change when the device is plugged into a different port of the controller, the by-id will change when the device is plugged into a port of a hardware controller subject to another subsystem. [1] Thus, both are not suitable to achieve persistent naming tolerant to hardware changes.
However, both provide important information to find a particular device in a large hardware infrastructure. For example, if you do not manually assign persistent labels ( by-label or by-partlabel ) and keep a directory with hardware port usage, by-id and by-path can be used to find a particular device.[2] [3]
by-id also creates World Wide Name links of storage devices that support it. Unlike other by-id links, WWNs are fully persistent and will not change depending on the used subsystem.
This article or section needs expansion.
by-partlabel
GPT partition labels can be defined in the header of the partition entry on GPT disks.
This method is very similar to the filesystem labels, except the partition labels do not get affected if the file system on the partition is changed.
All partitions that have partition labels are listed in the /dev/disk/by-partlabel directory.
The partition label of a device can be obtained with lsblk:
by-partuuid
Like GPT partition labels, GPT partition UUIDs are defined in the partition entry on GPT disks.
MBR does not support partition UUIDs, but Linux[5] and software using libblkid[6] (e.g. udev[7]) are capable of generating pseudo PARTUUIDs for MBR partitions. The format is SSSSSSSS—PP , where SSSSSSSS is a zero-filled 32-bit MBR disk signature, and PP is a zero-filled partition number in hexadecimal form. Unlike a regular PARTUUID of a GPT partition, MBR’s pseudo PARTUUID can change if the partition number changes.
The dynamic directory is similar to other methods and, like filesystem UUIDs, using UUIDs is preferred over labels.
The partition UUID of a device can be obtained with lsblk:
Static device names with udev
Using persistent naming
There are various applications that can be configured using persistent naming. Following are some examples of how to configure them.
fstab
Kernel parameters
To use persistent names in kernel parameters, the following prerequisites must be met. On a standard installation following the installation guide both prerequisites are met:
- You are using an initramfs image that has udev in it.
- For mkinitcpio, enable either the udev or systemd hook in /etc/mkinitcpio.conf
The location of the root filesystem is given by the parameter root on the kernel command line. The kernel command line is configured from the boot loader, see Kernel parameters#Configuration. To change to persistent device naming, only change the parameters which specify block devices, e.g. root and resume , while leaving other parameters as is. Various naming schemes are supported:
Persistent device naming using label and the LABEL= format, in this example Arch Linux is the LABEL of the root file system.
Persistent device naming using UUID and the UUID= format, in this example 0a3407de-014b-458b-b5c1-848e92a327a3 is the UUID of the root file system.
Persistent device naming using disk id and the /dev path format, in this example wwn-0x60015ee0000b237f-part2 is the id of the root partition.
Persistent device naming using GPT partition UUID and the PARTUUID= format, in this example 98a81274-10f7-40db-872a-03df048df366 is the PARTUUID of the root partition.
Persistent device naming using GPT partition label and the PARTLABEL= format, in this example GNU/Linux is the PARTLABEL of the root partition.
Источник
Ubuntu Documentation
This guide is primarily for external drives such as USB hard drives, USB flash drives, and flash memory cards. You can label internal disks, but to change their mount points, use MoveMountpointHowto which uses the file called Fstab. This guide covers editing partition labels (disk names) for FAT16/FAT32, NTFS, ext2/ext3, JFS, ReiserFS, and XFS filesystems.
By default, external drives automatically mounted at /media/disk then /media/disk-1 and so on. This is not very helpful when trying to find the drive you are looking for, especially if you have multiple devices plugged in. Labeled devices that are automatically mounted will be mounted in the /media directory using their label as the mount point, /media/ . ex: /media/my_external .
When choosing labels, be sure that the new mount point /media/ does not already exist since the directory will be created when the disk is mounted.
Using the Partition Editor
The file manager (Nautilus) currently does not support renaming disk partitions, but Gnome’s Partition Editor (GParted) does. To change a partition’s label, follow these directions. (Be careful using Partition Editor, as it’s capable of making your computer completely unusable if you do the wrong thing.)
Open the System >Administration menu and see if there’s an entry for GParted (previously Partition Editor).
If there is, launch it. If there isn’t, install the «gparted» package and it should now appear in the menu. Enter your password when prompted.
Disk drives are divided up into partitions. To find the partition you want to re-label, you first have to find the disk drive that contains it, using the drop-down menu in the upper right. It will show a device name like /dev/sdb and the drive’s total size in parentheses. After selecting a drive, you will see a list of all partitions on that drive.
If the partition is mounted (has a key icon next to it), right-click on the partition and select Unmount.
With the key icon gone, right-click on the partition and select Label. If you can’t select it, install the ntfsprogs package.
Enter the new partition name and press Ok.
The label change is now pending, but has not been completed. Press the Apply button near the top of the window. After confirming, it should say «All operations successfully completed». The drive now has a new label.
Using the Command line
There are at least 6 separate command line tools used to label a partition — the program used depends on the partition’s filesystem type:
For FAT16 and FAT32 partitions, use mlabel from the mtools package.
For NTFS partitions, use ntfslabel from the ntfs-3g package.
For ext2, ext3, or ext4 partitions, use e2label.
For JFS partitions, use jfs_tune.
For ReiserFS (v3) partitions, use reiserfstune.
For XFS partitions, use xfs_admin
Identify your Partition
For help with the terminal, see UsingTheTerminal.
Plug in your USB device and list your partitions with:
You can also list your mounted devices and their descriptions with:
For the rest of this tutorial we will use the following:
= your device /dev/sdxy, ex: /dev/sdb1
= your desired (new) label, ex: my_external
Install the Labeling Program
Based on the package names listed above for each filesystem type, install the correct package for your partition:
Here are all the different ones:
or install the appropriate package from Synaptic.
Unmount the Partition
Partitions generally need to be unmounted before you can fiddle with them, so unmount the partition of the device you want to change the label for:
If it was automounted, you can also unmount the drive by right clicking the desktop icon and clicking Unmount (or Eject in some cases).
Changing the Label
After you complete the appropriate porition for your filesystem, jump to the next section to verify the change.
Filesystems
FAT16 and FAT32
These filesystems are most often found on USB thumb drives, flash cards (like for a camera or cell phone), and older external USB hard drives.
Check the current label
Note that we’re using the special «::» drive which allows us to specify the device descriptor on the command line; otherwise we’d have to edit
/.mtoolsrc to assign a drive letter (see Option 2 under «Change the label»).
Change the label
Option 1
After unmounting and checking the current label (above), use
Ignore the «Volume label is XYZ» output as this is the old label. Jump to the Verify the Change section below.
Option 2
For Ubuntu 8.10 and up, edit mtools.conf as sudo
add something like for each drive:
(note the underscore _ should be used, as spaces are not allowed)
Error message
If you get a message like this:
You can easily ignore the check by running this command:
This filesystem is most often found on external USB and firewire hard drives or other Windows formatted disks.
Check the current label
Change the label
Note: 128 characters maximum.
Ubuntu caches the drive’s label so to see the full affects of the change it is not enough just to umount and mount it again. You have to umount, remove, put back, mount again.
ext2, ext3, and ext4
These filesystems are most often found on linux formatted drives.
Check the current label
Change the label
Note: 16 characters maximum.
These filesystems are most often found on IBM and some linux formatted disks.
Check the current label
Change the label
Note: 16 characters maximum.
ReiserFS (v3)
This filesystem is most often found on linux formatted disks.
Note: this could work with ReiserFS 4 too, I have not tried.
Change the label
Note: 16 characters maximum.
This filesystem is most often found on UNIX formatted disks.
Check the current label
Change the label
Note: 12 characters maximum.
Verify the Change
Now for the easiest part: unplug the drive, wait a second, then plug it back in. It should appear on your desktop with the new label and have its new mount point.
Without unplugging and having the device remount, you can also just run:
Other Resources
Some other related material:
RenameUSBDrive (последним исправлял пользователь knome 2013-12-14 11:20:15)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details
Источник