If you need to recover a file from a boot volume backup in Oracle Linux on an OCI compute instance, you may come across the difficulty of mounting the device, because the UUID of the backup is the same as that of the currently active boot volume.
To get around this issue, you need to generate a new UUID for the recovered backup.
To do this first clear out the metadata log on the recovered volume using xfs_repair, then change the UUID with xfs_admin.
In the example below, my active boot volume is device /dev/sdb, and the recovered boot volume which I attached via the OCI CLI is /dev/sdc. The file I want to recover (/path/foo) is on /dev/sdc3. Note that both devices have the same UUID:
$ blkid /dev/sdb3; blkid /dev/sdc3 /dev/sdb3: UUID="b1d6c458-09df-4003-91f8-274d9bb47090" TYPE="xfs" /dev/sdc3: UUID="b1d6c458-09df-4003-91f8-274d9bb47090" TYPE="xfs"
Trying to mount /dev/sdc3 results in an error:
$ mount -t xfs /dev/sdc3 /mnt/vol0 mount: wrong fs type, bad option, bad superblock on /dev/sdc3, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.
The error is somewhat misleading, but running dmesg as suggested, shows the issue:
$ dmesg | tail [14056.014024] XFS (sdc3): Filesystem has duplicate UUID b1d6c458-09df-4003-91f8-274d9bb47090 - can't mount
To give /dev/sdc3 a new UUID, first clear out the metadata log, then assign the new UUID:
$ xfs_repair -L /dev/sdc3 Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... . . . Phase 7 - verify and correct link counts... done root@cmr_test:~$ xfs_admin -U generate /dev/sdc3 Clearing log and setting UUID writing all SBs new UUID = 7f8c0d05-8605-4e22-8941-3eebe407a960
A quick check reveals that the UUIDs for /dev/sdb3 and /dev/sdc3 are different:
$ blkid /dev/sdb3; blkid /dev/sdc3 /dev/sdb3: UUID="b1d6c458-09df-4003-91f8-274d9bb47090" TYPE="xfs" PARTUUID="de4cf50d-6ab6-4b33-a1bb-b702baadb616" /dev/sdc3: UUID="7f8c0d05-8605-4e22-8941-3eebe407a960" TYPE="xfs" PARTUUID="de4cf50d-6ab6-4b33-a1bb-b702baadb616"
The device can now be mounted and the file recovered:
$ mount /dev/sdc3 /mnt/vol0 $ cp /mnt/vol0/path/foo /path/foo
Note that these instructions are for an xfs file system. For ext, use tune2fs to change the UUID:
tune2fs -U random /dev/sdb1
Please leave a comment if you have found this helpful.