meta data for this page
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| linux:fs:btrfs_as_root [2015/07/17 06:25] – external edit 127.0.0.1 | linux:fs:btrfs_as_root [2017/01/18 21:41] (current) – niziak | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | === System overview === | + | ====== BTRFS as root filesystem ====== |
| + | |||
| + | ===== System overview | ||
| - /dev/sda1 4.08GB ext4 "/" | - /dev/sda1 4.08GB ext4 "/" | ||
| - /dev/sda2 10.91GB extended | - /dev/sda2 10.91GB extended | ||
| Line 5: | Line 7: | ||
| - /dev/sda6 10.40GB ext4 "/ | - /dev/sda6 10.40GB ext4 "/ | ||
| - | === Boot from live-cd === | + | ===== Boot from live-cd |
| Btrfs support is heavily developed in Linux Kernel. So do not use old kernel. | Btrfs support is heavily developed in Linux Kernel. So do not use old kernel. | ||
| - | I was using gparted-live-0.22.0-1-amd64.iso | + | I was using gparted-live-0.22.0-1-amd64.iso |
| (NOTE: to match your existing system architecture (i586, amd64, etc)) | (NOTE: to match your existing system architecture (i586, amd64, etc)) | ||
| Which contains: | Which contains: | ||
| - Kernel 3.16.0-4-586 | - Kernel 3.16.0-4-586 | ||
| - btrfs utils version 3.17 | - btrfs utils version 3.17 | ||
| - | | ||
| - | | ||
| - | === Conversion === | ||
| - | fsck -f /dev/sda1 | ||
| - | fsck -f /dev/sda6 | ||
| - | btrfs-convert /dev/sda1 | ||
| - | Disk usage before conversion: used 1.56GB, free 2.53GB | + | ===== Update to kernel 4 ===== |
| - | after conversion: used 1.65GB, free 2.43GB | + | |
| - | + | ||
| - | btrfs check /dev/sda1 | + | |
| - | + | ||
| - | === Update system | + | |
| - | Mount new root filesystem: | + | |
| - | + | ||
| - | mount /dev/sda1 /mnt | + | |
| - | for i in dev dev/pts proc sys ; do mount --bind /$i /mnt/$i ; done | + | |
| - | chroot /mnt | + | |
| - | + | ||
| - | get new UUID of /dev/sda1 using " | + | |
| - | mount /dev/sda1 somewhere, go to etc/fstab and update to new UUID: | + | |
| - | + | ||
| - | UUID=a74f5787-aee1-4981-b7e6-fbd3cb6ac919 / | + | |
| - | + | ||
| - | update-grub | + | |
| - | grub-install /dev/sda | + | |
| - | + | ||
| - | exit | + | |
| - | + | ||
| - | reboot | + | |
| - | and remove Live CD with Gparted | + | |
| - | + | ||
| - | Rollback to ext2 is possible. There is subvolume ext2_saved on filesystem | + | |
| - | # btrfs subvolume list / | + | |
| - | To delete backup | + | |
| - | # btrfs subvolume delete / | + | |
| - | + | ||
| - | + | ||
| - | === Redundancy === | + | |
| - | + | ||
| - | === Prepare 2nd disc === | + | |
| - | Lets assume that we have 2nd disc for other than system stuff, but we want | + | |
| - | to use it as backup solution for system disc. System should be able to boot if one | + | |
| - | disc fails. | + | |
| - | + | ||
| - | "By default, metadata will be mirrored across two devices and data will be striped across all of the devices present. | + | |
| - | If only one device is present, metadata will be duplicated on that one device. " | + | |
| - | + | ||
| - | Make second disc bootable: | + | |
| - | grub-install /dev/sdb | + | |
| - | + | ||
| - | Now we have running and bootable system from BTRFS at /dev/sda1 | + | |
| - | Add second device to / volume. Device is unformatted, | + | |
| - | + | ||
| - | btrfs device add /dev/sdb1 / | + | |
| - | + | ||
| - | # btrfs filesystem show | + | |
| - | Label: none uuid: 2a3f41d6-571c-4ed5-91f1-ca5f5c1d3b5e | + | |
| - | Total devices 2 FS bytes used 1.37GiB | + | |
| - | devid 1 size 4.08GiB used 4.08GiB path /dev/sda1 | + | |
| - | devid 2 size 5.00GiB used 0.00B path /dev/sdb1 | + | |
| - | + | ||
| - | Btrfs v3.17 | + | |
| - | + | ||
| - | Replicate data to second volume. | + | |
| - | General command: | + | |
| - | + | ||
| - | btrfs balance start -d < | + | |
| - | + | ||
| - | Starts balance action on data (-d) and metadata (-m). | + | |
| - | For details please look into man btrfs balance | + | |
| - | Full command: | + | |
| - | + | ||
| - | btrfs balance start -dconvert=< | + | |
| - | + | ||
| - | Possible profiles are: raid0, raid1, raid10, raid5, raid6, dup, single | + | |
| - | + | ||
| - | single - is to put single copy of data (not stripping) and duplicated metadata | + | |
| - | + | ||
| - | dup - duplicate metadata - but it is not guaranteed that metadata is duplicated on separate devices | + | |
| - | + | ||
| - | "For now, RAID-1 means 'one copy of what's important exists on two of the drives | + | |
| - | in the array no matter how many drives there may be in it' | + | |
| - | + | ||
| - | It is possible to crate raid1 profile in degraded state, | + | |
| - | to add real 2nd hard disc later. | + | |
| - | As 2nd disc use small loop device and after creation remove loop device and remount | + | |
| - | in degraded mode. | + | |
| - | + | ||
| - | + | ||
| - | # btrfs fi df / | + | |
| - | Data, single: total=2.69GiB, | + | |
| - | System, single: total=32.00MiB, | + | |
| - | Metadata, single: total=1.36GiB, | + | |
| - | GlobalReserve, | + | |
| - | + | ||
| - | + | ||
| - | btrfs balance start -dconvert=dup -mconvert=dup / | + | |
| - | + | ||
| - | === Error: unable to start balance === | + | |
| - | ERROR in dmesg: | + | |
| - | [ 2687.757913] BTRFS error (device sda1): unable to start balance with target data profile 32 | + | |
| - | + | ||
| - | Update to kernel 4.0.2 and btrfs-tools v4 doesn' | + | |
| - | Probably dup (profile 32) cannot be used for data. | + | |
| - | + | ||
| - | It works: | + | |
| - | btrfs balance start -dconvert=raid1 -mconvert=raid1 / | + | |
| - | + | ||
| - | === Drive fail === | + | |
| - | Now shutdown system and disconnect 2nd drive | + | |
| - | + | ||
| - | Boot fail | + | |
| - | BTRFS: failed to read the system array on sda1 | + | |
| - | BTRFS: open_cree failed | + | |
| - | + | ||
| - | And initramfs console appear. | + | |
| - | + | ||
| - | mkdir /mnt | + | |
| - | mount /dev/sda1 /mnt | + | |
| - | + | ||
| - | the same error | + | |
| - | + | ||
| - | mount /dev/sda1 /mnt -odegraded | + | |
| - | + | ||
| - | WORKS! | + | |
| - | + | ||
| - | To boot automatically kernel with degraded btrfs, please add " | + | |
| - | / | + | |
| - | GRUB_CMDLINE_LINUX_DEFAULT=" | + | |
| - | Add to grub and fstab. Then update grub: | + | |
| - | update-grub | + | |
| - | grub-install /dev/sda | + | |
| - | grub-install /dev/sdb | + | |
| - | + | ||
| - | Remove missing device : | + | |
| - | btrfs device delete missing / | + | |
| - | + | ||
| - | Add new disc: | + | |
| - | btrfs device add /dev/sdb / | + | |
| - | + | ||
| - | Remove missing device - word ' | + | |
| - | btrfs device delete missing / | + | |
| - | + | ||
| - | ERROR: error removing the device ' | + | |
| - | + | ||
| - | There is command | + | |
| - | btrfs replace | + | |
| - | + | ||
| - | btrfs replace start -r 2 /dev/sdb1 / | + | |
| - | + | ||
| - | Because device is removed from system followin parameters are used: | + | |
| - | -r - use raid redundancy mechanism | + | |
| - | 2 - dev id | + | |
| - | /dev/sdb1 - new free device (not assigned to any btrfs) | + | |
| - | / - mount point | + | |
| - | + | ||
| - | Device needs to be same or greater size, but I made ideal clone of /dev/sda disc using sfdisk and | + | |
| - | above command complains that: | + | |
| - | BTRFS error (device sda1): target device is smaller than source device! | + | |
| - | + | ||
| - | So I created bigger device and replace process starts. With some errors in dmesg: | + | |
| - | + | ||
| - | [ 3185.709933] BTRFS: checksum error at logical 6796906496 on dev /dev/sda1, sector 5898312, root 5, inode 163698, offset 244748288, length 4096, links 1 (path: zero) | + | |
| - | [ 3185.711283] BTRFS: bdev /dev/sda1 errs: wr 0, rd 0, flush 0, corrupt 10, gen 0 | + | |
| - | [ 3185.712447] BTRFS: unable to fixup (regular) error at logical 6796906496 on dev /dev/sda1 | + | |
| - | [ 3190.557027] scrub_handle_errored_block: | + | |
| - | + | ||
| - | and finally | + | |
| - | + | ||
| - | [ 3305.403916] BTRFS: dev_replace from <missing disk> (devid 2) to /dev/sdb1 finished | + | |
| - | + | ||
| - | btrfs replace status / | + | |
| - | Started on 15.Jul 22:38:55, finished on 15.Jul 22:40:55, 0 write errs, 0 uncorr. read errs | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | Grub installed to /dev/sda /dev/sdb | + | |
| - | Test - remove sda, | + | |
| - | + | ||
| - | In grub menu - additional option to boot debian 8 from sdb1 shows. | + | |
| - | Booting from sdb1 stops an initramfs, because option to mount degraded is missing. | + | |
| - | + | ||
| - | Booting from original options, stuck on | + | |
| - | "A start job is running for dev-disk-by\x2duuid-fb8d9... 55s / 1min 30s" | + | |
| - | After timeout 1:30, system boots into emergency mode. | + | |
| - | "Give root password for maintenance" | + | |
| - | "(or type Control+D to continue) | + | |
| - | + | ||
| - | journalctl -a | + | |
| - | Jul 16 22:22:17 debian kernel: work still pending | + | |
| - | Jul 16 22:23:43 debian systemd[1]: Job dev-disk-by\x2duuid-fb8d97df\x2d625b\x2d440d\x2db63b\x2dcb529586df24.device/ | + | |
| - | Jul 16 22:23:43 debian systemd[1]: Timed out waiting for device dev-disk-by\x2duuid-fb8d97df\x2d625b\x2d440d\x2db63b\x2dcb529586df24.device. | + | |
| - | Jul 16 22:23:43 debian systemd[1]: Dependency failed for /home. | + | |
| - | Jul 16 22:23:43 debian systemd[1]: Dependency failed for Local File Systems. | + | |
| - | Jul 16 22:23:43 debian systemd[1]: Dependency failed for File System Check on / | + | |
| - | Jul 16 22:23:43 debian systemd-journal[177]: | + | |
| - | + | ||
| - | / | + | |
| - | + | ||
| - | + | ||
| - | This is because /home directory is missing (it was located on /dev/sda2) | + | |
| - | but whole /dev/sda removed. | + | |
| - | This bad behaviour, because I want system to be bootable even without additional disc. | + | |
| - | + | ||
| - | + | ||
| - | === TODO === | + | |
| - | Network in initramfs with SSH to repair remotely | + | |
| - | Network with SSH in maintenance mode | + | |
| - | + | ||
| - | === Bulletproof system === | + | |
| - | Run dropbear on alternative SSH port | + | |
| - | apt-get install dropbear | + | |
| - | / | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | === Update to kernel 4 === | + | |
| Edit / | Edit / | ||
| + | <code bash> | ||
| apt-get update | apt-get update | ||
| apt-get install linux-image-amd64 | apt-get install linux-image-amd64 | ||
| apt-get install btrfs-tools | apt-get install btrfs-tools | ||
| update-initramfs -u | update-initramfs -u | ||
| + | </ | ||
| + | |||
| + | * ERROR: Warning: / | ||
| + | * EXPLANATION: | ||
| + | * SOLUTION: ln -s / | ||
| + | |||
| + | Check btrfs-tools version | ||
| + | <code bash>/ | ||
| - | ERROR: Warning: / | ||
| - | EXPLANATION: | ||
| - | SOLUTION: ln -s / | ||
| - | /bin/btrfs version | + | ===== Converting dirs into subvolumes |
| + | 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. | ||
| + | Proposed subvolumes structure (where / is BTRFS root) | ||
| + | * /@ | ||
| + | * /@home | ||
| + | * /@var | ||
| + | Mount BTRFS filesystem (BTRFS root) to /mnt/btrfs. | ||
| + | ==== root ==== | ||
| + | * take a snapshot of root volume. Name of snapshot is ' | ||
| + | * '' | ||
| + | * delete files on BTRFS root (/ | ||
| + | * make @ subvolume a default root | ||
| + | * update fstab:< | ||
| + | * OR | ||
| + | * get @ subvolume id '' | ||
| + | * set default subvolume to use when system is mounted '' | ||
| + | ==== subdirectories ==== | ||
| + | * On BTRFS root create a new subvolume | ||
| + | * '' | ||
| + | * move files into the new subvolume as if it were a directory | ||
| + | * '' | ||
| + | * '' | ||
| + | * remove old directory | ||
| + | * '' | ||
| + | * update /etc/fstab to mount @home as /home | ||
| + | ===== fstab ==== | ||
| + | Do not use '' | ||
| + | Example working fstab file: | ||
| + | <file | / | ||
| + | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / | ||
| + | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / | ||
| + | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / | ||
| + | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / | ||
| + | UUID=ed730508-753e-4a7f-ac1e-bf8646f7bd63 / | ||
| + | </ | ||
| + | To prevent systemd to halt system during startup if device is not found (nofail and x-systemd.device-timeout): | ||
| + | <file | / | ||
| + | UUID=< | ||
| + | </ | ||
| + | NOTE: do not use autodefrag - it consumes lots of cpu | ||