1

I want to convert my existing full-disk btrfs (unpartitioned) filesystems to bcache.
To do so, I need to move data around and reformat the drives.
I have enough hdd space to do it in a couple steps.

Since I'm using btrfs, I thought btrfs send and btrfs receive would make this easy.

I have created a readonly snapshot of the fs I want to convert first and started sending it into a subvolume in another fs.

What I'm unclear about is how I would go about restoring that duplicated subvolume to the original disk once my superblock conversions have taken place.

The btrfs receive manpage indicates that it can only create new subvolumes and it also makes them readonly once the process is complete.

So how do I replace a fresh writable root subvolume from a received snapshot?

1

So how do I replace a fresh writable root subvolume from a received snapshot?

You can't.

In your case the top-level (root) subvolume (which is ID 5) is the / of your Linux filesystem; Nothing can exist adjacent to it. As you discovered, btrfs-receive creates a read-only subvolume, so what you'd have to do is create a read-write snapshot subvolume from the read-only one, and for that you'd need to be able to create a subvolume outside of /; Hence why you can't replace the top-level subvolume.

Notice that you said:

I have created a readonly snapshot of the fs I want to convert first and started sending it into a subvolume in another fs.

What you did though, is create a read-only snapshot of a subvolume, not the BTRFS filesystem as a whole. I don't see how you'd be able to create a snapshot of the top-level though. Weird.

Your best bet is to use a tool like partclone to backup the entire filesystem and then restore from that. Otherwise, you'd have to change your subvolume layout from flat, which is what you have, to nested. With a nested layout you'd have something like this:

/ (top-level)
|
|__ /rootfs (subvolume)
|   |
|   _/home
|
|__ /rootfs-backup (read-only subvolume, which you can delete later)
|   |
|   _/home

A nested layout gives you the ability to create snapshots of any subvolume in the filesystem (except the top-level, which you wouldn't need to do anyway). Then you'd simply mount the rootfs subvolume on /, instead of the entire filesystem. For example: mount -t btrfs /dev/sda1 -o defaults,subvol=/rootfs

  • Perhaps my wording was bad, by "root" I didn't mean / specifically, but rather the toplevel volume of a btrfs filesystem. I've now solved the problem by receiving the volume back onto the bcache-reformatted drive, setting it ro=false, and finally adding the mount option subvolid= to point to the received subvolume. This isn't as neat as I would've liked but it works. – Cobra_Fast Jul 21 '18 at 23:18

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.