This is nearly the title of a fine article (signed by Mr Technology…) and my notes of its implementation.
It is tested only on legacy boots, and is known not to work as is on some UEFI boots.
The interest of btrfs is big, and many good articles explain it, but I have not found good articles on its implementation on debian. The server is based on a debian with 2 RAID1 2T disks.
Let us start to install the system from debian-9.1.0-amd64-netinst.iso (on a flash USB key in this case). I skip here standard install procedures but,on the partition menu, create a main btrfs partition on the whole first disk, add the boot flag, mounted on /. On the second disk create a partition as on the 1rst disk but declare it of type “not in use”,but with the boot flag. Do not declare any other partition. Finish the installation normally.
As is, my system refused to boot, but with the USB key mounted, the system boots… And I had to :
grub-install /dev/sdX1 apt install --reinstall grub-pc
and then it boots.
We have now a basic server with btrfs file system.
We note /dev/sda and /dev/sdb the two disks, but it may differ on other systems.
If not soon done, add the boot flag now with fdisk to the second disk. Then add the 2nd disk to / and build the RAID:
apt update apt install btrfs-tools btrfs device add /dev/sdb1 / btrfs balance start -v -mconvert=raid1 -dconvert=raid1 /
You can use btrfs display commands to see the sitation all along :
btrfs fi show sudo btrfs fi usage /
I suggest to modify les logs dans /etc/systemd/journald.conf :
Ubuntu policy is to assign half of the memory to swap and divide it by the the number of CPU hearts.
apt install zram-tools
You should modify ALLOCATION to 33-50% or total RAM in /etc/default/zramswap
The interest of “containers” is great to isolate problems. I have choosen LXD. To say it simply, LXD is magic… Thanks to the developper team.
Create a simple bridge :
apt install bridge-utils
In /etc/network interfaces, here based on enp5s0 (not wan) interface :
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enps5s0 iface enp5s0 inet manual auto br0 iface br0 inet static address 192.168.163.1 netmask 255.255.255.0 gateway 192.168.163.254 network 192.168.163.0 broadcast 192.168.163.255 bridge_ports enp5s0 bridge_stp on bridge_maxwait 0 iface enp5s0 inet6 auto
apt install snapd snap install lxd
Logout, then log in again, then init lxd.
Default values are usually good (btrfs…), but do not declare any network but add br0 “manually” after, then add your user to lxd group :
lxd init [...] lxc network attach-profile br0 default eth0 adduser myuser lxd
Now myuser can manipulate containers :
lxc launch images:debian/stretch debian lxc start debian lxc exec debian bash ...
It is possible to choose to work as root in the containers as they are isolated from the host.
lxc export pgsql /media/lxd_containers/pgsql2020_01_12.tar.gz
After import, the container is on stopped state :
lxc import /media/lxd_containers/pgsql2020_01_12.tar.gz
apt install msmtp msmtp-mta
Et /etc/msmtprc :
account default host 192.168.12.34 auto_from off from email@example.com syslog LOG_MAIL
In case of failure, prevent the problem by having a 3rd empty disk ready…
To replace :
btrfs fi show btrfs replace start -rf /dev/sdb2 /dev/sda2 /