Installation On UEFI With MDRAID, via chroot

From Void Linux Wiki
Jump to: navigation, search

NOTE: This doc assumes you have already created your array in whatever BIOS control panel came with your hardware.

To begin, after booting from the Void Live CD, we need to install mdadm to assemble our RAID, and GPTFDisk to write our partitions:

$ sudo su
# xbps-install gptfdisk mdadm

Next, we'll assemble our RAID:

# mdadm --assemble --scan

Successful assembly should result in something akin to the following:

mdadm: Container /dev/md/imsm0 has been assembled with 2 drives
mdadm: Started /dev/md/<RAID> with 2 devices

We can further confirm by listing our disks. Our RAID should be identified with an "md" prefix, like so (and we can see it is split across our two hard drives):

# lsblk

NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 238.5G  0 disk
  md126       9:126  0   477G  0 raid0
sdb           8:16   0 238.5G  0 disk
  md126       9:126  0   477G  0 raid0

We'll use fdisk to write our GPT partition table:

# fdisk /dev/md126
> g
> w

With our partition table writ, we'll use GPTFDisk's cgdisk utility to write our partitions.

# cgdisk /dev/md126

For each new partition created, you will be prompted for a start sector (for which you can simply press [enter]), a size (in kibibytes, mebibytes, or gibibytes), and a type (as hex code). Our EFI partition must come first, and should be of type ef00. Swap is 8200, and the rest, 8300.

What you see below shows separate partitions for /boot, /boot/efi, /, /home, /var and /tmp.
You might just as well use only three, if you like (for /boot, boot/efi, and /).
The sizes are also a matter of discretion; most won't need so much space for /boot, but if you plan on rolling your own kernels, the extra space is necessary.

If you decide to partition differently from this example, you will, of course, need to adjust the mounting instructions listed further on.

Part.     #     Size        Partition Type            Partition Name
----------------------------------------------------------------
1               200.0 MiB   EFI System                EFI
2               550.0 MiB   Linux filesystem          GRUB
3               2.0 GiB     Linux swap                swap
4               2.0 GiB     Linux filesystem          tmp
5               6.0 GiB     Linux filesystem          var
6               12.0 GiB    Linux filesystem          Void
7               454.2 GiB   Linux filesystem          The Big Box

After setting up our partitions, we'll select 'Write', then 'Verify', and, finally, 'Quit'.

Run lsblk to verify the successful creation of our partitions:

# lsblk

And your list should now look something akin to this:

NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 238.5G  0 disk
  md126       9:126  0   477G  0 raid0
    md126p1   259:0  0   200M  0 md
    md126p2   259:1  0   550M  0 md
    md126p3   259:2  0     2G  0 md
    md126p4   259:3  0     2G  0 md
    md126p5   259:4  0     6G  0 md
    md126p6   259:5  0    12G  0 md
    md126p7   259:6  0 454.2G  0 md
sdb           8:16   0 238.5G  0 disk
  md126       9:126  0   477G  0 raid0
    md126p1   259:0  0   200M  0 md
    md126p2   259:1  0   550M  0 md
    md126p3   259:2  0     2G  0 md
    md126p4   259:3  0     2G  0 md
    md126p5   259:4  0     6G  0 md
    md126p6   259:5  0    12G  0 md
    md126p7   259:6  0 454.2G  0 md

We need, now, to write our filesystems to the partitions.

# mkfs.vfat -F32 /dev/md126p1
# mkfs.xfs /dev/md126p2
# mkfs.xfs /dev/md126p4
# mkfs.xfs /dev/md126p5
# mkfs.xfs /dev/md126p6
# mkfs.xfs /dev/md126p7

Activate our swap partition:

# mkswap /dev/md126p3

Now, we mount our volumes, making any necessary mount point directories along the way (the sequence is important, yes):

# mount /dev/md126p6 /mnt
# mkdir /mnt/boot
# mkdir /mnt/tmp
# mkdir /mnt/var

# mount /dev/md126p2 /mnt/boot
# mkdir /mnt/boot/efi 

# mount /dev/md126p1 /mnt/boot/efi
# mount /dev/md126p4 /mnt/tmp
# mount /dev/md126p5 /mnt/var

Now, we install Void, GRUB, and mdadm to the mounted filesystem:

# xbps-install -S -R http://repo3.voidlinux.eu/current -r /mnt base-system grub-x86_64-efi mdadm

Upon completion of the install, we set up our chroot jail, and chroot into our mounted filesystem:

# mount -t proc proc /mnt/proc
# mount -t sysfs sys /mnt/sys
# mount -o bind /dev /mnt/dev
# mount -t devpts pts /mnt/dev/pts
# cd /mnt
# chroot /mnt

To verify our install, we can have a look at the directory structure:

# ls -la

Which should look something akin to the following:

otal 12
drwxr-xr-x 16 root root 4096 Jan 17 15:27 .
drwxr-xr-x  3 root root 4096 Jan 17 15:16 ..
lrwxrwxrwx  1 root root    7 Jan 17 15:26 bin -> usr/bin
drwxr-xr-x  4 root root  127 Jan 17 15:37 boot
drwxr-xr-x  2 root root   17 Jan 17 15:26 dev
drwxr-xr-x 26 root root 4096 Jan 17 15:27 etc
drwxr-xr-x  2 root root    6 Jan 17 15:26 home
lrwxrwxrwx  1 root root    7 Jan 17 15:26 lib -> usr/lib
lrwxrwxrwx  1 root root    9 Jan 17 15:26 lib32 -> usr/lib32
lrwxrwxrwx  1 root root    7 Jan 17 15:26 lib64 -> usr/lib
drwxr-xr-x  2 root root    6 Jan 17 15:26 media
drwxr-xr-x  2 root root    6 Jan 17 15:26 mnt
drwxr-xr-x  2 root root    6 Jan 17 15:26 opt
drwxr-xr-x  2 root root    6 Jan 17 15:26 proc
drwxr-x---  2 root root   26 Jan 17 15:39 root
drwxr-xr-x  3 root root   17 Jan 17 15:26 run
lrwxrwxrwx  1 root root    8 Jan 17 15:26 sbin -> usr/sbin
drwxr-xr-x  2 root root    6 Jan 17 15:26 sys
drwxrwxrwt  2 root root    6 Jan 17 15:15 tmp
drwxr-xr-x 11 root root  123 Jan 17 15:26 usr
drwxr-xr-x 11 root root  150 Jan 17 15:26 var

While chrooted, we create the password for the root user, and set root access permissions:

# passwd root
# chown root:root /
# chmod 755 /

Create the hostname for the new install:

# echo <HOSTNAME> > /etc/hostname

Edit our rc.conf file, like so:

# vi /etc/rc.conf

HOSTNAME="<HOSTNAME>"

# Set RTC to UTC or localtime.
HARDWARECLOCK="UTC"

# Set timezone, availables timezones at /usr/share/zoneinfo.
TIMEZONE="America/Los_Angeles"

# Keymap to load, see loadkeys(8).
KEYMAP="us"

# Console font to load, see setfont(8).
#FONT="lat9w-16"

# Console map to load, see setfont(8).
#FONT_MAP=

# Font unimap to load, see setfont(8).
#FONT_UNIMAP=

# Kernel modules to load, delimited by blanks.
#MODULES=""

Enable the mdadm runit service:

# ln -s /etc/sv/mdadm /var/service/

In order to edit our fstab file, we need to grab the UUIDs for our volumes:

# blkid

Which should return something akin to the following:

#/dev/md126p1: UUID="C071-6887" TYPE="vfat" PARTLABEL="EFI" PARTUUID="b35386b0-30d8-4d9d-9bc1-b02e78a2c708"
#/dev/md126p2: UUID="d7d2ddae-cb94-4aea-bc4f-4784d6b3cc8e" TYPE="xfs" PARTLABEL="GRUB" PARTUUID="824a24e5-5795-4a98-9977-1e534e480fa6"
#/dev/md126p3: UUID="cfb8be30-1866-44a6-bdf5-60ced2a454f4" PARTLABEL="swap" PARTUUID="e4f25f1c-f74b-487b-9413-0f43a1ac1a99"
#/dev/md126p4: UUID="97060d6a-039e-469f-b0aa-2fca2e33f464" TYPE="xfs" PARTLABEL="tmp" PARTUUID="12e852ce-79cc-4447-a8a0-d93c41b1967a"
#/dev/md126p5: UUID="4fb9395f-42c2-4b27-8545-1e9c1703c94d" TYPE="xfs" PARTLABEL="var" PARTUUID="77a281f8-7c0a-41d0-9a50-91104411bc9e"
#/dev/md126p6: UUID="dcdd0c5a-020b-4167-a10d-cb81d71e2ae6" TYPE="xfs" PARTLABEL="Void" PARTUUID="79303ba0-9be9-4905-a382-e90ff908a43f"
#/dev/md126p7: UUID="4a24a9e9-3c04-4aa5-826b-da2122347094" TYPE="xfs" PARTLABEL="The Big Box" PARTUUID="3ffd3dd1-0d69-4839-b1ee-320f9d7162c6"

Once we have our UUIDs , we edit our fstab file, like so (with no noatime,nodiratime, if we are installing to an SSD):

# vi /etc/fstab

#
# See fstab(5).
#
# <file system> <dir>   <type>  <options>               <dump>  <pass>
#tmpfs           /tmp    tmpfs   defaults,nosuid,nodev   0       0t
UUID=dcdd0c5a-020b-4167-a10d-cb81d71e2ae6 / xfs rw,noatime,nodiratime,discard 0 1
UUID=d7d2ddae-cb94-4aea-bc4f-4784d6b3cc8e /boot xfs rw,noatime,nodiratime,discard 0 2
UUID=C071-6887 /boot/efi vfat rw,noatime,nodiratime,discard 0 2
UUID=97060d6a-039e-469f-b0aa-2fca2e33f464 /tmp xfs rw,noatime,nodiratime,discard,nosuid,nodev 0 2
UUID=4fb9395f-42c2-4b27-8545-1e9c1703c94d /var xfs rw,noatime,nodiratime,discard,nosuid,nodev 0 2
UUID=4a24a9e9-3c04-4aa5-826b-da2122347094 /home xfs rw,noatime,nodiratime,discard 0 2
UUID=cfb8be30-1866-44a6-bdf5-60ced2a454f4 swap swap rw,noatime,nodiratime,discard 0 0

We now create a configuration file for mdadm:

# vi /etc/mdadm.conf

# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

DEVICE partitions

# auto-create devices with the standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays

Once our mdadm.conf file is created, we need mdadm to update it with our array info:

# mdadm --detail --scan >> /etc/mdadm.conf

Open /etc/mdadm.conf and make a note of the second UUID, for our RAID. We'll be adding that to dracut.conf.

Next, we need to set our locale. We do this by uncommenting our locale in /etc/default/libc-locales:

# vi /etc/default/libc-locales
            
#en_NZ ISO-8859-1
#en_PH.UTF-8 UTF-8
#en_PH ISO-8859-1
#en_SG.UTF-8 UTF-8
#en_SG ISO-8859-1

en_US.UTF-8 UTF-8

#en_US ISO-8859-1
#en_ZA.UTF-8 UTF-8
#en_ZA ISO-8859-1
#en_ZM UTF-8
#en_ZW.UTF-8 UTF-8
#en_ZW ISO-8859-1
#es_AR.UTF-8 UTF-8
#es_AR ISO-8859-1
#es_BO.UTF-8 UTF-8
#es_BO ISO-8859-1
#es_CL.UTF-8 UTF-8
#es_CL ISO-8859-1
#es_CO.UTF-8 UTF-8
#es_CO ISO-8859-1
#es_CR.UTF-8 UTF-8
#es_CR ISO-8859-1
#es_CU UTF-8
...

Once we've established our locale, we're ready to configure:

# xbps-reconfigure -f glibc-locales

We now edit our dracut.conf file, enabling hostonly, adding our mdadm module, support for our /tmp directory, and command line parameters to assemble the RAID on startup:

# vi /etc/dracut.conf

# PUT YOUR CONFIG HERE OR IN separate files named *.conf
# in /etc/dracut.conf.d
# SEE man dracut.conf(5)

# Sample dracut config file

#logfile=/var/log/dracut.log
#fileloglvl=6

# Exact list of dracut modules to use.  Modules not listed here are not going
# to be included.  If you only want to add some optional modules use
# add_dracutmodules option instead.
#dracutmodules+=""

# dracut modules to omit
#omit_dracutmodules+=""

# dracut modules to add to the default
add_dracutmodules+=" mdraid "

# additional kernel modules to the default
#add_drivers+=""

# list of kernel filesystem modules to be included in the generic initramfs
#filesystems+=""

# build initrd only to boot current hardware
hostonly="yes"

# install local /etc/mdadm.conf
mdadmconf="yes"

# install local /etc/lvm/lvm.conf
#lvmconf="no"

# A list of fsck tools to install. If it's not specified, module's hardcoded
# default is used, currently: "umount mount /sbin/fsck* xfs_db xfs_check
# xfs_repair e2fsck jfs_fsck reiserfsck btrfsck". The installation is
# opportunistic, so non-existing tools are just ignored.
#fscks=""

# inhibit installation of any fsck tools
#nofscks="yes"

# mount / and /usr read-only by default
#ro_mnt="no"

# set the directory for temporary files
# default: /var/tmp
tmpdir=/tmp

# Additional kernel command line options
kernel_cmdline+=" rd.md.uuid=06bea12f:4e670e35:a82908ae:b626c42b "

We need to have a look at /lib/modules to get our Linux kernel version

# cd /lib/modules
# ls -la

Which should return something akin to:

drwxr-xr-x  3 root root   21 Jan 31 15:22 .
drwxr-xr-x 23 root root 8192 Jan 31 15:22 ..
drwxr-xr-x  3 root root 4096 Jan 31 15:22 4.0.4_1

Once dracut.conf has been edited, we can update dracut:

# dracut --force --hostonly '' 4.0.4_1

We are now ready to install GRUB and configure our install:

# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=void_grub --boot-directory=/boot --recheck --debug
# xbps-reconfigure -f linux4.0

Upon successful install and configure, we can exit both chroot and sudo, unmount our filesystem, and boot into our new Void install.

$ exit
# exit
# sudo umount -R /mnt
# sudo reboot

Congratulations, you've entered the void.

IF YOUR MACHINE DOES NOT DETECT VOID GRUB AS A BOOTABLE OPTION (A note about UEFI):

Void's Grub install, by default, installs the *.efi file as /boot/efi/EFI/GRUB/grubx64.efi
However, some UEFI implementations look for the file by a different name, and in a different subdirectory.

Copy grubx64.efi to another location, expected by some implementations:

mkdir /boot/efi/EFI/BOOT
cp -p /boot/efi/EFI/GRUB/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.efi

Alternatively, some implementations are case-sensitive, and seek the same file, with a lower-case name:

mkdir /boot/efi/EFI/BOOT
cp -p /boot/efi/EFI/GRUB/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi