Add check_loop_device helper for debootstrap-ng

This commit is contained in:
zador-blood-stained
2017-07-27 17:33:32 +03:00
parent fa7052927f
commit 8d52a811aa

View File

@@ -15,6 +15,7 @@
# mount_chroot
# umount_chroot
# unmount_on_exit
# check_loop_device
# custom_debootstrap_ng
#
@@ -365,15 +366,7 @@ prepare_partitions()
LOOP=$(losetup -f)
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
# check config-docker.conf for details on this hack
if [[ ! -b $LOOP ]]; then
if [[ $CONTAINER_COMPAT == yes && -b /tmp/$LOOP ]]; then
display_alert "Creating device node" "$LOOP"
mknod -m0660 $LOOP b 7 0x$(stat -c '%T' /tmp/$LOOP)
else
exit_with_error "Device node $LOOP does not exist"
fi
fi
check_loop_device "$LOOP"
# NOTE: losetup -P option is not available in Trusty
losetup $LOOP ${SDCARD}.raw
@@ -387,14 +380,7 @@ prepare_partitions()
rm -f $SDCARD/etc/fstab
if [[ -n $rootpart ]]; then
display_alert "Creating rootfs" "$ROOTFS_TYPE"
if [[ ! -b ${LOOP}p${rootpart} ]]; then
if [[ $CONTAINER_COMPAT == yes && -b /tmp/${LOOP}p${rootpart} ]]; then
display_alert "Creating device node" "${LOOP}p${rootpart}"
mknod -m0660 ${LOOP}p${rootpart} b 259 0x$(stat -c '%T' /tmp/${LOOP}p${rootpart})
else
exit_with_error "Device node ${LOOP}p${rootpart} does not exist"
fi
fi
check_loop_device "${LOOP}p${rootpart}"
mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} ${LOOP}p${rootpart}
[[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback ${LOOP}p${rootpart} > /dev/null
[[ $ROOTFS_TYPE == btrfs ]] && local fscreateopt="-o compress-force=zlib"
@@ -404,14 +390,7 @@ prepare_partitions()
fi
if [[ -n $bootpart ]]; then
display_alert "Creating /boot" "$bootfs"
if [[ ! -b ${LOOP}p${bootpart} ]]; then
if [[ $CONTAINER_COMPAT == yes && -b /tmp/${LOOP}p${bootpart} ]]; then
display_alert "Creating device node" "${LOOP}p${bootpart}"
mknod -m0660 ${LOOP}p${bootpart} b 259 0x$(stat -c '%T' /tmp/${LOOP}p${bootpart})
else
exit_with_error "Device node ${LOOP}p${bootpart} does not exist"
fi
fi
check_loop_device "${LOOP}p${bootpart}"
mkfs.${mkfs[$bootfs]} ${mkopts[$bootfs]} ${LOOP}p${bootpart}
mkdir -p $MOUNT/boot/
mount ${LOOP}p${bootpart} $MOUNT/boot/
@@ -559,3 +538,18 @@ unmount_on_exit()
rm -rf --one-file-system $SDCARD
exit_with_error "debootstrap-ng was interrupted"
} #############################################################################
# check_loop_device <device_node>
#
check_loop_device()
{
local device=$1
if [[ ! -b $device ]]; then
if [[ $CONTAINER_COMPAT == yes && -b /tmp/$device ]]; then
display_alert "Creating device node" "$device"
mknod -m0660 $device b 0x$(stat -c '%t' "/tmp/$device") 0x$(stat -c '%T' "/tmp/$device")
else
exit_with_error "Device node $device does not exist"
fi
fi
} #############################################################################