How to Change UUID of Linux Partition on CentOS 7

Share this Article :

Change UUIDUUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system.

If you cloned a virtual machine from vCenter, the metadata containing information of UUID for the filesystem will be identical for the original and cloned copy, therefore the UUID is no longer unique in /etc/fstab.

The following steps will show how to change UUID of linux partition on CentOS 7.

1) Use blkid command-line utility to determine device UUID :

# blkid

Sample output :

/dev/mapper/centos_centos71-root: UUID="2bc8e0d4-64b5-4dc8-bf4a-024fc980d98a" TYPE="ext4"
/dev/mapper/centos_centos71-swap: UUID="577f9541-8d2a-4666-ac8f-ff84b584eeca" TYPE="swap"
/dev/mapper/vg_data-centos7_vol: UUID="b100ad2b-ad89-4e2d-ba8e-7eda7d703c40" TYPE="ext4"

2) Another way to list out uuid by issue below command :

# ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 10 Dec 20 23:16 2bc8e0d4-64b5-4dc8-bf4a-024fc980d98a -> ../../dm-1
lrwxrwxrwx 1 root root 10 Dec 20 23:16 577f9541-8d2a-4666-ac8f-ff84b584eeca -> ../../dm-0
lrwxrwxrwx 1 root root 10 Dec 20 23:19 b100ad2b-ad89-4e2d-ba8e-7eda7d703c40 -> ../../dm-2

3) Verify the mounted partition :

Also Read :   How to Install Virtualmin on CentOS 7 / RHEL 7 / Oracle Linux 7

There is mounted /data in the system with UUID=”b100ad2b-ad89-4e2d-ba8e-7eda7d703c40″.

# df -lh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/centos_centos71-root   24G  3.1G   19G  15% /
devtmpfs                          1.9G     0  1.9G   0% /dev
tmpfs                             1.9G     0  1.9G   0% /dev/shm
tmpfs                             1.9G   25M  1.9G   2% /run
tmpfs                             1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                             500M     0  500M   0% /etc/nginx/cache
/dev/sda1                         477M  230M  218M  52% /boot
tmpfs                             380M     0  380M   0% /run/user/0
/dev/mapper/vg_data-centos7_vol   9.8G   37M  9.2G   1% /data

4. How to change UUID for /dev/mapper/vg_data-centos7_vol which is in /data mounted partition.

a) Generate new UUId using uuidgen utility :

# uuidgen
fb5c697b-d1d6-49ab-afcd-27a22a5007c8

b) Please take note that the UUID may only be changed when the filesystem is unmounted.

# umount /data

c) Change UUID for LVM /dev/mapper/vg_data-centos7_vol with new generated UUID :

# tune2fs /dev/mapper/vg_data-centos7_vol -U fb5c697b-d1d6-49ab-afcd-27a22a5007c8
tune2fs 1.42.9 (28-Dec-2013)

d) Mount back the /data partition :

# mount /dev/mapper/vg_data-centos7_vol /data

e) Update /etc/fstab :

Also Read :   How to Install Webmin on CentOS 7/RHEL 7/Oracle Linux 7

Option 1 :

UUID=fb5c697b-d1d6-49ab-afcd-27a22a5007c8 /data                   ext4    defaults        1 2

Option 2 :

/dev/mapper/vg_data-centos7_vol /data                   ext4    defaults        1 2

f) Verify new UUID for /dev/mapper/vg_data-centos7_vol

# blkid

Sample output :

/dev/mapper/centos_centos71-root: UUID="2bc8e0d4-64b5-4dc8-bf4a-024fc980d98a" TYPE="ext4"
/dev/mapper/centos_centos71-swap: UUID="577f9541-8d2a-4666-ac8f-ff84b584eeca" TYPE="swap"
/dev/mapper/vg_data-centos7_vol: UUID="fb5c697b-d1d6-49ab-afcd-27a22a5007c8" TYPE="ext4"

Source


Leave a Reply