Skip to content

Latest commit

 

History

History
275 lines (204 loc) · 11.3 KB

README-EXPERTS.md

File metadata and controls

275 lines (204 loc) · 11.3 KB

Buddy Linux (Experts Guide)

Notice

This guide file is deprecated.

Please look at install script to know the detailed installation procedure.

Introduction

This guide will provide you detailed instructions, as an alternative to the automated install script on how to install Linux on a LVM loopback disk booting from an arbitrary device (grub and boot partition), like a USB drive, without have to write to your PC internal disk boot sector.

Conventions

{{ ... }} : provide your own data/parameter.

Pre-requisites

  • Boot from a Live Debian or derivated distribution.
  • Insert a USB drive for bootloader, then umount it (if you want to boot from an external device).

Clone repository


sudo su -
apt-get install git

git clone https://github.com/antonio-petricca/buddy-linux.git
cd buddy-linux

Parameters

Set following (example) parameters as you need:

PARAM_BOOT_DEV=/dev/sdc
PARAM_BOOT_PART=1
PARAM_HOST_UUID=$(blkid -s UUID -o value -t LABEL=OS)
PARAM_HOST_FSTYPE=ntfs-3g
PARAM_HOST_FSOPTIONS=noatime
PARAM_LOOP_DIR=.linux-loops
PARAM_LOOP_SIZE=100
PARAM_LVM_VG=vg_system
PARAM_LVM_LV_ROOT=lv_root
PARAM_LVM_LV_SWAP=lv_swap
PARAM_LVM_LV_SWAP_SIZE=16G

Environment setup

BOOT_MNT=/mnt/boot
BOOT_PART=${PARAM_BOOT_DEV}${PARAM_BOOT_PART}
HOST_UUID=UUID=${PARAM_HOST_UUID}
HOST_MNT=/mnt/host
LOOP_DEV=$(losetup -f)
LOOP_DIR=${HOST_MNT}/${PARAM_LOOP_DIR}
LOOP_FILE=${LOOP_DIR}/${PARAM_LVM_VG}0.lvm
LOOP_SIZE=$((PARAM_LOOP_SIZE * 1000))
LVM_TARGET_MNT=/mnt/target
LVM_DEFAULT_CONF=${LVM_TARGET_MNT}/etc/default
LVM_GRUB_CONF=${LVM_TARGET_MNT}/etc/grub.d
LVM_DRACUT_CONF=${LVM_TARGET_MNT}/etc/dracut.conf.d
LVM_DRACUT_MODULES=${LVM_TARGET_MNT}/usr/lib/dracut/modules.d
LVM_INITRAMFS_CONF=${LVM_TARGET_MNT}/etc/initramfs-tools/conf.din
LVM_INITRAMFS_SCRIPTS=${LVM_TARGET_MNT}/etc/initramfs-tools/scripts
LVM_LOGROTATE_CONF=${LVM_TARGET_MNT}/etc/logrotate.d
LVM_RSYSLOG_CONF=${LVM_TARGET_MNT}/etc/rsyslog.d
LVM_LV_ROOT_DEV=/dev/${PARAM_LVM_VG}/${PARAM_LVM_LV_ROOT}

System loop files setup

Attention: I suggest you to create a NON LVM swap file because it cannot be accessed as a raw partition, avoiding you system freeze on low memory.

mkdir -p ${HOST_MNT}
mount ${HOST_UUID} ${HOST_MNT}

dd status=progress if=/dev/zero of=${LOOP_FILE} bs=1M count=${LOOP_SIZE}

losetup ${LOOP_DEV} ${LOOP_FILE}

pvcreate -v ${LOOP_DEV}
vgcreate -v ${PARAM_LVM_VG} ${LOOP_DEV}

lvcreate -v -L ${PARAM_LVM_LV_SWAP_SIZE} -n ${PARAM_LVM_LV_SWAP} ${PARAM_LVM_VG}

lvcreate -v -l 100%FREE -n ${PARAM_LVM_LV_ROOT} ${PARAM_LVM_VG}

Linux distribution install

ubiquity &
  - Partitioning: something else
  - "Device for boot loader installation": ${PARAM_BOOT_DEV}
  - ${BOOT_PART} ext4 512Mb @ "/boot"
  - /dev/mapper/${PARAM_LVM_VG}-${PARAM_LVM_LV_ROOT} @ "/"
  - ${PARAM_LVM_LV_SWAP} @ "swap"
  - Click on "Install Now"

Build InitRd image

mkdir -p ${LVM_TARGET_MNT}
mount ${LVM_LV_ROOT_DEV} ${LVM_TARGET_MNT}

mkdir -p ${BOOT_MNT}
mount ${BOOT_PART} ${BOOT_MNT}

echo "nameserver 8.8.8.8" > ${LVM_TARGET_MNT}/etc/resolv.conf

InitRamFs Tools

cp assets/initramfs/lvm-loops-setup ${LVM_INITRAMFS_SCRIPTS}/local-top/
chmod +x ${LVM_INITRAMFS_SCRIPTS}/local-top/*

cp assets/initramfs/lvm-loops-finalize ${LVM_INITRAMFS_SCRIPTS}/local-bottom/
chmod +x ${LVM_INITRAMFS_SCRIPTS}/local-bottom/*

cp assets/initramfs/compress ${LVM_INITRAMFS_CONF}

chroot ${LVM_TARGET_MNT} /usr/sbin/update-initramfs -uv -k all
mv -v ${LVM_TARGET_MNT}/boot/* ${BOOT_MNT}

Dracut

mount --bind /dev ${LVM_TARGET_MNT}/dev
mount --bind /dev ${LVM_TARGET_MNT}/dev/pts
mount --bind /sys ${LVM_TARGET_MNT}/sys
mount --bind /proc ${LVM_TARGET_MNT}/proc
mount --bind /run ${LVM_TARGET_MNT}/run
mount --bind ${BOOT_MNT} ${LVM_TARGET_MNT}/boot

chroot ${LVM_TARGET_MNT} /usr/bin/apt-get install -y --no-install-recommends dracut

cp -v assets/dracut/*.conf ${LVM_DRACUT_CONF}/
cp -rv assets/dracut/90buddy-linux/ ${LVM_DRACUT_MODULES}/

cp assets/dracut/update-dracut ${LVM_TARGET_MNT}/sbin/
chroot ${LVM_TARGET_MNT} /sbin/update-dracut --all

umount ${LVM_TARGET_MNT}/dev/pts
umount ${LVM_TARGET_MNT}/dev
umount ${LVM_TARGET_MNT}/sys
umount ${LVM_TARGET_MNT}/proc
umount ${LVM_TARGET_MNT}/run
umount ${LVM_TARGET_MNT}/boot

Grub configuration

Add settings to grub.cfg header:

  • vi ${LVM_DEFAULT_CONF}/grub

    • Set GRUB_TIMEOUT=30
    • Set GRUB_TIMEOUT_STYLE="menu"
  • cp -v assets/grub/buddy-linux.cfg ${LVM_DEFAULT_CONF}/grub.d/

  • cp -v assets/grub/10_buddy-linux ${LVM_GRUB_CONF}/

  • chmod -x ${LVM_GRUB_CONF}/10_linux

Customize ${LVM_DEFAULT_CONF}/grub.d/buddy-linux.cfg with your own settings ($${{ ... }}) ignoring any LVM warning...

mount --bind /dev ${LVM_TARGET_MNT}/dev
mount --bind /dev ${LVM_TARGET_MNT}/dev/pts
mount --bind /sys ${LVM_TARGET_MNT}/sys
mount --bind /proc ${LVM_TARGET_MNT}/proc
mount --bind ${BOOT_MNT} ${LVM_TARGET_MNT}/boot

chroot ${LVM_TARGET_MNT} /usr/sbin/update-grub

umount ${LVM_TARGET_MNT}/dev/pts
umount ${LVM_TARGET_MNT}/dev
umount ${LVM_TARGET_MNT}/sys
umount ${LVM_TARGET_MNT}/proc
umount ${LVM_TARGET_MNT}/boot

Filter out loops error messages

In order to keep your syslog file clean clean (please look at Known issues section) do:

cp assets/rsyslog/30-loop-errors.conf ${LVM_RSYSLOG_CONF}/
cp assets/rsyslog/buddy-linux ${LVM_LOGROTATE_CONF}/

Finally start Linux

sync
reboot

Restore boot drive to a new one

In order to use the boot-drive-backup tool you have to prepare a fresh (USB) drive:

  • Destroy all partitions.
  • Create a new 512Mb ext4 partition.
  • Flag it as BOOTable (else you will get an "Invalid partition table" warning at boot time that you may skip by pressing ESC key).
  • If you wish, partition remaining space as you need (for other use cases).
  • Now run boot-drive-restore to get help on its command line parameters.

FAQ

  1. If you create a new (USB) boot drive remember to update the boot partition UUID inside FSTAB, or use the form /dev/xxxyy to make it independent from your physycal device.
  2. Schedule boot-drive-backup to a cloud drive in order to make your system bootable due to a (USB) drive failure (restore backups by boot-drive-restore).
  3. You can install on MMC too (put /dev/mmcblk0p1 on FSTAB as /boot).
  4. If you host your loopback files on a NTFS volume you can gain performances by setting HOST_DEV_FSOPTIONS=noatime,async,big_writes inside buddy-linux.cfg.
  5. Systemd debug:

Known issues

  1. Unclean shutdown : mitigated by EXT4 journal recover (to be fixed).
  2. Syslog error "blk_update_request: I/O error, dev loopX, sector X" : it disappears on kernel 4.13 or above.
  3. Syslog error "print_req_error:: I/O error, dev loopX, sector X": get logged only once on kernel 4.15.
  4. Swap file on loopback device causes a total system freeze on heavy memory load. After a lot of search and experimentation, the only workaround I have found is to create a standalone swap file hosted inside the same folder of the LVM loop files.
  5. In case of rollback from Dracut, update-initramfs -u -k all does not recognize all the installed kernels, so you have to update the missing ones by hand.
  6. During shutdown with Dracut you get many warnings from dmraid. Please ignore them

NTFS driver update

I suggest you to keep NTFS-3G driver updated to the latest release.

Some references