Developers Club geek daily blog

1 year, 11 months ago
The CentOS installation on ZFS in UEFI

Has decided to try here the other day ZFS, and detailed and simple manual as to carry out it on CentOS has not found, has decided to correct situation. Besides there was a wish to set all this in the EFI mode. — not to stand still? And at the same time to understand for itself as DKMS, and also aspects of the manual RPM-based installation of distribution kits works.

ZFS has been selected too not accidentally as by this machine it was going to unroll hypervisor and to use zvol for storage of images of virtual computers. I wanted something bigger than program raid + lvm or simple file storage of images, something on similarity of ceph, but for one host it is too bold. Running forward I will tell that I was very pleased with this file system, its productivity and all its counters.

Preparation


For a start we will take LiveCD image of CentOS, for example from yandex cloud, live but not netinstall or minimal as for installation we will need completely working linux system is necessary. Let's write image on pig or flash card and we zgruzitsya from it. It is loaded it is necessary in efi the mode, otherwise it will not turn out to save the boot record in efi.

Let's set epel and zol repositories:

yum -y install epel-release
yum -y localinstall http://archive.zfsonlinux.org/epel/zfs-release.el7.noarch.rpm

Let's set packet with kernel headers:

yum -y install kernel-devel 

We will turn certain feint ears without which zfs simply will not gather on our LiveCD further:

rm -f /lib/modules/$(uname -r)/build
ln -s /usr/src/kernels/$(uname -r) /lib/modules/$(uname -r)/build

Now it is possible to set zfs packet:

yum -y install zfs 

Whether after installation of packet we will check the module and if all ok, we load it was installed:

dkms autoinstall
modprobe zfs

Marking of disks


In my case there are three disks on 2 tb everyone, I want them to mark in such a way that as a result on everyone it would appear on three sections:

  1. efi (fat16/100mb) — here will be is stored files of configuration and the loader
  2. boot (ext4/412mb) — these sections from all three disks we will integrate in program RAID1, kernels and the minimum images for loading of system will lie here.
  3. data (zfs/all the rest) — on these sections from all three disks we will create zpool with RAIDZ in which we will create sections necessary to us with mount points in/, / home and / var, etc., and we will install on them system.

We start marking:

parted /dev/sda
mklabel gpt
mkpart ESP fat16 1MiB 101MiB
set 1 boot on
mkpart boot 101MiB 513MiB
mkpart data 513MiB 100%

Poatoryaem too most for / dev/sdb and / dev/sdc. We create file system for the efi-section:

mkfs.msdos -F 16 /dev/sd{a,b,c}1

FAT16 is used not accidentally since the size of the minimum section with FAT32 — 512mb, and it is too much.

Ok, now we razbrertsya with ours / boot, we will create program RAID from the second sections on our disks, and at once file system on it:

mdadm --create --verbose /dev/md0 --level=1 --metadata=0.90 --raid-devices=3 /dev/sda2 /dev/sdb2 /dev/sdc2
mkfs.ext4 /dev/md0 

Time has come to create our zpool, for this operation it is recommended to address to disks on ID, here example as this team looked at me:

zpool create -m none -o ashift=12 rpool raidz \
/dev/disk/by-id/ata-TOSHIBA_DT01ACA200_74FWM9LKS-part3 \
/dev/disk/by-id/ata-TOSHIBA_DT01ACA200_74FWMHDKS-part3 \
/dev/disk/by-id/ata-TOSHIBA_DT01ACA200_74FWR4VKS-part3

You only should decide on the ashift parameter. For disks which size of the block is equal 512b it is necessary to specify the ashift=9 parameter, for 4k the disks ashift=12. It is possible to look at the disk block size the fdisk team - l.

Now we will create sections necessary to us, in zfs it is easy:

zfs create -o mountpoint=none rpool/ROOT
zfs create -o mountpoint=/ rpool/ROOT/centos-1
zfs create -o mountpoint=/home rpool/home
zfs create -o mountpoint=/var rpool/var

It is ready, we have marked disks.

Installation of system


Let's set manually so we will start. We mount all our sections in/MNT, pay attention that the section we mount efi only for one disk, we will deal with the others later:

zpool import -o altroot=/mnt rpool
mkdir -p /mnt/boot/efi
mount /dev/md0 /mnt/boot/
mount /dev/sda1 /mnt/boot/efi/

Just we have prepared space for our new system. Now initsiliziruy also we will set in it the main repository, and then and system with kernel:

rpm --root=/mnt --rebuilddb
curl -O http://mirror.yandex.ru/centos/7/os/x86_64/Packages/centos-release-7-1.1503.el7.centos.2.8.x86_64.rpm
rpm --root /mnt -ivh centos-release-*.rpm
yum -y --installroot=/mnt groupinstall base
yum -y --installroot=/mnt install kernel

When the guest system is installed, we will connect in it system directories of hostovy system and we execute chroot:

mount --bind /dev  /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys  /mnt/sys
chroot /mnt /bin/bash --login

Now we will start its setup. Let's write the DNS server, it is better local of course that would earn permission of names:

echo 'nameserver 192.168.225.1' > /etc/resolv.conf

Let's reinstall epel and zol repositories:

yum -y install epel-release
yum -y localinstall --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release.el7.noarch.rpm

And zfs has to be established without dancings with tambourine now:

yum -y install kernel-devel zfs 

Ok prodlozhay, we will set the time zone:

rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime

Hostneym, password rue:

echo 'one' > /etc/hostname
echo "root:newpass" | chpasswd

Let's write mount points in fstab. Sections on zfs do not need to be added to fstab in principle:

cat /proc/mounts | grep /boot >> /etc/fstab

It is also necessary to save information on ours raid array:

mkdir /etc/mdadm
mdadm --examine --scan >> /etc/mdadm/mdadm.conf

It is ready, our system is installed and configured, now we will deal with the loader.

Installation of the loader


In principle in case with efi it would be possible to do and without loader since linux kernel already for a long time supports EFISTUB (loading directly through efi without loader), but it not our case because: first: efi has undressed on which will have to there is our kernel it is impossible to integrate in program raid and consequently at each updating of kernel it is necessary to copy this section on other disks, secondly: centos is not really adapted for such loading from box, it is recommended to use nevertheless GRUB2.

Let's set GRUB2 for UEFI:

yum -y install grub2-efi

That grub2-install would not swear on zfs-sections to us it is necessary to skompirovat and set one more packet of grub-zfs-fixer:

yum groupinstall "Development Tools"
curl https://codeload.github.com/Rudd-O/zfs-fedora-installer/tar.gz/master | tar xzv
cd zfs-fedora-installer-master/
tar cvzf grub-zfs-fixer.tar.gz grub-zfs-fixer/
rpmbuild -ta grub-zfs-fixer.tar.gz
yum localinstall ~/rpmbuild/RPMS/noarch/grub-zfs-fixer-0.0.3-1.noarch.rpm

It is ready, now we will execute the GRUB2 installation and we will generate config:

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

GRUB2 had to create record in your efi, we will check:

efibootmgr -v

Let's copy our efi-section on other disks:

dd if=/dev/sda1 of=/dev/sdb1 bs=4M
dd if=/dev/sda1 of=/dev/sdc1 bs=4M


Now it was necessary only to add the zfs module to initramfs, for this purpose we will make:

yum -y install zfs-dracut
dracut -f /boot/initramfs-3.10.0-229.14.1.el7.x86_64.img 3.10.0-229.14.1.el7.x86_64

Pay attention, here as the first argument the way to initramfs and as the second the version of kernel is transferred. If not to set the second parameter, the image will be generated for the flowing started kernel and as we work in chroot, its version will be explicit less than set in guest system.

On it all. We leave chroot, otmontiruy/MNT. Also we reboot in our svezheustanovlenny system.

exit
umount -R /mnt
reboot

Sources:


HOWTO install Ubuntu to a Native ZFS Root Filesystem
HOWTO install Debian GNU Linux to a Native ZFS Root Filesystem
subject on Google Groups
subject on Hardforum

This article is a translation of the original post at habrahabr.ru/post/268711/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus