====== BTRFS as root (LVM and raid) ======
To setup BTRFS on 2 disc, first setup complete system for one disc, then connect 2nd disc and:
- clone partition layout to 2nd disc
- add 2nd disc to btrfs
- rebalance btrfs
- install grub on 2nd disc
- configure system to start with degraded disc, include btrfs tools in initramfs
===== /dev/sdb partitioning =====
- /dev/sdb
- 1MB free space + alignment
- /dev/sdb1 LVM
- /dev/disc2/swap2 (4GB)
- /dev/disc2/btrfs2 (80GB)
- /dev/disc2/pool2 (rest)
NOTE: Compare exact bytes size of 1st and 2nd disc, and adapt partition sizes to smaller disc!
[[http://serverfault.com/questions/279571/lvm-dangers-and-caveats]]
**Grub on GPT**
Grub on GPT requires some reserved space to embed itself (core.img) on disc. Otherwise error will be shown:
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
Small 2MiB partition with flag ''bios_grub'' is enough. Partition can be located everywhere on disc within 2TiB.
apt-get install parted lvm2
parted /dev/sdb
mklabel gpt
mkpart primary ext2 0 2MiB
set 1 bios_grub on
mkpart primary ext2 3MiB -1MiB
set 2 lvm on
pvcreate /dev/sdb2
lvmdiscscan
vgcreate disc2 /dev/sdb2
lvcreate -L 4GB -n swap2 disc2
lvcreate -L 80GB -n btrfs2 disc2
lvcreate -l 100%FREE -n pool2 disc2
===== Btrfs setup =====
**NOTE:** Create subvolumes for things which shouldn't be included in snapshot of parent volume. Like some /var/../cache, etc
[[https://wiki.archlinux.org/index.php/Snapper#Suggested_filesystem_layout]]
mkfs.btrfs /dev/disc2/btrfs2
mount -o noatime,compress=lzo,defaults /dev/disc2/btrfs2 /mnt
cd /mnt
btrfs subvolume create @
btrfs subvolume create @/@root
btrfs subvolume create @/@home
btrfs subvolume create @/@var
btrfs subvolume create @/@var/log
btrfs subvolume create @snapshots
btrfs subvolume list /mnt
btrfs subvolume set-default 259 /mnt # set to @/@root id
cd ..
umount /mnt
mkdir /mnt/{home,var,root}
mount -o noatime,compress=lzo,defaults,subvol=@/@root /dev/disc2/btrfs2 /mnt/root
mount -o noatime,compress=lzo,defaults,subvol=@/@home /dev/disc2/btrfs2 /mnt/home
mount -o noatime,compress=lzo,defaults,subvol=@/@var /dev/disc2/btrfs2 /mnt/var
# mount old disc in /mnt/sda1, etc
cp -ax /mnt/sda1/. /mnt/root
# or
# rsync -avxHAXP --numeric-ids /mnt/sda1/ /mnt/root/
cat /proc/mounts >> /mnt/root/etc/fstab
# edit /mnt/root/etc/fstab
Install grub loader
grub-install --recheck --root-directory=/mnt/root /dev/sdb
or
mount -t proc none /mnt/root/proc
mount -o bind /dev /mnt/root/dev
mount -t sysfs sys /mnt/root/sys
mount -o bind /mnt/var /mnt/root/var
chroot /mnt/root /bin/bash
grub-install --recheck /dev/sdb
update-grub
exit
umount /mnt/root/{proc,sys,dev,var}
umount /mnt/{var,home,root}
sync
reboot
===== Encrypted /dev/disc2/pool2 (btrfs) =====
apt-get install cryptsetup
Fill with random data [[https://niziak.spox.org/wiki/linux:fs:luks#fill_with_random_data]]
cryptsetup luksFormat --cipher aes-xts-plain64 --key-size 256 --hash sha256 --verify-passphrase --use-random /dev/disc2/pool2
cryptsetup luksOpen /dev/disc2/pool2 cryptpool
mkfs.btrfs /dev/mapper/cryptpool
mount -o noatime,compress=no /dev/mapper/cryptpool /mnt
Create subvolumes:
cd /mnt
btrfs subvolume create @pool
...
Copy data to ''/mnt''
Add fstab entry
/dev/mapper/cryptpool /POOL btrfs noauto,nofail,x-systemd.device-timeout=60,noatime,defaults,compress=no,subvol=@pool 0 0
[[https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Btrfs_on_top_of_dmcrypt]]
===== Add 2nd disc =====
See [[btrfs_multidisk]]