Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

[SOLVED]mounting rootfs folders under btrfs subvolumes

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
19 posts • Page 1 of 1
Author
Message
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

[SOLVED]mounting rootfs folders under btrfs subvolumes

  • Quote

Post by abdus » Sun Dec 11, 2022 7:26 am

hi there, how is it going.
i read this thread
https://wiki.gentoo.org/wiki/Filesystem/Security
so i thought of doing similar filesystem structure but with btrfs subvolumes instead of ext4 partitions.
i succeeded in mounting almost all the folders the way i wanted(as i guess), however i'm still facing a problem which is the apps no longer find their data that they were configured on.
please someone helps me figure out a way to move the data from the old directories to the new btrfs subvolumes. any needed information will be provided once requested.
the directories that i wasn't able to mount are

Code: Select all

/var/cache/distfiles 
and

Code: Select all

/var/cache/binpkgs
please help me mount them in btrfs subvolumes correctly
thank you
Last edited by abdus on Wed Jan 18, 2023 2:26 pm, edited 1 time in total.
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Sun Dec 11, 2022 10:00 am

Have you created btrfs subvolumes for distfiles and binpkgs?
If yes in fstab you should have an entry like

Code: Select all

UUID=<uuid of btrfs partition>	/var/cache/distfiles	btrfs	defaults,noatime,autodefrag,subvol=distfiles	0 0
etc
Or manually maybe

Code: Select all

mount -t btrfs -o subvol=distfiles UUID=<uuid of btrfs partition>  /var/cache/distfiles
etc
:)
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sun Dec 11, 2022 11:45 am

yes i forgot to mention that i want to mount them in fstab.
here is how they are:
#/dev/sda4 /var btrfs nodev,compress=lzo,subvolid=348 0 3 (commented them to be able to start the apps)
/dev/sda4 /usr/local btrfs nodev,compress=lzo,subvolid=349 0 3
/dev/sda4 /srv btrfs nodev,compress=lzo,subvolid=350 0 3
/dev/sda4 /root btrfs nodev,compress=lzo,subvolid=351 0 3
/dev/sda4 /opt btrfs nodev,compress=lzo,subvolid=355 0 3
#/dev/sda4 /nix btrfs nodev,compress=lzo.subvolid=356 0 3
#/dev/sda4 /var/log btrfs nodev,compress=lzo,subvolid=357 0 3
#/dev/sda4 /var/tmp btrfs nodev,compress=lzo,subvolid=358 0 3
#/dev/sda4 /var/cache/distfiles btrfs nodev,compress=lzo,subvolid=359 0 3
#/dev/sda4 /var/cache/binpkgs btrfs nodev,compress=lzo,subvolid=360 0 3
you answered something i was wondering about which is using the partition flags with btrfs subvolumes, thank you for that.
my problem is the subvolumes are empty so the installed apps cannot find the old configurations since they are in the old directories so they crash
i searched about the case, i found that there are 2 types of copying, first by moving the files themselves, and the second is like a virtual method. it appears like @subvolume (saw it in opensuse fstab)
how can i do that.
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Sun Dec 11, 2022 12:06 pm

In your fstab you omitted /

Code: Select all

/dev/sda4   /   btrfs defaults,noatime,compress=lzo   0 0
or
/dev/sda4   /   btrfs defaults,noatime,compress=lzo,subvol=@   0 0

 
Also plz replace your "0 3"s with "0 0"
I dont even think there is a "3".

Code: Select all

0 --> dont fscheck
1 --> fscheck
2  --> fscheck
A tip.
Next time you want to play with btrfs use an Arch live iso.
Create a btrfs partition, mount it on /mnt, create btrfs subvolumes on /mnt bootstrap a system on /mnt then use

Code: Select all

genfstab -U /mnt >> /mnt/etc/fstab
It will nicely and easilly create a nice fstab for you.
You can even try it now(with caution) with your Gentoo.
:)
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sun Dec 11, 2022 1:06 pm

it's an option, but i guess you need to see this https://packages.gentoo.org/packages/sys-fs/genfstab
i would like to thank everyone that contributed to the gentoo project in any means
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sun Dec 11, 2022 1:08 pm

alamahant wrote:Have you created btrfs subvolumes for distfiles and binpkgs?
If yes in fstab you should have an entry like

Code: Select all

UUID=<uuid of btrfs partition>	/var/cache/distfiles	btrfs	defaults,noatime,autodefrag,subvol=distfiles	0 0
etc
Or manually maybe

Code: Select all

mount -t btrfs -o subvol=distfiles UUID=<uuid of btrfs partition>  /var/cache/distfiles
etc
what is the command i need to execute before i put it in the fstab the way you did, and does it really matter?
i just followed the wiki above and executed

Code: Select all

sudo btrfs subvolume create /mnt/btrfs/vol1
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Sun Dec 11, 2022 1:50 pm

Its ok you do it the way you like.
I just mentioned that in complicated fses like btrfs the Archlinux genfstab util can simplify things a bit.
Ah ah ok perfect!
I didn't know genfstab is available in Gentoo also.
Foolish me..
sudo btrfs subvolume create /mnt/btrfs/vol1
If your btrfs partition is mounted on /mnt/btrfs then yes i think its the correct command.
More like

Code: Select all

btrfs subvolume create /mnt/btrfs/root
btrfs subvolume create /mnt/btrfs/var
btrfs subvolume create /mnt/btrfs/usr
etc
:)
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sun Dec 11, 2022 4:50 pm

what is the difference between mounting with "subvolid" and the one you mentioned "subvol"
does subvol make the files appear on the new subvolume or they both do the same? i guess it does not though (the thread below proves that)
no problem my friend, technology is always evolving and changing.
there is this thread and it tells how to make the new subvolumes with moving the data but it is not detailed enough
https://askubuntu.com/questions/100187/ ... subvolumes
please help me with it
thank you for the efforts you are doing with me
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Sun Dec 11, 2022 5:03 pm

what is the difference between mounting with "subvolid" and the one you mentioned "subvol"
I think both will work for you?
You mentioned consulting a suse fstab.
What do they use?
there is this thread and it tells how to make the new subvolumes with moving the data but it is not detailed enough
https://askubuntu.com/questions/100187/ ... subvolumes
please help me with it
Have you already installed gentoo on btrfs or you are working on a new install?
Plz mount your btrfs partition on /mnt and run

Code: Select all

btrfs subvolume list /mnt
:)
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Mon Dec 12, 2022 6:32 am

here is the fstab file of opensuse leap 15.4:

Code: Select all

UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /           btrfs  defaults             0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /var        btrfs  subvol=/@/var        0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /usr/local  btrfs  subvol=/@/usr/local  0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /tmp        btrfs  subvol=/@/tmp        0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /srv        btrfs  subvol=/@/srv        0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /root       btrfs  subvol=/@/root       0  0
UUID=45beb54b-0ec8-4b4e-8eab-315004f078a6  /opt        btrfs  subvol=/@/opt        0  0
/dev/mapper/cr_home                        /home       btrfs  defaults             0  0
UUID=33d9171e-c184-4923-919d-eb84b760a861  /boot       ext3   data=ordered         0  2 
i used subvolid from a thread online.
the fstab of opensuse is generated automatically when choosing btrfs as rootfs in opensuse
i would like to thank everyone that contributed to the gentoo project in any means
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Mon Dec 12, 2022 7:11 am

i'm not working on a new installation, it is an old one and i am trying to make the changes on it
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Mon Dec 12, 2022 3:02 pm

Ok then please mount your btrfs partition on /mnt
and run

Code: Select all

btrfs subvolume list /mnt
at the same time please post your full fstab.
Please use code tags.
Then we will create a proper fstab and all we wil be ok.
:)
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Fri Dec 16, 2022 10:49 am

i'm sorry for my late reply.
i'm sorry also to say that i deleted the subvolumes and referred back to the previous configurations.
however this is my fstab:

Code: Select all

/dev/sda1             /boot             ext4            defaults,noatime,noauto,ro,nouser               0 1
/dev/sda2             /boot/efi         vfat            defaults                                0 2
/dev/sda3             none              swap            sw                                      0 0
/dev/sda4             /                 btrfs           compress=lzo,noatime                    0 1
#/dev/sda4              /var            btrfs           nodev,compress=lzo,subvolid=348         0 3
#/dev/sda4              /usr/local      btrfs           nodev,compress=lzo,subvolid=349         0 3
#/dev/sda4              /srv            btrfs           nodev,compress=lzo,subvolid=350         0 3
#/dev/sda4              /root           btrfs           nodev,compress=lzo,subvolid=351         0 3
#/dev/sda4              /opt            btrfs           nodev,compress=lzo,subvolid=355         0 3
#/dev/sda4              /nix            btrfs           nodev,compress=lzo.subvolid=356         0 3
#/dev/sda4              /var/log        btrfs           nodev,compress=lzo,subvolid=357         0 3
#/dev/sda4              /var/tmp        btrfs           nodev,compress=lzo,subvolid=358         0 3
#/dev/sda4              /var/cache/distfiles    btrfs   nodev,compress=lzo,subvolid=359         0 3
#/dev/sda4              /var/cache/binpkgs      btrfs   nodev,compress=lzo,subvolid=360         0 3
i did not change "3" because i went back to the previous configs.
i guess all i have to do is to make snapshots and for every folder i add @ in front of the original name, mount it on the root folder and add it with subvol="@(folder) in fstab.
i will try it and tell if it worked.
i would like to thank everyone that contributed to the gentoo project in any means
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Fri Dec 16, 2022 11:03 am

i'm wrong, there is no way to make a snapshot for a folder
this thread explains it https://unix.stackexchange.com/question ... -directory
i got the same error when i tried.
the only remaining possible way is to copy or move the files.
i would like to thank everyone that contributed to the gentoo project in any means
Top
alamahant
Advocate
Advocate
Posts: 4032
Joined: Sat Mar 23, 2019 12:12 pm

  • Quote

Post by alamahant » Fri Dec 16, 2022 5:14 pm

You got me confused.Do you have a btrfs filesystem that contains a Gentoo installation or not?
Does your fstab reflect this filesystem?
:)
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Fri Dec 16, 2022 6:01 pm

abdus wrote:i'm wrong, there is no way to make a snapshot for a folder
Yes and no.
You can just btrfs sub create dir and then you can snapshot 'dir'. This assumes 'dir' didn't exist beforehand.

You can create nested subvolumes. Those subvolumes will automatically be mounted when you mount their parent.
I do this with every btrfs installation to avoid polluting my fstab.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sat Dec 17, 2022 7:03 am

alamahant wrote:You got me confused.Do you have a btrfs filesystem that contains a Gentoo installation or not?
Does your fstab reflect this filesystem?
i'm sorry for getting you confused.
i do have a system with gentoo on a btrfs filesystem. it is not a fresh install
my exact problem is finding a way to mount the system folders like /usr /var /opt etc, you know what i mean, on btrfs subvolumes like in opensuse fstab
not only that, mounting them with not having data loss as much as possible and keeping the system configs exactly the same.
i would like to thank everyone that contributed to the gentoo project in any means
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sat Dec 17, 2022 9:18 am

abdus wrote:my exact problem is finding a way to mount the system folders like /usr /var /opt etc, you know what i mean, on btrfs subvolumes
If you plan to have your root partition also on btrfs, Then you can simply:
  • Prepare your new btrfs

    Code: Select all

    mkdir /mnt/btrfs-root
    mkfs.btrfs <list of disks and/or partitions you want to dedicate to your btrfs pool>
  • mount it:

    Code: Select all

    mount <choose a single one the disks/parttions you formatted to btrfs> /mnt/btrfs-root
  • Create subvolumes inside of it (take this as an example):

    Code: Select all

    btrfs sub create /mnt/btrfs-root/usr
    btrfs sub create /mnt/btrfs-root/var
    mkdir /mnt/btrfs-root/var/cache
    btrfs sub create /mnt/btrfs-root/var/cache/distfiles
    btrfs sub create /mnt/btrfs-root/var/cache/binpkgs
    btrfs sub create /mnt/btrfs-root/opt
    
    ... There you can see you can treat subvolumes like a special directory inside btrfs. ;)
  • Copy files from your old root to the newly created btrfs root.
  • Adjust your system to your new btrfs.
    • You only need to add the root btrfs line into your fstab (along with maybe /boot and EFI partition)
If you don't plan to use btrfs on your root partition, then you need to add lines for each btrfs subvolume into your fstab.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
abdus
Apprentice
Apprentice
Posts: 190
Joined: Wed Feb 10, 2021 1:01 pm
Location: bandung

  • Quote

Post by abdus » Sun Dec 25, 2022 4:44 pm

thank you for your answers and help guys.
i am sorry for my late reply.
after trying multiple times i was eventually able to put the system folders in btrfs subvolumes
i did not need to use live cd except for /usr folder.
mostly all i had to do was renaming the folder by executing
sudo mv /opt /opt1 for example for all the folders, afterwards execute
sudo btrfs subvolume create /opt
sudo cp -a --reflink=always /opt1/*
checking the integrity of files in the subvolume
it's optional to put it in the fstab file
then deleting the /opt1 folder using
sudo rm -fR /opt1 i did that with all the other folders without live cd for the live cd i did it with usr folder i had to mount the partition in /mnt
execute the same commands but with adding /mnt to the paths.
i will try doing the same thing with the folders under /var later.
thank you guys.
i did not succeed from the first time there was a problem with programs starting and working then i repeated again and had kernel panic
if i do not succeed i simply rename the renamed folder to the original name or remove the line of the subvolume from fstab if it is not with the same name as the folder itself and reboot
i would like to thank everyone that contributed to the gentoo project in any means
Top
Post Reply

19 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic