Hi,
my collection of btrfs command line snippets.
Create and mount a filesystem
1 2 | root@debdev:~ # mkfs.btrfs /dev/sdb1 root@debdev:~ # mount /dev/sdb1 /mnt/sdb1 |
Create and delete subvolume
1 2 | root@debdev:~ # btrfs subvolume create /mnt/sdb1/subvol root@debdev:~ # btrfs subvolume delete /mnt/sdb1/subvol |
Show information of a btrfs volume
1 2 3 4 | root@debdev:~ # btrfs filesystem show /mnt/sdb1/ Label: none uuid: c818d114-5541-4cd3-9614-a4a96cb82427 Total devices 1 FS bytes used 208.00KiB devid 1 size 8.00GiB used 843.00MiB path /dev/sdb1 |
Disk free
1 | root@debdev:~ # btrfs filesystem df /mnt/sdb1 |
Disk usage
1 | root@debdev:~ # btrfs filesystem du /mnt/sdb1 |
Start scrubbing(check data integrity on your volume)
1 | root@debdev:~ # btrfs scrub start /mnt/sdb1 |
Mount a subvolume
1 2 3 | root@debdev:~ # btrfs subvolume list /mnt/sdb1 ID 257 gen 12 top level 5 path subvol root@debdev:~ # mount -o subvolid=257 /dev/sdb1 /mnt/subvol |
Create a snapshot, a snapshot is a subvolume
1 2 3 4 | root@debdev:~ # mkdir /mnt/sdb1/.snaps root@debdev:~ # btrfs subvolume snapshot /mnt/sdb1 /mnt/sdb1/.snaps/snapshot-`date +\%Y\%m\%d-\%H\%M%S` Create a snapshot of '/mnt/sdb1' in '/mnt/sdb1/.snaps/snapshot-20160718-215933' root@debdev:~ # btrfs subvolume delete /mnt/sdb1/.snaps/snapshot-20160718-215933 |
Make a snapshot/subvolume as default mount point
1 | root@debdev:~ # btrfs subvolume set-default 257 /mnt/sdb1 |
And set back to default
1 | root@debdev:~ # btrfs subvolume set-default 0 /mnt/sdb1 |
Set a Quota on a subvolume
1 | root@debdev:~ # btrfs qgroup limit 30M /mnt/sdb1 |
Add more space by adding a new harddisk to the volume. Note: If one device fails the whole volume is lost.
1 | root@debdev:~ # btrfs device add /dev/sdc1 /mnt/sdb1 |
Show filesystem information
1 2 3 4 5 | root@debdev:~ # btrfs filesystem show /mnt/sdb1/ Label: none uuid: c818d114-5541-4cd3-9614-a4a96cb82427 Total devices 2 FS bytes used 272.00KiB devid 1 size 8.00GiB used 891.00MiB path /dev/sdb1 devid 2 size 8.00GiB used 0.00B path /dev/sdc1 |
Remove a disk/device from a volume. All datas are moved to the remaining devices
1 | root@debdev:~ # btrfs device delete /dev/sdc1 /mnt/sdb1 |
Convert your volume to RAID1 (two devices necessary), Data (-d) and Metadata (-m)
1 | root@debdev:~ # btrfs balance start -mconvert=raid1 -dconvert=raid1 /mnt/sdb1 |
Check RAID level and errors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | root@debdev:~ # btrfs device usage /mnt/sdb1 /dev/sdb1 , ID: 1 Device size: 8.00GiB Data,single: 1.00GiB Data,RAID1: 2.00GiB Metadata,RAID1: 256.00MiB System,RAID1: 32.00MiB Unallocated: 4.72GiB /dev/sdc1 , ID: 2 Device size: 8.00GiB Data,RAID1: 2.00GiB Metadata,RAID1: 256.00MiB System,RAID1: 32.00MiB Unallocated: 5.72GiB |
RAID1 for new disks
1 | root@debdev:~ # mkfs.btrfs -d raid1 -m raid1 /dev/sdb1 /dev/sdc1 |
Replace a Disk if it is missing or failed
1 | root@debdev:~ # mount -t btrfs -o degraded /dev/sdc1 /mnt/sdb1 |
Find partition with btrfs signature
1 | root@debdev:~ # blkid |
Recover if device 1 (dev/sdb1) is missing. After a reboot /dev/sdc1 is now /dev/sdb1
1 2 3 | root@debdev:~ # btrfs filesystem show /dev/sdb1 warning, device 1 is missing root@debdev:~ # mount -t btrfs -o ro,degraded,usebackuproot /dev/sdb1 /mnt/sdb1 |
Get the missing device ID
1 2 3 4 5 6 7 8 9 10 11 | root@debdev:~ # btrfs device stats /mnt/sdb1 [devid:1].write_io_errs 0 [devid:1].read_io_errs 0 [devid:1].flush_io_errs 0 [devid:1].corruption_errs 0 [devid:1].generation_errs 0 [ /dev/sdb1 ].write_io_errs 0 [ /dev/sdb1 ].read_io_errs 0 [ /dev/sdb1 ].flush_io_errs 0 [ /dev/sdb1 ].corruption_errs 0 [ /dev/sdb1 ].generation_errs 0 |
And recover to a new disk/partition, currently /dev/sdc1
1 2 | root@debdev:~ # btrfs replace start 1 /dev/sdc1 /mnt/sdb1 root@debdev:~ # btrfs balance /mnt/sdb1 |
Convert your volume to RAID0
1 | root@debdev:~ # btrfs balance start -dconvert=raid0 -mconvert=raid0 -f /mnt/sdb1 |
Or to single volume
1 | root@debdev:~ # btrfs balance start -mconvert=single -dconvert=single /mnt/sdb1 |
Reorganize all datas
1 | root@debdev:~ # btrfs balance |
to be continued
Michael