posts:node: Add a post on Node and npm
[blog.git] / posts / btrfs.mdwn
1 I'm currently migrating my netbook's SSD to [btrfs][] to save space
2 and increase corruption checking.  Here are my notes on what I did.
3
4 The netbook uses a USB stick to store its entire file system.  Small
5 and slow, but cheap (actually, this USB stick was free as in beer ;).
6 I initially tried to convert to btrfs on the fly, but I'd previously
7 had it running [ext2][] with 1 [KiB][] blocks, and `btrfs-convert`
8 didn't like the small blocks.
9
10 So we'll have to create a new filesystem from scratch.  Plug the USB
11 stick into a real computer to rework the drive, and copy the data off
12 the old partition:
13
14     # mkdir /mnt/btrfs
15     # mount /dev/sdb2 /mnt/btrfs
16     # mkdir /tmp/old
17     # rsync -av /mnt/btrfs/ /tmp/old/
18
19 Unmount and create a new file system on your partition:
20
21     # umount /dev/sdb2
22     # mkfs.btrfs -L GENTOO -m single -d single /dev/sdb2
23
24 Note that I've disabled raid for both the metadata and data to save
25 space.  This will make it harder to recover from corruption, but the
26 checksumming will still detect the *presence* of corruption.  Now,
27 mount the new filesystem:
28
29     # mount -t btrfs -o compress,compress-force,ssd,noacl /dev/sdb2 /mnt/btrfs
30
31 and populate `/mnt/btrfs` with the filesystem for the netbook:
32
33     # rsync -av /tmp/old/ /mnt/btrfs/
34
35 I'm not sure exactly how much space I've saved (I forgot to check
36 while I was still in ext2), and free space is a [tricky issue][space],
37 but:
38
39     $ df -h /dev/sdb2
40     Filesystem            Size  Used Avail Use% Mounted on
41     /dev/sdb2             3.7G  1.3G  2.5G  34% /tmp/a
42     $ btrfs filesystem df /mnt/btrfs/
43     Data: total=1.47GB, used=951.89MB
44     Metadata: total=776.00MB, used=289.24MB
45     System: total=4.00MB, used=4.00KB
46     # btrfs filesystem show /dev/sdb2
47     Label: 'GENTOO'  uuid: 3c4ba41f-13ca-4549-b093-e0114e748d88
48             Total devices 1 FS bytes used 1.21GB
49             devid    1 size 3.66GB used 2.24GB path /dev/sdb2
50
51     Btrfs Btrfs v0.19
52
53 So now there is plenty of breathing room.
54
55 Besides checksumming and compression, I was also interested in
56 [snapshots][].  Take a snapshot with
57
58     # btrfs subvolume snapshot /mnt/btrfs /mnt/btrfs/snapshot_name
59
60 Mount the snapshot with
61
62     # mount -t btrfs -o subvol=snapshot_name,... /dev/sdb2 /mnt/btrfs
63
64 [btrfs]: http://btrfs.wiki.kernel.org/
65 [ext2]: http://en.wikipedia.org/wiki/Ext2
66 [KiB]: http://en.wikipedia.org/wiki/Kibibyte
67 [space]: https://btrfs.wiki.kernel.org/index.php/FAQ#Why_are_there_so_many_ways_to_check_the_amount_of_free_space.3F
68 [snapshots]: https://btrfs.wiki.kernel.org/index.php/UseCases#Snapshots_and_subvolumes
69
70 [[!tag tags/linux]]