-2

how to find string boot on the /etc/fstab file and replace UUID with kernel device name /dev/sda1?

cat /etc/fstab
/dev/mapper/vg00-root   /                       xfs     defaults        0 0
UUID=6fc6605f-796e-4e0b-a8f7-8b339c46b1a9 /boot                   xfs     defaults        0 0
/dev/mapper/vg00-tmp    /tmp                    xfs     defaults        0 0
/dev/mapper/vg00-var    /var                    xfs     defaults        0 0
/dev/mapper/vg00-crash  /var/crash              xfs     defaults        0 0
/dev/mapper/vg00-log    /var/log                xfs     defaults        0 0
/dev/mapper/vg00-swap   swap                    swap    defaults        0 0

sed 's/UUID/\/dev\/sda1/g' /etc/fstab
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

0

List files under /dev/disk/by-uuid:

ls -l /dev/disk/by-uuid/

...to obtain something like this:

lrwxrwxrwx 1 root root 10 ott  4 18:37 53bc3708-e45d-4352-977a-a62c6a4fd5c8 -> ../../dm-1
lrwxrwxrwx 1 root root 10 ott  4 18:37 6a23dfcf-e36d-45c8-a468-d3976b5239f3 -> ../../dm-0
lrwxrwxrwx 1 root root 10 ott  4 18:37 7d6e75e9-7ed2-4412-8acd-2de50ffa0034 -> ../../sda1

As you see, you find the old style device name in the right of the output, as link target.

In the uplevel directory, you can find disks categorized by id and by path, not only by uuid. Beautiful!

0

I'm making the assumption that you want to replace UUID=6fc6605f-796e-4e0b-a8f7-8b339c46b1a9 for /dev/sda1/, which is in general a bad idea. The UUID is a unique id belonging to the disk. If you want to replace the disk, I suggest to try to get the UUID with blkid.

Otherwise, you should extend the regex in order to replace that part:

$ sed 's/UUID=6fc[^ ]*/\/dev\/sda1/g' fstab

Note that U've added 6fc to make sure you will not change every UUID= line.

Bayou
  • 3,293
  • 1
  • 9
  • 22