Outils pour utilisateurs

Outils du site


public:a_perfect_btrfs_server

Ceci est une ancienne révision du document !


A "perfect" btrfs server

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.

Install basic debian

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.

Build the RAID1

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 /

Update init system

… to allow boot in case of failure of one disk of the RAID1.

Include 'degraded' option in GRUB_CMDLINE_LINUX in /etc/grub.d/10_linux :

GRUB_CMDLINE_LINUX="rootflags=degraded,subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"

Then :

update-grub
grub-install /dev/sda1
grub-install /dev/sdb1

And too replace “default” options with “degraded,noatime,nodiratime,subvol=@” in btrfs line in /etc/fstab :

UUID=...   / btrfs   degraded,noatime,nodiratime,subvol=@   0  0

Add zram based swap

Ubuntu policy is to assign half of the memory to swap and divide it by the the number of CPU hearts. This is done by zram-config which is not available in debian. I have choosen :

git  clone https://github.com/Jiab77/systemd-zram
cd systemd-zram
./install.sh

Here you can modify /etc/systemd/zram.conf from 33% to 50 for next reboot…

apt install bc, in order to get /use/sbin/zramstat ok.

Install lxd

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.

Prepare the bridge

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 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        

Install lxd

It is discussed whether installing lxd with snap is a good solution. Currently, I have choosen to install from the sources.

From sources

In your home directory (not root) :

cd ~
apt install acl dnsmasq-base git golang liblxc1 lxc-dev libacl1-dev make pkg-config rsync squashfs-tools tar xz-utils
mkdir -p ~/go
export GOPATH=~/go
go get -d -v github.com/lxc/lxd/lxd
cd $GOPATH/src/github.com/lxc/lxd
make
cd $GOPATH/bin

I did move lxc,lxd to /usr/local/bin and create a /etc/systemd/system/lxd.service :

[Unit]
Description=LXD - main daemon
After=lxcfs.service
Requires=lxcfs.service

[Service]
EnvironmentFile=-/etc/environment
ExecStartPre=/usr/lib/x86_64-linux-gnu/lxc/lxc-apparmor-load
ExecStart=/usr/local/bin/lxd --group sudo --debug  --logfile=/var/log/lxd/lxd.log
ExecStartPost=/usr/local/bin/lxd waitready --timeout=600
KillMode=process
TimeoutStartSec=600s
TimeoutStopSec=30s
Restart=on-failure
LimitNOFILE=1048576
LimitNPROC=infinity
TasksMax=infinity

[Install]
WantedBy=multi-user.target
Alias=lxd.service

with snap

All this can be simplified installing lxd via snap:

apt install snapd
snap install lxd

Logout, then log in again, then init lxd.

Initialize 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.

public/a_perfect_btrfs_server.1515676498.txt.gz · Dernière modification : 2018/01/11 13:14 de admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki