Btrfs is a relatively new file system which offers a number of features such as transparent compression, snapshots, online volume resizing, etc… It is increasingly used in GNU/Linux distributions. Here, I'll outline the main commands you need to know when using this file system.
⚠️To avoid data loss, ensure to back up your data before starting any resizing task. And make sure you understand the commands before entering them.⚠️
root@host:~# gdisk /dev/sda
Command (? for help): d
Partition number (1-3): 3
Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-125829086, default = 3147776) or {+-}size{KMGTP}: 3147776
Last sector (3147776-125829086, default = 167772126) or {+-}size{KMGTP}:
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
root@host:~# partprobe
root@host:~# btrfs filesystem resize max /
root@host:~# btrfs filesystem resize -1G /data/
root@host:~# btrfs scrub start /
root@host:~# btrfs scrub status /
root@host:~# btrfs subvolume create /home/SUBV
root@host:~# btrfs subvolume list /
root@host:~# mount /dev/sda3 -o subvol=SUBV /home/SUBV/
root@host:~# mkfs.btrfs /dev/sdb1
root@host:~# btrfs filesystem defragment -r -v /
root@host:~# btrfs filesystem usage /
root@host:~# btrfs filesystem du /home/user/file
root@host:~# btrfs filesystem df /
root@host:~# btrfs dev stats /
root@host:~# btrfs filesystem show /
root@host:~# btrfs subvolume list /
root@host:~# mkdir /.snapshots
root@host:~# btrfs subvolume snapshot -r / /.snapshots/\@$(date +%Y.%m.%d)
root@host:~# btrfs subvolume delete /.snapshots/@2024.05.04/
UUID=4e39e49c-6934-41f5-97fd-cb7c699a78a5 / btrfs defaults,compress=zstd,subvol=@rootfs 0 0
root@host:~# btrfs filesystem defragment -r -v -czstd /home/user/
Contact :