Configure systems to mount file systems at boot by Universally Unique ID (UUID) or label

We will work with the following structure created in the previous post:

# lvs 
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 myvg1 -wi-a----- 300.00m
lv02 myvg1 -wi-a----- 100.00m
lv03 myvg1 -wi-a----- 100.00m
root myvg1 -wi-ao---- 5.29g
swap myvg1 -wi-ao---- 716.00m

Part I. Assign a file system to the logical volumes created:

For lv01 I will assign the fs ext3 without a label:

# mkfs.ext3 /dev/myvg1/lv01
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
76912 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
38 block groups
8192 blocks per group, 8192 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

For lv02 I will assign the fs ext4 with the label myext4:

# mkfs.ext4 -L myext4 /dev/myvg1/lv02
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=myext4
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

# mkfs.ext4 /dev/myvg1/lv03
...

If you want add a label to an fs, you can use the tune2fs command:

blkid command to locate/print block device attributes. But to avoid errors, it’s recommended to use a different label.

Already created the fs, now we must mount them. But first is necessary to create the mount points…

Part II. Mount the created file systems.

Mount file systems lv01 using UUID:

# echo "UUID="8bf1eff5-7adb-48cb-8bb5-b2fbbed4a878" /mnt/lv01 ext3 defaults 0 0 " >> /etc/fstab

Mount file systems lv02 using the label:

# echo "LABEL="myext4" /mnt/lv02 ext4 defaults 0 0" >> /etc/fstab

Mount file systems lv03 using the path:

# echo "/dev/mapper/myvg1-lv03 /mnt/lv03 ext4 defaults 0 0" >> /etc/fstab
This is how the fstab file looks now

Execute the mount -a command, instead of restarting. If no errors appear, everything is fine. You can verify with the command df -hT to see the mounted fs.

# mount -a
[root@cliente1 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/myvg1-root xfs 5.3G 3.2G 2.2G 59% /
devtmpfs devtmpfs 905M 0 905M 0% /dev
tmpfs tmpfs 920M 152K 920M 1% /dev/shm
tmpfs tmpfs 920M 8.9M 911M 1% /run
tmpfs tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 173M 842M 17% /boot
tmpfs tmpfs 184M 4.0K 184M 1% /run/user/42
tmpfs tmpfs 184M 12K 184M 1% /run/user/1000
/dev/mapper/myvg1-lv01 ext3 283M 2.1M 266M 1% /mnt/lv01
/dev/mapper/myvg1-lv02 ext4 93M 1.6M 85M 2% /mnt/lv02
/dev/mapper/myvg1-lv03 ext4 93M 1.6M 85M 2% /mnt/lv03

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *