meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
linux:fs:btrfs:multidisk [2025/03/24 08:32] – removed - external edit (Unknown date) 127.0.0.1 | linux:fs:btrfs:multidisk [2025/03/24 08:32] (current) – ↷ Page moved and renamed from linux:fs:btrfs_multidisk to linux:fs:btrfs:multidisk niziak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== BTRFS on multiple devices ====== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== Encryption layout ===== | ||
+ | |||
+ | ==== BTRFS on crypted devices ==== | ||
+ | | btrfs raid1 || | ||
+ | | crypt | crypt | | ||
+ | | sda1 | ||
+ | |||
+ | * (-) Encryption has to be performed twice (no problem for modern CPUs) | ||
+ | * (+) Bit-flips can be detected immediately and corrected by BTRFS | ||
+ | * (-) not possible to get benefit from hybrid RAID1 (mixed disc HDD & SSD) | ||
+ | |||
+ | |||
+ | ==== BTRFS on crypted devices with LVM ==== | ||
+ | |||
+ | | btrfs raid1 || | ||
+ | | crypt | crypt | | ||
+ | | LVM | LVM | | ||
+ | | (DM-Cache on fast SSD) || | ||
+ | | sda1 | ||
+ | |||
+ | * (-) Encryption has to be performed twice (no problem for modern CPUs) | ||
+ | * (+) Bit-flips can be detected immediately and corrected by BTRFS | ||
+ | * (-) not possible to get benefit from hybrid RAID1 (mixed disc HDD & SSD) | ||
+ | * (-) small overhead from LVM but | ||
+ | * (+) DM-cache with SSD disc can be used: [[https:// | ||
+ | |||
+ | ==== BTRFS on soft RAID1 ==== | ||
+ | | btrfs || | ||
+ | | crypt || | ||
+ | | raid1 || | ||
+ | | sda1 | sdb1 | | ||
+ | |||
+ | * (+) encryption performed only once (less CPU consumption) | ||
+ | * (-) Bit-flips detected only during RAID1 scan. | ||
+ | * (+) Benefits from hybrid RAID1 (SSH & HHD) using " | ||
+ | |||
+ | |||
+ | |||
+ | ===== 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. | ||
+ | |||
+ | Copy partition layouts from sdb to sda drive: | ||
+ | <code bash> | ||
+ | sudo sfdisk -d /dev/sdb > parts | ||
+ | sudo sfdisk | ||
+ | </ | ||
+ | |||
+ | Recreate LVM layout if needed. | ||
+ | |||
+ | ===== btrfs 2nd disk ===== | ||
+ | ==== Add 2nd disc to btrfs ==== | ||
+ | <code bash> | ||
+ | btrfs device add / | ||
+ | btrfs device usage / | ||
+ | nice ionice -c3 btrfs balance start -v -dconvert=raid1 -mconvert=raid1 -dsoft -msoft / | ||
+ | btrfs device usage / | ||
+ | </ | ||
+ | Note: " | ||
+ | |||
+ | Make sure that data on both disc are the same. Especially system data are on both disc in RAID1 mode. | ||
+ | |||
+ | <code bash> | ||
+ | # btrfs device usage / | ||
+ | /dev/sda3, ID: 1 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | /dev/sdc5, ID: 2 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | OR | ||
+ | |||
+ | ==== Create blank 2nd disc ==== | ||
+ | NOT POSSIBLE: | ||
+ | |||
+ | < | ||
+ | <code bash> | ||
+ | mkfs.btrfs -d raid1 -m raid1 -L btrfs_pool2 / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Balance command ==== | ||
+ | <code bash> | ||
+ | |||
+ | 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 create 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 in degraded mode. | ||
+ | |||
+ | ==== 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: | ||
+ | <code bash> | ||
+ | |||
+ | |||
+ | ===== GRUB ===== | ||
+ | |||
+ | To boot automatically kernel with degraded btrfs, please add " | ||
+ | |||
+ | <file | / | ||
+ | GRUB_CMDLINE_LINUX_DEFAULT=" | ||
+ | </ | ||
+ | Add to grub and fstab. Then update grub: | ||
+ | <code bash> | ||
+ | update-grub | ||
+ | grub-install /dev/sda | ||
+ | grub-install /dev/sdb | ||
+ | reboot | ||
+ | </ | ||
+ | |||
+ | There is a boot issue (see below) when grub root dir (/ | ||
+ | |||
+ | * Install prerequisites | ||
+ | * <code bash> | ||
+ | * Duplicate boot partition size | ||
+ | * <code bash> | ||
+ | sudo sfdisk -d /dev/sda > parts | ||
+ | sudo sfdisk | ||
+ | </ | ||
+ | * copy data from ''/ | ||
+ | * Umount ''/ | ||
+ | * <code bash> | ||
+ | * Clear previous RAID headers | ||
+ | * <code bash> | ||
+ | * Crate soft RAID1 | ||
+ | * <code bash> | ||
+ | * <code bash> | ||
+ | * update ''/ | ||
+ | * mount ''/ | ||
+ | * copy backed-up data to ''/ | ||
+ | * Save mdadm configuration: | ||
+ | * <code bash> | ||
+ | * grub-install /dev/sda | ||
+ | * grub-install /dev/sdb | ||
+ | * update-grub | ||
+ | * update-initramfs | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Boot issues ===== | ||
+ | |||
+ | ==== No degraded option ==== | ||
+ | Boot fail | ||
+ | BTRFS: failed to read the system array on sda1 | ||
+ | BTRFS: open_cree failed | ||
+ | |||
+ | And initramfs console appear. | ||
+ | |||
+ | <code bash> | ||
+ | mkdir /mnt | ||
+ | mount /dev/sda1 /mnt | ||
+ | </ | ||
+ | the same error | ||
+ | < | ||
+ | WORKS! | ||
+ | |||
+ | ==== Grub wrong root= ==== | ||
+ | === PROBLEM === | ||
+ | **'' | ||
+ | <file / | ||
+ | linux / | ||
+ | / | ||
+ | </ | ||
+ | More here: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | === SOLUTION === | ||
+ | Fixed in Debian Stretch (testing) version **grub-pc_2.02~beta3-3** | ||
+ | Now UUID is used multiple roots. UUID of btrfs filesystem placed on 2 disc is the same: | ||
+ | <file / | ||
+ | linux / | ||
+ | </ | ||
+ | <code bash> | ||
+ | # blkid | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | So, kernel cmdline parameter **'' | ||
+ | |||
+ | ==== no symbol table ==== | ||
+ | **PROBLEM** | ||
+ | Grub says: | ||
+ | < | ||
+ | **SOLUTION** | ||
+ | Grub was not reinstalled after update | ||
+ | <code bash> | ||
+ | grub-install /dev/sda | ||
+ | grub-install /dev/sdb | ||
+ | update-grub | ||
+ | </ | ||
+ | |||
+ | ==== ALERT! / | ||
+ | |||
+ | **PROBLEM** | ||
+ | Grub loads kernel and initramfs correctly, but: | ||
+ | '' | ||
+ | After some while, initramfs shell is available. | ||
+ | < | ||
+ | ALERT! | ||
+ | Dropping to shell! | ||
+ | </ | ||
+ | |||
+ | Unfortunatelly initramfs cannot activate LVM volumes when kernel cmdline '' | ||
+ | <code bash> | ||
+ | lvm lvscan | ||
+ | </ | ||
+ | To boot manually: | ||
+ | <code bash> | ||
+ | lvm vgchange -ay | ||
+ | mount / | ||
+ | exit | ||
+ | </ | ||
+ | System should start - but once. | ||
+ | |||
+ | Problem is located in ''/ | ||
+ | Script check if specified root device needs to be activated by LVM. | ||
+ | When UUID is used it is executing code: | ||
+ | <code bash> | ||
+ | /dev/*/*) | ||
+ | # Could be /dev/VG/LV; use lvs to check | ||
+ | if lvm lvs -- " | ||
+ | lvchange_activate " | ||
+ | fi | ||
+ | ;; | ||
+ | </ | ||
+ | In result, command | ||
+ | <code bash>lvm lvs -- disc/ | ||
+ | is executed, resulting following output: | ||
+ | < | ||
+ | |||
+ | Debian bugs about similar problem: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | |||
+ | **solution** | ||
+ | |||
+ | Install lvm2 package version 2.02.168-1 (Debian Stretch). Previously was 2.02.111-2.2+deb8u1 (Debian Jessie). | ||
+ | <code bash> | ||
+ | update-initramfs -k all -u | ||
+ | btrfs scrub / | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | force LVM activation: [[http:// | ||
+ | |||
+ | Also '' | ||
+ | |||
+ | |||
+ | <file | / | ||
+ | BINARIES="/ | ||
+ | </ | ||
+ | <code bash> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ====== Disc fail (removed) ====== | ||
+ | |||
+ | Make sure, all system, metadata and data is balanced to RAID1 mode. Without this it cannot be possible to mount degraded btrfs in RW mode. | ||
+ | During RW operation in degraded mode, single system, metadata and data structures will be created on BTRFS so it will need rebalance after missing disc will be connected again. | ||
+ | |||
+ | |||
+ | === error: disk not found === | ||
+ | < | ||
+ | error: disk ' | ||
+ | Entering rescue mode... | ||
+ | grub rescue> | ||
+ | </ | ||
+ | |||
+ | GRUB 2 is unable to find the grub folder or its contents are missing/ | ||
+ | |||
+ | grub.cfg sets prefix variable to missing LVM (lvimd/< | ||
+ | < | ||
+ | prefix=' | ||
+ | insmod gettext | ||
+ | </ | ||
+ | |||
+ | Rescue shell is very limited. Try to start '' | ||
+ | < | ||
+ | set prefix=' | ||
+ | insmod normal | ||
+ | normal | ||
+ | </ | ||
+ | |||
+ | Keeping /boot/grub in multidevice BTRFS is stupid idea. Another problem comes when BTRFS is not clean, and cannot be used by GRUB to load own modules. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ====== Replace bad disc ====== | ||
+ | |||
+ | <code bash> | ||
+ | btrfs device add / | ||
+ | btrfs device delete missing / | ||
+ | </ | ||
+ | Note: Word ' | ||
+ | < | ||
+ | ERROR: error removing the device ' | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | btrfs filesystem show | ||
+ | btrfs replace start 6 / | ||
+ | </ | ||
+ | |||
+ | Don't forget to restore correct data state: | ||
+ | <code bash> | ||
+ | btrfs scrub start / | ||
+ | btrfs balance start -v -dconvert=raid1 -mconvert=raid1 / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Fine tuning ===== | ||
+ | * Run dropbear on alternative SSH port | ||
+ | <code bash> | ||
+ | apt-get install dropbear | ||
+ | vi / | ||
+ | </ | ||
+ | * Add your ssh public key to ''/ | ||
+ | * <code bash> | ||
+ | * Change MAC address of eth0 (for initramfs remote access) | ||
+ | <file | / | ||
+ | ACTION==" | ||
+ | </ | ||
+ | Another option is to add '' | ||
+ | |||
+ | Don't forget to propgate changes: | ||
+ | <code bash> | ||
+ | update-grub | ||
+ | update-initramfs -k all -u | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== TODO ===== | ||
+ | * backup GPT header | ||
+ | * backup LVM header | ||
+ | * backup LUKS header | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ??????????? | ||
+ | ??????????? | ||
+ | ??????????? | ||
+ | ??????????? | ||
+ | ??????????? | ||
+ | |||
+ | 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) | ||
+ | |||
+ | <code bash> | ||
+ | < | ||
+ | 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 / | ||
+ | but whole /dev/sda removed. | ||
+ | This bad behaviour, because I want system to be bootable even without additional disc. | ||
+ | |||
+ | |||