# helper functions {{{
cleanup() {
- set -x
- einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
- einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
+ if [ -n "$CHROOT_VARIABLES" ] ; then
+ einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
+ fi
+
+ if [ -n "$STAGES" ] ; then
+ einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
+ fi
# Remove temporary mountpoint again
if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
- einfo "Removing directory ${MNTPOINT}"
- rmdir "$MNTPOINT"
- eend $?
+ rmdir "$MNTPOINT" 2>/dev/null
fi
# make sure $TARGET is not mounted when exiting grml-debootstrap
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1
- # ugly, but make sure we really don't leave anything (/proc /proc is intended)
- for ARG in /sys /proc /proc ; do
+ # ugly, but make sure we really don't leave anything (/proc /proc and
+ # /dev /dev are intended, trying to work around timing issues, see #657023)
+ for ARG in /sys /proc /proc /dev /dev ; do
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1
umount "$MNTPOINT"/$ARG >/dev/null 2>&1
done
- umount "$MNTPOINT"/dev >/dev/null 2>&1
- [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1
+ if [ -n "$ISODIR" ] ; then
+ [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1
+ fi
if [ -n "$DIRECTORY" ] ; then
einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
cleanup
[ -n "$1" ] && EXIT="$1" || EXIT="1"
- [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
+ [ -n "$2" ] && einfo "Notice: remove $STAGES/$2 to reexecute the stage"
exit "$EXIT"
}
# }}}
# make sure we have what we need {{{
-check4progs debootstrap dialog || bailout 1
+check4progs debootstrap || bailout 1
# }}}
# source main configuration file {{{
# make sure we have what we need {{{
if [ -n "$VIRTUAL" ] ; then
- check4progs kpartx mksh qemu-img || bailout 1
+ check4progs kpartx mksh parted qemu-img || bailout 1
fi
# }}}
# interactive mode {{{
interactive_mode()
{
+ check4progs dialog || bailout 1
+
welcome_dialog
prompt_for_release
dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
parted -s "${TARGET}" 'mkpart primary ext3 2M -1'
+ # 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 ; 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 -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
if [ -z "${DEVINFO}" ] ; then
eerror "Error setting up loopback device." ; eend 1
preparechroot execute_pre_scripts chrootscript execute_scripts \
umount_chroot finalize_vm fscktool ; do
if stage "${i}" ; then
- $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
+ $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "$i"
fi
done