You are not logged in.

#1 2014-03-12 22:28:20

rdahlgren
Member
From: Middle States, USA
Registered: 2014-02-17
Posts: 36
Website

Convert root partition to btrfs subvol?

I've got an existing system that uses separate btrfs partitions mounted to:

sda1 (SSD) -> /
sdb1 -> /var
sdb2 -> /tmp
sdb3 -> /home
sdb4 -> /icebox

As I've been using the system more and learning about what btrfs has to offer.  I'd really like to be able to snapshot /usr, /lib, and friends to help insulate me from accidental system breakage. In this thread, I'd love some tips on how I might migrate my root partition to a subvolume in order to use snapshots.

The references I've seen on the wiki and these forums regarding root subvolumes assume this is done during installation.

Offline

#2 2014-03-12 22:57:20

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,901
Website

Re: Convert root partition to btrfs subvol?

Snapshotting /lib makes no sense, as it's a symbolic link to /usr/lib.. Maybe you meant that you want to snapshot your root partition as a whole, rather than specific directories? That's certainly the way I would (and do!) go about it.

How is your current root partition set up? I understand that it's btrfs, but have you set up a subdirectory for it, or did you install to your toplevel btrfs root?


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2014-03-12 22:58:38

rdahlgren
Member
From: Middle States, USA
Registered: 2014-02-17
Posts: 36
Website

Re: Convert root partition to btrfs subvol?

The partition mounted to root is the toplevel btrfs root. Thanks for the tip about /lib :-)

Offline

#4 2014-03-12 23:21:02

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,901
Website

Re: Convert root partition to btrfs subvol?

I personally don't like putting everything in the btrfs root, I prefer to have my Arch root in a self-contained subvolume, e.g. ${btrfsroot}/_rootsubvolume. That way I can mount ${btrfsroot} somewhere else (/var/lib/btrfs-root in my case), and create snapshots there.

So I might have /var/lib/btrfs-root/_rootsnapshot-20140312, a snapshot of /var/lib/btrfs-root/_rootsubvolume before I run my daily pacman -Syu. If something goes wrong at my next reboot, in my bootloader I could put "rootflags=subvol=_rootsnapshot-20140312" instead of my usual "rootflags=subvol=_rootsubvolume", and boot the pre-update system.

This only works if everything system-related is on the same subvolume, so I don't have a separate /var (if I did, it would mean my rollback system would be using the pre-rollback pacman database causing discrepancies between what pacman thinks is currently installed, and what is actually currently installed).

/home and /boot can still be on separate partitions, if you know what you're doing. You just need to be aware that, if you update your kernel on /boot, the modules on ${btrfsroot}/_rootsnapshot-blahblahblah may be outdated. This can mean that rolling back to a snapshot can leave you at an emergency shell, rather than the stable OS you snapshotted it at.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2014-03-13 00:37:04

rdahlgren
Member
From: Middle States, USA
Registered: 2014-02-17
Posts: 36
Website

Re: Convert root partition to btrfs subvol?

I like your suggestions WorMzy.

Is my best bet to boot onto some installation media and 'dd' my existing root onto a subvol? That was sort of the nuts and bolts of my question: is there any easy way to move the data on a btrfs root into a subvol? My gut says no, but I can't just let hope die :-)

Thanks for the responses btw. It's helpful to get more examples of real-world btrfs use (rather than articles about "Wouldn't this setup be cool?!?").

Offline

#6 2014-03-13 08:37:47

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,901
Website

Re: Convert root partition to btrfs subvol?

Since ${BTRFSROOT} is a subvolume, all you really need to do to move it is:

btrfs snapshot / /_rootsubvolume

If you're going with my suggestions, then you probably want to boot a liveCD so that you can copy (remember to do so recursively, while preserving permissions), your /var partition's contents to /_rootsubvolume/var (as a directory, not a subvolume).

Remember to update your bootloader and your fstab.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#7 2014-03-13 16:11:28

rdahlgren
Member
From: Middle States, USA
Registered: 2014-02-17
Posts: 36
Website

Re: Convert root partition to btrfs subvol?

Thanks a lot! I'll give this a shot in a few hours :-)

Offline

Board footer

Powered by FluxBB