This guide file is deprecated.
Please look at install script to know the detailed installation procedure.
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.
{{ ... }}
: provide your own data/parameter.
- 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).
sudo su -
apt-get install git
git clone https://github.com/antonio-petricca/buddy-linux.git
cd buddy-linux
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
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}
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}
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"
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
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}
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
Add settings to grub.cfg header:
-
vi ${LVM_DEFAULT_CONF}/grub
- Set
GRUB_TIMEOUT=30
- Set
GRUB_TIMEOUT_STYLE="menu"
- Set
-
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
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}/
sync
reboot
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.
- 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.
- 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).
- You can install on MMC too (put /dev/mmcblk0p1 on FSTAB as /boot).
- 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. - Systemd debug:
- Kernel debug parameters:
systemd.log_level=debug systemd.log_target=console console=ttyS0,38400 console=tty1
- [Client](https://gist.github.com/snb/284940/11e6354f170be602c9c2f67b59d489ed49ebd143:
screen /tmp/host-pipe.socket
- Unclean shutdown : mitigated by EXT4 journal recover (to be fixed).
- Syslog error "blk_update_request: I/O error, dev loopX, sector X" : it disappears on kernel 4.13 or above.
- Syslog error "print_req_error:: I/O error, dev loopX, sector X": get logged only once on kernel 4.15.
- 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.
- 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.
- During shutdown with Dracut you get many warnings from dmraid. Please ignore them
I suggest you to keep NTFS-3G driver updated to the latest release.
- A Quick Dracut Module
- Back to “initramfs” on Debian by systemd “shutdown to initramfs” feature
- blk_update_request: I/O error (1)
- blk_update_request: I/O error (2)
- blk_update_request: I/O error (3)
- Block: loop: improve performance via blk-mq
- Clean shutdown with systemd
- CentOS7 Dracut lvm command not found
- Bug#778849: Support restoring initrd on shutdown and pivoting into it
- Diagnosing Boot Problems
- Dracut introduction
- dracut-ntfsloop: Mount image on NTFS partition
- dracut-shutdown (8)
- dracut-shutdown.service
- eMMC transfer speed significantly slower than stock u-boot
- Ensure that loopback root and host are unmounted on shutdown
- High load freezes ubuntu completely everytime
- Hint: "blk_update_request: I/O error, dev loop0, sector xxxxxxxx" + freezing system (SSD) workaround?
- How to debug Dracut problems
- How to debug Systemd problems
- Kernel Hard Freezing Very Often
- Linux File Systems: Ext2 vs Ext3 vs Ext4
- Netconsole
- Netconsole
- systemd/src/core/killall.c
- systemd and Storage Daemons for the Root File System
- systemd shutdown: switch-root after remounting root fs ro
- System freeze on high memory usage
- System freeze on high memory usage
- The initrd Interface of systemd
- vgchange may deadlock in initramfs when VG present that's not used for rootfs
- Virtualbox serial console