Hits : 4067


btrfs notes:



SubVolume & SnapShot


# btrfs subvolume create /mnt/data/subvolume_name
Create subvolume '/mnt/data/subvolume_name'
 
# ls -ld /mnt/data/subvolume_name
drwxr-xr-x 1 root root 0 Aug 11 23:21 /mnt/data/subvolume_name
 
# ls -la /mnt/data/subvolume_name/
total 4
drwxr-xr-x 1 root root  0 Aug 11 23:21 .
drwxr-xr-x 1 root root 70 Aug 11 23:21 ..
 
# btrfs subvolume show /mnt/data/subvolume_name/
/mnt/data/subvolume_name
	Name: 			subvolume_name
	uuid: 			8c19d666-2700-ed49-b7cc-483b82076d6b
	Parent uuid: 		–
	Creation time: 		2013-08-11 23:21:25
	Object ID: 		1294
	Generation (Gen): 	13705
	Gen at creation: 	13705
	Parent: 		5
	Top Level: 		5
	Flags: 			–
	Snapshot(s):
 
# btrfs subvolume list -a /mnt/data/subvolume_name/
ID 1294 gen 13705 top level 5 path <FS_TREE>/subvolume_name
 
# dmesg > /mnt/data/subvolume_name/dmesg.log
 
# ls -la /mnt/data/subvolume_name/
total 52
drwxr-xr-x 1 root root    18 Aug 11 23:22 .
drwxr-xr-x 1 root root    70 Aug 11 23:21 ..
-rw-r--r-- 1 root root 47948 Aug 11 23:22 dmesg.log
 
# btrfs subvolume snapshot -r /mnt/data/subvolume_name/ /mnt/data/subvolume_name_snap_01
Create a readonly snapshot of '/mnt/data/subvolume_name/' in '/mnt/data/subvolume_name_snap_01'
 
# ls -la /mnt/data/subvolume_name_snap_01/
total 52
drwxr-xr-x 1 root root    18 Aug 11 23:22 .
drwxr-xr-x 1 root root   114 Aug 11 23:23 ..
-rw-r--r-- 1 root root 47948 Aug 11 23:22 dmesg.log
 
# rm -f /mnt/data/subvolume_name_snap_01/dmesg.log 
rm: cannot remove '/mnt/data/subvolume_name_snap_01/dmesg.log': Read-only file system
 
# ls -la /mnt/data/subvolume_name/
total 52
drwxr-xr-x 1 root root    18 Aug 11 23:22 .
drwxr-xr-x 1 root root   114 Aug 11 23:23 ..
-rw-r--r-- 1 root root 47948 Aug 11 23:22 dmesg.log
 
# rm -f /mnt/data/subvolume_name/dmesg.log 
removed '/mnt/data/subvolume_name/dmesg.log'
 
# ls -la /mnt/data/subvolume_name_snap_01/
total 52
drwxr-xr-x 1 root root    18 Aug 11 23:22 .
drwxr-xr-x 1 root root   114 Aug 11 23:23 ..
-rw-r--r-- 1 root root 47948 Aug 11 23:22 dmesg.log
 
# btrfs subvolume delete /mnt/data/subvolume_name_snap_01/
Delete subvolume '/mnt/data/subvolume_name_snap_01'
 
# btrfs subvolume delete /mnt/data/subvolume_name
Delete subvolume '/mnt/data/subvolume_name'

top


mount a subvolume


# mount -t btrfs -o subvol=subvolume_name /dev/disk/by-uuid/a9b086df-d62b-40f7-bd05-4ff6911c3d24 /media/

# ls -la /media/
total 52
drwxr-xr-x  1 root root    18 Αύγ  11 23:37 .
drwxr-xr-x 19 root root  4096 Αύγ  11 11:00 ..
-rw-r--r--  1 root root 48104 Αύγ  11 23:37 dmesg.log


top


remove a disk


from a live mount point !


The btrfs is on UUID=a9b086df-d62b-40f7-bd05-4ff6911c3d24


# blkid
 
/dev/mapper/seagate250: LABEL="data" UUID="a9b086df-d62b-40f7-bd05-4ff6911c3d24" UUID_SUB="a12e4786-7033-4dd0-9c7c-11719e82ab2e" TYPE="btrfs" 
/dev/mapper/maxtor250 : LABEL="data" UUID="a9b086df-d62b-40f7-bd05-4ff6911c3d24" UUID_SUB="113ca627-caaf-453d-b29e-b2218fc9ac43" TYPE="btrfs" 
/dev/mapper/western1T : LABEL="data" UUID="a9b086df-d62b-40f7-bd05-4ff6911c3d24" UUID_SUB="8e6c89ad-7efc-4677-8242-db0e05337359" TYPE="btrfs" 
 
# df -h /mnt/data/
Filesystem      Size  Used Avail Use% Mounted on /dev/dm-6       1,4T  549G  366G  61% /mnt/data
 
# btrfs device delete /dev/mapper/seagate250 /mnt/data
 
... [wait] ...

on another shell:


# dmesg | tail

[ 3251.338634] btrfs: relocating block group 1671040073728 flags 9
[ 3292.008232] btrfs: found 14 extents
[ 3295.327223] btrfs: found 14 extents
[ 3295.990889] btrfs: relocating block group 1667818848256 flags 9

# df -h /mnt/data/
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-6       1,4T  550G  1,4T  30% /mnt/data


in the end 


# btrfs fi show

Label: 'data'  uuid: a9b086df-d62b-40f7-bd05-4ff6911c3d24
	Total devices 2 FS bytes used 547.53GB
	devid    1 size 931.51GB used 382.04GB path /dev/dm-6
	devid    3 size 233.76GB used 169.03GB path /dev/dm-5

Btrfs v0.20-rc1-253-g7854c8b


and


# df -h /mnt/data/
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-6       1,2T  549G  132G  81% /mnt/data


and 


# btrfs fi df /mnt/data/
Data, RAID0: total=336.00GB, used=334.03GB
Data: total=213.01GB, used=212.88GB
System, RAID1: total=32.00MB, used=56.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=1.00GB, used=628.14MB


top


add a new disk


before:


$ df
Filesystem                      1K-blocks      Used Available Use% Mounted on
/dev/mapper/western1T          1221875864 575344768 137364560  81% /mnt/data


adding:


# btrfs dev add /dev/mapper/western1Tb /mnt/data/


after:


$ df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/western1T           2,1T  549G  1,2T  33% /mnt/data


top


balance the data between disks


eg. raid0 example


# btrfs balance /mnt/data
# btrfs balance resume /mnt/data
# btrfs balance pause /mnt/data


top



scrubbing the btrfs mount point


# btrfs scrub start /mnt/data/
scrub started on /mnt/data/, fsid a9b086df-d62b-40f7-bd05-4ff6911c3d24 (pid=12408)

# btrfs scrub status /mnt/data/
scrub status for a9b086df-d62b-40f7-bd05-4ff6911c3d24
        scrub started at Thu Dec  5 13:58:47 2013, running for 200 seconds
        total bytes scrubbed: 18.49GB with 0 errors


top