4

I'm trying to assign a partition label to a GPT partition, and use that partition label as an identifier for mounting in Ubuntu 14.04.

So first I setup GPT and created a partition on the volume:

~# parted /dev/vdb -s -- mklabel gpt
~# parted /dev/vdb -s -- mkpart primary 0 -1
Warning: The resulting partition is not properly aligned for best performance.

And then I assigned the partition label "TEST" to partition 1:

~# parted /dev/vdb -s -- name 1 TEST

And formatted the partition with ext4:

~# mkfs.ext4 /dev/vdb1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214391 blocks
1310719 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

From here, I can see that there's a symlink to vdb1 under /dev/disk/by-partlabel as expected:

~# ls -l /dev/disk/by-partlabel/
total 0
lrwxrwxrwx 1 root root 10 Aug 12 13:10 TEST -> ../../vdb1

And so I set the contents of my fstab accordingly (saw PARTLABEL in archwiki):

~# cat /etc/fstab
LABEL=cloudimg-rootfs   /    ext4   defaults    0 0
PARTLABEL=TEST /opt/ops/backup ext4 defaults 0 0

But I'm unable to mount the device using PARTLABEL=TEST:

~# mount -a
mount: special device PARTLABEL=TEST does not exist

Upon further inspection, I noticed that blkid is listing vdb1 without a PARTLABEL:

~# blkid
/dev/sr0: LABEL="config-2" TYPE="iso9660" 
/dev/vda1: LABEL="cloudimg-rootfs" UUID="56ea71ab-5e1b-43ce-a0fb-be31f6f224ac" TYPE="ext4" 
/dev/vdb1: UUID="6f446b13-e62a-42c5-953b-68298ab93dbd" TYPE="ext4"

I've tried restarting udev, but to no avail:

~# service udev restart
udev stop/waiting
udev start/running, process 12959
~# blkid
/dev/sr0: LABEL="config-2" TYPE="iso9660" 
/dev/vda1: LABEL="cloudimg-rootfs" UUID="56ea71ab-5e1b-43ce-a0fb-be31f6f224ac" TYPE="ext4" 
/dev/vdb1: UUID="6f446b13-e62a-42c5-953b-68298ab93dbd" TYPE="ext4"

Why might a proper symlink be showing up under /dev/disk/by-partlabel, although that label isn't showing up as a PARTLABEL value alongside the disk in blkid?

Thanks!

Brandon DeRosier
  • 246
  • 1
  • 2
  • 8

2 Answers2

2

While I haven't figured out why PARTLABEL=TEST doesn't work as well as why the labels are not showing up in blkid, I just worked around this by mounting via the /dev/disk/by-partlabel symlinks:

$ cat /etc/fstab
LABEL=cloudimg-rootfs   /    ext4   defaults    0 0
/dev/disk/by-partlabel/TEST /opt/ops/backup ext4 defaults 0 0

I've decided to go with this for now while working with partition labels in my configuration management, but I'm still very interested in knowing why blkid is not displaying the PARTLABEL for the disk.

Brandon DeRosier
  • 246
  • 1
  • 2
  • 8
0

Try filesystem labels. For me this works great on several systems.

Use filesystem-tools (e2label, mkfs, ntfslabel etc) or gparted to label the partition after or during formatting.

my fstab looks like this:

# <file system>   <mount point>   <type> <options>         <dump>  <pass>
LABEL=KUBUNTU     /               ext4    discard,relatime,errors=remount-ro      0       1
LABEL=UEFI        /media/UEFI     vfat    discard,relatime,noauto                 0       0
LABEL=SWAP        none            swap    sw                                      0       0
LABEL=DATA        /media/DATA     ext4    defaults                                0       2
JPT
  • 113
  • 1
  • 7