Initial guide of BtrFs


link: http://manpages.courier-mta.org/htmlman8/wipefs.8.html



First lets list our volumes on the machine before plugin an new usb disk:

lsblk -f
NAME   FSTYPE LABEL    UUID                                 MOUNTPOINT
sda                                                         
├─sda1 vfat   SYSTEM   1AD8-5F99                            /boot/efi
├─sda2 ntfs   Recovery 1072DD5B72DD45DE                     
├─sda3                                                      
├─sda4 ntfs   OS       B6C4E84CC4E81103                     
├─sda5 ntfs            B6888D7C888D3BBD                     
├─sda6 ntfs   Data     3052F17652F14160                     
├─sda7 ext4            996041a9-b7de-4d69-8373-a7e8796f085e /
├─sda8 swap            d318244a-2bcf-435e-891d-fced6caa71a8 [SWAP]
└─sda9 ntfs   Restore  AADCFB33DCFAF901                     


Now plugin the usb drive and the results are:
NAME   FSTYPE LABEL    UUID                                 MOUNTPOINT
sda                                                         
├─sda1 vfat   SYSTEM   1AD8-5F99                            /boot/efi
├─sda2 ntfs   Recovery 1072DD5B72DD45DE                     
├─sda3                                                      
├─sda4 ntfs   OS       B6C4E84CC4E81103                     
├─sda5 ntfs            B6888D7C888D3BBD                     
├─sda6 ntfs   Data     3052F17652F14160                     
├─sda7 ext4            996041a9-b7de-4d69-8373-a7e8796f085e /
├─sda8 swap            d318244a-2bcf-435e-891d-fced6caa71a8 [SWAP]
└─sda9 ntfs   Restore  AADCFB33DCFAF901                     
sdb   

We have an new blank disk plugged in !!!

First install needed tools:

sudo apt install btrfs-tools tree

Delete any signature of another file system and creates a signature backup file ~/wipefs-sdb-<offset>.bak for each signature with command:
sudo wipefs --all --backup /dev/sdb

sudo dd if=~/wipefs-sdb-0x00000438.bak of=/dev/sdb seek=$((0x00000438)) bs=1 conv=notrunc()
Restores an ext2 signature from the backup file ~/wipefs-sdb-0x00000438.bak.


Lets create an btrfs volume at sdb:

sudo mkfs.btrfs -f -d single -m dup -L root /dev/sdb

btrfs-progs v4.4
See http://btrfs.wiki.kernel.org for more information.
Label: root
UUID: 1da2f837-675c-41de-ac88-088bcab75199
Node size: 16384
Sector size: 4096
Filesystem size: 2.73TiB
Block group profiles:
Data: single 8.00MiB
Metadata: DUP 1.01GiB
System: DUP 12.00MiB
SSD detected: no
Incompat features: extref, skinny-metadata
Number of devices: 1
Devices:
ID SIZE PATH
1 2.73TiB /dev/sdb

Check status of btrfs :
sudo btrfs fi show
Label: 'root' uuid: 1da2f837-675c-41de-ac88-088bcab75199
 Total devices 1 FS bytes used 112.00KiB
devid 1 size 2.73TiB used 2.02GiB path /dev/sdb

Mount the device at /mnt/USB
sudo mount /dev/sdb /mnt/USB

Check usage os device:
sudo btrfs fi usage /mnt/USB
Overall:
    Device size: 2.73TiB
    Device allocated: 2.02GiB
    Device unallocated: 2.73TiB
    Device missing: 0.00B
    Used: 512.00KiB
    Free (estimated): 2.73TiB (min: 1.36TiB)
    Data ratio: 1.00
    Metadata ratio: 2.00
    Global reserve: 16.00MiB (used: 0.00B)
Data,single: Size:8.00MiB, Used:256.00KiB
    /dev/sdb 8.00MiB
Metadata,DUP: Size:1.00GiB, Used:112.00KiB
    /dev/sdb 2.00GiB
System,DUP: Size:8.00MiB, Used:16.00KiB
    /dev/sdb 16.00MiB
Unallocated:
    /dev/sdb 2.73TiB

There is no subvolume:
sudo btrfs subvolume list /mnt/USB

Now lets create rootfs subvolume and set it as default:
sudo btrfs subvolume create /mnt/USB/rootfs

There is 1 subvolume:
sudo btrfs subvolume list /mnt/USB
ID 257 gen 7 top level 5 path rootfs

List the directories:
tree -L 2 /mnt/USB/
/mnt/USB/
└── rootfs
1 directory, 0 files


You may mount this subvolume with:
sudo umount /mnt/USB
sudo mount -t btrfs -o subvol=rootfs LABEL=root /mnt/USB
or
sudo mount -t btrfs -o subvolid=257 LABEL=root /mnt/USB

Get the default subvolume:
sudo btrfs subvolume get-default /mnt/USB
ID 5 (FS_TREE)

Set it the default subvolume:
sudo btrfs subvolume set-default 257 /mnt/USB

Get the default subvolume again:
sudo btrfs subvolume get-default /mnt/USB
ID 257 gen 7 top level 5 path rootfs

Now lets create my own subvolumes:
sudo umount /mnt/USB
sudo mount -t btrfs -o subvolid=5 LABEL=root /mnt/USB

sudo mkdir /mnt/USB/snapshots
sudo btrfs subvolume create /mnt/USB/rootfs/home
sudo mkdir /mnt/USB/rootfs/srv
sudo btrfs subvolume create /mnt/USB/rootfs/srv/mysql
sudo btrfs subvolume create /mnt/USB/rootfs/srv/svn
sudo btrfs subvolume create /mnt/USB/rootfs/srv/www
sudo mkdir /mnt/USB/rootfs/srv/samba
sudo mkdir /mnt/USB/rootfs/srv/media
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Backups
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Documents
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Movies
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Music
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Pictures
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Server
sudo mkdir /mnt/USB/rootfs/srv/media/Torrent
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/Users
sudo btrfs subvolume create /mnt/USB/rootfs/srv/media/xxx

List them with:
sudo btrfs subvolume list /mnt/USB
ID 257 gen 30 top level 5 path rootfs
ID 258 gen 43 top level 257 path rootfs/home
ID 259 gen 44 top level 257 path rootfs/srv/mysql
ID 260 gen 47 top level 257 path rootfs/srv/svn
ID 261 gen 47 top level 257 path rootfs/srv/www
ID 262 gen 45 top level 257 path rootfs/srv/media/Backups
ID 263 gen 46 top level 257 path rootfs/srv/media/Documents
ID 264 gen 32 top level 257 path rootfs/srv/media/Movies
ID 265 gen 30 top level 257 path rootfs/srv/media/Music
ID 266 gen 35 top level 257 path rootfs/srv/media/Pictures
ID 267 gen 46 top level 257 path rootfs/srv/media/Server
ID 268 gen 34 top level 257 path rootfs/srv/media/Users
ID 269 gen 30 top level 257 path rootfs/srv/media/xxx



If you want to turn COW off on some directories with heavy read and write like database files you may just:
sudo chattr -R +C /mnt/USB/rootfs/srv/mysql

If you want to turn compress on on some directories with heavy read and write like database files you may just:
sudo btrfs filesystem defragment -r -v -czlib /mnt/USB/rootfs/srv/media/Backups
sudo chattr -R +c /mnt/USB/rootfs/srv/media/Backups

sudo btrfs filesystem defragment -r -v -clzo /mnt/USB/rootfs/srv/media/Documents
sudo chattr -R +c /mnt/USB/rootfs/srv/media/Documents

sudo btrfs filesystem defragment -r -v -czlib /mnt/USB/rootfs/srv/media/Server
sudo chattr -R +c /mnt/USB/rootfs/srv/media/Server

sudo btrfs filesystem defragment -r -v -czlib /mnt/USB/rootfs/srv/www
sudo chattr -R +c /mnt/USB/rootfs/srv/www

sudo btrfs filesystem defragment -r -v -czlib /mnt/USB/rootfs/srv/svn
sudo chattr -R +c /mnt/USB/rootfs/srv/svn


To delete a subvolume just issue:
sudo btrfs subvolume delete /mnt/USB/rootfs


To check intregity use:

sudo btrfs scrub start /mnt/USB/rootfs
sudo btrfs scrub status /mnt/USB/rootfs


check sumary information:
sudo btrfs filesystem df /mnt/USB/
Data, single: total=8.00MiB, used=256.00KiB
System, DUP: total=8.00MiB, used=16.00KiB
Metadata, DUP: total=1.00GiB, used=320.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B


To make snapshopt you need to mount btrfs and them execute: 
sudo mkdir /mnt/btrfs
sudo mount -t btrfs -o subvolid=5 LABEL=root /mnt/btrfs
sudo btrfs subvolume snapshot -r /mnt/btrfs/rootfs /mnt/btrfs/snapshots/rootfs.$(date +%Y-%m-%d)



The kernel config to boot btrfs should be compiled with these options:
General setup  --->
  [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
Device Drivers  --->
  [*] Multiple devices driver support (RAID and LVM)  --->
    {*}   RAID support
    [*]     Autodetect RAID arrays during kernel boot
    <*>     Linear (append) mode
    <*>     RAID-0 (striping) mode
    {*}     RAID-1 (mirroring) mode
    {*}     RAID-10 (mirrored striping) mode
    {*}     RAID-4/RAID-5/RAID-6 mode
File systems  --->
  <*> Btrfs filesystem support
  [*]   Btrfs POSIX Access Control Lists






O URL específico do gadget não foi encontrado