2 # Filename: grml-debootstrap
3 # Purpose: wrapper around debootstrap for installing plain Debian via Grml
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2+
7 ################################################################################
11 VERSION="$(dpkg-query --show --showformat='${Version}' "$PN")"
12 VERSION="${VERSION:-unknown}"
13 MNTPOINT="/mnt/debootstrap.$$"
16 [ -n "$CHROOT_SCRIPTS" ] || CHROOT_SCRIPTS='yes'
17 [ -n "$CONFFILES" ] || CONFFILES='/etc/debootstrap'
18 [ -n "$DEBCONF" ] || DEBCONF='yes'
19 [ -n "$DEBIAN_FRONTEND" ] || DEBIAN_FRONTEND='noninteractive'
20 [ -n "$DEBOOTSTRAP" ] || DEBOOTSTRAP='debootstrap'
21 [ -n "$DEFAULT_LANGUAGE" ] || DEFAULT_LANGUAGE='en_US:en'
22 [ -n "$DEFAULT_LOCALES" ] || DEFAULT_LOCALES='en_US.UTF-8'
23 [ -n "$DISK_IDENTIFIER" ] || DISK_IDENTIFIER='26ada0c0-1165-4098-884d-aafd2220c2c6'
24 [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes'
25 [ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://http.debian.net/debian'
26 [ -n "$FIXED_DISK_IDENTIFIERS" ] || FIXED_DISK_IDENTIFIERS="no"
27 [ -n "$FORCE" ] || FORCE=''
28 [ -n "$HOSTNAME" ] || HOSTNAME='grml'
29 [ -n "$INITRD" ] || INITRD='yes'
30 [ -n "$INSTALL_NOTES" ] || INSTALL_NOTES='/etc/debootstrap/install_notes'
31 [ -n "$LOCALES" ] || LOCALES='yes'
32 [ -n "$MIRROR" ] || MIRROR="$FALLBACK_MIRROR"
33 [ -n "$MKFS" ] || MKFS='mkfs.ext4'
34 [ -n "$MKFS_OPTS" ] || MKFS_OPTS=''
35 [ -n "$PACKAGES" ] || PACKAGES='yes'
36 [ -n "$PRE_SCRIPTS" ] || PRE_SCRIPTS='yes'
37 [ -n "$RECONFIGURE" ] || RECONFIGURE='console-data'
38 [ -n "$RELEASE" ] || RELEASE='jessie'
39 [ -n "$RM_APTCACHE" ] || RM_APTCACHE='yes'
40 [ -n "$SCRIPTS" ] || SCRIPTS='yes'
41 [ -n "$SECURE" ] || SECURE='yes'
42 [ -n "$TIMEZONE" ] || TIMEZONE='Europe/Vienna'
43 [ -n "$TUNE2FS" ] || TUNE2FS='tune2fs -c0 -i0'
44 [ -n "$UPGRADE_SYSTEM" ] || UPGRADE_SYSTEM='yes'
45 [ -n "$VMSIZE" ] || VMSIZE="2G"
47 # inside the chroot system locales might not be available, so use minimum:
51 # make sure interactive mode is only executed when
52 # using an empty configuration file or option --interactive
58 echo "$PN - wrapper around debootstrap for installing Debian
64 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
65 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
66 instead of fetching packages from a mirror.
67 -r, --release <name> Release of new Debian system (default: jessie).
68 -t, --target <target> Target partition (/dev/...) or directory where the
69 system should be installed to.
70 -p, --mntpoint <mnt> Mountpoint used for mounting the target system,
71 has no effect if -t is given and represents a directory.
72 --debopt <params> Extra parameters passed to the debootstrap command.
73 --interactive Use interactive mode (frontend).
74 --nodebootstrap Skip debootstrap, only do configuration to the target.
75 --grub <device> Target for grub installation. Usage example: /dev/sda
76 --arch <arch> Set target architecture, use for installing i386 on amd64.
77 --filesystem <fs> Filesystem that should be used when target is a partition
78 or Virtual Machine (see --vmfile).
79 --force Do not prompt for user acknowledgement.
81 Options for Virtual Machine deployment:
83 --vm Set up a Virtual Machine, instead of plainly installing
84 to a partition or directory, to be combined with --target,
85 like: --vm --target /dev/mapper/your-vm-disk
86 --vmfile Like --vm, but install into a file (raw format).
87 Example: --vmfile --target /mnt/sda1/qemu.img
88 --vmsize <size> Use specified size for size of VM file (default: 2G).
89 Syntax as supported by qemu-img, like: --vmsize 3G
91 Configuration options:
93 -c, --config <file> Use specified configuration file, defaults to
94 /etc/debootstrap/config
95 -d, --confdir <path> Place of config files for debootstrap, defaults
97 --packages <file> Install packages defined in specified list file
98 instead of using /etc/debootstrap/packages.
99 --nopackages Skip installation of packages defined in
100 /etc/debootstrap/packages
101 --nokernel Skip installation of default kernel images.
102 --nointerfaces Do not copy /etc/network/interfaces from host system
104 (This option is automatically enabled when using --vmfile.)
105 --defaultinterfaces Install a default /etc/network/interfaces file (enabling
106 DHCP for eth0) instead of taking over config from host system.
107 --debconf <file> Pre-seed packages using specified pre-seed db file.
108 --grmlrepos Enable Grml's Debian repository (deb.grml.org).
109 --backportrepos Enable Debian's backports repository (backports.debian.org).
110 --keep_src_list Do not overwrite user provided apt sources.list.
111 --hostname <name> Hostname of Debian system.
112 --nopassword Do not prompt for the root password.
113 --password <pwd> Use specified password as password for user root.
114 --bootappend <line> Add specified appendline to kernel whilst booting.
115 --chroot-scripts <d> Execute chroot scripts from specified directory.
116 --pre-scripts <dir> Execute scripts from specified directory (before chroot-scripts).
117 --scripts <dir> Execute scripts from specified directory (after chroot-scripts).
121 -v, --verbose Increase verbosity.
122 --debug Execute in very verbose way.
123 -h, --help Print this usage information and exit.
124 -V, --version Show summary of options and exit.
126 Usage examples can be found in the grml-debootstrap manpage.
127 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
131 if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then
133 echo 'Please notice that this script requires root permissions!'
138 # early helper functions {{{
149 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
150 printf " ${GOOD}*${NORMAL} $*"
156 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
157 printf " ${BAD}*${NORMAL} $*\n" >&2
163 local retval="${1:-0}"
165 if [ "$retval" -gt 0 ]; then
166 printf " ${BAD}-> Failed (rc=${retval})${NORMAL}\n"
172 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
173 echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
180 which "$arg" >/dev/null 2>&1 || RC="$arg"
182 if [ -n "$RC" ] ; then
183 echo "$RC not installed"
189 # helper functions {{{
191 if [ -n "$CHROOT_VARIABLES" ] ; then
192 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
195 if [ -n "$STAGES" ] ; then
196 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
199 # Remove temporary mountpoint again
200 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
201 rmdir "$MNTPOINT" 2>/dev/null
204 # make sure $TARGET is not mounted when exiting grml-debootstrap
205 if [ -n "$MNTPOINT" ] ; then
206 if grep -q "$MNTPOINT" /proc/mounts ; then
207 # make sure nothing is left inside chroot so we can unmount it
208 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
209 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
211 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1
213 # ugly, but make sure we really don't leave anything (/proc /proc and
214 # /dev /dev are intended, trying to work around timing issues, see #657023)
215 for ARG in /sys /proc /proc /dev /dev ; do
216 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1
217 umount "$MNTPOINT"/$ARG >/dev/null 2>&1
220 if [ -n "$ISODIR" ] ; then
221 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1
224 if [ -n "$DIRECTORY" ] ; then
225 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
227 einfo "Unmounting $MNTPOINT"
232 if [ -n "$STAGES" ] ; then
233 echo -n "Removing stages directory ${STAGES}: "
234 rm -rf "$STAGES" && echo 'done'
237 # remove directory only if we used the default with process id inside the name
238 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
239 einfo "Removing directory ${MNTPOINT}"
246 if [ -n "${ORIG_TARGET}" ] ; then
247 einfo "Removing loopback mount of file ${ORIG_TARGET}."
248 kpartx -d "${ORIG_TARGET}" ; eend $?
252 # we want to exit smoothly and clean:
257 [ -n "$1" ] && EXIT="$1" || EXIT="1"
258 [ -n "$2" ] && einfo "Notice: remove $STAGES/$2 to reexecute the stage"
262 trap bailout HUP INT QUIT TERM
264 # we want to execute all the functions only once, simple check for it:
266 if [ -n "$2" ] ; then
267 echo "$2" > "${STAGES}/${1}"
269 elif grep -q 'done' "${STAGES}/${1}" 2>/dev/null ; then
270 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
271 ewarn " To reexecute it clean up the according directory inside $STAGES" ; eend 0
277 # make sure we have what we need {{{
278 check4progs debootstrap || bailout 1
281 # source main configuration file {{{
282 if [ -r /etc/debootstrap/config ] ; then
283 . /etc/debootstrap/config
287 # cmdline handling {{{
288 # source external command line parameter-processing script
289 if [ -r ./cmdlineopts.clp ] ; then
291 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
292 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
294 eerror "Error: cmdline function file not found, exiting."
299 # == business-logic of command line parameter-processing
301 # source configuration file in <confdir> if supplied. {{{
302 [ "$_opt_confdir" ] && {
303 CONFFILES=$_opt_confdir
304 einfo "Using config files under $CONFFILES/."
305 if ! [ -r "$CONFFILES/config" ] ; then
306 eerror "Error: config file $CONFFILES/config not found."; eend 1; bailout 1
308 if ! . "$CONFFILES/config" ; then
309 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; bailout 1
311 # restore the command line parameter value
312 CONFFILES=$_opt_confdir
316 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
317 [ "$_opt_iso" ] && ISO=$_opt_iso
318 [ "$_opt_release" ] && RELEASE=$_opt_release
319 [ "$_opt_target" ] && TARGET=$_opt_target
320 [ "$_opt_vm" ] && VIRTUAL=1
321 [ "$_opt_vmfile" ] && VMFILE=1 && VIRTUAL=1
322 [ "$_opt_vmsize" ] && VMSIZE=$_opt_vmsize
323 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
324 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
325 [ "$_opt_interactive" ] && INTERACTIVE=1
326 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
327 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
328 [ "$_opt_packages_set" ] && PACKAGES='yes'
329 [ "$_opt_nopackages" ] && PACKAGES=''
330 [ "$_opt_debconf_set" ] && DEBCONF='yes'
331 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
332 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
333 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
334 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
335 [ "$_opt_grmlrepos" ] && GRMLREPOS='yes'
336 [ "$_opt_backportrepos" ] && BACKPORTREPOS='yes'
337 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
338 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
339 [ "$_opt_nopassword" ] && NOPASSWORD='yes'
340 [ "$_opt_defaultinterfaces" ] && USE_DEFAULT_INTERFACES="true"
341 [ "$_opt_nointerfaces" ] && NOINTERFACES="true"
342 [ "$_opt_nokernel" ] && NOKERNEL="true"
343 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
344 [ "$_opt_grub" ] && GRUB=$_opt_grub
345 [ "$_opt_arch" ] && ARCH=$_opt_arch
346 [ "$_opt_insecure" ] && echo "Warning: --insecure is deprecated, continuing anyway."
347 [ "$_opt_force" ] && FORCE=$_opt_force
348 [ "$_opt_verbose" ] && VERBOSE="-v"
349 [ "$_opt_debug" ] && DEBUG="true"
351 if [ "$DEBUG" = "true" ] ; then
355 [ "$_opt_help" ] && {
361 [ "$_opt_version" ] && {
362 einfo "$PN - version $VERSION"
363 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
369 # check for root permissions {{{
370 if ! check4root ; then
371 echo "For usage instructions please execute '$PN --help'."
376 # make sure we have what we need {{{
377 if [ -n "$VIRTUAL" ] ; then
378 check4progs kpartx mksh parted qemu-img || bailout 1
382 # source specified configuration file {{{
383 if [ -n "$CONFIGFILE" ] ; then
384 einfo "Reading specified config file $CONFIGFILE."
385 if ! . "$CONFIGFILE" ; then
386 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; bailout 1
391 # backwards compability checks {{{
392 if [ -n "$GROOT" ] ; then
393 eerror "Error: you seem to have \$GROOT configured."
394 eerror "This variable is no longer supported, please visit the"
395 eerror "grml-debootstrap documentation for details."
400 if echo "$GRUB" | grep -q '^hd' ; then
401 eerror "Error: this syntax for the grub configuration variable is no longer supported."
402 eerror "Please do not use hd... any longer but /dev/sdX instead."
411 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
412 Do you want to continue installing Debian using this frontend?" 0 0 || bailout 0
419 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
421 grep -v 'Extended$' | \
422 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md[0-9]* 2>/dev/null || true);
424 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
425 dialog --title "$PN" --trim \
426 --msgbox "Sorry, no partitions found. Please configure your
427 harddisks (see /proc/partitions) using a tool like fdisk,
428 cfdisk, gpart, gparted,..." 0 0
432 PARTITION_LIST=$(for i in $AVAILABLE_PARTITIONS ; do
433 fs="$(blkid -s TYPE -o value "$i" 2>/dev/null)"
434 [ -n "$fs" ] || fs='[no_filesystem_yet]'
439 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
440 --menu "Please select the target partition:" 0 0 0 \
442 [ $? -eq 0 ] || bailout 1
446 # ask for bootmanager {{{
447 prompt_for_bootmanager()
451 if echo "$TARGET" | grep -q "/dev/md" ; then
452 MBRPART="all disks of Software RAID $TARGET"
454 # figure out whole disk device
456 for device in /dev/disk/by-id/*
458 [ "$(readlink -f "$device")" = "${TARGET}" ] || continue
462 [ -n "$found" ] && MBRDISK=$(echo "${device}" |sed -e 's/-part[0-9][0-9]*$//')
463 if [ -e "$MBRDISK" ]; then
464 MBRDISK=$(readlink -f "$MBRDISK")
466 # fall back to old behaviour
467 MBRDISK=$(echo "${TARGET}" | sed -e 's/[0-9][0-9]*$//')
470 MBRPART="MBR of $MBRDISK"
473 for device in cciss/c0d0 sda hda; do
474 if [ "/dev/$device" != "${MBRDISK}" ]; then
475 grep -q $device /proc/partitions && \
476 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
479 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
483 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
484 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
485 mbr "install bootmanager into $MBRPART" \
486 nowhere "do not install bootmanager at all" \
487 ${ADDITIONAL_PARAMS})
488 [ $? -eq 0 ] || bailout 3
493 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
494 if echo "$TARGET" | grep -q "/dev/md" ; then
513 # ask for Debian release {{{
516 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='jessie'
517 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
518 "Please enter the Debian release you would like to use for installation:" \
524 sid Debian/unstable)"
525 [ $? -eq 0 ] || bailout
529 # ask for hostname {{{
530 prompt_for_hostname()
532 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
533 "Please enter the hostname you would like to use for installation:" \
535 [ $? -eq 0 ] || bailout
539 # ask for password {{{
540 prompt_for_password()
542 if [ "$_opt_nopassword" ] ; then
543 einfo "Skip asking for root password as requested."
549 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
550 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
551 "Please enter the password for the root account:" 10 60)
552 [ $? -eq 0 ] || bailout
554 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
555 "Please enter the password for the root account again for \
556 confirmation:" 10 60)
557 [ $? -eq 0 ] || bailout
559 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
560 dialog --stdout --title "${PN}" --ok-label \
561 "Retry" --msgbox "Passwords do not match!" 10 60
564 ROOTPASSWORD="$ROOTPW1"
568 # ask for Debian mirror {{{
571 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
573 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
574 --menu "Where do you want to install from?" 0 0 0 \
575 net "install via network (downloading from mirror)" \
576 local "install from local directory/mirror"
578 [ $? -eq 0 ] || bailout
580 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
581 [ -n "$MIRROR" ] || MIRROR='http://http.debian.net/debian'
582 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
583 "Please enter Debian mirror you would like to use for installing packages." \
585 [ $? -eq 0 ] || bailout
586 else # CHOOSE_MIRROR == local
587 [ -n "$ISO" ] || ISO='/mnt/mirror'
588 ISO="$(dialog --stdout --title "${PN}" --inputbox \
589 "Please enter directory name you would like to use for installing packages." \
591 [ $? -eq 0 ] || bailout
596 # software raid setup {{{
597 config_swraid_setup()
601 # Currently we support only raid1:
604 MD_LIST=$(for i in $(seq 0 9) ; do
605 awk '{print $4}' /proc/partitions | grep -q "md$i" || \
606 echo "/dev/md$i /dev/md$i"
609 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
610 --menu "Which device do you want to use for ${RAIDLEVEL}?
612 Notice: activated devices will not be listed for security reasons. Anyway, please make sure the selected device is not in use already!" 0 0 0 \
614 [ $? -eq 0 ] || bailout 20
616 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
618 grep -v 'Extended$' | \
619 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
620 [ -n "$AVAILABLE_PARTITIONS" ] || echo "Fatal error: no partitions available?"
621 PARTITION_LIST=$(for i in $AVAILABLE_PARTITIONS ; do
622 echo "$i $(blkid -s TYPE -o value "$i" 2>/dev/null || echo '[no_filesystem_yet]') off"
625 dialog --title "$PN" --separate-output \
626 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
627 $PARTITION_LIST 2>"$TMPFILE"
628 [ $? -eq 0 ] || bailout
629 SELECTED_PARTITIONS="$(cat "$TMPFILE")"
632 for i in $(cat "$TMPFILE") ; do
633 NUM_PARTITIONS=$(( NUM_PARTITIONS + 1 ))
636 # force metadata version 0.90 for lenny so old grub can boot from this array.
638 if [ "$RELEASE" = "lenny" ]; then
639 METADATA_VERSION="-e0"
643 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
644 --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
646 if [ "$RC" = 0 ] ; then
647 dialog --title "$PN" --msgbox \
648 "Creating $TARGET was successful." 0 0
649 rm -f "$TMPFILE" "$ERRORFILE"
651 dialog --title "$PN" --msgbox \
652 "There was an error setting up $TARGET:
657 rm -f "$TMPFILE" "$ERRORFILE"
665 if dialog --stdout --title "$PN" \
666 --defaultno --yesno "Do you want to configure Software RAID?
668 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
674 # user should recheck his configuration {{{
675 # support full automatic installation:
677 dialog --timeout 10 --title "$PN" \
678 --yesno "Do you want to stop at this stage?
680 Notice: you are running ${PN} in non-interactive mode.
681 ${PN} will install Debian ${RELEASE} on ${TARGET}.
682 Last chance to quit. Timeout of 10 seconds running....
684 Do you want to stop now?" 0 0 2>/dev/null
688 # make sure the user is aware of the used configuration {{{
691 if [ -n "$AUTOINSTALL" ] ; then
692 if checkforrun ; then
693 eerror "Exiting as requested" ; eend 0
696 elif [ -n "$INTERACTIVE" ] ; then
698 INFOTEXT="Please recheck configuration before execution:
700 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
702 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
704 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
705 Using release: $RELEASE"
706 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
707 Using hostname: $HOSTNAME"
708 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
709 Using mirror: $MIRROR"
710 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
712 [ -n "$ARCH" ] && INFOTEXT="$INFOTEXT
717 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
719 dialog --title "$PN" --no-collapse \
720 --yesno "$INFOTEXT" 0 0
721 [ $? -eq 0 ] || bailout 0
723 else # if not running automatic installation display configuration and prompt for execution:
724 einfo "$PN [${VERSION}] - Please recheck configuration before execution:"
726 echo " Target: $TARGET"
728 # do not display if MNTPOINT is the default one
729 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
731 if [ -n "$VIRTUAL" ] ; then
732 echo " Install grub: yes"
734 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
737 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
738 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
739 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
740 [ -n "$ISO" ] && echo " Using ISO: $ISO"
741 [ -n "$ARCH" ] && echo " Using arch: $ARCH"
742 if [ -n "$VIRTUAL" ] ; then
743 echo " Deploying as Virtual Machine."
744 if [ -n "$VMSIZE" -a -n "$VMFILE" ]; then
745 echo " Using Virtual Disk file with size of ${VMSIZE}."
749 if [ ! -t 0 -a -z "$ROOTPASSWORD" -a -z "$NOPASSWORD" ] ; then
751 echo " You do not have a TTY allocated, your password will be shown in"
752 echo " plaintext on the terminal! If you are using SSH, try its -t option!"
756 echo " Important! Continuing will delete all data from ${TARGET}!"
758 if [ -n "$FORCE" ] ; then
759 einfo "Skip user acknowledgement as requested via --force option."
762 einfon "Is this ok for you? [y/N] "
764 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
765 eerror "Exiting as requested." ; eend 1
773 # interactive mode {{{
776 check4progs dialog || bailout 1
786 prompt_for_bootmanager
795 # run interactive mode if we didn't get the according configuration yet
796 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
797 # only target might be unset, so make sure the INTERACTIVE flag is set as well
803 # architecture setup {{{
804 if [ -n "$ARCH" ] ; then
805 ARCHCMD="--arch $ARCH"
806 ARCHINFO=" (${ARCH})"
808 ARCH="$(dpkg --print-architecture)"
809 ARCHCMD="--arch $ARCH"
810 ARCHINFO=" (${ARCH})"
814 # It is not possible to build amd64 on i686. {{{
815 CURRENT_ARCH="$(uname -m)"
816 if [ "$CURRENT_ARCH" != "x86_64" ] ; then
817 if [ "$ARCH" = "amd64" ] ; then
818 eerror "It is not possible to build amd64 on $CURRENT_ARCH." ; eend 1
826 # finally make sure at least $TARGET is set [the partition for the new system] {{{
827 if [ -n "$TARGET" ] ; then
828 SHORT_TARGET="${TARGET##*/}"
830 eerror "Please adjust $CONFFILES/config or..."
831 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
837 if [ -z "$STAGES" ] ; then
838 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
839 [ -d "$STAGES" ] || mkdir -p "$STAGES"
842 if [ -r "$STAGES"/grml-debootstrap ] ; then
843 if grep -q 'done' "${STAGES}/grml-debootstrap" ; then
844 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
845 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
850 # partition handling {{{
854 set_target_directory(){
855 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
861 # make sure we normalise the path to an absolute directory name so something like:
862 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
864 TARGET="$(readlink -f "$TARGET")"
867 if [ -b "$TARGET" ] || [ -n "$VIRTUAL" ] ; then
874 # make sure we have the right syntax when using an iso image {{{
875 if [ -n "$ISO" ] ; then
888 # Debian ISOs do not contain signed Release files {{{
889 if [ -n "$ISO" ] ; then
890 DEBOOTSTRAP_OPT="$DEBOOTSTRAP_OPT --no-check-gpg"
894 # create filesystem {{{
896 if [ -n "$DIRECTORY" ] ; then
897 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
901 if grep -q "$TARGET" /proc/mounts ; then
902 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
906 # mkfs.ext* might prompt with "/dev/sdX# contains a ext* file system
907 # created on ... Proceed anyway? (y,n)" which we want to skip in force mode
908 if [ -n "$MKFS" ] && [ -n "$FORCE" ] ; then
911 einfo "Enabling force option (-F) for mkfs.ext* tool as requested via --force switch."
912 MKFS_OPTS="$MKFS_OPTS -F"
918 if [ -n "$MKFS" ] ; then
919 einfo "Running $MKFS $MKFS_OPTS on $TARGET"
920 "$MKFS" $MKFS_OPTS "$TARGET" ; RC=$?
922 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
923 if ! echo "$MKFS" | grep -q "mkfs.ext" ; then
924 eerror "Not changing disk uuid for $TARGET because $MKFS doesn't seem to match for ext{2,3,4} file system"
928 einfo "Changing disk uuid for $TARGET to fixed (non-random) value $DISK_IDENTIFIER using tune2fs"
929 tune2fs "$TARGET" -U "$DISK_IDENTIFIER"
934 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
935 # will fail to detect the uuid in the chroot
936 if echo "$TARGET" | grep -q "/dev/md" ; then
937 blockdev --rereadpt "${TARGET}"
938 elif ! [ -n "$VIRTUAL" ] ; then
939 blockdev --rereadpt "${TARGET%%[0-9]*}"
941 # give the system 2 seconds, otherwise we might run into
942 # race conditions :-/
945 eval "$(blkid -o udev "$TARGET" 2>/dev/null)"
946 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
953 # modify filesystem settings {{{
955 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
956 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
963 # mount the new partition or if it's a directory do nothing at all {{{
965 if [ -n "$DIRECTORY" ] ; then
966 einfo "Running grml-debootstrap on a directory, nothing to mount."
968 if grep -q "$TARGET" /proc/mounts ; then
969 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
971 if ! [ -d "${MNTPOINT}" ] ; then
972 [ -n "$VIRTUAL" ] || mkdir -p "${MNTPOINT}"
974 einfo "Mounting $TARGET to $MNTPOINT"
976 mount -o rw,suid,dev "$TARGET" "$MNTPOINT"
980 if [ -n "$ISODIR" ] ; then
981 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
982 mkdir -p "$MNTPOINT/$ISODIR"
983 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
989 # prepare VM image for usage with debootstrap {{{
991 if [ -z "$VIRTUAL" ] ; then
992 return 0 # be quiet by intention
995 if [ -b "$TARGET" -a -n "$VMFILE" ] ; then
996 eerror "Error: specified virtual disk target ($TARGET) is an existing block device."
1000 if [ ! -b "$TARGET" -a -z "$VMFILE" ] ; then
1001 eerror "Error: specified virtual disk target ($TARGET) does not exist yet."
1006 ORIG_TARGET="$TARGET" # store for later reuse
1008 if [ -n "$VMFILE" ]; then
1009 qemu-img create -f raw "${TARGET}" "${VMSIZE}"
1011 echo 4 66 | /usr/share/grml-debootstrap/bootgrub.mksh -A | dd of="$TARGET" conv=notrunc
1012 dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
1013 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
1014 einfo "Adjusting disk signature to a fixed (non-random) value"
1015 MBRTMPFILE=$(mktemp)
1016 dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1
1017 echo -en "\x41\x41\x41\x41\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1
1018 dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc
1021 parted -s "${TARGET}" 'mkpart primary ext4 2M -1'
1023 # if dm-mod isn't available then kpartx will fail with
1024 # "Is device-mapper driver missing from kernel? [...]"
1025 if ! kpartx -av "$TARGET" >/dev/null 2>&1 || ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then
1026 einfo "Device-mapper not ready yet, trying to load dm-mod module."
1027 modprobe dm-mod ; eend $?
1030 # make sure loop module is present
1031 if ! losetup -f >/dev/null 2>&1; then
1032 einfo "Can not find a usable loop device, retrying after loading loop module."
1034 if losetup -f >/dev/null 2>&1; then
1035 einfo "Found a usable loop device now, continuing."
1037 eerror "Error finding usable loop device" ; eend 1
1042 DEVINFO=$(kpartx -asv "$TARGET") # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
1043 if [ -z "${DEVINFO}" ] ; then
1044 eerror "Error setting up loopback device." ; eend 1
1048 # hopefully this always works as expected
1049 LOOP=$(echo "${DEVINFO}" | sed 's/.* linear //; s/ [[:digit:]]*//') # 'loop1'
1050 LOOP_PART="$(echo "${DEVINFO##add map }" | sed 's/ .*//')" # 'loop1p1'
1051 export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'
1053 blockdev --rereadpt "${LOOP}"
1055 if [ -z "$TARGET" ] ; then
1056 eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1
1062 # make VM image bootable and unmount it {{{
1064 if [ -z "${VIRTUAL}" ] ; then
1068 if ! mount "${TARGET}" "${MNTPOINT}" ; then
1069 eerror "Error: Mounting ${TARGET} failed, can not continue." ; eend 1
1073 einfo "Installing Grub as bootloader."
1074 mount -t proc none "${MNTPOINT}"/proc
1075 mount -t sysfs none "${MNTPOINT}"/sys
1076 mount --bind /dev "${MNTPOINT}"/dev
1078 mkdir -p "${MNTPOINT}/boot/grub"
1079 if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
1080 eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
1085 lenny|squeeze|wheezy)
1086 cp "${MNTPOINT}"/usr/lib/grub/i386-pc/* "${MNTPOINT}/boot/grub/"
1089 cp -a "${MNTPOINT}"/usr/lib/grub/i386-pc "${MNTPOINT}/boot/grub/"
1092 chroot "${MNTPOINT}" grub-mkimage -O i386-pc -p "(hd0,msdos1)/boot/grub" -o /tmp/core.img biosdisk part_msdos ext2
1093 dd if="${MNTPOINT}/tmp/core.img" of="${ORIG_TARGET}" conv=notrunc seek=4
1094 rm -f "${MNTPOINT}/tmp/core.img"
1096 einfo "Updating grub configuration file."
1097 if [ -n "$BOOT_APPEND" ] ; then
1098 sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" "${MNTPOINT}"/etc/default/grub
1100 chroot "${MNTPOINT}" update-grub
1103 lenny|squeeze|wheezy)
1104 einfo "Adjusting grub.cfg for successful boot sequence."
1105 sed -i "s;root=[^ ]\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg
1109 umount "${MNTPOINT}"/proc
1110 umount "${MNTPOINT}"/sys
1111 umount "${MNTPOINT}"/dev
1112 umount "${MNTPOINT}"
1113 kpartx -d "${ORIG_TARGET}" >/dev/null
1117 # install main chroot {{{
1118 debootstrap_system() {
1119 if [ "$_opt_nodebootstrap" ]; then
1120 einfo "Skipping debootstrap as requested."
1124 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
1127 eerror "Error: $MNTPOINT not mounted, can not continue."
1131 if [ -n "$ISO" ] ; then
1132 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${ISO}"
1133 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
1134 "$DEBOOTSTRAP" $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$ISO"
1137 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
1138 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
1139 "$DEBOOTSTRAP" $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$MIRROR"
1143 if [ $RC -ne 0 ] ; then
1144 if [ -r "$MNTPOINT/debootstrap/debootstrap.log" ] && \
1145 [ -s "$MNTPOINT/debootstrap/debootstrap.log" ] ; then
1146 einfo "Presenting last ten lines of debootstrap.log:"
1147 tail -10 "${MNTPOINT}"/debootstrap/debootstrap.log
1148 einfo "End of debootstrap.log"
1156 # prepare chroot via chroot-script {{{
1158 einfo "Preparing chroot system"
1160 # provide variables to chroot system
1161 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
1162 touch "$CHROOT_VARIABLES"
1163 chmod 600 "$CHROOT_VARIABLES" # make sure nobody except root can read it
1164 echo "# Configuration of ${PN}" > "$CHROOT_VARIABLES"
1165 [ -n "$ARCH" ] && echo "ARCH=\"$ARCH\"" >> "$CHROOT_VARIABLES"
1166 [ -n "$BACKPORTREPOS" ] && echo "BACKPORTREPOS=\"$BACKPORTREPOS\"" >> "$CHROOT_VARIABLES"
1167 [ -n "$CHROOT_SCRIPTS" ] && echo "CHROOT_SCRIPTS=\"$CHROOT_SCRIPTS\"" >> "$CHROOT_VARIABLES"
1168 [ -n "$CONFFILES" ] && echo "CONFFILES=\"$CONFFILES\"" >> "$CHROOT_VARIABLES"
1169 [ -n "$DEBCONF" ] && echo "DEBCONF=\"$DEBCONF\"" >> "$CHROOT_VARIABLES"
1170 [ -n "$DEBIAN_FRONTEND" ] && echo "DEBIAN_FRONTEND=\"$DEBIAN_FRONTEND\"" >> "$CHROOT_VARIABLES"
1171 [ -n "$DEBOOTSTRAP" ] && echo "DEBOOTSTRAP=\"$DEBOOTSTRAP\"" >> "$CHROOT_VARIABLES"
1172 [ -n "$DEFAULT_LOCALES" ] && echo "DEFAULT_LOCALES=\"$DEFAULT_LOCALES\"" >> "$CHROOT_VARIABLES"
1173 [ -n "$DEFAULT_LANGUAGE" ] && echo "DEFAULT_LANGUAGE=\"$DEFAULT_LANGUAGE\"" >> "$CHROOT_VARIABLES"
1174 [ -n "$EXTRAPACKAGES" ] && echo "EXTRAPACKAGES=\"$EXTRAPACKAGES\"" >> "$CHROOT_VARIABLES"
1175 [ -n "$FALLBACK_MIRROR" ] && echo "FALLBACK_MIRROR=\"$FALLBACK_MIRROR\"" >> "$CHROOT_VARIABLES"
1176 [ -n "$FORCE" ] && echo "FORCE=\"$FORCE\"" >> "$CHROOT_VARIABLES"
1177 [ -n "$GRMLREPOS" ] && echo "GRMLREPOS=\"$GRMLREPOS\"" >> "$CHROOT_VARIABLES"
1178 [ -n "$GRUB" ] && echo "GRUB=\"$GRUB\"" >> "$CHROOT_VARIABLES"
1179 [ -n "$HOSTNAME" ] && echo "HOSTNAME=\"$HOSTNAME\"" >> "$CHROOT_VARIABLES"
1180 [ -n "$INITRD" ] && echo "INITRD=\"$INITRD\"" >> "$CHROOT_VARIABLES"
1181 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=\"$INSTALL_NOTES\"" >> "$CHROOT_VARIABLES"
1182 [ -n "$ISODIR" ] && echo "ISODIR=\"$ISO\"" >> "$CHROOT_VARIABLES"
1183 [ -n "$ISO" ] && echo "ISO=\"$ISO\"" >> "$CHROOT_VARIABLES"
1184 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=\"$KEEP_SRC_LIST\"" >> "$CHROOT_VARIABLES"
1185 [ -n "$LOCALES" ] && echo "LOCALES=\"$LOCALES\"" >> "$CHROOT_VARIABLES"
1186 [ -n "$MIRROR" ] && echo "MIRROR=\"$MIRROR\"" >> "$CHROOT_VARIABLES"
1187 [ -n "$MKFS" ] && echo "MKFS=\"$MKFS\"" >> "$CHROOT_VARIABLES"
1188 [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=\"true\"" >> "$CHROOT_VARIABLES"
1189 [ -n "$NOKERNEL" ] && echo "NOKERNEL=\"true\"" >> "$CHROOT_VARIABLES"
1190 [ -n "$PACKAGES" ] && echo "PACKAGES=\"$PACKAGES\"" >> "$CHROOT_VARIABLES"
1191 [ -n "$PRE_SCRIPTS" ] && echo "PRE_SCRIPTS=\"$PRE_SCRIPTS\"" >> "$CHROOT_VARIABLES"
1192 [ -n "$RECONFIGURE" ] && echo "RECONFIGURE=\"$RECONFIGURE\"" >> "$CHROOT_VARIABLES"
1193 [ -n "$RELEASE" ] && echo "RELEASE=\"$RELEASE\"" >> "$CHROOT_VARIABLES"
1194 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=\"$RM_APTCACHE\"" >> "$CHROOT_VARIABLES"
1195 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=\"$ROOTPASSWORD\"" >> "$CHROOT_VARIABLES"
1196 [ -n "$SCRIPTS" ] && echo "SCRIPTS=\"$SCRIPTS\"" >> "$CHROOT_VARIABLES"
1197 [ -n "$SECURE" ] && echo "SECURE=\"$SECURE\"" >> "$CHROOT_VARIABLES"
1198 [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=\"$SELECTED_PARTITIONS\"" >> "$CHROOT_VARIABLES"
1199 [ -n "$TARGET" ] && echo "TARGET=\"$TARGET\"" >> "$CHROOT_VARIABLES"
1200 [ -n "$UPGRADE_SYSTEM" ] && echo "UPGRADE_SYSTEM=\"$UPGRADE_SYSTEM\"" >> "$CHROOT_VARIABLES"
1201 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=\"$TARGET_UUID\"" >> "$CHROOT_VARIABLES"
1202 [ -n "$TIMEZONE" ] && echo "TIMEZONE=\"$TIMEZONE\"" >> "$CHROOT_VARIABLES"
1203 [ -n "$TUNE2FS" ] && echo "TUNE2FS=\"$TUNE2FS\"" >> "$CHROOT_VARIABLES"
1204 [ -n "$VMSIZE" ] && echo "VMSIZE=\"$VMSIZE\"" >> "$CHROOT_VARIABLES"
1206 cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script
1207 chmod 755 "${MNTPOINT}"/bin/chroot-script
1208 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
1210 # make sure we have our files for later use via chroot-script
1211 cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/
1212 # make sure we adjust the configuration variables accordingly:
1213 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" "${MNTPOINT}"/etc/debootstrap/config
1214 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" "${MNTPOINT}"/etc/debootstrap/config
1215 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" "${MNTPOINT}"/etc/debootstrap/config
1218 if [ -n "$INSTALL_NOTES" ] ; then
1219 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" "${MNTPOINT}"/etc/debootstrap/
1222 # package selection:
1223 cp $VERBOSE "${_opt_packages:-$CONFFILES/packages}" \
1224 "${MNTPOINT}"/etc/debootstrap/packages
1226 # debconf preseeding:
1227 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
1228 [ -f "${_opt_debconf}" ] && [ "$DEBCONF" = 'yes' ] && \
1229 cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections
1231 # copy scripts that should be executed inside the chroot:
1232 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
1233 [ -d "$_opt_chroot_scripts" ] && [ "$CHROOT_SCRIPTS" = 'yes' ] && {
1234 mkdir -p "${MNTPOINT}"/etc/debootstrap/chroot-scripts
1235 cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/
1238 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
1239 cp $VERBOSE "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables
1241 cp $VERBOSE -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/
1243 # make sure we can access network [relevant for cdebootstrap]
1244 [ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf
1246 # provide system's /etc/hosts to the target:
1247 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
1248 cp $VERBOSE /etc/hosts "${MNTPOINT}"/etc/hosts
1251 # setup default locales
1252 [ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen
1254 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
1255 ( cd "${MNTPOINT}"/dev && tar zxf /etc/debootstrap/devices.tar.gz )
1257 # copy any existing files to chroot
1258 [ -d "${CONFFILES}"/bin ] && cp $VERBOSE -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/
1259 [ -d "${CONFFILES}"/boot ] && cp $VERBOSE -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/
1260 [ -d "${CONFFILES}"/etc ] && cp $VERBOSE -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/
1261 [ -d "${CONFFILES}"/sbin ] && cp $VERBOSE -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/
1262 [ -d "${CONFFILES}"/share ] && cp $VERBOSE -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/
1263 [ -d "${CONFFILES}"/usr ] && cp $VERBOSE -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/
1264 [ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/
1267 DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
1269 # Include files from /etc/network/interfaces.d when using
1270 # ifupdown v0.7.44 or newer:
1271 #source-directory /etc/network/interfaces.d
1274 iface lo inet loopback
1277 iface eth0 inet dhcp
1280 if [ -n "$NOINTERFACES" ] ; then
1281 einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0
1282 elif [ -n "$USE_DEFAULT_INTERFACES" ] ; then
1283 einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options."
1284 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1286 elif [ -n "$VIRTUAL" ] ; then
1287 einfo "Setting up Virtual Machine, installing default /etc/network/interfaces"
1288 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1290 elif [ -r /etc/network/interfaces ] ; then
1291 einfo "Copying /etc/network/interfaces from host to target system"
1292 cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
1295 ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
1296 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1300 # install config file providing some example entries
1301 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
1302 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
1309 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
1310 execute_pre_scripts() {
1311 # make sure we have $MNTPOINT available for our scripts
1313 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
1314 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
1315 for script in ${pre_scripts}/* ; do
1316 if [ -x "$script" ] ; then
1317 einfo "Executing pre-script $script"
1325 # execute all scripts in /etc/debootstrap/scripts/ {{{
1327 # make sure we have $MNTPOINT available for our scripts
1329 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
1330 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
1331 for script in ${scripts}/* ; do
1332 if [ -x "$script" ] ; then
1333 einfo "Executing script $script"
1343 local mountpoint="$2"
1345 for (( try=1; try<=tries; try++ )); do
1346 if [[ ${try} -eq ${tries} ]]; then
1347 # Last time, show errors this time
1348 umount "${mountpoint}" && return 0
1350 # Not last time, hide errors until fatal
1351 if umount "${mountpoint}" 2>/dev/null ; then
1358 return 1 # Tried enough
1361 # execute chroot-script {{{
1363 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
1367 if ! [ -x "$MNTPOINT/bin/chroot-script" ] ; then
1368 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
1371 einfo "Executing chroot-script now"
1372 mount --bind /dev "$MNTPOINT"/dev
1373 if [ "$DEBUG" = "true" ] ; then
1374 chroot "$MNTPOINT" /bin/sh -x /bin/chroot-script ; RC=$?
1376 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
1378 try_umount 3 "$MNTPOINT"/dev
1382 # finally get rid of chroot-script again, there's no good reason to
1383 # keep it on the installed system
1384 if grep -q GRML_CHROOT_SCRIPT_MARKER "${MNTPOINT}/bin/chroot-script" ; then
1385 einfo "Removing chroot-script again"
1386 rm -f "${MNTPOINT}/bin/chroot-script"
1389 einfo "Keeping chroot-script as string GRML_CHROOT_SCRIPT_MARKER could not be found"
1395 # unmount $MNTPOINT {{{
1398 # display installation notes:
1399 if [ -n "$INSTALL_NOTES" ] ; then
1400 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
1403 if [ -n "$ISODIR" ] ; then
1404 if grep -q "$ISODIR" /proc/mounts ; then
1405 einfo "Unmount $MNTPOINT/$ISODIR"
1406 umount "$MNTPOINT/$ISODIR"
1411 if grep -q "$MNTPOINT" /proc/mounts ; then
1412 if [ -n "$PARTITION" ] ; then
1413 einfo "Unmount $MNTPOINT"
1421 # execute filesystem check {{{
1423 if [ -n "$VIRTUAL" ] ; then
1424 einfo "Skipping filesystem check because we deploy a virtual machine."
1428 if [ "$FSCK" = 'yes' ] ; then
1429 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
1430 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
1431 "$FSCKTOOL" "$TARGET"
1437 # now execute all the functions {{{
1438 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
1439 preparechroot execute_pre_scripts chrootscript execute_scripts \
1440 umount_chroot finalize_vm fscktool ; do
1441 if stage "${i}" ; then
1443 stage "${i}" 'done' && rm -f "${STAGES}/${i}"
1453 # end dialog of autoinstallation {{{
1454 if [ -n "$AUTOINSTALL" ] ; then
1455 if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1456 Automatically rebooting in 10 seconds.
1458 Choose Cancel to skip rebooting." 10 60 10 ; then
1459 noeject noprompt reboot
1462 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1466 ## END OF FILE #################################################################
1467 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=2