25

I've made backups of my BTRFS filesystem using Clonezilla, and have restored one of those backups to a file named 2013-11-29.sda3.img.

I need to get some files out of this backup, but there's a hitch. Since the backup is of this machine, I cannot mount the backup anywhere on my filesystem, as its UUID matches the UUID of /.

Is there a way that I can change the UUID of the backup volume? As I understand it, BTRFS stores UUID information in every block on the filesystem, which complicates things for my purposes. However, is there a way that I could modify this? I understand that it'd probably take a long time to do, but that doesn't concern me. My main concern is keeping the server online. The backup is fairly large, so transferring it to another machine would take quite a while.

What are my options?

2 Answers 2

41

With the program btrfstune, which is part of more recent versions of the normal btrfs-tools, the UUID of a offline file system can be changed. If the partition is eg. /dev/sda1, use following command to generate a new, random UUID:

btrfstune -u /dev/sda1

To specify which value should be used, use an uppercase -U followed by a (valid) UUID string, for example:

sudo btrfstune -U e0c5b943-1c02-44a2-bbaf-87ebda5e363b /dev/sdaX
5
  • What is the difference in practice between -m/-M and -u/-U? Commented May 22, 2019 at 13:50
  • Looks like -m/-M is pretty new. More info in the btrfs-progs commit and kernel commit messages. Commented May 22, 2019 at 14:04
  • Having tried this - both -U and -M crash with a BUG_ON for me and corrupt the filesystem. Don't try this without backups! Commented May 22, 2019 at 18:46
  • Indeed all bets are off with a corrupt file system. And the number one reason to want to do this is because you are trying to swap out a corrupt filesystem. I have used this technique successfully, but the only reason is I wasn't sure if /boot/cmdline.txt was the only place referencing the UUID. If possible it better to use a new random UUID, and update the references.
    – user6856
    Commented Apr 29, 2023 at 2:13
  • I love this answer but also wanted to leave a note/reminder that you can still mount by path. mount /dev/nvme0n1p1 -o subvol=yoursubvolume for example.
    – BoeroBoy
    Commented Jul 27, 2023 at 8:42
-1

There is no way to do that for the moment. Actually, the volume UUID is used in each node of the chunk tree. You'll have to change them in there also assuming that the headers of the chunks/device are not hashed. BTRFS was really not design to allow this kind of backup.

This is really sad, but the easiest way to handle that is to use another computer.

If I may, I'd like to suggest you to stop backuping your data this way.

  1. If your partitions are important as a whole, backup with dd/clonezilla. When you need to restore your backups, restore the whole partition at once. Don't do this kind of hybrid backups: you specifically saved your partitions at the bloc level. So you have to restore it at the bloc level. Otherwise, you are using a spoon to cut the meat. As you certainly noticed, this solution is usually not used because it offers no versatility.

  2. If your data are important, backup with rsync or a similar tool on another disk : your data will always be accessible, you backup exactly what you want, you are backuping at the file level, etc.

Note that BTRFS has some (now limited) backuping features. BTRFS is moving fast, I guess more backuping features will come out in the future.

Oh, you've been warned already ;) Automated Clonezilla backup and GPG encryption

BTW, encryption is easier to apply on files using either LUKS for partition-based encryption or EnFS or EncryptFS for file-based encryption.

3
  • The main question was how to simply mount an image backup, when the image FS is BTRFS. I guess I'm going to have to make another Clonezilla backup of my current operating system status, restore the old backup, do what I need to do, and then restore back to current. Wish there was an easier way, but hey, if it works, it works. Commented Dec 11, 2013 at 21:16
  • The main answer is that you can't if it shares the same UUID as another partition on the disk :)
    – user21228
    Commented Dec 12, 2013 at 20:29
  • You might want to delete the answer. As either you got this completely wrong, or the tool btrfstune wasn't available when you originally answered.
    – user6856
    Commented Apr 29, 2023 at 2:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .