Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve checks to make sure loop and dm-mod module are present #111

Merged
merged 2 commits into from Nov 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 15 additions & 19 deletions grml-debootstrap
Expand Up @@ -1387,6 +1387,21 @@ prepare_vm() {
bailout 1
fi

# make sure loop module is present and an usable loop device exists
modprobe -q loop
if ! losetup -f >/dev/null 2>&1; then
eerror "Error finding usable loop device" ; eend 1
bailout 1
fi

# if dm-mod isn't available then kpartx will fail with
# "Is device-mapper driver missing from kernel? [...]"
modprobe -q dm-mod
if ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then
einfo "Device-mapper support missing in kernel."
bailout 1
fi

ORIG_TARGET="$TARGET" # store for later reuse

if [ -n "$VMFILE" ]; then
Expand All @@ -1404,25 +1419,6 @@ prepare_vm() {
parted -s "${TARGET}" 'mkpart primary ext4 2M -1'
parted -s "${TARGET}" 'set 1 boot on'

# if dm-mod isn't available then kpartx will fail with
# "Is device-mapper driver missing from kernel? [...]"
if ! kpartx -av "$TARGET" >/dev/null 2>&1 || ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then
einfo "Device-mapper not ready yet, trying to load dm-mod module."
modprobe dm-mod ; eend $?
fi

# make sure loop module is present
if ! losetup -f >/dev/null 2>&1; then
einfo "Can not find a usable loop device, retrying after loading loop module."
modprobe loop
if losetup -f >/dev/null 2>&1; then
einfo "Found a usable loop device now, continuing."
else
eerror "Error finding usable loop device" ; eend 1
bailout 1
fi
fi

DEVINFO=$(kpartx -asv "$TARGET") # e.g. 'add map loop0p1 (254:5): 0 20477 linear 7:0 3'
if [ -z "${DEVINFO}" ] ; then
eerror "Error setting up loopback device." ; eend 1
Expand Down