Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
|
lpi2:btrfs [2019/12/17 10:17] dirk_streubel |
lpi2:btrfs [2025/10/17 11:38] (aktuell) ingo_wichmann [Subvolume zum default-Volume machen] |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== 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: | ext? nach btrfs konvertieren: | ||
| man btrfs-convert | man btrfs-convert | ||
| + | |||
| + | oder besser: | ||
| Dateisystem anlegen und mounten: | Dateisystem anlegen und mounten: | ||
| mkfs.btrfs /dev/sda2 | mkfs.btrfs /dev/sda2 | ||
| - | mkdir /mnt/btrfs | + | btrfs filesystem show |
| - | mount /dev/sda2 /mnt/btrfs | + | mount -m -o noatime /dev/sda2 /mnt/btrfs |
| - | time cp -a /usr/share/ /mnt/btrfs | + | (( TODO: [[https://wiki.tnonline.net/w/Blog/The_case_for_(no)_atime_on_Linux|noatime]] nachvollziehen |
| + | )) | ||
| cd /mnt/btrfs | cd /mnt/btrfs | ||
| - | | + | |
| - | Informationen über das Dateisystem anzeigen: | + | Beispieldaten hinein kopieren: |
| + | time cp -a /usr/share/ . | ||
| + | |||
| + | ===== Reflink / CoW ===== | ||
| + | |||
| + | Schnelle Kopien dank reflink/CoW: | ||
| + | time cp -a share/ share2 | ||
| + | |||
| + | ===== Daten komprimieren ===== | ||
| + | Daten komprimieren: (( Data loss on rotated journal files on BTRFS volumes using compression: https://github.com/systemd/systemd/issues/9112 )) ((Mehr Datenverbrauch durch Defragmentation: [[https://btrfs.readthedocs.io/en/latest/Defragmentation.html|Defragmentation does not preserve extent sharing, e.g. files created by cp --reflink or existing on multiple snapshots. Due to that the data space consumption may increase.]] )) | ||
| + | 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 . | btrfs subvolume show . | ||
| - | -> Subvolume ID: 5 | + | -> ''Subvolume ID'': 5 |
| btrfs subvolume list . | btrfs subvolume list . | ||
| Zeile 20: | Zeile 49: | ||
| btrfs subvolume list . | btrfs subvolume list . | ||
| btrfs subvolume show subvol1 | btrfs subvolume show subvol1 | ||
| - | -> Subvolume ID: 259 | + | -> ''Subvolume ID'': 256 |
| - | -> Parent ID: 5 | + | -> ''Parent ID'': 5 |
| time mv ./share/ ./subvol1/ | time mv ./share/ ./subvol1/ | ||
| | | ||
| Zeile 27: | Zeile 56: | ||
| mv subvol1/ subvol2 | mv subvol1/ subvol2 | ||
| + | Subvolume (erneut) mounten: | ||
| + | mkdir /mnt/subvol2 | ||
| + | mount -o subvol=/subvol2 /dev/sda2 /mnt/subvol2 | ||
| + | |||
| + | ===== Snapshots ===== | ||
| Snapshot erstellen: | Snapshot erstellen: | ||
| - | btrfs subvolume snapshot subvol2 snap1 | + | time btrfs subvolume snapshot subvol2 snap1 |
| btrfs subvolume list . | btrfs subvolume list . | ||
| btrfs subvolume show snap1 | btrfs subvolume show snap1 | ||
| - | -> Subvolume ID: 260 | + | -> Subvolume ID: 257 |
| -> Parent ID: 5 | -> Parent ID: 5 | ||
| Zeile 37: | Zeile 71: | ||
| btrfs subvolume snapshot -r subvol2 snap_ro1 | btrfs subvolume snapshot -r subvol2 snap_ro1 | ||
| - | btrfs filesystem df -h . | + | btrfs filesystem usage . |
| btrfs filesystem du -s --human-readable . | btrfs filesystem du -s --human-readable . | ||
| du -sh . | du -sh . | ||
| Zeile 45: | Zeile 79: | ||
| btrfs filesystem du -s --human-readable snap1 | btrfs filesystem du -s --human-readable snap1 | ||
| + | ===== Backup mit send und receive ===== | ||
| + | ==== Initiales Vollbackup ==== | ||
| + | Read-only Snapshot erstellen: | ||
| + | btrfs subvolume snapshot -r subvol2 snap_ro2 | ||
| + | Backup übertragen: | ||
| + | btrfs send snap_ro2 | ssh 192.168.122.74 btrfs receive /mnt/btrfs | ||
| + | (( | ||
| + | Mit ''pv'' Datenmenge anzeigen: | ||
| + | btrfs send -p snap_ro2 | pv | ssh 192.168.122.74 btrfs receive /mnt/btrfs | ||
| + | )) | ||
| + | ==== Inkrement ==== | ||
| + | Daten ändern: | ||
| + | touch subvol2/status | ||
| + | date -r subvol2/status | ||
| + | Read-only Snapshot erstellen: | ||
| + | btrfs subvolume snapshot -r subvol2 snap_ro3 | ||
| + | Backup übertragen: | ||
| + | btrfs send -p snap_ro2 snap_ro3 | ssh 192.168.122.74 btrfs receive /mnt/btrfs | ||
| + | Testen, ob Daten angekommen sind: | ||
| + | ssh 192.168.122.74 date -r /mnt/btrfs/snap_ro3/status | ||
| + | |||
| + | ===== Subvolume zum default-Volume machen ===== | ||
| + | cd /mnt/btrfs | ||
| + | Snapshot des root-Volumes erstellen: | ||
| + | btrfs subvolume snapshot . 2025011300 | ||
| + | btrfs subvolume show 2025011300 | ||
| + | -> ''Subvolume ID'' kopieren, z.B. 258 | ||
| + | btrfs subvolume set-default 256 2025011300/ | ||
| + | Daten (nicht Subvolumes!) aus root-Volume löschen: | ||
| + | rm -rf --one-file-system /mnt/btrfs | ||
| + | |||
| + | testen: | ||
| + | ls | ||
| + | cd .. | ||
| + | umount btrfs | ||
| + | mount btrfs | ||
| + | ls btrfs | ||
| + | |||
| + | ===== Top-Subvolume mounten ===== | ||
| + | mkdir /mnt/btrfs | ||
| + | mount -o subvolid=5,subvol=/ /dev/sda2 /mnt/btrfs | ||
| + | <file txt /etc/fstab> | ||
| + | UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/btrfs btrfs noauto,subvolid=5,subvol=/ 0 0 | ||
| + | </file> | ||
| + | |||
| + | ===== 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 <id> <new-disk> <mount-point> | ||
| + | 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 . | ||
| + | |||
| + | ===== zum RAID1 erweitern ===== | ||
| + | btrfs device add /dev/vde . | ||
| + | btrfs -v balance start -mconvert=raid1,soft -dconvert=raid1,soft . | ||
| + | btrfs device usage . | ||
| + | |||
| + | ====== BTRFS bei SuSE ====== | ||
| + | ++++ SuSE default root layout | | ||
| SuSE default: | SuSE default: | ||
| Zeile 81: | Zeile 189: | ||
| subvolid=$(btrfs subvolume show $target/@/.snapshots/1/snapshot | sed -rn 's/.*Object ID:\s+//p') | subvolid=$(btrfs subvolume show $target/@/.snapshots/1/snapshot | sed -rn 's/.*Object ID:\s+//p') | ||
| btrfs subvolume set-default "$subvolid" "$target" | btrfs subvolume set-default "$subvolid" "$target" | ||
| + | ++++ | ||