summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Hagen <kim@sentrium.io>2021-07-29 15:42:06 -0500
committerKim Hagen <kim@sentrium.io>2021-07-29 15:42:06 -0500
commitf81f65598555f88f1b0535807da7418e5326be67 (patch)
tree1b1083ec4100a1cfea184e941781b4ac05bb880c
parentca2a4e78bedd6ec8d6dffd94009163596c1c5e1c (diff)
downloadvyos-live-build-f81f65598555f88f1b0535807da7418e5326be67.tar.gz
vyos-live-build-f81f65598555f88f1b0535807da7418e5326be67.zip
create loop partitions with mknod instead of bind mounting /dev
-rwxr-xr-xfunctions/losetup.sh97
-rwxr-xr-xscripts/build/chroot_devpts101
2 files changed, 113 insertions, 85 deletions
diff --git a/functions/losetup.sh b/functions/losetup.sh
index 9d9b46e5d..8cacfcf82 100755
--- a/functions/losetup.sh
+++ b/functions/losetup.sh
@@ -31,6 +31,39 @@ Lodetach ()
sync
sleep 1
+ if [ "${LB_IMAGE_TYPE}" = "hdd" ];
+ then
+ case "${LB_BUILD_WITH_CHROOT}" in
+ true)
+ PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings "${DEVICE}" | tail -n +2 | sort)
+ COUNTER=1
+ for i in $PARTITIONS; do
+ if [ -e "chroot/${DEVICE}p${COUNTER}" ]
+ then
+ Chroot chroot "rm -f ${DEVICE}p${COUNTER}"
+ fi
+ if [ -e "${DEVICE}p${COUNTER}" ]
+ then
+ rm -f ${DEVICE}p${COUNTER}
+ fi
+ COUNTER=$((COUNTER + 1))
+ done
+ ;;
+
+ false)
+ PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings "${DEVICE}" | tail -n +2 | sort)
+ COUNTER=1
+ for i in $PARTITIONS; do
+ if [ -e "${DEVICE}p${COUNTER}" ]
+ then
+ rm -f ${DEVICE}p${COUNTER}
+ fi
+ COUNTER=$((COUNTER + 1))
+ done
+ ;;
+ esac
+ fi
+
${LB_LOSETUP} -d "${DEVICE}" || Lodetach "${DEVICE}" "$(expr ${ATTEMPT} + 1)"
}
@@ -46,19 +79,57 @@ Losetup ()
LOOPDEVICE="$(echo ${DEVICE}p${PARTITION})"
- if [ "${PARTITION}" = "0" ]
- then
- Echo_message "Mounting %s with offset 0" "${DEVICE}"
-
- ${LB_LOSETUP} --partscan "${DEVICE}" "${FILE}"
- else
- SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
- OFFSET="$(expr ${SECTORS} '*' 512)"
-
- Echo_message "Mounting %s with offset %s" "${DEVICE}" "${OFFSET}"
-
- ${LB_LOSETUP} --partscan -o "${OFFSET}" "${DEVICE}" "${FILE}"
- fi
+ if [ "${LB_IMAGE_TYPE}" = "hdd" ]
+ then
+ losetup --partscan "${DEVICE}" "${FILE}"
+ case "${LB_BUILD_WITH_CHROOT}" in
+ true)
+ PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings "${DEVICE}" | tail -n +2 | sort)
+ COUNTER=1
+ for i in $PARTITIONS; do
+ MAJ=$(echo $i | cut -d: -f1)
+ MIN=$(echo $i | cut -d: -f2)
+ if [ ! -e "chroot/${DEVICE}p${COUNTER}" ]
+ then
+ Chroot chroot "mknod ${DEVICE}p${COUNTER} b $MAJ $MIN"
+ fi
+ if [ ! -e "${DEVICE}p${COUNTER}" ]
+ then
+ mknod ${DEVICE}p${COUNTER} b $MAJ $MIN
+ fi
+ COUNTER=$((COUNTER + 1))
+ done
+ ;;
+
+ false)
+ PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings "${DEVICE}" | tail -n +2 | sort)
+ COUNTER=1
+ for i in $PARTITIONS; do
+ MAJ=$(echo $i | cut -d: -f1)
+ MIN=$(echo $i | cut -d: -f2)
+ if [ ! -e "${DEVICE}p${COUNTER}" ]
+ then
+ mknod ${DEVICE}p${COUNTER} b $MAJ $MIN
+ fi
+ COUNTER=$((COUNTER + 1))
+ done
+ ;;
+ esac
+ else
+ if [ "${PARTITION}" = "0" ]
+ then
+ Echo_message "Mounting %s with offset 0" "${DEVICE}"
+
+ ${LB_LOSETUP} --partscan "${DEVICE}" "${FILE}"
+ else
+ SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
+ OFFSET="$(expr ${SECTORS} '*' 512)"
+
+ Echo_message "Mounting %s with offset %s" "${DEVICE}" "${OFFSET}"
+
+ ${LB_LOSETUP} --partscan -o "${OFFSET}" "${DEVICE}" "${FILE}"
+ fi
+ fi
}
# adapted from lib/ext2fs/mkjournal.c, default block size is 4096 bytes (/etc/mke2fs.conf).
diff --git a/scripts/build/chroot_devpts b/scripts/build/chroot_devpts
index 713ff28ae..d917bc4d4 100755
--- a/scripts/build/chroot_devpts
+++ b/scripts/build/chroot_devpts
@@ -29,89 +29,46 @@ Require_stagefile .build/config .build/bootstrap
case "${1}" in
install)
- if [ "${LIVE_IMAGE_TYPE}" = "hdd" ]; then
- Echo_message "Begin mounting /dev..."
+ Echo_message "Begin mounting /dev/pts..."
- # Checking stage file
- Check_stagefile .build/chroot_devpts
+ # Checking stage file
+ Check_stagefile .build/chroot_devpts
- # Checking lock file
- Check_lockfile .lock
+ # Checking lock file
+ Check_lockfile .lock
- # Creating lock file
- Create_lockfile .lock
+ # Creating lock file
+ Create_lockfile .lock
- # Creating mountpoint
- mount --bind /dev chroot/dev || true
- mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
+ # Creating mountpoint
+ mkdir -p chroot/dev/pts
- # Creating stage file
- Create_stagefile .build/chroot_devpts
- else
- Echo_message "Begin mounting /dev/pts..."
+ # Mounting /dev/pts
+ mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
- # Checking stage file
- Check_stagefile .build/chroot_devpts
+ # Creating stage file
+ Create_stagefile .build/chroot_devpts
+ ;;
- # Checking lock file
- Check_lockfile .lock
+ remove)
+ Echo_message "Begin unmounting /dev/pts..."
- # Creating lock file
- Create_lockfile .lock
+ # Checking lock file
+ Check_lockfile .lock
- # Creating mountpoint
- mkdir -p chroot/dev/pts
+ # Creating lock file
+ Create_lockfile .lock
- # Mounting /dev/pts
- mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
+ # Unmounting /dev/pts
+ if grep -qs "$(pwd)/chroot/dev/pts" /proc/mounts || Find_files chroot/dev/pts/*
+ then
+ umount chroot/dev/pts
+ else
+ umount -f chroot/dev/pts > /dev/null 2>&1 || true
+ fi
- # Creating stage file
- Create_stagefile .build/chroot_devpts
- fi
- ;;
-
- remove)
- if [ "${LIVE_IMAGE_TYPE}" = "hdd" ]; then
- Echo_message "Begin unmounting /dev..."
-
- # Checking lock file
- Check_lockfile .lock
-
- # Creating lock file
- Create_lockfile .lock
-
- # Unmounting /dev
- if grep -qs "$(pwd)/chroot/dev" /proc/mounts || Find_files chroot/dev/*
- then
- umount chroot/dev/pts
- umount chroot/dev
- else
- umount -f chroot/dev/pts > /dev/null 2>&1 || true
- umount -f chroot/dev > /dev/null 2>&1 || true
- fi
-
- # Removing stage file
- rm -f .build/chroot_devpts
- else
- Echo_message "Begin unmounting /dev/pts..."
-
- # Checking lock file
- Check_lockfile .lock
-
- # Creating lock file
- Create_lockfile .lock
-
- # Unmounting /dev/pts
- if grep -qs "$(pwd)/chroot/dev/pts" /proc/mounts || Find_files chroot/dev/pts/*
- then
- umount chroot/dev/pts
- else
- umount -f chroot/dev/pts > /dev/null 2>&1 || true
- fi
-
- # Removing stage file
- rm -f .build/chroot_devpts
- fi
+ # Removing stage file
+ rm -f .build/chroot_devpts
;;
*)