2

Background: The host OS is an Azure Oracle Linux 7.8 instance with its OS disk mounted via /dev/sda entries. /dev/sda2 (/) is btrfs. I have another Azure Oracle Linux 7.8 instance that is broken, so I wanted to attach its disk to debug. Once attached to my host OS, because the attached disk is from the same Oracle Linux 7.8 image, its UUIDs are the same as my host, and it seems to create some confusion/corruption with mounts. Below is the output of lsblk after Azure has finished attaching the image:

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb       8:16   0    4G  0 disk
└─sdb1    8:17   0    4G  0 part /mnt
sr0      11:0    1  628K  0 rom
fd0       2:0    1    4K  0 disk
sdc       8:32   0   50G  0 disk
├─sdc15   8:47   0  495M  0 part
├─sdc2    8:34   0   49G  0 part /      <--- isn't really sdc2, its mounted from sda2
├─sdc14   8:46   0    4M  0 part
└─sdc1    8:33   0  500M  0 part
sda       8:0    0  100G  0 disk
├─sda2    8:2    0   99G  0 part
├─sda14   8:14   0    4M  0 part
├─sda15   8:15   0  495M  0 part /boot/efi
└─sda1    8:1    0  500M  0 part /boot

You can see it thinks root / is mounted via /dev/sdc2, but this disk (/dev/sdc) has literally only just been attached. I can only presume the UUID conflict is causing this (could it be anything else?), but now I can't mount the real/attached /dev/sdc2 to debug that disk because the system thinks its already mounted.

Is there anyway to prevent this happening as I attach the disk?

2
+25

You can change the btrfs UUID with btrfstune before you mount the disk (or unmount it first).

# first show the existing UUID (and keep for later)
sudo blkid /dev/sdc2

# change to a new UUID
sudo btrfstune -M $(uuidgen) /dev/sdc2

Also see -U but -M should be sufficient. You can later restore the original uuid with the same method (in place of uuidgen).

Make a backup before you try this.

| improve this answer | |
  • This doesn't work as it thinks it's already mounted - the output I pasted is before I've done anything at the OS level, so I can't even change the UUID. – AndyC Oct 5 at 20:39
  • I thought lsblk was just showing it as mounted (as by your comment). What error do you get when you try the btrfstune command? – laktak Oct 5 at 21:04
  • lsblk shows it as mounted but I don't think its limited to lsblk - /etc/mtab or /proc/mounts etc all show the same, and any mount-related tool thinks its mounted as well including btrfstune, e.g. # btrfstune -f -u /dev/sdc2 ERROR: /dev/sdc2 is mounted – AndyC Oct 5 at 22:45
  • I had issues with duplicate UUIDs as well but the system would always mount one drive (at random) not both. If /dev/sda2 is mounted are you seeing the system from the other machine at /? /dev/sda2 is mounted as well? What does findmnt say? Did you try to simply sudo mount /dev/sdc2 /mnt/ – laktak Oct 6 at 6:29
  • / content still seems to be the original /dev/sda2 (pretty sure it would be technically impossible for a live running system to be magically swapped for another root disk without anything breaking). It seems to be anything that calls the underlying mount library calls thinks /dev/sdc2 is mounted. If I detach the disk lsblk doesn't even list root mounted, but the system is still happily there and working. The UUIDs just seem to be confusing those calls. I just need a way of stopping this automatic detection/update or whatever is being triggered when the disk is attached. – AndyC Oct 6 at 10:16
2

I do not think this is possible. If there are multiple BTRFS filesystems with duplicate UUIDs visible in the system, you cannot use them without a risk of data corruption - https://btrfs.wiki.kernel.org/index.php/Gotchas

You would need to hide one device first, like removing from SCSI echo 1 > /sys/block/sde/device/delete, change the UUID on the other, and get the first device back, echo "- - -" > /sys/class/scsi_host/host0/scan But you cannot do it since you have BTRFS already mounted as root filesystem. I think you have to attach to a different machine (avoiding UUID conflict).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.