While trying to recover my ec2 instance, I noticed I could not mount the root volume of that instance on other machine without generating a new UUID using
xfs_admin -U generate /dev/xdfg
.
(This is due to a the system saying it couldn't mount the drive due to having a duplicate UUID, I still don't know why it said that)
This allowed me to access the volume. However, when attempting to mount it back and boot on the original ec2 instance the boot fails and produced a
unknown filesystem
error and prompted to use grub rescue.
To resolve this, I mounted the drive back on the secondary machine and changed its UUID back to it's original, luckily I had it in my console history.
xfs_admin -U xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx /dev/xdfg
This allowed me to boot back into the machine.
Question
So for the sake of curiosity what about the UUID prevents the system to boot? When mounted on a separate machine with both UUID, the system knew that the filesystem was xfs
.
While the part of the question has been already answered here: https://unix.stackexchange.com/questions/137862/why-does-fstab-use-uuid-instead-of-the-actual-file-system-name
I will try to provide another explanation. Currently you are using UUID to mount the root filesystem via fstab. This has one advantage when adding a hardware you always refer to the same disk. When you are changing your boot disk make sure you change the UUID in your fstab. Use
blkid
command to get a new disk UUID. This is fairly easy when you attach both disks to the same system, get the new UUID and change the UUID in the fstab and before removing the old disk you need to copy the root file system to the new disk.You may use another way without specifying the UUID in the fstab. You will need to refer for instance to /dev/sda and specify the file system in fstab. You may later on fail when you attach a second drive and the system changes /dev/sda of the root disk to /dev/sdb for instance. This is where the UUID comes handy.
Embedded systems and also some other systems might have the boot directory together with /etc/fstab on their own partition, so when you supply wrong UUID at the boot time and system does not find it, the system will simply not boot.
So before changing the disk, you will need to check the boot partition layout, the fstab location and mounting the devices at the boot time.