meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:fs:btrfs_as_root [2016/04/21 08:07] niziak [Converting dirs into subvolumes] |
linux:fs:btrfs_as_root [2017/01/18 21:41] (current) niziak |
||
---|---|---|---|
Line 16: | Line 16: | ||
- btrfs utils version 3.17 | - btrfs utils version 3.17 | ||
- | |||
- | ===== Conversion ===== | ||
- | <code bash> | ||
- | fsck -f /dev/sda1 | ||
- | fsck -f /dev/sda6 | ||
- | |||
- | btrfs-convert /dev/sda1 | ||
- | </code> | ||
- | |||
- | Disk usage before conversion: used 1.56GB, free 2.53GB | ||
- | after conversion: used 1.65GB, free 2.43GB | ||
- | |||
- | <code bash>btrfs check /dev/sda1</code> | ||
- | |||
- | ===== Update system ===== | ||
- | Mount new root filesystem: | ||
- | |||
- | <code bash> | ||
- | mount /dev/sda1 /mnt | ||
- | for i in dev dev/pts proc sys ; do mount --bind /$i /mnt/$i ; done | ||
- | chroot /mnt | ||
- | </code> | ||
- | |||
- | get new UUID of /dev/sda1 using "blkid" | ||
- | mount /dev/sda1 somewhere, go to etc/fstab and update to new UUID: | ||
- | |||
- | UUID=a74f5787-aee1-4981-b7e6-fbd3cb6ac919 / btrfs defaults 0 1 | ||
- | |||
- | <code bash> | ||
- | update-grub | ||
- | grub-install /dev/sda | ||
- | |||
- | exit | ||
- | |||
- | reboot | ||
- | </code> | ||
- | |||
- | and remove Live CD with Gparted | ||
- | |||
- | ===== rollback to ext FS ===== | ||
- | Rollback to ext2 is possible. There is subvolume ext2_saved on filesystem. | ||
- | <code bash>btrfs subvolume list /</code> | ||
- | To delete backup | ||
- | <code bash>btrfs subvolume delete /ext2_saved</code> | ||
===== Update to kernel 4 ===== | ===== Update to kernel 4 ===== | ||
Line 79: | Line 35: | ||
===== Converting dirs into subvolumes ===== | ===== Converting dirs into subvolumes ===== | ||
- | To make backups, snapshoting, moving much easier and faster, every directory you want to backup by snapshot should be a subvolume. Also root filesystem should be created in separate subvolume not in btrfs root. | + | To make backups, snapshots, moving much easier and faster, every directory you want to backup by snapshot should be a subvolume. Also root filesystem should be created in separate subvolume not in btrfs root. |
To distinguish volumes from directories we will use @ character at beginning of subvolume name. This is Ubuntu naming convention for subvolumes. | To distinguish volumes from directories we will use @ character at beginning of subvolume name. This is Ubuntu naming convention for subvolumes. | ||
Line 87: | Line 43: | ||
* /@home | * /@home | ||
* /@var | * /@var | ||
+ | |||
+ | Mount BTRFS filesystem (BTRFS root) to /mnt/btrfs. | ||
==== root ==== | ==== root ==== | ||
- | * take a snapshot of root volume | + | * take a snapshot of root volume. Name of snapshot is '@' |
- | * ''btrfs subvolume snapshot . @root'' | + | * ''btrfs subvolume snapshot /mnt/btrfs @'' |
- | * make @root subvolume a default root | + | * delete files on BTRFS root (/mnt/btrfs) |
- | * update <file | /etc/fstab> | + | * make @ subvolume a default root |
- | UUID=739e6086-d925-4bdb-94f5-26d8c10dc171 / btrfs defaults,subvol=@root | + | * update fstab:<file | /etc/fstab>UUID=739e6086-d925-4bdb-94f5-26d8c10dc171 / btrfs defaults,subvol=@</file> |
- | </file> | + | * OR |
- | or | + | * get @ subvolume id ''btrfs subvolume list /mnt/btrfs'' |
- | * set @root subvolume default mount path ''btrfs subvolume set-default @root /'' | + | * set default subvolume to use when system is mounted ''btrfs subvolume set-default 256 /mnt/btrfs'' |
- | * | + | |
- | * move directory to subvolume (cp --reflink is much faster on BTRFS) | + | |
==== subdirectories ==== | ==== subdirectories ==== | ||
Line 105: | Line 62: | ||
* move files into the new subvolume as if it were a directory | * move files into the new subvolume as if it were a directory | ||
* ''mv /mnt/btrs/@/home/* /mnt/btrfs/@home/'' | * ''mv /mnt/btrs/@/home/* /mnt/btrfs/@home/'' | ||
+ | * ''cp --reflink'' is much faster on BTRFS | ||
* remove old directory | * remove old directory | ||
* ''rmdir /mnt/btrfs/@/home'' | * ''rmdir /mnt/btrfs/@/home'' | ||
* update /etc/fstab to mount @home as /home | * update /etc/fstab to mount @home as /home | ||
+ | ===== fstab ==== | ||
+ | Do not use ''errors=remount-ro'' option which is not valid for BTRFS. | ||
+ | Example working fstab file: | ||
+ | <file | /etc/fstab> | ||
+ | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / btrfs defaults,subvol=@,compress=no 0 0 | ||
+ | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 /var btrfs defaults,subvol=@var,compress=no 0 0 | ||
+ | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 /var/log btrfs defaults,subvol=@varlog,compress=no 0 0 | ||
+ | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 /home btrfs defaults,subvol=@home,compress=no 0 0 | ||
+ | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 /mnt/btrfs btrfs noauto,defaults,subvolid=5,compress=no 0 0 | ||
+ | </file> | ||
+ | |||
+ | To prevent systemd to halt system during startup if device is not found (nofail and x-systemd.device-timeout): | ||
+ | <file | /etc/fstab> | ||
+ | UUID=<the_device_uuid> /mount/point btrfs nofail,x-systemd.device-timeout=10,noatime,compress=lzo,autodefrag 0 0 | ||
+ | </file> | ||
+ | NOTE: do not use autodefrag - it consumes lots of cpu |