summaryrefslogtreecommitdiff
path: root/functions
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 /functions
parentca2a4e78bedd6ec8d6dffd94009163596c1c5e1c (diff)
downloadvyos-live-build-f81f65598555f88f1b0535807da7418e5326be67.tar.gz
vyos-live-build-f81f65598555f88f1b0535807da7418e5326be67.zip
create loop partitions with mknod instead of bind mounting /dev
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/losetup.sh97
1 files changed, 84 insertions, 13 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).