====== btrfs ======
Status:
* https://btrfs.readthedocs.io/en/stable/Status.html
* https://silvenga.com/posts/btrfs-and-lessons-learned/
Paket:
* Debian: ''btrfs-progs btrfsmaintenance''
===== Dateisystem anlegen =====
ext? nach btrfs konvertieren:
man btrfs-convert
oder besser:
Dateisystem anlegen und mounten:
mkfs.btrfs /dev/sda2
btrfs filesystem show
mkdir /mnt/btrfs
mount -o noatime /dev/sda2 /mnt/btrfs
(( TODO: [[https://wiki.tnonline.net/w/Blog/The_case_for_(no)_atime_on_Linux|noatime]] nachvollziehen
))
cd /mnt/btrfs
Beispieldaten hinein kopieren:
time cp -a /usr/share/ .
===== Daten komprimieren =====
Daten komprimieren: (( https://github.com/systemd/systemd/issues/9112 ))
btrfs filesystem df -h .
-> ''Data, single: total=2.01GiB, used=1.53GiB''
btrfs filesystem defragment -czstd -r share/
btrfs filesystem df -h .
-> ''Data, single: total=3.01GiB, used=740.17MiB''
btrfs filesystem usage .
===== Subvolumes =====
Informationen über das top-level Subvolume anzeigen:
btrfs subvolume show .
-> ''Subvolume ID'': 5
btrfs subvolume list .
-> noch keine Subvolumes
Subvolume anlegen und Daten hinein verschieben:
btrfs subvolume create subvol1
btrfs subvolume list .
btrfs subvolume show subvol1
-> ''Subvolume ID'': 256
-> ''Parent ID'': 5
time mv ./share/ ./subvol1/
Subvolume umbenennen:
mv subvol1/ subvol2
Subvolume (erneut) mounten:
mkdir /mnt/subvol2
mount -o subvol=/subvol2 /dev/sda2 /mnt/subvol2
===== Snapshots =====
Snapshot erstellen:
time btrfs subvolume snapshot subvol2 snap1
btrfs subvolume list .
btrfs subvolume show snap1
-> Subvolume ID: 257
-> Parent ID: 5
Read-only Snapshot erstellen:
btrfs subvolume snapshot -r subvol2 snap_ro1
btrfs filesystem usage .
btrfs filesystem du -s --human-readable .
du -sh .
du -shx .
btrfs filesystem du -s --human-readable subvol2
du -sh subvol2
btrfs filesystem du -s --human-readable snap1
===== Subvolume zum default-Volume machen =====
cd /mnt/btrfs
Snapshot des root-Volumes erstellen:
btrfs subvolume snapshot . 2025011300
Daten (nicht Subvolumes!) aus root-Volume löschen:
ls 2025011300 | xargs echo rm -rf
-> prüfen, das da keine Verzeichnisse mit verschachtelten Subvolumes enthalten sind
ls 2025011300 | xargs rm -rf
btrfs subvolume show 2025011300
-> ''Subvolume ID'' kopieren, z.B. 258
btrfs subvolume set-default 256 2025011300/
testen:
ls
cd ..
umount btrfs
mount btrfs
ls btrfs
===== Top-Subvolume mounten =====
mkdir /mnt/btrfs
mount -o subvolid=5,subvol=/ /dev/sda2 /mnt/btrfs
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/btrfs btrfs noauto,subvolid=5,subvol=/ 0 0
===== Datenträger tauschen =====
==== langsam ====
btrfs device usage .
btrfs device add /dev/sda6 .
btrfs device usage .
btrfs device del /dev/sda2 .
watch -d btrfs filesystem usage -T .
==== schneller & fehlertoleranter ====
# btrfs replace start
btrfs replace start 1 /dev/sda6 .
btrfs replace status .
== Doku ==
* https://wiki.tnonline.net/w/Btrfs/Replacing_a_disk
* [[https://btrfs.readthedocs.io/en/latest/btrfs-replace.html|man btrfs-replace]]
===== Dateisystem vergrößern =====
Datenträger/Volume auf dem das BTRFS liegt vergrößern, dann:
btrfs device usage .
btrfs filesystem resize max .
btrfs device usage .
====== BTRFS bei SuSE ======
++++ SuSE default root layout |
SuSE default:
mkfs.btrfs ${BOOT_DEVICE}2
uuid=$(lsblk -n -o uuid ${BOOT_DEVICE}2)
mkdir $target
mount UUID="$uuid" $target || exit
btrfs subvolume create ${target%/}/@
btrfs subvolume create ${target%/}/@/.snapshots
mkdir -p ${target%/}/@/.snapshots/1
btrfs subvolume create ${target%/}/@/.snapshots/1/snapshot
mkdir -p ${target%/}/@/boot/grub2
btrfs subvolume create ${target%/}/@/boot/grub2/i386-pc
btrfs subvolume create ${target%/}/@/boot/grub2/x86_64-efi
btrfs subvolume create ${target%/}/@/opt
btrfs subvolume create ${target%/}/@/srv
btrfs subvolume create ${target%/}/@/tmp
mkdir -p ${target%/}/@/usr
btrfs subvolume create ${target%/}/@/usr/local
mkdir -p ${target%/}/@/var
btrfs subvolume create ${target%/}/@/var/crash
mkdir -p ${target%/}/@/var/lib/libvirt
btrfs subvolume create ${target%/}/@/var/lib/libvirt/images
btrfs subvolume create ${target%/}/@/var/lib/mailman
btrfs subvolume create ${target%/}/@/var/lib/mariadb
btrfs subvolume create ${target%/}/@/var/lib/mysql
btrfs subvolume create ${target%/}/@/var/lib/named
btrfs subvolume create ${target%/}/@/var/lib/pgsql
btrfs subvolume create ${target%/}/@/var/log
btrfs subvolume create ${target%/}/@/var/opt
btrfs subvolume create ${target%/}/@/var/spool
btrfs subvolume create ${target%/}/@/var/tmp
subvolid=$(btrfs subvolume show $target/@/.snapshots/1/snapshot | sed -rn 's/.*Object ID:\s+//p')
btrfs subvolume set-default "$subvolid" "$target"
++++