2

I'm using btrfs and snapper. So, I have many periodic btrfs snapshots, which are marked read-only (can of course be changed by btrfs to r/w and changed back.)

Let's say during my initial install I set a vimrc. And, let's say now I want to change the vimrc, so that if I go back to any of the snapshots my vimrc is the new one. Yeah, this totally re-writes history, and goes against the idea of having historical backups. But let's say that I change active snapshots often for testing and don't want to keep having to re-change certain configuration files like this. And I'm OK with blowing away my backups of the file.

Right now, there should be only one copy of the vimrc file contents that are being used/pointed to, since it's never been modified since the very first snapshot.

Is there a way I can modify the vimrc file, so that "all of them" are updated?

Can I bypass copy on write during the edit, doing so just for the one file, so any system files in he background still use COW? I see I can't use chattr's NOCOW because the file isn't new or empty. Is there another way?

Or, do I have to edit the live file, turn all the snapshots to r/w, perform a cp -ax --reflink=always to all the snapshot files, and turn all the snapshots to r/o? There's a lot of snapshots to do this to. (Granted a script would make this less painful.)

  • I'm pretty sure you'll have to make the volumes read-write to do this, there's simply no other way around it (what good would read-only snapshots be if they just let you edit them willy nilly). And disabling cow won't help, that'll just make it so that duplicate blocks are made instead of pointing to existing ones. – etskinner May 8 '17 at 20:28
0

There is no way to do this from within the BTRFS toolset.

However:

Boot the system from a live medium and open the raw partition (i.e. /dev/sda1) in a hex editor. Use the search function to scan the disk for the file, and make your alterations a file this short should be all in one extent, so it'll be easy. Since the file has never been edited there should be only one copy of it to mess with. Otherwise use fstrim or similar tools to zero out the unused portions of the disk to eliminate extraneout copies.

NOTE: The file length MUST NOT be changed or you will screw things up. You can make it shorter and pad it with nulls or something, but you cannot make it longer or you will corrupt your filesystem.

NOTE: Due to BTRFS checksums, a read error will be detected if you just mount the filesystem and try to use it. You'll have to use the repair tools to discard and rebuild the entire checksum tree. Make sure you don't have any corrupted data that requires recovering before attempting this.

NOTE: THIS IS A BAD IDEA AND ALMOST CERTAINLY NOT WORTH THE EFFORT AND RISK! JUST LEAVE YOUR SNAPSHOTS AS THEY ARE AND MAKE A NOTE TO UPDATE THIS ONE FILE IF YOU EVER HAVE TO REVERT. IT'LL BE FINE!

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.