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 for service in ssh mdadm ; do
209 if [ -x "${MNTPOINT}/etc/init.d/${service}" ] ; then
210 chroot "$MNTPOINT" "/etc/init.d/${service}" stop
214 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1
216 # ugly, but make sure we really don't leave anything (/proc /proc and
217 # /dev /dev are intended, trying to work around timing issues, see #657023)
218 for ARG in /sys /proc /proc /dev /dev ; do
219 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1
220 umount "$MNTPOINT"/$ARG >/dev/null 2>&1
223 if [ -n "$ISODIR" ] ; then
224 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1
227 if [ -n "$DIRECTORY" ] ; then
228 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
230 einfo "Unmounting $MNTPOINT"
235 if [ -n "$STAGES" ] ; then
236 echo -n "Removing stages directory ${STAGES}: "
237 rm -rf "$STAGES" && echo 'done'
240 # remove directory only if we used the default with process id inside the name
241 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
242 einfo "Removing directory ${MNTPOINT}"
249 if [ -n "${ORIG_TARGET}" ] ; then
250 einfo "Removing loopback mount of file ${ORIG_TARGET}."
251 kpartx -d "${ORIG_TARGET}" ; eend $?
255 # we want to exit smoothly and clean:
260 [ -n "$1" ] && EXIT="$1" || EXIT="1"
261 [ -n "$2" ] && einfo "Notice: remove $STAGES/$2 to reexecute the stage"
265 trap bailout HUP INT QUIT TERM
267 # we want to execute all the functions only once, simple check for it:
269 if [ -n "$2" ] ; then
270 echo "$2" > "${STAGES}/${1}"
272 elif grep -q 'done' "${STAGES}/${1}" 2>/dev/null ; then
273 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
274 ewarn " To reexecute it clean up the according directory inside $STAGES" ; eend 0
280 # make sure we have what we need {{{
281 check4progs debootstrap || bailout 1
284 # source main configuration file {{{
285 if [ -r /etc/debootstrap/config ] ; then
286 . /etc/debootstrap/config
290 # cmdline handling {{{
291 # source external command line parameter-processing script
292 self_dir="$(dirname "$(which "$0")")"
293 if [ -r "${self_dir}"/cmdlineopts.clp ] ; then
294 . "${self_dir}"/cmdlineopts.clp
295 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
296 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
298 eerror "Error: cmdline function file not found, exiting."
303 # == business-logic of command line parameter-processing
305 # source configuration file in <confdir> if supplied. {{{
306 [ "$_opt_confdir" ] && {
307 CONFFILES=$_opt_confdir
308 einfo "Using config files under $CONFFILES/."
309 if ! [ -r "$CONFFILES/config" ] ; then
310 eerror "Error: config file $CONFFILES/config not found."; eend 1; bailout 1
312 if ! . "$CONFFILES/config" ; then
313 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; bailout 1
315 # restore the command line parameter value
316 CONFFILES=$_opt_confdir
320 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
321 [ "$_opt_iso" ] && ISO=$_opt_iso
322 [ "$_opt_release" ] && RELEASE=$_opt_release
323 [ "$_opt_target" ] && TARGET=$_opt_target
324 [ "$_opt_vm" ] && VIRTUAL=1
325 [ "$_opt_vmfile" ] && VMFILE=1 && VIRTUAL=1
326 [ "$_opt_vmsize" ] && VMSIZE=$_opt_vmsize
327 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
328 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
329 [ "$_opt_interactive" ] && INTERACTIVE=1
330 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
331 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
332 [ "$_opt_packages_set" ] && PACKAGES='yes'
333 [ "$_opt_nopackages" ] && PACKAGES=''
334 [ "$_opt_debconf_set" ] && DEBCONF='yes'
335 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
336 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
337 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
338 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
339 [ "$_opt_grmlrepos" ] && GRMLREPOS='yes'
340 [ "$_opt_backportrepos" ] && BACKPORTREPOS='yes'
341 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
342 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
343 [ "$_opt_nopassword" ] && NOPASSWORD='yes'
344 [ "$_opt_defaultinterfaces" ] && USE_DEFAULT_INTERFACES="true"
345 [ "$_opt_nointerfaces" ] && NOINTERFACES="true"
346 [ "$_opt_nokernel" ] && NOKERNEL="true"
347 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
348 [ "$_opt_grub" ] && GRUB=$_opt_grub
349 [ "$_opt_arch" ] && ARCH=$_opt_arch
350 [ "$_opt_insecure" ] && echo "Warning: --insecure is deprecated, continuing anyway."
351 [ "$_opt_force" ] && FORCE=$_opt_force
352 [ "$_opt_verbose" ] && VERBOSE="-v"
353 [ "$_opt_debug" ] && DEBUG="true"
355 if [ "$DEBUG" = "true" ] ; then
359 [ "$_opt_help" ] && {
365 [ "$_opt_version" ] && {
366 einfo "$PN - version $VERSION"
367 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
373 # check for root permissions {{{
374 if ! check4root ; then
375 echo "For usage instructions please execute '$PN --help'."
380 # make sure we have what we need {{{
381 if [ -n "$VIRTUAL" ] ; then
382 check4progs kpartx mksh parted qemu-img || bailout 1
386 # source specified configuration file {{{
387 if [ -n "$CONFIGFILE" ] ; then
388 einfo "Reading specified config file $CONFIGFILE."
389 if ! . "$CONFIGFILE" ; then
390 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; bailout 1
395 # backwards compability checks {{{
396 if [ -n "$GROOT" ] ; then
397 eerror "Error: you seem to have \$GROOT configured."
398 eerror "This variable is no longer supported, please visit the"
399 eerror "grml-debootstrap documentation for details."
404 if echo "$GRUB" | grep -q '^hd' ; then
405 eerror "Error: this syntax for the grub configuration variable is no longer supported."
406 eerror "Please do not use hd... any longer but /dev/sdX instead."
415 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
416 Do you want to continue installing Debian using this frontend?" 0 0 || bailout 0
423 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
425 grep -v 'Extended$' | \
426 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md[0-9]* 2>/dev/null || true);
428 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
429 dialog --title "$PN" --trim \
430 --msgbox "Sorry, no partitions found. Please configure your
431 harddisks (see /proc/partitions) using a tool like fdisk,
432 cfdisk, gpart, gparted,..." 0 0
436 PARTITION_LIST=$(for i in $AVAILABLE_PARTITIONS ; do
437 fs="$(blkid -s TYPE -o value "$i" 2>/dev/null)"
438 [ -n "$fs" ] || fs='[no_filesystem_yet]'
443 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
444 --menu "Please select the target partition:" 0 0 0 \
446 [ $? -eq 0 ] || bailout 1
450 # ask for bootmanager {{{
451 prompt_for_bootmanager()
455 if echo "$TARGET" | grep -q "/dev/md" ; then
456 MBRPART="all disks of Software RAID $TARGET"
458 # figure out whole disk device
460 for device in /dev/disk/by-id/*
462 [ "$(readlink -f "$device")" = "${TARGET}" ] || continue
466 [ -n "$found" ] && MBRDISK=$(echo "${device}" |sed -e 's/-part[0-9][0-9]*$//')
467 if [ -e "$MBRDISK" ]; then
468 MBRDISK=$(readlink -f "$MBRDISK")
470 # fall back to old behaviour
471 MBRDISK=$(echo "${TARGET}" | sed -e 's/[0-9][0-9]*$//')
474 MBRPART="MBR of $MBRDISK"
477 for device in cciss/c0d0 sda hda; do
478 if [ "/dev/$device" != "${MBRDISK}" ]; then
479 grep -q $device /proc/partitions && \
480 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
483 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
487 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
488 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
489 mbr "install bootmanager into $MBRPART" \
490 nowhere "do not install bootmanager at all" \
491 ${ADDITIONAL_PARAMS})
492 [ $? -eq 0 ] || bailout 3
497 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
498 if echo "$TARGET" | grep -q "/dev/md" ; then
517 # ask for Debian release {{{
520 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='jessie'
521 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
522 "Please enter the Debian release you would like to use for installation:" \
528 sid Debian/unstable)"
529 [ $? -eq 0 ] || bailout
533 # ask for hostname {{{
534 prompt_for_hostname()
536 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
537 "Please enter the hostname you would like to use for installation:" \
539 [ $? -eq 0 ] || bailout
543 # ask for password {{{
544 prompt_for_password()
546 if [ "$_opt_nopassword" ] ; then
547 einfo "Skip asking for root password as requested."
553 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
554 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
555 "Please enter the password for the root account:" 10 60)
556 [ $? -eq 0 ] || bailout
558 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
559 "Please enter the password for the root account again for \
560 confirmation:" 10 60)
561 [ $? -eq 0 ] || bailout
563 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
564 dialog --stdout --title "${PN}" --ok-label \
565 "Retry" --msgbox "Passwords do not match!" 10 60
568 ROOTPASSWORD="$ROOTPW1"
572 # ask for Debian mirror {{{
575 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
577 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
578 --menu "Where do you want to install from?" 0 0 0 \
579 net "install via network (downloading from mirror)" \
580 local "install from local directory/mirror"
582 [ $? -eq 0 ] || bailout
584 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
585 [ -n "$MIRROR" ] || MIRROR='http://http.debian.net/debian'
586 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
587 "Please enter Debian mirror you would like to use for installing packages." \
589 [ $? -eq 0 ] || bailout
590 else # CHOOSE_MIRROR == local
591 [ -n "$ISO" ] || ISO='/mnt/mirror'
592 ISO="$(dialog --stdout --title "${PN}" --inputbox \
593 "Please enter directory name you would like to use for installing packages." \
595 [ $? -eq 0 ] || bailout
600 # software raid setup {{{
601 config_swraid_setup()
605 # Currently we support only raid1:
608 MD_LIST=$(for i in $(seq 0 9) ; do
609 awk '{print $4}' /proc/partitions | grep -q "md$i" || \
610 echo "/dev/md$i /dev/md$i"
613 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
614 --menu "Which device do you want to use for ${RAIDLEVEL}?
616 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 \
618 [ $? -eq 0 ] || bailout 20
620 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
622 grep -v 'Extended$' | \
623 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
624 [ -n "$AVAILABLE_PARTITIONS" ] || echo "Fatal error: no partitions available?"
625 PARTITION_LIST=$(for i in $AVAILABLE_PARTITIONS ; do
626 echo "$i $(blkid -s TYPE -o value "$i" 2>/dev/null || echo '[no_filesystem_yet]') off"
629 dialog --title "$PN" --separate-output \
630 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
631 $PARTITION_LIST 2>"$TMPFILE"
632 [ $? -eq 0 ] || bailout
633 SELECTED_PARTITIONS="$(cat "$TMPFILE")"
636 for i in $(cat "$TMPFILE") ; do
637 NUM_PARTITIONS=$(( NUM_PARTITIONS + 1 ))
640 # force metadata version 0.90 for lenny so old grub can boot from this array.
642 if [ "$RELEASE" = "lenny" ]; then
643 METADATA_VERSION="-e0"
647 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
648 --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
650 if [ "$RC" = 0 ] ; then
651 dialog --title "$PN" --msgbox \
652 "Creating $TARGET was successful." 0 0
653 rm -f "$TMPFILE" "$ERRORFILE"
655 dialog --title "$PN" --msgbox \
656 "There was an error setting up $TARGET:
661 rm -f "$TMPFILE" "$ERRORFILE"
669 if dialog --stdout --title "$PN" \
670 --defaultno --yesno "Do you want to configure Software RAID?
672 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
678 # user should recheck his configuration {{{
679 # support full automatic installation:
681 dialog --timeout 10 --title "$PN" \
682 --yesno "Do you want to stop at this stage?
684 Notice: you are running ${PN} in non-interactive mode.
685 ${PN} will install Debian ${RELEASE} on ${TARGET}.
686 Last chance to quit. Timeout of 10 seconds running....
688 Do you want to stop now?" 0 0 2>/dev/null
692 # make sure the user is aware of the used configuration {{{
695 if [ -n "$AUTOINSTALL" ] ; then
696 if checkforrun ; then
697 eerror "Exiting as requested" ; eend 0
700 elif [ -n "$INTERACTIVE" ] ; then
702 INFOTEXT="Please recheck configuration before execution:
704 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
706 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
708 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
709 Using release: $RELEASE"
710 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
711 Using hostname: $HOSTNAME"
712 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
713 Using mirror: $MIRROR"
714 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
716 [ -n "$ARCH" ] && INFOTEXT="$INFOTEXT
721 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
723 dialog --title "$PN" --no-collapse \
724 --yesno "$INFOTEXT" 0 0
725 [ $? -eq 0 ] || bailout 0
727 else # if not running automatic installation display configuration and prompt for execution:
728 einfo "$PN [${VERSION}] - Please recheck configuration before execution:"
730 echo " Target: $TARGET"
732 # do not display if MNTPOINT is the default one
733 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
735 if [ -n "$VIRTUAL" ] ; then
736 echo " Install grub: yes"
738 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
741 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
742 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
743 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
744 [ -n "$ISO" ] && echo " Using ISO: $ISO"
745 [ -n "$ARCH" ] && echo " Using arch: $ARCH"
746 if [ -n "$VIRTUAL" ] ; then
747 echo " Deploying as Virtual Machine."
748 if [ -n "$VMSIZE" -a -n "$VMFILE" ]; then
749 echo " Using Virtual Disk file with size of ${VMSIZE}."
753 if [ ! -t 0 -a -z "$ROOTPASSWORD" -a -z "$NOPASSWORD" ] ; then
755 echo " You do not have a TTY allocated, your password will be shown in"
756 echo " plaintext on the terminal! If you are using SSH, try its -t option!"
760 echo " Important! Continuing will delete all data from ${TARGET}!"
762 if [ -n "$FORCE" ] ; then
763 einfo "Skip user acknowledgement as requested via --force option."
766 einfon "Is this ok for you? [y/N] "
768 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
769 eerror "Exiting as requested." ; eend 1
777 # interactive mode {{{
780 check4progs dialog || bailout 1
790 prompt_for_bootmanager
799 # run interactive mode if we didn't get the according configuration yet
800 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
801 # only target might be unset, so make sure the INTERACTIVE flag is set as well
807 # architecture setup {{{
808 if [ -n "$ARCH" ] ; then
809 ARCHCMD="--arch $ARCH"
810 ARCHINFO=" (${ARCH})"
812 ARCH="$(dpkg --print-architecture)"
813 ARCHCMD="--arch $ARCH"
814 ARCHINFO=" (${ARCH})"
818 # It is not possible to build amd64 on i686. {{{
819 CURRENT_ARCH="$(uname -m)"
820 if [ "$CURRENT_ARCH" != "x86_64" ] ; then
821 if [ "$ARCH" = "amd64" ] ; then
822 eerror "It is not possible to build amd64 on $CURRENT_ARCH." ; eend 1
830 # finally make sure at least $TARGET is set [the partition for the new system] {{{
831 if [ -n "$TARGET" ] ; then
832 SHORT_TARGET="${TARGET##*/}"
834 eerror "Please adjust $CONFFILES/config or..."
835 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
841 if [ -z "$STAGES" ] ; then
842 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
843 [ -d "$STAGES" ] || mkdir -p "$STAGES"
846 if [ -r "$STAGES"/grml-debootstrap ] ; then
847 if grep -q 'done' "${STAGES}/grml-debootstrap" ; then
848 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
849 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
854 # partition handling {{{
858 set_target_directory(){
859 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
865 # make sure we normalise the path to an absolute directory name so something like:
866 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
868 TARGET="$(readlink -f "$TARGET")"
871 if [ -b "$TARGET" ] || [ -n "$VIRTUAL" ] ; then
878 # make sure we have the right syntax when using an iso image {{{
879 if [ -n "$ISO" ] ; then
892 # Debian ISOs do not contain signed Release files {{{
893 if [ -n "$ISO" ] ; then
894 DEBOOTSTRAP_OPT="$DEBOOTSTRAP_OPT --no-check-gpg"
898 # create filesystem {{{
900 if [ -n "$DIRECTORY" ] ; then
901 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
905 if grep -q "$TARGET" /proc/mounts ; then
906 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
910 # mkfs.ext* might prompt with "/dev/sdX# contains a ext* file system
911 # created on ... Proceed anyway? (y,n)" which we want to skip in force mode
912 if [ -n "$MKFS" ] && [ -n "$FORCE" ] ; then
915 einfo "Enabling force option (-F) for mkfs.ext* tool as requested via --force switch."
916 MKFS_OPTS="$MKFS_OPTS -F"
922 if [ -n "$MKFS" ] ; then
923 einfo "Running $MKFS $MKFS_OPTS on $TARGET"
924 "$MKFS" $MKFS_OPTS "$TARGET" ; RC=$?
926 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
927 if ! echo "$MKFS" | grep -q "mkfs.ext" ; then
928 eerror "Not changing disk uuid for $TARGET because $MKFS doesn't seem to match for ext{2,3,4} file system"
932 einfo "Changing disk uuid for $TARGET to fixed (non-random) value $DISK_IDENTIFIER using tune2fs"
933 tune2fs "$TARGET" -U "$DISK_IDENTIFIER"
938 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
939 # will fail to detect the uuid in the chroot
940 if echo "$TARGET" | grep -q "/dev/md" ; then
941 blockdev --rereadpt "${TARGET}"
942 elif ! [ -n "$VIRTUAL" ] ; then
943 blockdev --rereadpt "${TARGET%%[0-9]*}"
945 # give the system 2 seconds, otherwise we might run into
946 # race conditions :-/
949 eval "$(blkid -o udev "$TARGET" 2>/dev/null)"
950 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
957 # modify filesystem settings {{{
959 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
960 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
967 # mount the new partition or if it's a directory do nothing at all {{{
969 if [ -n "$DIRECTORY" ] ; then
970 einfo "Running grml-debootstrap on a directory, nothing to mount."
972 if grep -q "$TARGET" /proc/mounts ; then
973 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
975 if ! [ -d "${MNTPOINT}" ] ; then
976 [ -n "$VIRTUAL" ] || mkdir -p "${MNTPOINT}"
978 einfo "Mounting $TARGET to $MNTPOINT"
980 mount -o rw,suid,dev "$TARGET" "$MNTPOINT"
984 if [ -n "$ISODIR" ] ; then
985 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
986 mkdir -p "$MNTPOINT/$ISODIR"
987 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
993 # prepare VM image for usage with debootstrap {{{
995 if [ -z "$VIRTUAL" ] ; then
996 return 0 # be quiet by intention
999 if [ -b "$TARGET" -a -n "$VMFILE" ] ; then
1000 eerror "Error: specified virtual disk target ($TARGET) is an existing block device."
1004 if [ ! -b "$TARGET" -a -z "$VMFILE" ] ; then
1005 eerror "Error: specified virtual disk target ($TARGET) does not exist yet."
1010 ORIG_TARGET="$TARGET" # store for later reuse
1012 if [ -n "$VMFILE" ]; then
1013 qemu-img create -f raw "${TARGET}" "${VMSIZE}"
1015 echo 4 66 | /usr/share/grml-debootstrap/bootgrub.mksh -A | dd of="$TARGET" conv=notrunc
1016 dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
1017 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
1018 einfo "Adjusting disk signature to a fixed (non-random) value"
1019 MBRTMPFILE=$(mktemp)
1020 dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1
1021 echo -en "\x41\x41\x41\x41\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1
1022 dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc
1025 parted -s "${TARGET}" 'mkpart primary ext4 2M -1'
1027 # if dm-mod isn't available then kpartx will fail with
1028 # "Is device-mapper driver missing from kernel? [...]"
1029 if ! kpartx -av "$TARGET" >/dev/null 2>&1 || ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then
1030 einfo "Device-mapper not ready yet, trying to load dm-mod module."
1031 modprobe dm-mod ; eend $?
1034 # make sure loop module is present
1035 if ! losetup -f >/dev/null 2>&1; then
1036 einfo "Can not find a usable loop device, retrying after loading loop module."
1038 if losetup -f >/dev/null 2>&1; then
1039 einfo "Found a usable loop device now, continuing."
1041 eerror "Error finding usable loop device" ; eend 1
1046 DEVINFO=$(kpartx -asv "$TARGET") # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
1047 if [ -z "${DEVINFO}" ] ; then
1048 eerror "Error setting up loopback device." ; eend 1
1052 # hopefully this always works as expected
1053 LOOP=$(echo "${DEVINFO}" | sed 's/.* linear //; s/ [[:digit:]]*//') # 'loop1'
1054 LOOP_PART="$(echo "${DEVINFO##add map }" | sed 's/ .*//')" # 'loop1p1'
1055 export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'
1057 blockdev --rereadpt "${LOOP}"
1059 if [ -z "$TARGET" ] ; then
1060 eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1
1066 # make VM image bootable and unmount it {{{
1068 if [ -z "${VIRTUAL}" ] ; then
1072 if ! mount "${TARGET}" "${MNTPOINT}" ; then
1073 eerror "Error: Mounting ${TARGET} failed, can not continue." ; eend 1
1077 einfo "Installing Grub as bootloader."
1078 mount -t proc none "${MNTPOINT}"/proc
1079 mount -t sysfs none "${MNTPOINT}"/sys
1080 mount --bind /dev "${MNTPOINT}"/dev
1082 mkdir -p "${MNTPOINT}/boot/grub"
1083 if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
1084 eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
1089 lenny|squeeze|wheezy)
1090 cp "${MNTPOINT}"/usr/lib/grub/i386-pc/* "${MNTPOINT}/boot/grub/"
1093 cp -a "${MNTPOINT}"/usr/lib/grub/i386-pc "${MNTPOINT}/boot/grub/"
1096 chroot "${MNTPOINT}" grub-mkimage -O i386-pc -p "(hd0,msdos1)/boot/grub" -o /tmp/core.img biosdisk part_msdos ext2
1097 dd if="${MNTPOINT}/tmp/core.img" of="${ORIG_TARGET}" conv=notrunc seek=4
1098 rm -f "${MNTPOINT}/tmp/core.img"
1100 einfo "Updating grub configuration file."
1101 if [ -n "$BOOT_APPEND" ] ; then
1102 sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" "${MNTPOINT}"/etc/default/grub
1104 chroot "${MNTPOINT}" update-grub
1107 lenny|squeeze|wheezy)
1108 einfo "Adjusting grub.cfg for successful boot sequence."
1109 sed -i "s;root=[^ ]\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg
1113 umount "${MNTPOINT}"/proc
1114 umount "${MNTPOINT}"/sys
1115 umount "${MNTPOINT}"/dev
1116 umount "${MNTPOINT}"
1117 kpartx -d "${ORIG_TARGET}" >/dev/null
1121 # install main chroot {{{
1122 debootstrap_system() {
1123 if [ "$_opt_nodebootstrap" ]; then
1124 einfo "Skipping debootstrap as requested."
1128 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
1131 eerror "Error: $MNTPOINT not mounted, can not continue."
1135 if [ -n "$ISO" ] ; then
1136 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${ISO}"
1137 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
1138 "$DEBOOTSTRAP" $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$ISO"
1141 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
1142 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
1143 "$DEBOOTSTRAP" $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT "$RELEASE" "$MNTPOINT" "$MIRROR"
1147 if [ $RC -ne 0 ] ; then
1148 if [ -r "$MNTPOINT/debootstrap/debootstrap.log" ] && \
1149 [ -s "$MNTPOINT/debootstrap/debootstrap.log" ] ; then
1150 einfo "Presenting last ten lines of debootstrap.log:"
1151 tail -10 "${MNTPOINT}"/debootstrap/debootstrap.log
1152 einfo "End of debootstrap.log"
1160 # prepare chroot via chroot-script {{{
1162 einfo "Preparing chroot system"
1164 # provide variables to chroot system
1165 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
1166 touch "$CHROOT_VARIABLES"
1167 chmod 600 "$CHROOT_VARIABLES" # make sure nobody except root can read it
1168 echo "# Configuration of ${PN}" > "$CHROOT_VARIABLES"
1169 [ -n "$ARCH" ] && echo "ARCH=\"$ARCH\"" >> "$CHROOT_VARIABLES"
1170 [ -n "$BACKPORTREPOS" ] && echo "BACKPORTREPOS=\"$BACKPORTREPOS\"" >> "$CHROOT_VARIABLES"
1171 [ -n "$CHROOT_SCRIPTS" ] && echo "CHROOT_SCRIPTS=\"$CHROOT_SCRIPTS\"" >> "$CHROOT_VARIABLES"
1172 [ -n "$CONFFILES" ] && echo "CONFFILES=\"$CONFFILES\"" >> "$CHROOT_VARIABLES"
1173 [ -n "$DEBCONF" ] && echo "DEBCONF=\"$DEBCONF\"" >> "$CHROOT_VARIABLES"
1174 [ -n "$DEBIAN_FRONTEND" ] && echo "DEBIAN_FRONTEND=\"$DEBIAN_FRONTEND\"" >> "$CHROOT_VARIABLES"
1175 [ -n "$DEBOOTSTRAP" ] && echo "DEBOOTSTRAP=\"$DEBOOTSTRAP\"" >> "$CHROOT_VARIABLES"
1176 [ -n "$DEFAULT_LOCALES" ] && echo "DEFAULT_LOCALES=\"$DEFAULT_LOCALES\"" >> "$CHROOT_VARIABLES"
1177 [ -n "$DEFAULT_LANGUAGE" ] && echo "DEFAULT_LANGUAGE=\"$DEFAULT_LANGUAGE\"" >> "$CHROOT_VARIABLES"
1178 [ -n "$EXTRAPACKAGES" ] && echo "EXTRAPACKAGES=\"$EXTRAPACKAGES\"" >> "$CHROOT_VARIABLES"
1179 [ -n "$FALLBACK_MIRROR" ] && echo "FALLBACK_MIRROR=\"$FALLBACK_MIRROR\"" >> "$CHROOT_VARIABLES"
1180 [ -n "$FORCE" ] && echo "FORCE=\"$FORCE\"" >> "$CHROOT_VARIABLES"
1181 [ -n "$GRMLREPOS" ] && echo "GRMLREPOS=\"$GRMLREPOS\"" >> "$CHROOT_VARIABLES"
1182 [ -n "$GRUB" ] && echo "GRUB=\"$GRUB\"" >> "$CHROOT_VARIABLES"
1183 [ -n "$HOSTNAME" ] && echo "HOSTNAME=\"$HOSTNAME\"" >> "$CHROOT_VARIABLES"
1184 [ -n "$INITRD" ] && echo "INITRD=\"$INITRD\"" >> "$CHROOT_VARIABLES"
1185 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=\"$INSTALL_NOTES\"" >> "$CHROOT_VARIABLES"
1186 [ -n "$ISODIR" ] && echo "ISODIR=\"$ISO\"" >> "$CHROOT_VARIABLES"
1187 [ -n "$ISO" ] && echo "ISO=\"$ISO\"" >> "$CHROOT_VARIABLES"
1188 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=\"$KEEP_SRC_LIST\"" >> "$CHROOT_VARIABLES"
1189 [ -n "$LOCALES" ] && echo "LOCALES=\"$LOCALES\"" >> "$CHROOT_VARIABLES"
1190 [ -n "$MIRROR" ] && echo "MIRROR=\"$MIRROR\"" >> "$CHROOT_VARIABLES"
1191 [ -n "$MKFS" ] && echo "MKFS=\"$MKFS\"" >> "$CHROOT_VARIABLES"
1192 [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=\"true\"" >> "$CHROOT_VARIABLES"
1193 [ -n "$NOKERNEL" ] && echo "NOKERNEL=\"true\"" >> "$CHROOT_VARIABLES"
1194 [ -n "$PACKAGES" ] && echo "PACKAGES=\"$PACKAGES\"" >> "$CHROOT_VARIABLES"
1195 [ -n "$PRE_SCRIPTS" ] && echo "PRE_SCRIPTS=\"$PRE_SCRIPTS\"" >> "$CHROOT_VARIABLES"
1196 [ -n "$RECONFIGURE" ] && echo "RECONFIGURE=\"$RECONFIGURE\"" >> "$CHROOT_VARIABLES"
1197 [ -n "$RELEASE" ] && echo "RELEASE=\"$RELEASE\"" >> "$CHROOT_VARIABLES"
1198 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=\"$RM_APTCACHE\"" >> "$CHROOT_VARIABLES"
1199 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=\"$ROOTPASSWORD\"" >> "$CHROOT_VARIABLES"
1200 [ -n "$SCRIPTS" ] && echo "SCRIPTS=\"$SCRIPTS\"" >> "$CHROOT_VARIABLES"
1201 [ -n "$SECURE" ] && echo "SECURE=\"$SECURE\"" >> "$CHROOT_VARIABLES"
1202 [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=\"$SELECTED_PARTITIONS\"" >> "$CHROOT_VARIABLES"
1203 [ -n "$TARGET" ] && echo "TARGET=\"$TARGET\"" >> "$CHROOT_VARIABLES"
1204 [ -n "$UPGRADE_SYSTEM" ] && echo "UPGRADE_SYSTEM=\"$UPGRADE_SYSTEM\"" >> "$CHROOT_VARIABLES"
1205 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=\"$TARGET_UUID\"" >> "$CHROOT_VARIABLES"
1206 [ -n "$TIMEZONE" ] && echo "TIMEZONE=\"$TIMEZONE\"" >> "$CHROOT_VARIABLES"
1207 [ -n "$TUNE2FS" ] && echo "TUNE2FS=\"$TUNE2FS\"" >> "$CHROOT_VARIABLES"
1208 [ -n "$VMSIZE" ] && echo "VMSIZE=\"$VMSIZE\"" >> "$CHROOT_VARIABLES"
1210 cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script
1211 chmod 755 "${MNTPOINT}"/bin/chroot-script
1212 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
1214 # make sure we have our files for later use via chroot-script
1215 cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/
1216 # make sure we adjust the configuration variables accordingly:
1217 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" "${MNTPOINT}"/etc/debootstrap/config
1218 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" "${MNTPOINT}"/etc/debootstrap/config
1219 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" "${MNTPOINT}"/etc/debootstrap/config
1222 if [ -n "$INSTALL_NOTES" ] ; then
1223 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" "${MNTPOINT}"/etc/debootstrap/
1226 # package selection:
1227 cp $VERBOSE "${_opt_packages:-$CONFFILES/packages}" \
1228 "${MNTPOINT}"/etc/debootstrap/packages
1230 # debconf preseeding:
1231 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
1232 [ -f "${_opt_debconf}" ] && [ "$DEBCONF" = 'yes' ] && \
1233 cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections
1235 # copy scripts that should be executed inside the chroot:
1236 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
1237 [ -d "$_opt_chroot_scripts" ] && [ "$CHROOT_SCRIPTS" = 'yes' ] && {
1238 mkdir -p "${MNTPOINT}"/etc/debootstrap/chroot-scripts
1239 cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/
1242 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
1243 cp $VERBOSE "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables
1245 cp $VERBOSE -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/
1247 # make sure we can access network [relevant for cdebootstrap]
1248 [ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf
1250 # provide system's /etc/hosts to the target:
1251 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
1252 cp $VERBOSE /etc/hosts "${MNTPOINT}"/etc/hosts
1255 # setup default locales
1256 [ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen
1258 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
1259 ( cd "${MNTPOINT}"/dev && tar zxf /etc/debootstrap/devices.tar.gz )
1261 # copy any existing files to chroot
1262 [ -d "${CONFFILES}"/bin ] && cp $VERBOSE -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/
1263 [ -d "${CONFFILES}"/boot ] && cp $VERBOSE -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/
1264 [ -d "${CONFFILES}"/etc ] && cp $VERBOSE -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/
1265 [ -d "${CONFFILES}"/sbin ] && cp $VERBOSE -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/
1266 [ -d "${CONFFILES}"/share ] && cp $VERBOSE -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/
1267 [ -d "${CONFFILES}"/usr ] && cp $VERBOSE -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/
1268 [ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/
1271 DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
1273 # Include files from /etc/network/interfaces.d when using
1274 # ifupdown v0.7.44 or newer:
1275 #source-directory /etc/network/interfaces.d
1278 iface lo inet loopback
1281 iface eth0 inet dhcp
1284 if [ -n "$NOINTERFACES" ] ; then
1285 einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0
1286 elif [ -n "$USE_DEFAULT_INTERFACES" ] ; then
1287 einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options."
1288 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1290 elif [ -n "$VIRTUAL" ] ; then
1291 einfo "Setting up Virtual Machine, installing default /etc/network/interfaces"
1292 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1294 elif [ -r /etc/network/interfaces ] ; then
1295 einfo "Copying /etc/network/interfaces from host to target system"
1296 cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
1299 ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
1300 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1304 # install config file providing some example entries
1305 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
1306 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
1313 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
1314 execute_pre_scripts() {
1315 # make sure we have $MNTPOINT available for our scripts
1317 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
1318 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
1319 for script in ${pre_scripts}/* ; do
1320 if [ -x "$script" ] ; then
1321 einfo "Executing pre-script $script"
1329 # execute all scripts in /etc/debootstrap/scripts/ {{{
1331 # make sure we have $MNTPOINT available for our scripts
1333 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
1334 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
1335 for script in ${scripts}/* ; do
1336 if [ -x "$script" ] ; then
1337 einfo "Executing script $script"
1345 # execute chroot-script {{{
1347 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
1351 if ! [ -x "$MNTPOINT/bin/chroot-script" ] ; then
1352 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
1355 einfo "Executing chroot-script now"
1356 mount --bind /dev "$MNTPOINT"/dev
1357 if [ "$DEBUG" = "true" ] ; then
1358 chroot "$MNTPOINT" /bin/sh -x /bin/chroot-script ; RC=$?
1360 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
1362 umount "$MNTPOINT"/dev
1366 # finally get rid of chroot-script again, there's no good reason to
1367 # keep it on the installed system
1368 if grep -q GRML_CHROOT_SCRIPT_MARKER "${MNTPOINT}/bin/chroot-script" ; then
1369 einfo "Removing chroot-script again"
1370 rm -f "${MNTPOINT}/bin/chroot-script"
1373 einfo "Keeping chroot-script as string GRML_CHROOT_SCRIPT_MARKER could not be found"
1379 # unmount $MNTPOINT {{{
1382 # display installation notes:
1383 if [ -n "$INSTALL_NOTES" ] ; then
1384 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
1387 if [ -n "$ISODIR" ] ; then
1388 if grep -q "$ISODIR" /proc/mounts ; then
1389 einfo "Unmount $MNTPOINT/$ISODIR"
1390 umount "$MNTPOINT/$ISODIR"
1395 if grep -q "$MNTPOINT" /proc/mounts ; then
1396 if [ -n "$PARTITION" ] ; then
1397 einfo "Unmount $MNTPOINT"
1405 # execute filesystem check {{{
1407 if [ -n "$VIRTUAL" ] ; then
1408 einfo "Skipping filesystem check because we deploy a virtual machine."
1412 if [ "$FSCK" = 'yes' ] ; then
1413 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
1414 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
1415 "$FSCKTOOL" "$TARGET"
1421 # now execute all the functions {{{
1422 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
1423 preparechroot execute_pre_scripts chrootscript execute_scripts \
1424 umount_chroot finalize_vm fscktool ; do
1425 if stage "${i}" ; then
1427 stage "${i}" 'done' && rm -f "${STAGES}/${i}"
1437 # end dialog of autoinstallation {{{
1438 if [ -n "$AUTOINSTALL" ] ; then
1439 if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1440 Automatically rebooting in 10 seconds.
1442 Choose Cancel to skip rebooting." 10 60 10 ; then
1443 noeject noprompt reboot
1446 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1450 ## END OF FILE #################################################################
1451 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=2