Creating BTRFS subvolumes on top of already setup BTFRS filesystems

Kernels, Network, and Services configuration
Post Reply
Posts: 129
Joined: 2016-09-11 18:04

Creating BTRFS subvolumes on top of already setup BTFRS filesystems

#1 Post by 4joeyirosh1 »

Hi!I have Debian 11 64 bit installed on my machine.Just to mention in advance,I am no Debian expert so maybe I havent framed my question correctly thus forgive and correct me if I am asking my questions below from a point of ignorance.I am here to learn.

I have BTRFS linux partitions and also Windows partitions as I have a dual boot Windows 10 Debian 11 machine.My partitions are as shown below from gparted.


Thus I have BTRFS filesystems.When I did my Debian installation,I never created BTFRS subvolumes and this is giving me problems doing timeshift restores especially if I have stored backup on external drive and needed to restore this or if I have corrupted my boot or root partitions and I need to restore from a live CD.When I try the live CD restore option I get error below


Thus I assume I need to create BTRFS subvolumes to enable the restores to take place but I already have data in my linux partitions like root,boot and home and I assume that if I tried to create BTRFS sub-volumes it might compromise my current files in these BTRFS filesystems rendering my debian unusable.Is this the case?

Hence what I am asking is if I can create BTRFS subvolumes on top of my BTFRS filesystems and still retain exact files and file structures of my root,boot,home partitions and have my Debian remain usable as before and still achive Timeshift restores and how do I go about this?

I hope I have framed my question properly and if it looks like a weird question to ask recall I am no linux expert.

User avatar
Posts: 1900
Joined: 2015-04-02 13:15
Been thanked: 1 time

Re: Creating BTRFS subvolumes on top of already setup BTFRS filesystems

#2 Post by bester69 »

think of subvolumes as if they were regular folders that works like logical btrfs partitions..

I have 4 suvbolumes in my installation, all of them in root subvolume
/@home (home partition subvolume)
/@rootsys (installation system)
/@MIDATA (all my data partition subvolume)
/@cache (ln -s /media/cache /home/myuser/.cache)

Code: Select all

UUID=c649c9a7-6ed6-482b-9326-026837988bb7 /              btrfs   subvol=@rootsys,defaults,noatime,ssd,space_cache,inode_cache 0 1
UUID=c649c9a7-6ed6-482b-9326-026837988bb7 /home          btrfs   subvol=@home,defaults,noexec,noatime,ssd,space_cache,inode_cache 0 2
UUID=c649c9a7-6ed6-482b-9326-026837988bb7 /media/MIDATA    btrfs   subvol=@MIDATA,defaults,noexec,noatime,ssd,space_cache,inode_cache 0 2
UUID=c649c9a7-6ed6-482b-9326-026837988bb7 /media/cache    btrfs   subvol=@cache,defaults,noexec,noatime,ssd,space_cache,inode_cache 0 2
still retain exact files and file structures of my root,boot,home partitions
You will need to recreate your partitions as logical subvolume partitions and then edit fstab to point to right subvolume path and finally update grub to find out new subvolume paths for booting.

for boot you would do.:
sudo mount -t btrfs /dev/sda1 /mnt (>> mount root main btrfs partition)
sudo btrfs subvolume create @boot (>> creates a new subvolume names @boot)

sudo rsync -aAXv /boot/ /mnt/@boot/ (livecd clone folder)

or Using btrfs send /receive : this way, might be trustable:

Code: Select all

sudo btrfs subvolume snapshot -r  /boot/ /boot/.SOURCE (create source snapshot only read permission)
sudo btrfs subvolume create  -r  /mnt/@boot.TARGET (create subvolume target only read permission)
sudo btrfs send -v   /boot/.SOURCE | pv -s 14G |sudo btrfs receive   /mnt/@boot.TARGET  (>> clone subvolume between partitions keeping extended permissions)
sudo btrfs subvolume snapshot /mnt/@boot.TARGET /mnt/@boot  (remove only read suvolume mode by doing just a snapshot)
sudo btrfs subvolume delete /mnt/@boot.TARGET /boot/.SOURCE
for root you would do.:
(As you will use root partition as main partition, you just need to move all root folder one level up into @rootsys directory subvolume)
sudo mount -t btrfs /dev/sda1 /mnt (mount root partition in mnt)
cd /mnt && sudo btrfs create subvolume @rootsys (>> creates system subvolume named @rootsys)
sudo mv /boot /bin /usr /lib ........ @rootsys/ ( >> from livecd session move all files and folders within root subvolume @rootsys, !!dont include home, boot and rest of suvolumes within @rootsys/ ) ; the resultring root structure would just have your subvolumes like this.:

/@home (home partition subvolume)
/@rootsys (installation system)
/@MIDATA (all my data partition subvolume)

/@cache (ln -s /media/cache /home/myuser/.cache)

Now you just need to edit fstab within @rootsys , do chroot to @rootsys and update-grub.. in fstab dont forget to edit before updating grub all suvolumes paths, reboot and thats all.

** if you're scary with moving system structure on level up into @rootsys, :!: you can leave all together, and create first a snapshot of root before creating others subvolumes in root...
sudo btrfs subvolume snaphot / /@rootsys (>> this would avoid using move mv)
and later you would create rest of subvolumes in root as well... this way you would have all together such like this.:

/@rootsys (snapshot system)

And you would be able to keep your current installation and test new configuration by just switching between both of them by using chroot+update-grub, dont forget fstab of @rootsys must have his updated paths subvolumes before updating grub
bester69 wrote:You wont change my mind when I know Im right, Im not an ...

Post Reply