Alpine LVM installation with UEFI/Legacy BIOS booting support

1 post / 0 new
#1 Fri, 2018-03-23 17:09
timfayz
  • timfayz's picture
  • Offline
  • Last seen: 1 day 23 hours ago
  • Joined: 2018-01-19

Hi folks! :)
I'm very new to Alpine and want somebody help me to check if the steps I've done are correct with regards to my intention.
I want to move from Arch+Windows [GPT, dual boot using built-in EFI menu] to Alpine+Windows [GPT, legacy BIOS booting support, XEN, LVM partitions for both Alpine as Dom0 and virtualized Windows as Dom1]. Let's say it is my "research" idea :). How to make an instance of Windows in XEN and how to install it is out of the scope. I will do it on my own. I'm concerning more about booting process: propertly configured flags & options, syslinux.conf, included features & modules into initramfs, etc. The installation will be made using external HDD. There are two reasons for this: (1) to be sure everything works ok before moving to built-in one and (2) to make the solution portable/Live. **Please, no GRUB**. Want to make it done using SYSLINUX only.

So, here is how I "imagine" the disk layout should be:

[mbrgpt.bin] # see [3]
[protective MBR]
[GPT table]
EFI partition (FAT32, 200MB) # mount point is /mnt/EFI, see [1]
LVM partition
    /boot (FAT32, 200MB)  # mount point is /mnt/LVM/boot, see [2]
    / (EXT4, 40GB)        # mount point is /mnt/LVM/root
    windows (NTFS, 60GB)
   ...

This is my assumption list:

  • [1] I need to copy /usr/share/syslinux/efi64/syslinux.efi as /mnt/EFI/EFI/Boot/bootx64.efi and create /mnt/EFI/loader/entries/alpine.conf. Content of the latter should coincide with syslinux.cfg. For reference I use: https://wiki.alpinelinux.org/wiki/Create_UEFI_boot_USB#Create_configuration_files_for_boot_loader
  • [2] I know it's not a good idea to make /boot part of LVM structure but for research purposes - want it to be a logical volume anyway (or do not create it at all). I heard at Arch Linux forum that SYSLINUX does support it. However, didn't find any "witnesses" on the web.
  • [3] If I boot from legacy BIOS system, gptmbr.bin should somehow to find and jump over to /mnt/LVM/boot/syslinux/ldsyslinux.c32. Then load syslinux.cfg and determine how XEN kernel should be started.
  • If I boot from UEFI system, syslinux.efi starts and options taken from loader/entries/alpine.conf (certainly, content should coincide with syslinux.cfg).

There is some uncertainty about the things I didn't find much information on the web:

  • Difference between Syslinux's ldlinux.sys and ldlinux.c32. There is some information on Arch's wiki which says sys is loader and loads rest of itself from c32. Nothing more..
  • Difference between Syslinux's mbr.bin and gptmbr.bin boot records. Seems like the second one is what I need but don't know why.

This is my "TODO" list (things like mkdir & umount were skiped for short). Please note, steps marked with (?) need for additional clarification:

1. Partitioning medium
gdisk /dev/sdx
# create new GPT table
# create EFI partition and set type to "EFI System" (sdx1)
# create Linux LVM part and set type to "Linux LVM" (sdx2)
# set an attribute for EFI part (?)
# known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable (seems like this is what gptmbr.bin need to pick it up)
60: read-only
62: hidden
63: do not automount
 
2. Format EFI partition 
apk add dosfstools
mkfs.fat -F 32 /dev/sdx1
 
3. Copy SYSLINUX's UEFI bootloader
mount /dev/sdx1 /mnt/EFI
cp /usr/share/syslinux/efi64/syslinux.efi /mnt/EFI/EFI/Boot/bootx64.efi
 
4. Install LVM
apk add lvm2
rc-update add lvm
# add device mapper
modprobe dm-mod
echo dm-mod >> /etc/modules
 
5. Create LVM layout
pvcreate /dev/sdx2
vgcreate vg0 /dev/sdX2
# root
lvcreate -n root -L 40G vg0
mkfs.ext4 /dev/vg0/root
# boot
lvcreate -n boot -L 200M vg0
mkfs.fat -F 32 /dev/vg0/boot
# windows etc goes here ...
 
6. Rebuild initramfs
mount /dev/vg0/root /mnt/LVM/root
vi /etc/mkinitfs/mkinitfs.conf # append lvm to features=".."
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /mnt/LVM/boot
 
7. Create swap file
mount /dev/vg0/root /mnt/LVM/root && cd /mnt/LVM/root
fallocate -l 2G ./swapfile
# or dd if=/dev/zero of=./swapfile bs=1M count=2048
chmod 600 ./swapfile
mkswap ./swapfile
swapon ./swapfile
rc-update add swap
# add '/swapfile none swap defaults 0 0' to /etc/fstab
 
8. Install SYSLINUX package & burn VBR
apk add syslinux
dd if=/usr/share/syslinux/gptmbr.bin of=/dev/sdx
 
9. Copy Alpine
mount /dev/vg0/boot /mnt/LVM/boot
setup-bootable /path/to/latest-alpine.iso /mnt/LVM/boot
 
10. Install SYSLINUX and tight things together
syslinux --directory /boot/syslinux/ --install /dev/sdb1
vi /mnt/LVM/boot/syslinux/syslinux.cfg # (?)
vi /mnt/EFI/loader/entries/alpine.conf # (?)
 
Last. Store changes made locally into root
lbu package - | tar -C /mnt/LVM/root -xzf -

Questions:

  1. Are the steps above a good way to go? If I missed something or overcomplicated, please let me know.
  2. Do I need to mark /dev/vg0/boot somehow in order gptmbr.bin could find the partition when it boots?
  3. Can I get rid of LVM boot partition and substitute /mnt/LVM/boot with /mnt/LVM/root where I mentioned it?