You are not logged in.

#1 2021-12-09 19:18:23

WaywardPooch
Member
Registered: 2021-12-09
Posts: 3

[Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Hello!

I've just installed Arch Linux using the included python guided installer, and everything is up and running great! I did realize, though, that I forgot to make subvolumes for "@" and "@home" when I partitioned my system.

After much reading, I still have no clue how best to split up a single btrfs partition, mounted at "/", into separate subvolumes. In an ideal world, I would like to have the following subvolumes:

- @ -- for my root/system
- @home -- for my home directory
- @snapshots -- for holding snapshots of my root subvolume

When I run...

sudo btrfs subvolume list /

I get back:

ID 256 gen 10 top level 5 path var/lib/portables
ID 257 gen 11 top level 5 path var/lib/machines

When I run...

lsblk

I get back (for my system drive):

nvme0n1     259:0    0 465.8G  0 disk 
├─nvme0n1p1 259:1    0   512M  0 part /boot
└─nvme0n1p2 259:2    0 465.3G  0 part /

My "/boot" partition is formatted as fat32, and I am using "systemd-boot" as my bootloader.

I have backed up all data valuable to me. I do not want to reinstall my OS, as everything is in working order.

I know there are a few ways to do this, but I would love it if someone could help me out with this; I know I need to edit my fstab file somewhere, and probably boot with a live USB, but really don't know the steps for this process.

Thank you, whoever ends up helping!

Last edited by WaywardPooch (2021-12-09 22:37:23)

Offline

#2 2021-12-09 19:58:26

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

You don't need a live ISO.

Take a snapshot for the new root filesystem:

# btrfs subvolume snapshot / /@

Then create the new /@home & /@snapshots:

# btrfs subvolume create /@home
# btrfs subvolume create /@snapshots

Copy the contents over:

# rsync -aAXv /home/ /@home ; sync

Then correct /@/etc/fstab  to reflect the desired configuration and modify systemd-boot so the kernel can find the new root filesystem subvolume (rootflags=subvol=@) and boot into it.

Once there you can mount the root partition and delete the old root filesystem.


Jin, Jîyan, Azadî

Offline

#3 2021-12-09 20:04:48

WaywardPooch
Member
Registered: 2021-12-09
Posts: 3

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Head_on_a_Stick wrote:

You don't need a live ISO.

Take a snapshot for the new root filesystem:

# btrfs subvolume snapshot / /@

Then create the new /@home & /@snapshots:

# btrfs subvolume create /@home
# btrfs subvolume create /@snapshots

Copy the contents over:

# rsync -aAXv /home/ /@home ; sync

Then correct /@/etc/fstab  to reflect the desired configuration and modify systemd-boot so the kernel can find the new root filesystem subvolume (rootflags=subvol=@) and boot into it.

Once there you can mount the root partition and delete the old root filesystem.

Thank you so much for the instructions! I will try them immediately and report back if/when successful.

Offline

#4 2021-12-09 22:24:10

WaywardPooch
Member
Registered: 2021-12-09
Posts: 3

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Is there a way that I can verify the changes were successful? Following your instructions, my PC is booting properly and my fstab file was edited as follows (seemed like the logical edits based on what I could read). Basically, my root folder and home folder in my file browser appear identical to what I started with, only without the @, @home, and @snapshots folders being visible in "/".

# <file system> <dir>   <type>  <options>                                   <dump> <pass>
/dev/nvme0n1p2  /       btrfs   rw,relatime,ssd,space_cache=v2,subvol=/@    0      0
/dev/nvme0n1p2  /home   btrfs   defaults,subvol=/@home                      0      0

I'm guessing that because of the mount points I specified being the same as what they were, it should look the same, no? Is there a way for me to view the "true" file tree of my drive without wrecking anything (or, is there a "preferred" way/place for me to mount them)?

Also, thank you for the solution -- if this all looks correct, I will mark the thread as solved.

EDIT: Forgot to read your last sentence; simply mount the entire partition itself to a temporary location to check out the structure; it all looks good to me (I see all the @ folders created earlier, along with the residual junk from before the snapshot copy). Thank you for the help, Head_on_a_Stick! Hopefully someone else in the same predicament will find this post.

Last edited by WaywardPooch (2021-12-10 02:02:46)

Offline

#5 2021-12-10 18:57:16

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

For completeness sake: the subvolume layout can be confirmed with

findmnt /dev/nvme0n1p2

Jin, Jîyan, Azadî

Offline

#6 2023-01-01 20:18:38

userrrr
Member
Registered: 2023-01-01
Posts: 7

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Hi!

Just a follow-up question on this, if it's ok.
I had installed on ext4, then post installation, from life usb, I converted my root to btrfs - with no subvolumes yet. Managed somehow to get it to boot again (fstab change fs type to btrfs, then grub still complained, (first said it cannot read the fs type and ent right back into grub recover, then after somefixing, wnet all the way to the selection and would from there only boot the fallback initramfs version) but eventually, it got fixed)
Then, I found this thread and followed the instructions: made the snapshot of / to /@  (sudo btrfs subvolume snapshot / /@ ), edited the fstab to include the subvolumes .
rebooted, expecting fail, but it boots fine.
yet I think it still boots the old / and not /@
you mentioned one step that I didn't know how to do:  "  systemd-boot so the kernel can find the new root filesystem subvolume (rootflags=subvol=@)  "
No idea how or where to accomplish that.
ls / shows the expected dirs like bin and home, but also @ and @home
/home/me  seems to be identical to /@/home/me and so it seems this one is mounted fine, just not the @-subvol for root. /@/home/me seems to be the old and unused one. creating a test file the does not show up on ls ~ , so i renamed it to home-old, just in case.
But how do I get the system to boot from /@/ instead of /dev/dm-0 directly?
What do I need to do?
timeshift is making snapshots fine now, but of @ and @home only, whereas my system that i use and update still is old in /

Last edited by userrrr (2023-01-01 20:37:46)

Offline

#7 2023-01-02 12:11:08

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

userrrr wrote:

But how do I get the system to boot from /@/ instead of /dev/dm-0 directly?

Edit the kernel command line parameters in your bootloader configuration.

No idea about Timeshift though, I've never used it. I rolled my own snapshot and restore system.


Jin, Jîyan, Azadî

Offline

#8 2023-01-02 19:48:18

userrrr
Member
Registered: 2023-01-01
Posts: 7

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Head_on_a_Stick wrote:
userrrr wrote:

But how do I get the system to boot from /@/ instead of /dev/dm-0 directly?

Edit the kernel command line parameters in your bootloader configuration.

Where is that? And edit what there exactly?
grub.cfg? or what is bootloader configuration
I have a file /etc/default/grub is that the one?
if so, it has a line root=/dev/... is that the line to edit?
if so, how do i edit it? just append ",subvol=/@" ?
if so, then afterwards, I just have to run grub-config and I'm done?
if not, what else?

Offline

#9 2023-01-02 19:57:45

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Press "e" at the GRUB menu to edit the menuentry. The relevant parameter is "rootflags=subvol=".

Are you sure you're not already booted into the @ subvolume? See post #7 for a way to check. If you've used grub-mkconfig to generate /boot/grub/grub.cfg it should have configured the menuentry to boot into that subvolume anyway. If it hasn't you've probably configured it incorrectly.

Dare I ask which guide was followed when you installed this system?


Jin, Jîyan, Azadî

Offline

#10 2023-01-02 20:01:29

userrrr
Member
Registered: 2023-01-01
Posts: 7

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

findmnt /dev/dm-0                                                                                                                                                         
TARGET SOURCE                                                        FSTYPE OPTIONS
/      /dev/mapper/luks-6ebbe337-fa09-48d3-9560-fbc11fc69dec         btrfs  rw,noatime,space_cache,subvolid=5,subvol=/
/home  /dev/mapper/luks-6ebbe337-fa09-48d3-9560-fbc11fc69dec[/@home] btrfs  rw,noatime,space_cache,subvolid=341,subvol=/@home


Is this the way you referred to?

the reason why I think it's not booted into the subvol is this (but maybe I interpret it wrongly):

ls /                                                                                                                                                                             
@    boot                desktopfs-pkgs.txt  etc         @home  lib    lost+found  old  proc  rootfs-pkgs.txt  sbin  sys              tmp  var
bin  crypto_keyfile.bin  dev                 ext2_saved  home   lib64  mnt         opt  root  run              srv   timeshift-btrfs  usr
ls /@/                                                                                                                                                                         
bin  boot  crypto_keyfile.bin  desktopfs-pkgs.txt  dev  etc  ext2_saved  home-old  lib  lib64  lost+found  mnt  newwww  opt  proc  root  rootfs-pkgs.txt  run  sbin  srv  sys  tmp  usr  var
         

So in / I still see @ and @home. I thought that if /@ is mounted to /  , then ls / should show the contents of @ but not @ itself.
and files i called old and newwwww

re guides: the initial install was made by a friend. liks-encrypted, ext4, apart from that, pretty vanilla i think.
i then googled some and converted to btrfs. i think it was on the btrfs site somewhere. used built-in btrfs-convert, and a balance.
Then, followed your instructions from this thread

Last edited by userrrr (2023-01-02 20:11:36)

Offline

#11 2023-01-02 20:02:33

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Yeah, kind of. I don't do LUKS though. Sorry.


Jin, Jîyan, Azadî

Offline

#12 2023-01-02 20:14:14

userrrr
Member
Registered: 2023-01-01
Posts: 7

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Head_on_a_Stick wrote:

If you've used grub-mkconfig to generate /boot/grub/grub.cfg it should have configured the menuentry to boot into that subvolume anyway. If it hasn't you've probably configured it incorrectly.

I never told grub about the subvolumes, though, only about ext4 now being btrfs. Should I include this rootflags command in grub.cfg? Currently it does not contain rootflags at all.

Last edited by userrrr (2023-01-02 20:16:51)

Offline

#13 2023-01-02 20:24:44

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

userrrr wrote:

the initial install was made by a friend

Ask them for help then.

userrrr wrote:

converted to btrfs. i think it was on the btrfs site somewhere. used built-in btrfs-convert, and a balance

That broke my box when I tried that. I wouldn't recommend converting.


Jin, Jîyan, Azadî

Offline

#14 2023-01-02 21:03:26

userrrr
Member
Registered: 2023-01-01
Posts: 7

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

I now tried adding rootlag=subvol=@ right after root=... in /etc/default/grub, then ran sudo grub-mkconfig -o /boot/grub/grub.cfg   and rebooted. This broke the system: cannot mount /boot/efi
so i booted from a snapshot now. booted fine. restoring this snapshot does not work since it is a snapshot of /@/  and it reverts /@/ back to an hor ago, but leaves / untouched, yet that is what it is starting to boot from....


I'll if I can get a hold of my friend again.
going off for now...

Offline

#15 2023-01-03 06:42:14

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,842
Website

Re: [Solved] Split up Single BTRFS "/" Partition Into Subvolumes

Please do not post here again unless and until you have installed the system yourself by following the official installation guide or by using archinstall. Those are the only methods supported here.

And if you do post here again please refrain from hi-jacking other people's threads, especially if they are already marked [SOLVED]. Thanks.


Jin, Jîyan, Azadî

Offline

Board footer

Powered by FluxBB