From 909115cc43f06c2305e6fb1b75832d73014da60e Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Tue, 23 Oct 2018 01:07:23 +0800 Subject: supporting specifying the block device name as root/boot partition Now we can build a live USB like this: ./buildlive --boot /dev/sdb1 --root /dev/sdb2 \ manjaro/64/kde xubuntu/18.04 --- buildlive | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/buildlive b/buildlive index 3440592..ef9b285 100755 --- a/buildlive +++ b/buildlive @@ -14,6 +14,8 @@ DATADIR= INSTALL_GRUB=1 GRUBCFG_ONLY=0 DOWNLOAD_ONLY=0 +UMOUNT_BOOT=0 +UMOUNT_ROOT=0 . functions.sh @@ -42,6 +44,18 @@ options: EOF } +try_mount() { + local mnt + if [[ "$1" =~ ^/dev ]] + then + mnt=$(mktemp -u /media/buildlive.XXXXXX) + udevil mount "$1" "$mnt" > /dev/null + else + mnt="$1" + fi + echo "$mnt" +} + unset ISOPATH CFGFILE="$HOME/.liveusb-builder" test -f "$CFGFILE" && source "$CFGFILE" || true @@ -100,8 +114,20 @@ if [[ -z "$ROOTPATH" && "$DOWNLOAD_ONLY" == 0 ]]; then exit 1 fi +_mnt="$(try_mount "$ROOTPATH")" +if [ "${_mnt}" != "$ROOTPATH" ]; then + ROOTPATH="${_mnt}" + UMOUNT_ROOT=1 +fi + if [[ -z "$BOOTPATH" ]]; then BOOTPATH="$ROOTPATH" +else + _mnt="$(try_mount "$BOOTPATH")" + if [ "${_mnt}" != "$BOOTPATH" ]; then + BOOTPATH="${_mnt}" + UMOUNT_BOOT=1 + fi fi if [[ "$DOWNLOAD_ONLY" == 0 ]]; then @@ -181,3 +207,12 @@ elif [ "$INSTALL_GRUB" == 1 ]; then as-root grub-install --boot-directory="$BOOTPATH" --efi-directory="$BOOTPATH" --bootloader-id=grub --target=x86_64-efi --removable --no-nvram "$DEVNAME" fi fi + +if [ "$UMOUNT_BOOT" == 1 ]; then + msg 'Trying to umount the boot mountpoint, you may need to wait for sync() to complete.' + udevil umount "$BOOTPATH" +fi +if [ "$UMOUNT_ROOT" == 1 ]; then + msg 'Trying to umount the root mountpoint, you may need to wait for sync() to complete.' + udevil umount "$ROOTPATH" +fi -- cgit v1.2.3