migmedia.net

linux

ZFS-Root auf Gentoo

2015-06-18

ZFS-fähige Admin-Disk booten: SystemRescueCd oder xyinn

Disk leeren:

sgdisk -Z /dev/sda
sgdisk -Z /dev/sdb

Partitionieren: Für BIOS und UEFI Rechner:

sgdisk -a 4096 --new=1:+0:+2M      --typecode=1:EF02 --change-name=1:"BIOS boot partition"  /dev/sda
sgdisk -a 4096 --new=2:+129M:+200M --typecode=2:EF00 --change-name=2:"EFI " /dev/sda
sgdisk -a 4096 --new=3:+129M:+1G   --typecode=3:8300 --change-name=3:"gentoo boot" /dev/sda
sgdisk -a 4096 --new=4:+129M:-129M --typecode=4:bf00 --change-name=4:"tank1" /dev/sda

sgdisk -a 4096 --new=1:+129M:-129M --typecode=1:bf00 --change-name=1:"tank2" /dev/sdb

Jetzt ist ein Neustart erforderlich, damit Linux das neue Partitions-Schema erkennt.

ls -l /dev/disk/by-id/  

Zeigt die Partitions IDs an

Anlegen des zpools.

zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -O compression=lz4 -m none -R /mnt/gentoo tank mirror /dev/sda4 /dev/sdb1

zfs create -o mountpoint=none tank/ROOT
zfs create -o mountpoint=/ tank/ROOT/gentoo

# Create home directories
zfs create -o mountpoint=/home tank/HOME
zfs create -o mountpoint=/root tank/HOME/root

# Create portage directories
zfs create -o mountpoint=none -o setuid=off tank/GENTOO
zfs create -o mountpoint=/usr/portage -o atime=off tank/GENTOO/portage
zfs create -o mountpoint=/usr/portage/distfiles -o compression=off tank/GENTOO/distfiles

# Create portage build directory
zfs create -o mountpoint=/var/tmp/portage -o sync=disabled tank/GENTOO/build-dir

# Create optional packages directory
zfs create -o mountpoint=/usr/portage/packages tank/GENTOO/packages


# Set bootfs
zpool set bootfs=tank/ROOT/gentoo tank
zfs create -V 8G -b $(getconf PAGESIZE) \
              -o primarycache=metadata \
              -o com.sun:auto-snapshot=false tank/ROOT/swap
mkswap -f /dev/zvol/tank/ROOT/swap
swapon /dev/zvol/tank/ROOT/swap

Stage3 herunterladen.

wget 'ftp://gentoo.osuosl.org/pub/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-[0-9]*.tar.bz2'
tar -xvjpf stage3-amd64-*.tar.bz2 -C /mnt/gentoo

mkdir -p /mnt/gentoo/etc/zfs
cp /tmp/zpool.cache /mnt/gentoo/etc/zfs/zpool.cache
cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

Nun können wir unseren neuen Rechner beziehen.

mount -t proc none /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys

chroot /mnt/gentoo /bin/bash
env-update; source /etc/profile; export PS1="(chroot) $PS1"; cd

Portage-Dateien herunterladen & einen Kernel compilieren.

env GENTOO_MIRRORS="http://gentoo.osuosl.org" emerge-webrsync
emerge sys-kernel/genkernel sys-kernel/gentoo-sources
emerge app-editors/vim

mkfs.ext2 /dev/sda3
mount /dev/sda3 /boot

genkernel kernel --no-clean --no-mountboot

ZFS Installieren

mkdir -p /etc/portage/package.accept_keywords
echo "sys-kernel/spl ~amd64" >> /etc/portage/package.accept_keywords/zfs
echo "sys-fs/zfs-kmod ~amd64" >> /etc/portage/package.accept_keywords/zfs
echo "sys-fs/zfs ~amd64" >> /etc/portage/package.accept_keywords/zfs
emerge sys-fs/zfs
rc-update add zfs boot
# Flush the page cache to ensure GRUB2 sees the latest disk content
echo 1 > /proc/sys/vm/drop_caches
echo "sys-boot/grub:2 libzfs -truetype" >> /etc/portage/package.use/system
echo "sys-boot/grub:2 ~amd64" >> /etc/portage/package.accept_keywords/system
emerge sys-boot/grub:2
touch /etc/mtab
grub2-install /dev/sda
touch /boot/grub/grub.cfg

sed -i  -e "s_/dev/BOOT_/dev/sda3_g" \
   -e "s/\(.*\)\/\(ROOT\|SWAP\)\(.*\)/\#\1\/\2\3/g" /etc/fstab

sed -i -e 's_#?BOOTLOADER=".*"_BOOTLOADER="grub2"_g' \
  -e 's_#ZFS="no"_ZFS="yes"_g' \
  -e 's:#CMD_CALLBACK="":CMD_CALLBACK="emerge @module-rebuild":g' \
  /etc/genkernel.conf

genkernel all --no-clean --no-mountboot

grub2-mkconfig -o /boot/grub/grub.cfg

System vorbereiten:

echo PORTAGE_NICENESS=19 >> /etc/portage/make.conf
emerge app-admin/syslog-ng app-admin/logrotate sys-process/cronie
rc-update add cronie default
rc-update add sshd default

Referenzen: