Installare Arch Linux su ZFS

Da GolemWiki.
Jump to navigation Jump to search

Requisiti

  • Un sistema funzionante con Arch Linux x86_64
  • Almeno 4 GB di RAM

Installation media

Dato che lo ZFS non è ufficialmente supportato da nessuna distribuzione Linux, tantomento da Arch, sarà necessario realizzare un'immagine live creata appositamente per questo scopo.

Archiso

A tale scopo, Arch Linux mette a disposizione un pacchetto, denominato Archiso, contenente una serie di script per la realizzazione di supporti per l'installazione.

# pacman -S archiso

Copiare il contenuto del pacchetto in una directory di lavoro, es.: /root/media

# cp -r /usr/share/archiso/configs/releng /root/media


Per aggiungere il supporto allo ZFS occorre:

  • Modificare le seguenti righe al file pacman.conf di archiso
[demz-repo-core]
SigLevel = Never
Server = http://demizerone.com/$repo/$arch
  • Aggiungere le seguenti righe al file packages.x86_64
spl-utils
spl
zfs-utils
zfs
net-tools
  • Lanciare lo script
# ./build.sh -v

L'immagine sarà generata nella directory /root/media/out

Boot col nuovo supporto (CD/USB)

Effettuare il boot e scegliere l'architettura x86_64, ZFS non è ben supportato su i686.

SSH

Si consiglia di abilitare il demone ssh ed effettuare il processo di installazione collegandosi da un altro computer così da poter effettuare copia ed incolla da questa o altre guide.

# systemctl enable sshd.service
# systemctl start sshd.service

Partizionamento

Per non dover ricorrere ad una partizione di /boot in un formato supportato da Linux (es.: ext2,3,4 o reiser) ed utilizzare ZFS come unico filesystem del sistema si consiglia di partizionare il disco secondo il nuovo formato GPT.


You need to create two partitions on your devices. The first will be a small utility partition where Grub itself will be installed. The second is for your main zpool. Since the contents of the utility partition change very infrequently (only when Grub is upgraded), there's no need to mirror this partition with MDADM or similar. This partition serves the same purpose as the first few blocks of the MBR where Grub is traditionally installed. Giving Grub this additional utility partition is required since the total amount of code necessary to support ZFS is too big to fit in the usual boot locations.

In contrast to a traditional /boot partition where the kernel and initramfs are kept on the separate /boot partition, this arrangement allows the kernel and ramdisk to reside within ZFS and be mirrored or otherwise replicated by the normal ZFS logic.

  1. Create a bios_grub partition (type EF02) starting at 1MB with size 64MB. The
  2. 1MB offset is to ensure proper sector alignment for SSD's and other 4k sector drives.
  3. After the utility partition, the rest of the drive is setup for ZFS. Repeat for all
  4. drives to be used in the pool.
  $ sgdisk \
   --new=1:2048:133120 --typecode=1:EF02 --change-name=1:"grub" \
   --largest-new=2 --typecode=2:BF01 --change-name=2:"zfs" \
   /dev/sda


  1. Create a pool:
   $ zpool create rpool sda2
  1. The zpool will initially be mounted at /rpool, but we need to move it to /mnt/ to work on it
   $ zfs unmount rpool
   $ zfs set mountpoint=/mnt/ rpool
                                            1. $ zfs set canmount=off rpool
   $ zfs create -o mountpoint=legacy rpool/ROOT
   $ zpool set bootfs=rpool/ROOT rpool
   
  1. Now mount the root filesystem in the usual spot:
   $ mount -t zfs rpool/ROOT /mnt


  1. In addition to the root dataset, we'll create several other datasets to help keep things organized.
  2. Note that /bin, /boot, /sbin, /etc, /dev, /sys, and /proc must all be in the root dataset, not part of sub-datasets.
   $ zfs create rpool/home
   $ zfs create rpool/usr/src
   $ zfs create rpool/var
   $ zfs create rpool/srv


  1. zpool set cachefile=/etc/zfs/rpool.cache rpool

Copy zpool.cache Now is also a good time to copy over the zpool cache so your initramfs will have access to it.

   $ mkdir -p /mnt/etc/zfs
   $ cp /etc/zfs/rpool.cache /mnt/etc/zfs/rpool.cache


  1. pacstrap /mnt base base-devel


  1. #
  2. CHROOT #
  3. #
  1. arch-chroot /mnt


  1. zpool set cachefile=/etc/zfs/rpool.cache rpool


I don't have uefi so I install the regular grub

  1. pacman -S grub


                                                    1. DIVERSAMENTE ########################################################
  1. mkdir /boot/EFI
  2. mount /dev/sda1 /boot/EFI
  3. grub-install --target=x86_64-efi --efi-directory=$esp --bootloader-id=grub --recheck --debug
  4. grub-mkconfig -o /boot/grub/grub.cfg


  1. nano /etc/fstab

rpool/ROOT / zfs noatime 0 0


Edit /etc/mkinitcpio.conf and add zfs before filesystems. Also, move keyboard hook before zfs so you can type in console if something goes wrong. Your HOOKS line should look something like this:

HOOKS="base udev autodetect modconf block keyboard zfs filesystems"


Edit the pacman.conf in the chroot adding those lines

[demz-repo-core] Server = http://demizerone.com/$repo/$arch SigLevel = Never

  1. pacman -Sy
  2. pacman -S archzfs


To regenerate the initramfs with the command:

  1. mkinitcpio -p linux
  1. ln -s /usr/share/zoneinfo/Europe/Rome /etc/localtime
  1. nano /etc/vconsole.conf

KEYMAP=it


Create Swap (Optional) Running swap in ZVOL will currently deadlock when the system grows into swap. If you NEED swap, you must create separate partitions for it and setup mdadm in necessary.

Swap can be run from with the zpool as a zvol:
   # Set size as desired. Checksum'ing isn't necessary for swap and turning it off improves performance.
   $ zfs create -V 2G rpool/swap
   $ zfs set checksum=off rpool/swap
   $ swapon /dev/rpool/swap
   $ echo "/dev/rpool/swap    none    swap    sw    0 0" >> /mnt/etc/fstab


  1. grub-mkconfig -o /boot/grub/grub.cfg
  2. grub-install /dev/sda

Add zfs=bootfs to the kernel line of grub.cfg


  1. systemctl enable zfs.service
  1. exit
  2. zfs unmount -a
  3. zfs set mountpoint=/ rpool
  1. cp /etc/zfs/rpool.cache /mnt/etc/zfs/rpool.cache
  1. zpool export rpool


After the first boot

If everything went fine up to this point, your system will boot. Once. For your system to be able to reboot without issues, you need to enable the zfs service and set the hostid. When running ZFS on root, the machine's hostid will not be available at the time of mounting the root filesystem. There are two solutions to this. You can either place your spl hostid in the kernel parameters in your boot loader. For example, adding spl.spl_hostid=0x00bab10c. The other solution is to make sure that there is a hostid in /etc/hostid, and then regenerate the initramfs image. Which will copy the hostid into the initramfs image.

# hostid > /etc/hostid
# mkinitcpio -p linux


Trucchi

Limitare l'utilizzo di RAM

# echo "options zfs zfs_arc_max=2147483648" > /etc/modprobe.d/zfs.conf


Bibliografia

https://github.com/pendor/gentoo-zfs-install/blob/master/install/GentooInstall.mdown

https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-install-Ubuntu-to-a-Native-ZFS-Root-Filesystem

http://www.howtoforge.com/a-beginners-guide-to-btrfs

https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_ZFS

https://bbs.archlinux.org/viewtopic.php?pid=1365007#p1365007