btrfs is used by SUSE12 for the /root partition – where it is doing daily snapshots of the installed OS.
It has more functionality built-in than just storing files.
This article wants to take btrfs for a test-drive.
btrfs and raid
snapshots in 2012 with SuSE
Btrfs is a modern copy on write (CoW) filesystem for Linux aimed at implementing advanced features while also focusing on fault tolerance, repair and easy administration.
Jointly developed at multiple companies, Btrfs is licensed under the GPL and open for contribution from anyone.
The following companies use Btrfs in production:
- Facebook (testing in production as of 2014/04)
- Jolla (smartphone)
- Lavu (iPad point of sale solution. Used for compressed log storage on webservers.)
- Rockstor (BTRFS powered FOSS NAS solution)
- Tripadvisor (mid term log storage)
- NAS devices from Thecus support Btrfs support since FW 2.05.04 (release notes)
- Synology (NAS vendor) features Btrfs starting in DiskStation Manager (DSM) v6.0
- HostDime (as of 2017/01, used for backup drives and underlying FS for OpenStack cloud)
- Mendix (since end 2014) for backup servers using snapshots and rsync (remotes are mostly ext4) and for incremental replication (fast and often) for disaster recovery purposes using snapshots and send/receive (btrbk)
create and mount a btrfs partition
fdisk /dev/sdb; # create a new partition 10G mkfs.btrfs -L LABEL /dev/sdb7; # format it mkfs.btrfs -L LABEL -f /dev/sdb7; # if it is allready btrfs formatted btrfs-progs v4.7.3 See http://btrfs.wiki.kernel.org for more information. Performing full device TRIM (10.00GiB) ... Label: (null) UUID: Node size: 16384 Sector size: 4096 Filesystem size: 10.00GiB Block group profiles: Data: single 8.00MiB Metadata: DUP 1.00GiB System: DUP 8.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 10.00GiB /dev/sdb7 lsblk -fs|grep btrfs sdb7 btrfs 52b80a42-4737-4cc9-b939-afe0a8c6c0ea mkdir /mnt/btrfs; # create mountpoint mount /dev/sdb7 /mnt/btrfs; # mount the partition
show basic info about this filesystem
btrfs filesystem show; # show all available btrfs partitions Label: none uuid: 52b80a42-4737-4cc9-b939-afe0a8c6c0ea Total devices 1 FS bytes used 384.00KiB devid 1 size 10.00GiB used 2.02GiB path /dev/sdb7 btrfs filesystem df /mnt/btrfs/ Data, single: total=7.98GiB, used=7.98GiB System, DUP: total=8.00MiB, used=16.00KiB Metadata, DUP: total=1.00GiB, used=8.70MiB GlobalReserve, single: total=512.00MiB, used=0.00B
btrfs filesystem resize -1g /mnt/btrfs Resize '/mnt/btrfs' of '-1g' df -Th|grep btrfs /dev/sdb7 btrfs 9.0G 17M 7.0G 1% /mnt/btrfs btrfs filesystem resize +1g /mnt/btrfs Resize '/mnt/btrfs' of '+1g' df -Th|grep btrfs /dev/sdb7 btrfs 10G 17M 8.0G 1% /mnt/btrfs
create and restore snapshots
snapper is not SUSE only 😉
unfortunately – snapshots under btrfs – are a bit complicated IMHO.
Does snapper really revert everything?
Snapper will revert all files (text and binary) including permissions, ownership and extended attributes and also remove and recreate files and directories. File timestamps are not reverted. Some files are excluded, e.g. /etc/mtab.
It’s recommended to always use the status command to see in advance what files snapper will process. (Snapper FAQ)
Snapper is a command-line program for filesystem snapshot management. It can create, delete and compare snapshots and undo changes done between snapshots.
Snapper never modifies the content of snapshots.
Thus snapper creates read-only snapshots if supported by the kernel.
Supported filesystems are btrfs and ext4 as well as snapshots of LVM logical volumes with thin-provisioning.
Q: Does snapper support ext4?
A: Yes, but only experimentally and you need a special kernel and e2fsprogs. For more information see the next4 project. (src)
Some filesystems might not be supported depending on your installation.
apt-cache search btrfs|grep snap snapper - Linux filesystem snapshot management tool snapper -c LABEL create-config /mnt/btrfs/; # enable recurring snapshots for this partition ... stuck.
what are subvolumes?
Separate internal filesystem roots.
A Btrfs subvolume is an independently mountable POSIX filetree and not a block device (and cannot be treated as one). Most other POSIX filesystems have a single mountable root, Btrfs has an independent mountable root for the volume (top level subvolume) and for each subvolume; a Btrfs volume can contain more than a single filetree, it can contain a forest of filetrees. A Btrfs subvolume can be thought of as a POSIX file namespace.
A subvolume in Btrfs is not similar to a LVM logical volume or a ZFS subvolume. With LVM, a logical volume is a block device in its own right (which could for example contain any other filesystem or container like dm-crypt, MD RAID, etc.), this is not the case with Btrfs.
A Btrfs subvolume root directory differs from a directory in that each subvolume defines a distinct inode number space (distinct inodes in different subvolumes can have the same inumber) and each inode under a subvolume has a distinct device number (as reported by stat(2)). Each subvolume root can be accessed as implicitly mounted via the volume (top level subvolume) root, if that is mounted, or it can be mounted in its own right.
So, given a filesystem structure like this:
toplevel (volume root directory) +-- dir_1 (normal directory) | +-- file_2 (normal file) | \-- file_3 (normal file) \-- subvol_a (subvolume root directory) +-- subvol_b (subvolume root directory, nested below subvol_a) | \-- file_4 (normal file) \-- file_5 (normal file)
let’s create some:
btrfs subvolume create /mnt/btrfs/sub1 Create subvolume '/mnt/btrfs/sub1' btrfs subvolume create /mnt/btrfs/sub2 Create subvolume '/mnt/btrfs/sub2' btrfs subvolume create /mnt/btrfs/sub2/sub2.1 Create subvolume '/mnt/btrfs/sub2/sub2.1' btrfs subvolume list /mnt/btrfs; # show all subvolumes ID 257 gen 11 top level 5 path sub1 ID 258 gen 13 top level 5 path sub2 ID 259 gen 13 top level 258 path sub2/sub2.1
umount /dev/sdb7 root@debian9:~# btrfs check --repair /dev/sdb7 enabling repair mode Checking filesystem on /dev/sdb7 UUID: 52b80a42-4737-4cc9-b939-afe0a8c6c0ea checking extents Fixed 0 roots. checking free space cache cache and super generation don't match, space cache will be invalidated checking fs roots checking csums checking root refs found 393216 bytes used err is 0 total csum bytes: 0 total tree bytes: 131072 total fs tree bytes: 32768 total extent tree bytes: 16384 btree space waste bytes: 124760 file data blocks allocated: 262144 referenced 262144
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!