In this short tutorial, we will walk you through how to get UUID
of the filesystem so that it can be used in /etc/fstab.
First of all, keep in mind you need to format your logical volume to get UUID
registered in the kernel for it. Logical volume without filesystem on it won’t be having UUID attached to it. If you are using partitioning volume manager then disk partitions will have PARTUUID (partition UUID) even if you don’t format them. But it’s not useful in /etc/fstab
since fstab deals with formatted partitions.
How to find UUID for logical volume
For this tutorial consider below setup –
[root@kerneltalks ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 1G 0 disk
└─datavg-lvol0 253:0 0 1020M 0 lvm
We have one logical volume named lvol0
in the volume group datavg
and now we need to find UUID
for it. Use command blkid
and grep
for your logical volume name to get your desired output –
[root@kerneltalks ~]# blkid |grep lvol0
/dev/mapper/datavg-lvol0: UUID="5caaee32-c3d3-429e-bad7-2898cf923805" TYPE="ext4"
You can see you have UUID
for the lvol you mentioned and along with it also sourced its filesystem type which is ext4
.
How to add UUID entry in /etc/fstab
Lets add this UUID
entry in /etc/fstab
using format –
<UUID> <mount directory> <FS type> <mount options> <dump> <pass>
So our entry will look like –
UUID=5caaee32-c3d3-429e-bad7-2898cf923805 /data ext4 defaults 0 0
We are mounting it on /data
directory with default mount options and no fschecks. Add this entry to fstab and run mount -a
and mount point established!
[root@kerneltalks ~]# df -Ph /data1
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/datavg-lvol0 988M 2.6M 919M 1% /data
How to find UUID for disk partition
Consider below setup for finding UUID for disk partition.
[root@kerneltalks ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 1G 0 disk
└─xvdf1 202:81 0 1023M 0 part
Here we have one non-root disk /dev/xvdf
with one full partition /dev/xvdf1
on it. And it’s not yet formatted with any filesystem. Now if you run blkid
command you will find PARTUUID
for this partition.
[root@kerneltalks ~]# blkid |grep xvdf1
/dev/xvdf1: PARTUUID="6d123669-01"
I format it so that I can mount it on the directory. And after formatting it with the ext4 filesystem here is UUID making an entry!
[root@kerneltalks ~]# blkid | grep xvdf1
/dev/xvdf1: UUID="05ba450d-9c60-43f1-9dd1-8b6f89857961" TYPE="ext4" PARTUUID="6d123669-01"
You can compare this output with earlier one and you can see after formatting with ext4
you get UUID
which can be used in /etc/fstab
as explained earlier in this post.
olol says
You don’t need the “blkid | grep”, just use “lsblk -o +UUID” to add an uuid column to lsblk.
won says
lsblk –fs