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="yes"
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 {{{
152 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
153 printf " ${GOOD}*${NORMAL} $*"
159 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
160 printf " ${BAD}*${NORMAL} $*\n" >&2
166 local retval="${1:-0}"
168 if [ $retval -gt 0 ]; then
169 printf " ${BAD}-> Failed (rc=${retval})${NORMAL}\n"
175 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
176 echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
183 which $arg >/dev/null 2>&1 || RC="$arg"
185 if [ -n "$RC" ] ; then
186 echo "$RC not installed"
192 # helper functions {{{
194 if [ -n "$CHROOT_VARIABLES" ] ; then
195 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
198 if [ -n "$STAGES" ] ; then
199 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
202 # Remove temporary mountpoint again
203 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
204 rmdir "$MNTPOINT" 2>/dev/null
207 # make sure $TARGET is not mounted when exiting grml-debootstrap
208 if [ -n "$MNTPOINT" ] ; then
209 if grep -q "$MNTPOINT" /proc/mounts ; then
210 # make sure nothing is left inside chroot so we can unmount it
211 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
212 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm 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 if [ -r ./cmdlineopts.clp ] ; then
294 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
295 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
297 eerror "Error: cmdline function file not found, exiting."
302 # == business-logic of command line parameter-processing
304 # source configuration file in <confdir> if supplied. {{{
305 [ "$_opt_confdir" ] && {
306 CONFFILES=$_opt_confdir
307 einfo "Using config files under $CONFFILES/."
308 if ! [ -r "$CONFFILES/config" ] ; then
309 eerror "Error: config file $CONFFILES/config not found."; eend 1; bailout 1
311 if ! . "$CONFFILES/config" ; then
312 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; bailout 1
314 # restore the command line parameter value
315 CONFFILES=$_opt_confdir
319 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
320 [ "$_opt_iso" ] && ISO=$_opt_iso
321 [ "$_opt_release" ] && RELEASE=$_opt_release
322 [ "$_opt_target" ] && TARGET=$_opt_target
323 [ "$_opt_vm" ] && VIRTUAL=1
324 [ "$_opt_vmfile" ] && VMFILE=1 && VIRTUAL=1
325 [ "$_opt_vmsize" ] && VMSIZE=$_opt_vmsize
326 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
327 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
328 [ "$_opt_interactive" ] && INTERACTIVE=1
329 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
330 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
331 [ "$_opt_packages_set" ] && PACKAGES='yes'
332 [ "$_opt_nopackages" ] && PACKAGES=''
333 [ "$_opt_debconf_set" ] && DEBCONF='yes'
334 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
335 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
336 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
337 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
338 [ "$_opt_grmlrepos" ] && GRMLREPOS='yes'
339 [ "$_opt_backportrepos" ] && BACKPORTREPOS='yes'
340 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
341 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
342 [ "$_opt_nopassword" ] && NOPASSWORD='yes'
343 [ "$_opt_defaultinterfaces" ] && DEFAULTINTERFACES="true"
344 [ "$_opt_nointerfaces" ] && NOINTERFACES="true"
345 [ "$_opt_nokernel" ] && NOKERNEL="true"
346 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
347 [ "$_opt_grub" ] && GRUB=$_opt_grub
348 [ "$_opt_arch" ] && ARCH=$_opt_arch
349 [ "$_opt_insecure" ] && echo "Warning: --insecure is deprecated, continuing anyway."
350 [ "$_opt_force" ] && FORCE=$_opt_force
351 [ "$_opt_verbose" ] && VERBOSE="-v"
352 [ "$_opt_debug" ] && DEBUG="true"
354 if [ "$DEBUG" = "true" ] ; then
358 [ "$_opt_help" ] && {
364 [ "$_opt_version" ] && {
365 einfo "$PN - version $VERSION"
366 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
372 # check for root permissions {{{
373 if ! check4root ; then
374 echo "For usage instructions please execute '$PN --help'."
379 # make sure we have what we need {{{
380 if [ -n "$VIRTUAL" ] ; then
381 check4progs kpartx mksh parted qemu-img || bailout 1
385 # source specified configuration file {{{
386 if [ -n "$CONFIGFILE" ] ; then
387 einfo "Reading specified config file $CONFIGFILE."
388 if ! . "$CONFIGFILE" ; then
389 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; bailout 1
394 # backwards compability checks {{{
395 if [ -n "$GROOT" ] ; then
396 eerror "Error: you seem to have \$GROOT configured."
397 eerror "This variable is no longer supported, please visit the"
398 eerror "grml-debootstrap documentation for details."
403 if echo "$GRUB" | grep -q '^hd' ; then
404 eerror "Error: this syntax for the grub configuration variable is no longer supported."
405 eerror "Please do not use hd... any longer but /dev/sdX instead."
414 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
415 Do you want to continue installing Debian using this frontend?" 0 0 || bailout 0
422 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
424 grep -v 'Extended$' | \
425 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
427 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
428 dialog --title "$PN" --trim \
429 --msgbox "Sorry, no partitions found. Please configure your
430 harddisks (see /proc/partitions) using a tool like fdisk,
431 cfdisk, gpart, gparted,..." 0 0
435 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
436 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [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
553 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
554 "Please enter the password for the root account again for \
555 confirmation:" 10 60)
556 [ $? -eq 0 ] || bailout
558 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
559 $(dialog --stdout --title "${PN}" --ok-label \
560 "Retry" --msgbox "Passwords do not match!" 10 60)
563 ROOTPASSWORD="$ROOTPW1"
567 # ask for Debian mirror {{{
570 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
572 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
573 --menu "Where do you want to install from?" 0 0 0 \
574 net "install via network (downloading from mirror)" \
575 local "install from local directory/mirror"
577 [ $? -eq 0 ] || bailout
579 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
580 [ -n "$MIRROR" ] || MIRROR='http://http.debian.net/debian'
581 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
582 "Please enter Debian mirror you would like to use for installing packages." \
584 [ $? -eq 0 ] || bailout
585 else # CHOOSE_MIRROR == local
586 [ -n "$ISO" ] || ISO='/mnt/mirror'
587 ISO="$(dialog --stdout --title "${PN}" --inputbox \
588 "Please enter directory name you would like to use for installing packages." \
590 [ $? -eq 0 ] || bailout
595 # software raid setup {{{
596 config_swraid_setup()
600 # Currently we support only raid1:
603 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
604 # --menu "Which RAID level do you want to use?" 0 0 0 \
605 # raid1 "Software RAID level 1" \
606 # raid5 "Software RAID level 5")
607 #[ $? -eq 0 ] || bailout 20
609 MD_LIST=$(for i in $(seq 0 9) ; do
610 awk '{print $4}' /proc/partitions | grep -q md$i || \
611 echo "/dev/md$i /dev/md$i"
614 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
615 --menu "Which device do you want to use for ${RAIDLEVEL}?
617 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 \
619 [ $? -eq 0 ] || bailout 20
621 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
623 grep -v 'Extended$' | \
624 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
625 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
626 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
627 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet]) off"
630 dialog --title "$PN" --separate-output \
631 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
632 $PARTITION_LIST 2>$TMPFILE
633 [ $? -eq 0 ] || bailout
635 SELECTED_PARTITIONS="$(cat $TMPFILE)"
638 for i in $(cat $TMPFILE) ; do
639 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
642 # force metadata version 0.90 for lenny so old grub can boot from this array.
644 if [ $RELEASE = "lenny" ]; then
645 METADATA_VERSION="-e0"
649 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
650 --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
652 if [ "$RC" = 0 ] ; then
653 dialog --title "$PN" --msgbox \
654 "Creating $TARGET was successful." 0 0
655 rm -f "$TMPFILE" "$ERRORFILE"
657 dialog --title "$PN" --msgbox \
658 "There was an error setting up $TARGET:
663 rm -f "$TMPFILE" "$ERRORFILE"
671 if dialog --stdout --title "$PN" \
672 --defaultno --yesno "Do you want to configure Software RAID?
674 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
680 # user should recheck his configuration {{{
681 # support full automatic installation:
683 dialog --timeout 10 --title "$PN" \
684 --yesno "Do you want to stop at this stage?
686 Notice: you are running ${PN} in non-interactive mode.
687 ${PN} will install Debian ${RELEASE} on ${TARGET}.
688 Last chance to quit. Timeout of 10 seconds running....
690 Do you want to stop now?" 0 0 2>/dev/null
694 # make sure the user is aware of the used configuration {{{
697 if [ -n "$AUTOINSTALL" ] ; then
698 if checkforrun ; then
699 eerror "Exiting as requested" ; eend 0
702 elif [ -n "$INTERACTIVE" ] ; then
704 INFOTEXT="Please recheck configuration before execution:
706 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
708 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
710 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
711 Using release: $RELEASE"
712 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
713 Using hostname: $HOSTNAME"
714 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
715 Using mirror: $MIRROR"
716 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
718 [ -n "$ARCH" ] && INFOTEXT="$INFOTEXT
723 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
725 dialog --title "$PN" --no-collapse \
726 --yesno "$INFOTEXT" 0 0
727 [ $? -eq 0 ] || bailout 0
729 else # if not running automatic installation display configuration and prompt for execution:
730 einfo "$PN [${VERSION}] - Please recheck configuration before execution:"
732 echo " Target: $TARGET"
734 # do not display if MNTPOINT is the default one
735 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
737 if [ -n "$VIRTUAL" ] ; then
738 echo " Install grub: yes"
740 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
743 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
744 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
745 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
746 [ -n "$ISO" ] && echo " Using ISO: $ISO"
747 [ -n "$ARCH" ] && echo " Using arch: $ARCH"
748 if [ -n "$VIRTUAL" ] ; then
749 echo " Deploying as Virtual Machine."
750 if [ -n "$VMSIZE" -a -n "$VMFILE" ]; then
751 echo " Using Virtual Disk file with size of ${VMSIZE}."
755 if [ ! -t 0 -a -z "$ROOTPASSWORD" -a -z "$NOPASSWORD" ] ; then
757 echo " You do not have a TTY allocated, your password will be shown in"
758 echo " plaintext on the terminal! If you are using SSH, try its -t option!"
762 echo " Important! Continuing will delete all data from ${TARGET}!"
764 if [ -n "$FORCE" ] ; then
765 einfo "Skip user acknowledgement as requested via --force option."
768 einfon "Is this ok for you? [y/N] "
770 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
771 eerror "Exiting as requested." ; eend 1
779 # interactive mode {{{
782 check4progs dialog || bailout 1
792 prompt_for_bootmanager
801 # run interactive mode if we didn't get the according configuration yet
802 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
803 # only target might be unset, so make sure the INTERACTIVE flag is set as well
809 # architecture setup {{{
810 if [ -n "$ARCH" ] ; then
811 ARCHCMD="--arch $ARCH"
812 ARCHINFO=" (${ARCH})"
814 ARCH="$(dpkg --print-architecture)"
815 ARCHCMD="--arch $ARCH"
816 ARCHINFO=" (${ARCH})"
820 # It is not possible to build amd64 on i686. {{{
821 CURRENT_ARCH="$(uname -m)"
822 if [ "$CURRENT_ARCH" != "x86_64" ] ; then
823 if [ "$ARCH" = "amd64" ] ; then
824 eerror "It is not possible to build amd64 on $CURRENT_ARCH." ; eend 1
832 # finally make sure at least $TARGET is set [the partition for the new system] {{{
833 if [ -n "$TARGET" ] ; then
834 SHORT_TARGET="${TARGET##*/}"
836 eerror "Please adjust $CONFFILES/config or..."
837 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
843 if [ -z "$STAGES" ] ; then
844 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
845 [ -d "$STAGES" ] || mkdir -p "$STAGES"
848 if [ -r "$STAGES"/grml-debootstrap ] ; then
849 if grep -q done $STAGES/grml-debootstrap ; then
850 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
851 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
856 # partition handling {{{
860 set_target_directory(){
861 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
867 # make sure we normalise the path to an absolute directory name so something like:
868 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
870 TARGET="$(readlink -f $TARGET)"
873 if [ -b "$TARGET" ] || [ -n "$VIRTUAL" ] ; then
880 # make sure we have the right syntax when using an iso image {{{
881 if [ -n "$ISO" ] ; then
894 # Debian ISOs do not contain signed Release files {{{
895 if [ -n "$ISO" ] ; then
896 DEBOOTSTRAP_OPT="$DEBOOTSTRAP_OPT --no-check-gpg"
900 # create filesystem {{{
902 if [ -n "$DIRECTORY" ] ; then
903 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
907 if grep -q "$TARGET" /proc/mounts ; then
908 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
912 # mkfs.ext* might prompt with "/dev/sdX# contains a ext* file system
913 # created on ... Proceed anyway? (y,n)" which we want to skip in force mode
914 if [ -n "$MKFS" ] && [ -n "$FORCE" ] ; then
917 einfo "Enabling force option (-F) for mkfs.ext* tool as requested via --force switch."
918 MKFS_OPTS="$MKFS_OPTS -F"
924 if [ -n "$MKFS" ] ; then
925 einfo "Running $MKFS $MKFS_OPTS on $TARGET"
926 $MKFS $MKFS_OPTS $TARGET ; RC=$?
928 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
929 if ! echo "$MKFS" | grep -q "mkfs.ext" ; then
930 eerror "Not changing disk uuid for $TARGET because $MKFS doesn't seem to match for ext{2,3,4} file system"
934 einfo "Changing disk uuid for $TARGET to fixed (non-random) value $DISK_IDENTIFIER using tune2fs"
935 tune2fs "$TARGET" -U "$DISK_IDENTIFIER"
940 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
941 # will fail to detect the uuid in the chroot
942 if echo "$TARGET" | grep -q "/dev/md" ; then
943 blockdev --rereadpt "${TARGET}"
944 elif ! [ -n "$VIRTUAL" ] ; then
945 blockdev --rereadpt "${TARGET%%[0-9]*}"
947 # give the system 2 seconds, otherwise we might run into
948 # race conditions :-/
951 eval $(blkid -o udev $TARGET 2>/dev/null)
952 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
959 # modify filesystem settings {{{
961 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
962 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
969 # mount the new partition or if it's a directory do nothing at all {{{
971 if [ -n "$DIRECTORY" ] ; then
972 einfo "Running grml-debootstrap on a directory, nothing to mount."
974 if grep -q $TARGET /proc/mounts ; then
975 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
977 if ! [ -d "${MNTPOINT}" ] ; then
978 [ -n "$VIRTUAL" ] || mkdir -p "${MNTPOINT}"
980 einfo "Mounting $TARGET to $MNTPOINT"
982 mount -o rw,suid,dev $TARGET $MNTPOINT
986 if [ -n "$ISODIR" ] ; then
987 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
988 mkdir -p "$MNTPOINT/$ISODIR"
989 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
995 # prepare VM image for usage with debootstrap {{{
997 if [ -z "$VIRTUAL" ] ; then
998 return 0 # be quiet by intention
1001 if [ -b "$TARGET" -a -n "$VMFILE" ] ; then
1002 eerror "Error: specified virtual disk target ($TARGET) is an existing block device."
1006 if [ ! -b "$TARGET" -a -z "$VMFILE" ] ; then
1007 eerror "Error: specified virtual disk target ($TARGET) does not exist yet."
1012 ORIG_TARGET="$TARGET" # store for later reuse
1014 if [ -n "$VMFILE" ]; then
1015 qemu-img create -f raw "${TARGET}" "${VMSIZE}"
1017 echo 4 66 | /usr/share/grml-debootstrap/bootgrub.mksh -A | dd of="$TARGET" conv=notrunc
1018 dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
1019 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
1020 einfo "Adjusting disk signature to a fixed (non-random) value"
1021 MBRTMPFILE=$(mktemp)
1022 dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1
1023 echo -en "\x41\x41\x41\x41\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1
1024 dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc
1027 parted -s "${TARGET}" 'mkpart primary ext4 2M -1'
1029 # if dm-mod isn't available then kpartx will fail with
1030 # "Is device-mapper driver missing from kernel? [...]"
1031 if ! kpartx -av $TARGET >/dev/null 2>&1 || ! grep -q device-mapper /proc/misc >/dev/null 2>&1 ; then
1032 einfo "Device-mapper not ready yet, trying to load dm-mod module."
1033 modprobe dm-mod ; eend $?
1036 # make sure loop module is present
1037 if ! losetup -f >/dev/null 2>&1; then
1038 einfo "Can not find a usable loop device, retrying after loading loop module."
1040 if losetup -f >/dev/null 2>&1; then
1041 einfo "Found a usable loop device now, continuing."
1043 eerror "Error finding usable loop device" ; eend 1
1048 DEVINFO=$(kpartx -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
1049 if [ -z "${DEVINFO}" ] ; then
1050 eerror "Error setting up loopback device." ; eend 1
1054 # hopefully this always works as expected
1055 LOOP=$(echo ${DEVINFO} | sed 's/.* linear //; s/ [[:digit:]]*//') # '/dev/loop1'
1056 BLOCKDEV=$(echo "${DEVINFO}" | sed -e 's/.* (\(.*:.*\)).*/\1/') # '253:0'
1057 LOOP_PART="$(echo ${DEVINFO##add map } | sed 's/ .*//')" # '/dev/loop1p1'
1058 export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'
1060 blockdev --rereadpt "${LOOP}"
1062 if [ -z "$TARGET" ] ; then
1063 eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1
1069 # make VM image bootable and unmount it {{{
1071 if [ -z "${VIRTUAL}" ] ; then
1075 if ! mount "${TARGET}" "${MNTPOINT}" ; then
1076 eerror "Error: Mounting ${TARGET} failed, can not continue." ; eend 1
1080 einfo "Installing Grub as bootloader."
1081 mount -t proc none "${MNTPOINT}"/proc
1082 mount -t sysfs none "${MNTPOINT}"/sys
1083 mount --bind /dev "${MNTPOINT}"/dev
1085 mkdir -p "${MNTPOINT}/boot/grub"
1086 if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
1087 eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
1091 cp "${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
1102 umount "${MNTPOINT}"/proc
1103 umount "${MNTPOINT}"/sys
1104 umount "${MNTPOINT}"/dev
1106 einfo "Adjusting grub.cfg for successful boot sequence."
1107 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ]; then
1108 sed -i "s;root=[^ ]\+;root=UUID=$DISK_IDENTIFIER;" /boot/grub/grub.cfg
1110 sed -i "s;set root=.*;set root='(hd0,msdos1)';" "${MNTPOINT}"/boot/grub/grub.cfg
1111 sed -i "s;root=[^ ]\+;root=/dev/sda1;" "${MNTPOINT}"/boot/grub/grub.cfg
1114 umount "${MNTPOINT}"
1115 kpartx -d "${ORIG_TARGET}" >/dev/null
1119 # install main chroot {{{
1120 debootstrap_system() {
1121 if [ "$_opt_nodebootstrap" ]; then
1122 einfo "Skipping debootstrap as requested."
1126 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
1129 eerror "Error: $MNTPOINT not mounted, can not continue."
1133 if [ -n "$ISO" ] ; then
1134 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${ISO}"
1135 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
1136 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
1139 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
1140 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
1141 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
1145 if [ $RC -ne 0 ] ; then
1146 if [ -r "$MNTPOINT/debootstrap/debootstrap.log" ] && \
1147 [ -s "$MNTPOINT/debootstrap/debootstrap.log" ] ; then
1148 einfo "Presenting last ten lines of debootstrap.log:"
1149 tail -10 $MNTPOINT/debootstrap/debootstrap.log
1150 einfo "End of debootstrap.log"
1158 # prepare chroot via chroot-script {{{
1160 einfo "Preparing chroot system"
1162 # provide variables to chroot system
1163 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
1164 touch $CHROOT_VARIABLES
1165 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
1166 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
1167 [ -n "$ARCH" ] && echo "ARCH=\"$ARCH\"" >> $CHROOT_VARIABLES
1168 [ -n "$BACKPORTREPOS" ] && echo "BACKPORTREPOS=\"$BACKPORTREPOS\"" >> $CHROOT_VARIABLES
1169 [ -n "$CHROOT_SCRIPTS" ] && echo "CHROOT_SCRIPTS=\"$CHROOT_SCRIPTS\"" >> $CHROOT_VARIABLES
1170 [ -n "$CONFFILES" ] && echo "CONFFILES=\"$CONFFILES\"" >> $CHROOT_VARIABLES
1171 [ -n "$DEBCONF" ] && echo "DEBCONF=\"$DEBCONF\"" >> $CHROOT_VARIABLES
1172 [ -n "$DEBIAN_FRONTEND" ] && echo "DEBIAN_FRONTEND=\"$DEBIAN_FRONTEND\"" >> $CHROOT_VARIABLES
1173 [ -n "$DEBOOTSTRAP" ] && echo "DEBOOTSTRAP=\"$DEBOOTSTRAP\"" >> $CHROOT_VARIABLES
1174 [ -n "$DEFAULT_LOCALES" ] && echo "DEFAULT_LOCALES=\"$DEFAULT_LOCALES\"" >> $CHROOT_VARIABLES
1175 [ -n "$DEFAULT_LANGUAGE" ] && echo "DEFAULT_LANGUAGE=\"$DEFAULT_LANGUAGE\"" >> $CHROOT_VARIABLES
1176 [ -n "$EXTRAPACKAGES" ] && echo "EXTRAPACKAGES=\"$EXTRAPACKAGES\"" >> $CHROOT_VARIABLES
1177 [ -n "$FALLBACK_MIRROR" ] && echo "FALLBACK_MIRROR=\"$FALLBACK_MIRROR\"" >> $CHROOT_VARIABLES
1178 [ -n "$FORCE" ] && echo "FORCE=\"$FORCE\"" >> $CHROOT_VARIABLES
1179 [ -n "$GRMLREPOS" ] && echo "GRMLREPOS=\"$GRMLREPOS\"" >> $CHROOT_VARIABLES
1180 [ -n "$GRUB" ] && echo "GRUB=\"$GRUB\"" >> $CHROOT_VARIABLES
1181 [ -n "$HOSTNAME" ] && echo "HOSTNAME=\"$HOSTNAME\"" >> $CHROOT_VARIABLES
1182 [ -n "$INITRD" ] && echo "INITRD=\"$INITRD\"" >> $CHROOT_VARIABLES
1183 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=\"$INSTALL_NOTES\"" >> $CHROOT_VARIABLES
1184 [ -n "$ISODIR" ] && echo "ISODIR=\"$ISO\"" >> $CHROOT_VARIABLES
1185 [ -n "$ISO" ] && echo "ISO=\"$ISO\"" >> $CHROOT_VARIABLES
1186 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=\"$KEEP_SRC_LIST\"" >> $CHROOT_VARIABLES
1187 [ -n "$LOCALES" ] && echo "LOCALES=\"$LOCALES\"" >> $CHROOT_VARIABLES
1188 [ -n "$MIRROR" ] && echo "MIRROR=\"$MIRROR\"" >> $CHROOT_VARIABLES
1189 [ -n "$MKFS" ] && echo "MKFS=\"$MKFS\"" >> $CHROOT_VARIABLES
1190 [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=\"true\"" >> $CHROOT_VARIABLES
1191 [ -n "$NOKERNEL" ] && echo "NOKERNEL=\"true\"" >> $CHROOT_VARIABLES
1192 [ -n "$PACKAGES" ] && echo "PACKAGES=\"$PACKAGES\"" >> $CHROOT_VARIABLES
1193 [ -n "$PRE_SCRIPTS" ] && echo "PRE_SCRIPTS=\"$PRE_SCRIPTS\"" >> $CHROOT_VARIABLES
1194 [ -n "$RECONFIGURE" ] && echo "RECONFIGURE=\"$RECONFIGURE\"" >> $CHROOT_VARIABLES
1195 [ -n "$RELEASE" ] && echo "RELEASE=\"$RELEASE\"" >> $CHROOT_VARIABLES
1196 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=\"$RM_APTCACHE\"" >> $CHROOT_VARIABLES
1197 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=\"$ROOTPASSWORD\"" >> $CHROOT_VARIABLES
1198 [ -n "$SCRIPTS" ] && echo "SCRIPTS=\"$SCRIPTS\"" >> $CHROOT_VARIABLES
1199 [ -n "$SECURE" ] && echo "SECURE=\"$SECURE\"" >> $CHROOT_VARIABLES
1200 [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=\"$SELECTED_PARTITIONS\"" >> $CHROOT_VARIABLES
1201 [ -n "$TARGET" ] && echo "TARGET=\"$TARGET\"" >> $CHROOT_VARIABLES
1202 [ -n "$UPGRADE_SYSTEM" ] && echo "UPGRADE_SYSTEM=\"$UPGRADE_SYSTEM\"" >> $CHROOT_VARIABLES
1203 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=\"$TARGET_UUID\"" >> $CHROOT_VARIABLES
1204 [ -n "$TIMEZONE" ] && echo "TIMEZONE=\"$TIMEZONE\"" >> $CHROOT_VARIABLES
1205 [ -n "$TUNE2FS" ] && echo "TUNE2FS=\"$TUNE2FS\"" >> $CHROOT_VARIABLES
1206 [ -n "$VMSIZE" ] && echo "VMSIZE=\"$VMSIZE\"" >> $CHROOT_VARIABLES
1208 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
1209 chmod 755 $MNTPOINT/bin/chroot-script
1210 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
1212 # make sure we have our files for later use via chroot-script
1213 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
1214 # make sure we adjust the configuration variables accordingly:
1215 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
1216 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
1217 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
1220 if [ -n "$INSTALL_NOTES" ] ; then
1221 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
1224 # package selection:
1225 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
1226 $MNTPOINT/etc/debootstrap/packages
1228 # debconf preseeding:
1229 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
1230 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
1231 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
1233 # copy scripts that should be executed inside the chroot:
1234 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
1235 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
1236 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
1237 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
1240 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
1241 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
1243 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
1245 # make sure we can access network [relevant for cdebootstrap]
1246 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
1248 # provide system's /etc/hosts to the target:
1249 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
1250 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
1253 # setup default locales
1254 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
1256 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
1257 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
1259 # copy any existing files to chroot
1260 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
1261 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
1262 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
1263 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
1264 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
1265 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
1266 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
1269 DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
1271 # Include files from /etc/network/interfaces.d when using
1272 # ifupdown v0.7.44 or newer:
1273 #source-directory /etc/network/interfaces.d
1276 iface lo inet loopback
1279 iface eth0 inet dhcp
1282 if [ -n "$NOINTERFACES" ] ; then
1283 einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0
1284 elif [ -n "$DEFAULT_INTERFACES" ] ; then
1285 einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options."
1286 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1288 elif [ -n "$VIRTUAL" ] ; then
1289 einfo "Setting up Virtual Machine, installing default /etc/network/interfaces"
1290 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1292 elif [ -r /etc/network/interfaces ] ; then
1293 einfo "Copying /etc/network/interfaces from host to target system"
1294 cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
1297 ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
1298 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1302 # install config file providing some example entries
1303 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
1304 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
1311 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
1312 execute_pre_scripts() {
1313 # make sure we have $MNTPOINT available for our scripts
1315 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
1316 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
1317 for script in ${pre_scripts}/* ; do
1318 if [ -x "$script" ] ; then
1319 einfo "Executing pre-script $script"
1327 # execute all scripts in /etc/debootstrap/scripts/ {{{
1329 # make sure we have $MNTPOINT available for our scripts
1331 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
1332 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
1333 for script in ${scripts}/* ; do
1334 if [ -x "$script" ] ; then
1335 einfo "Executing script $script"
1343 # execute chroot-script {{{
1345 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
1349 if ! [ -x "$MNTPOINT/bin/chroot-script" ] ; then
1350 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
1353 einfo "Executing chroot-script now"
1354 mount --bind /dev "$MNTPOINT"/dev
1355 if [ "$DEBUG" = "true" ] ; then
1356 chroot "$MNTPOINT" /bin/sh -x /bin/chroot-script ; RC=$?
1358 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
1360 umount "$MNTPOINT"/dev
1364 # finally get rid of chroot-script again, there's no good reason to
1365 # keep it on the installed system
1366 if grep -q GRML_CHROOT_SCRIPT_MARKER "${MNTPOINT}/bin/chroot-script" ; then
1367 einfo "Removing chroot-script again"
1368 rm -f "${MNTPOINT}/bin/chroot-script"
1371 einfo "Keeping chroot-script as string GRML_CHROOT_SCRIPT_MARKER could not be found"
1377 # unmount $MNTPOINT {{{
1380 # display installation notes:
1381 if [ -n "$INSTALL_NOTES" ] ; then
1382 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
1385 if [ -n "$ISODIR" ] ; then
1386 if grep -q "$ISODIR" /proc/mounts ; then
1387 einfo "Unmount $MNTPOINT/$ISODIR"
1388 umount "$MNTPOINT/$ISODIR"
1393 if grep -q "$MNTPOINT" /proc/mounts ; then
1394 if [ -n "$PARTITION" ] ; then
1395 einfo "Unmount $MNTPOINT"
1403 # execute filesystem check {{{
1405 if [ -n "$VIRTUAL" ] ; then
1406 einfo "Skipping filesystem check because we deploy a virtual machine."
1410 if [ "$FSCK" = 'yes' ] ; then
1411 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
1412 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
1419 # now execute all the functions {{{
1420 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
1421 preparechroot execute_pre_scripts chrootscript execute_scripts \
1422 umount_chroot finalize_vm fscktool ; do
1423 if stage "${i}" ; then
1424 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "$i"
1431 # end dialog of autoinstallation {{{
1432 if [ -n "$AUTOINSTALL" ] ; then
1433 if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1434 Automatically rebooting in 10 seconds.
1436 Choose Cancel to skip rebooting." 10 60 10 ; then
1437 noeject noprompt reboot
1440 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1444 ## END OF FILE #################################################################
1445 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=2