You are not logged in.
Hey guys!
Please I need some clarifications about what Wiki is suggesting about "/" when mounting subvolumes using BTRFS.
I cannot fully understand what to do, I really appreciate your help. ![]()
Should I create a "parent" subvolume with path /main and mount / inside /main?
And then use other subvolumes, eg.: /home = /main/home, etc...?
But... Then... What should I declare inside /etc/fstab?
Here's my current configuration:
$ mount
/dev/sda3 on / type btrfs (rw,relatime,compress=zstd:3,ssd,space_cache=v2,autodefrag,subvolid=5,subvol=/)
$ cat /etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.
# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda3 LABEL=ARCH
UUID=3cdec25f-04e2-4bec-b602-8ae0059411de / btrfs rw,relatime,autodefrag,compress=zstd:3,ssd,space_cache=v2,subvolid=5,subvol=/ 0 0
# /dev/sda1 LABEL=ESP
UUID=4542-BF6D /efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2
# /dev/sda2 LABEL=SWAP
UUID=85e7c388-fc29-46b1-a8aa-9b5354acc8ef none swap defaults 0 0
$ sudo blkid
/dev/sda2: LABEL="SWAP" UUID="85e7c388-fc29-46b1-a8aa-9b5354acc8ef" TYPE="swap" PARTLABEL="SWAP" PARTUUID="628cf2cb-2850-48c5-8fe3-f88157efd40a"
/dev/sda3: LABEL="ARCH" UUID="3cdec25f-04e2-4bec-b602-8ae0059411de" UUID_SUB="fff3faf7-824f-4c71-9ffe-cd944e2b432f" BLOCK_SIZE="4096" TYPE="btrfs" PARTLABEL="ARCH" PARTUUID="5ed06b59-0420-4469-a24c-0ffa0d7d5ff7"
/dev/sda1: LABEL_FATBOOT="ESP" LABEL="ESP" UUID="4542-BF6D" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="ESP" PARTUUID="b7d43ba1-76e0-4cb9-83b9-f67c8d51a523"
$ sudo btrfs subvolume list --sort=path -t -a -p -u -q /
ID gen parent top level parent_uuid uuid path
-- --- ------ --------- ----------- ---- ----
257 727 5 5 - b478f0f0-5442-8f4e-935c-73a6f3788549 var/lib/machines
256 727 5 5 - de7c3ab7-980d-2543-9f11-3d35c372db06 var/lib/portables
$ sudo lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 vfat FAT32 ESP 4542-BF6D 260,2M 0% /efi
├─sda2 swap 1 SWAP 85e7c388-fc29-46b1-a8aa-9b5354acc8ef [SWAP]
└─sda3 btrfs ARCH 3cdec25f-04e2-4bec-b602-8ae0059411de 57,9G 45% /Thanks
<49,17,III,I> Fama di loro il mondo esser non lassa;
<50,17,III,I> misericordia e giustizia li sdegna:
<51,17,III,I> non ragioniam di lor, ma guarda e passa.
Offline
Hey guys!
Please I need some clarifications about what Wiki is suggesting about "/" when mounting subvolumes using BTRFS.
I cannot fully understand what to do, I really appreciate your help.Should I create a "parent" subvolume with path /main and mount / inside /main?
And then use other subvolumes, eg.: /home = /main/home, etc...?
But... Then... What should I declare inside /etc/fstab?
Last month I re-installed and by the way started using BTRFS for the first time: lots of doubts at the time, indeed. Please, see my recent post: is it good practice to create subvolumes while installing to BTRFS ?
It seems there are two main approaches to BTRFS volume creation:
- creating whatever you want on the root mount-point (like we always did for ext4 etc); eg: (for a data drive) /data (EXT4) ... period.
- creating a skeleton root (default mount) with only any other needed mount-points for any sub-volumes we want.
Either approach has its pros and cons, but, the second one, was advised/recommended/whatever on many sites while I did my research on the matter; better content separation will ease future snapshot management (if ever needed) etc etc.
Implementing the second approach took me a while, needed to piece the bits together and many sites/pages were outdated, were short on details, and/or lacked something very important: to make the parent root volume the default one after creating all the other sub-volumes, otherwise, no successful boot at all.
In short for any given drive:
parent (root) sub-volume (default)
sub-volume # 1
sub-volume # 2
sub-volume # 3
...
From my fstab (check relevant volume ...86a935552eb0); eg:
PARTUUID=eca82c38-b61e-4800-a15b-3eadc552d8b3 /boot vfat defaults,discard,utf8,dmask=0022,fmask=0022,umask=0022,noatime,rw 0 2
PARTUUID=c195aefd-3769-4fc7-8fec-86a935552eb0 / btrfs defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,subvolid=256,subvol=/,rw 0 0
PARTUUID=c195aefd-3769-4fc7-8fec-86a935552eb0 /var btrfs defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,subvolid=257,subvol=/sub-volume-data,rw 0 0
PARTUUID=c195aefd-3769-4fc7-8fec-86a935552eb0 /tmp btrfs defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,subvolid=258,subvol=/sub-volume-temp,rw 0 0
PARTUUID=c195aefd-3769-4fc7-8fec-86a935552eb0 /root btrfs defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,subvolid=259,subvol=/sub-volume-homeroot,rw 0 0
PARTUUID=c195aefd-3769-4fc7-8fec-86a935552eb0 /home btrfs defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,subvolid=260,subvol=/sub-volume-home,rw 0 0
PARTUUID=e588a3c0-7664-41c3-b8f1-44ecafb76051 /data ext4 defaults,noatime,rw 0 2My system drive:
- has a sub-volume ID=256 which is the root one for /
- has a sub-volume ID=257 which is labeled sub-volume-data for /var
- has a sub-volume ID=258 which is labeled sub-volume-temp for /tmp
- has a sub-volume ID=259 which is labeled sub-volume-homeroot for /root
- has a sub-volume ID=260 which is labeled sub-volume-home for /home
Following is an excerpt of my installation script that I think could prove helpful for your understanding on the subject:
### assuming target system drive is already manually-formatted; eg: for HGST SSD 100 GB:
### eg: sgdisk --new='1:4096:+1G ' --typecode='1:EF00' --change-name='1:system-EFI' '/dev/sd?'; ### 1 GB system-EFI for FAT32
### eg: sgdisk --new='2: :+90G' --typecode='2:8304' --change-name='2:system-NIX' '/dev/sd?'; ### 90 GB system-NIX for BTRFS including sub‐volumes for var, tmp, root, home
### eg: sgdisk --print '/dev/sd?';
### eg: mkfs.fat -F '32' -n 'system-EFI' '/dev/sd?1'; ### FAT32 … do not use any outdated file-system: FAT → VFAT → FAT32 (this one)
### eg: mkfs.btrfs --csum='crc32c' --label='system-NIX' '/dev/sd?2'; ### BTRFS
### ∙ notes for BTRFS configuration: [/etc/mkinitcpio.conf] with modules='(crc32c)' to enable faster compression times
### ∙ notes for BTRFS configuration [/etc/fstab] with compress=zstd … when automatically mounted
### ∙ notes for BTRFS mount -o compress='zstd' /dev/sd?# /mnt/whatever/; … when manually mounted
typeset strBTRFSoptions='defaults,ssd,space_cache=v2,compress=zstd,commit=30,noatime,rw'; ### my default options to mount BTRFS file-systems
typeset strFAT32options='defaults,discard,utf8,dmask=0022,fmask=0022,umask=0022,noatime,rw'; ### my default options to mount FAT32 file-systems
### CAUTION … with the following IDs !
### volume IDs as drive WWN-based IDs … FSTAB using these may be possible (see man mount) but udevd will be required in HOOKS in [/etc/mkinitcpio.conf] … AND, there's no guarantee the EFI entries can also handle these:
### volume ID from [/dev/disk/by-id/] wwn-0x 5000cca0132a327c -part1 → ../../sdd1 … on system drive
### volume ID from [/dev/disk/by-id/] wwn-0x 5000cca0132a327c -part2 → ../../sdd2 … on system drive
### volume ID from [/dev/disk/by-id/] wwn-0x 55cd2e404c63af53 -part1 → ../../sdc1 … on data-buffer-2 drive … currently mounted as data
### volume IDs as UUIDs … will be using this set instead:
### volume ID from [/dev/disk/by-partuuid/] c3c15aa8-9577-4103-b1e2-e4f554d7fd15 → /dev/sdd1/ … on system drive
### volume ID from [/dev/disk/by-partuuid/] f47191f1-cd5c-4a21-8c8c-39c40412e77a → /dev/sdd2/ … on system drive
### volume ID from [/dev/disk/by-partuuid/] e588a3c0-7664-41c3-b8f1-44ecafb76051 → /dev/sdc1/ … on data-buffer-2 drive … currently mounted as data
typeset strIDPATHdrives='/dev/disk/by-id/wwn-0x'; ### ie: will be identifying drives by WWN
typeset strIDPATHvolumes='/dev/disk/by-partuuid/'; ### ie: will be identifying volumes by UUID
typeset strIDPATHcurrent='./configure-boot-storage-ID-current-';
typeset strDriveSystemWWN='5000cca0132a327c'; ### ie: HGST SSD 100 GB SAS
typeset strDriveDataBuffer2WWN='55cd2e404c63af53'; ### ie: Intel SSD 160 GB SATA
typeset strVolumeSystemEFIUUID='eca82c38-b61e-4800-a15b-3eadc552d8b3'; ### ie: should be [/dev/sd?1/]
typeset strVolumeSystemNIXUUID='c195aefd-3769-4fc7-8fec-86a935552eb0'; ### ie: should be [/dev/sd?2/]
typeset strVolumeDataBuffer2UUID='e588a3c0-7664-41c3-b8f1-44ecafb76051'; ### ie: should be [/dev/sd?1/]
typeset strDriveSystem="${strIDPATHdrives}${strDriveSystemWWN}";
typeset strDriveDataBuffer2="${strIDPATHdrives}${strDriveDataBuffer2WWN}";
typeset strVolumeSystemEFI="${strIDPATHvolumes}${strVolumeSystemEFIUUID}";
typeset strVolumeSystemNIX="${strIDPATHvolumes}${strVolumeSystemNIXUUID}";
typeset strVolumeSystemNIXID='sub-volume-';
typeset strVolumeSystemNIXIDroot="${strVolumeSystemNIXID}root";
typeset strVolumeSystemNIXIDdata="${strVolumeSystemNIXID}data";
typeset strVolumeSystemNIXIDtemp="${strVolumeSystemNIXID}temp";
typeset strVolumeSystemNIXIDhome="${strVolumeSystemNIXID}home";
typeset strVolumeSystemNIXIDhomeroot="${strVolumeSystemNIXID}homeroot";
typeset strVolumeDataBuffer2="${strIDPATHvolumes}${strVolumeDataBuffer2UUID}";
typeset strSystemTMP='/mnt/system/';
if /usr/bin/test 1 -eq 0; then ### safe-check to avoid running this accidentally while in production
### CAUTION … DO NOT ALLOW this to run before checking the above sgdisk output
if ! /usr/bin/test -d "${strSystemTMP}"; then
/usr/bin/mkdir "${strSystemTMP}"; ### ie: on the liveIMG file-system
fi;
if /usr/bin/test -d "${strSystemTMP}"; then ### we are on the live image environment: it's a go:
if /usr/bin/test ! '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}")'/]' = "${strSystemTMP}"; then
/usr/bin/printf "mounting [${strSystemTMP}] …\n";
/usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions}" "${strVolumeSystemNIX}" "${strSystemTMP}"; ### ie: on a volatile mount-point on the live image file-system
fi;
if /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}")'/]' = "[${strSystemTMP}]" \
&& /usr/bin/test -z $(/usr/bin/find "${strSystemTMP}" -mindepth '1' -maxdepth '1' -print -quit) \
; then ### proceed if there's no leftovers (possibly from a previous attempt):
/usr/bin/printf "creating sub‐volumes on [${strSystemTMP}] …\n";
### the rationale here is to create sub‐volumes for anything holding variable user data; ie: RW data
### this could prove useful for system backups/snapshots as advised on some forums … although the pros and the cons are not very clear to me right now
/usr/bin/btrfs subvolume create "${strSystemTMP}${strVolumeSystemNIXIDroot}"; ### this will be the root file‐system holding all other sub‐volumes
/usr/bin/btrfs subvolume create "${strSystemTMP}${strVolumeSystemNIXIDdata}";
/usr/bin/btrfs subvolume create "${strSystemTMP}${strVolumeSystemNIXIDtemp}";
/usr/bin/btrfs subvolume create "${strSystemTMP}${strVolumeSystemNIXIDhomeroot}";
/usr/bin/btrfs subvolume create "${strSystemTMP}${strVolumeSystemNIXIDhome}";
### from BTRFS btrfs-subvolume man page: a freshly‐created file‐system is also a sub‐volume that cannot be removed or replaced by another sub‐volume
### from BTRFS btrfs-subvolume man page: this is also the sub‐volume that will be mounted by default (unless changed with set-default)
/usr/bin/btrfs subvolume list -p "${strSystemTMP}";
/usr/bin/printf "current default sub‐volume is: "; /usr/bin/btrfs subvolume get-default "${strSystemTMP}";
typeset strVolumeSystemNIXIDrootNO=$(/usr/bin/btrfs subvolume list "${strSystemTMP}" \
| /usr/bin/grep --regexp="${strVolumeSystemNIXIDroot}" \
| /usr/bin/grep --only-matching --perl-regexp '^ID [0-9]+' \
| /usr/bin/sed 's/ID //'\
); ### needing BTRFS sub‐volume number ID
/usr/bin/printf "setting default sub‐volume to [${strVolumeSystemNIXIDrootNO}]=[${strVolumeSystemNIXIDroot}] …\n";
/usr/bin/btrfs subvolume set-default "${strVolumeSystemNIXIDrootNO}" "${strSystemTMP}"; ### needs an unmount/mount to take action
/usr/bin/btrfs subvolume list -p "${strSystemTMP}";
/usr/bin/printf "current default sub‐volume is: "; /usr/bin/btrfs subvolume get-default "${strSystemTMP}";
unset -v strVolumeSystemNIXIDrootNO;
### so we currently have; eg: /dev/sd?2 on /mnt/system type btrfs (rw,noatime,compress=zstd:3,ssd,space_cache=v2,commit=120,subvolid=5,subvol=/) … as following:
### /mnt/system/sub-volume-root
### /mnt/system/sub-volume-data
### /mnt/system/sub-volume-temp
### /mnt/system/sub-volume-homeroot
### /mnt/system/sub-volume-home
### there are no more directories and/or files on [/mnt/system/] at this point; only the sub‐volumes shown as normal directories
### we won't need this default sub‐volume anymore; we'll be using the new default one:
/usr/bin/printf "re-mounting [${strSystemTMP}] to get the new default sub‐volume up‐and‐running …";
/usr/bin/sync && /usr/bin/umount "${strSystemTMP}";
/usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions}" "${strVolumeSystemNIX}" "${strSystemTMP}"; ### ie: on a volatile mount-point on the live image file-system
/usr/bin/printf "creating mount-points on [${strSystemTMP}] …\n";
/usr/bin/mkdir --mode='700' \
"${strSystemTMP}boot/" \
"${strSystemTMP}data/" \
"${strSystemTMP}home/" \
"${strSystemTMP}root/" \
"${strSystemTMP}tmp/" \
"${strSystemTMP}tmp-workspace/" \
"${strSystemTMP}var/" \
"${strSystemTMP}usb/" \
;
/usr/bin/printf "mounting [${strSystemTMP}boot/] …\n"; /usr/bin/mount -t 'vfat' --options="${strFAT32options}" "${strVolumeSystemEFI}" "${strSystemTMP}boot/";
/usr/bin/printf "mounting [${strVolumeSystemNIXIDdata}] …\n"; /usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions},subvol=${strVolumeSystemNIXIDdata}" "${strVolumeSystemNIX}" "${strSystemTMP}var/";
/usr/bin/printf "mounting [${strVolumeSystemNIXIDtemp}] …\n"; /usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions},subvol=${strVolumeSystemNIXIDtemp}" "${strVolumeSystemNIX}" "${strSystemTMP}tmp/";
/usr/bin/printf "mounting [${strVolumeSystemNIXIDhomeroot}] …\n"; /usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions},subvol=${strVolumeSystemNIXIDhomeroot}" "${strVolumeSystemNIX}" "${strSystemTMP}root/";
/usr/bin/printf "mounting [${strVolumeSystemNIXIDhome}] …\n"; /usr/bin/mount -t 'btrfs' --options="${strBTRFSoptions},subvol=${strVolumeSystemNIXIDhome}" "${strVolumeSystemNIX}" "${strSystemTMP}home/";
if /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}boot")']' = "[${strSystemTMP}boot]" \
&& /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}var" )']' = "[${strSystemTMP}var]" \
&& /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}tmp" )']' = "[${strSystemTMP}tmp]" \
&& /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}root")']' = "[${strSystemTMP}root]" \
&& /usr/bin/test '['$(/usr/bin/findmnt --noheadings --output='TARGET' --mountpoint="${strSystemTMP}home")']' = "[${strSystemTMP}home]" \
; then
/usr/bin/printf "everything already‐mounted on [${strSystemTMP}]: changing permissions accordingly …\n";
/usr/bin/chmod '700' "${strSystemTMP}home/";
/usr/bin/chmod '700' "${strSystemTMP}root/";
/usr/bin/printf "everything already‐mounted on [${strSystemTMP}]: updating drive and volume IDs on FSTAB and EFI entries …\n";
/usr/bin/genfstab -U "${strSystemTMP}" > '/etc/fstab';
...
fi;
fi;
fi;
fi;edit: fixed a wrong permission in the script that I forgot to change after my last installation:
from:
/usr/bin/chmod '700' "${strSystemTMP}home/";to:
/usr/bin/chmod '755' "${strSystemTMP}home/";Last edited by dawnofman (2022-06-01 05:23:34)
Offline
I always put my root (/) on a subvolume of the btrfs root subvolume (subvolid=5). I also make my /home a subvolume of the btrfs root subvolume. / and /home are, of course, mounted during the course of normal operations.
The only time I mount the btrfs root subvolume is to make snapshots of / and /home. After my snapshots have been migtared to external storage, I umount the btrfs root subvolume.
Offline