From f81f65598555f88f1b0535807da7418e5326be67 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Thu, 29 Jul 2021 15:42:06 -0500 Subject: create loop partitions with mknod instead of bind mounting /dev --- functions/losetup.sh | 97 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 13 deletions(-) (limited to 'functions/losetup.sh') 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). -- cgit v1.2.3