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_LOCALES" ] || DEFAULT_LOCALES='en_US.UTF-8'
22 [ -n "$DEFAULT_LANGUAGE" ] || DEFAULT_LANGUAGE='en_US:en'
23 [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes'
24 [ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://http.debian.net/debian'
25 [ -n "$FORCE" ] || FORCE=''
26 [ -n "$HOSTNAME" ] || HOSTNAME='grml'
27 [ -n "$INITRD" ] || INITRD='yes'
28 [ -n "$INSTALL_NOTES" ] || INSTALL_NOTES='/etc/debootstrap/install_notes'
29 [ -n "$LOCALES" ] || LOCALES='yes'
30 [ -n "$MIRROR" ] || MIRROR="$FALLBACK_MIRROR"
31 [ -n "$MKFS" ] || MKFS='mkfs.ext4'
32 [ -n "$PACKAGES" ] || PACKAGES='yes'
33 [ -n "$PRE_SCRIPTS" ] || PRE_SCRIPTS='yes'
34 [ -n "$RECONFIGURE" ] || RECONFIGURE='console-data'
35 [ -n "$RELEASE" ] || RELEASE='wheezy'
36 [ -n "$RM_APTCACHE" ] || RM_APTCACHE='yes'
37 [ -n "$SCRIPTS" ] || SCRIPTS='yes'
38 [ -n "$SECURE" ] || SECURE='yes'
39 [ -n "$TIMEZONE" ] || TIMEZONE='Europe/Vienna'
40 [ -n "$TUNE2FS" ] || TUNE2FS='tune2fs -c0 -i0'
41 [ -n "$UPGRADE_SYSTEM" ] || UPGRADE_SYSTEM='yes'
42 [ -n "$VMSIZE" ] || VMSIZE="2G"
43 [ -n "$FIXED_DISK_IDENTIFIERS" ] || FIXED_DISK_IDENTIFIERS="no"
45 # inside the chroot system locales might not be available, so use minimum:
49 # make sure interactive mode is only executed when
50 # using an empty configuration file or option --interactive
56 echo "$PN - wrapper around debootstrap for installing Debian
62 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
63 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
64 instead of fetching packages from a mirror.
65 -r, --release <name> Release of new Debian system (default: wheezy).
66 -t, --target <target> Target partition (/dev/...) or directory where the
67 system should be installed to.
68 -p, --mntpoint <mnt> Mountpoint used for mounting the target system,
69 has no effect if -t is given and represents a directory.
70 --debopt <params> Extra parameters passed to the debootstrap command.
71 --interactive Use interactive mode (frontend).
72 --nodebootstrap Skip debootstrap, only do configuration to the target.
73 --grub <device> Target for grub installation. Usage example: /dev/sda
74 --arch <arch> Set target architecture, use for installing i386 on amd64.
75 --filesystem <fs> Filesystem that should be used when target is a partition
76 or Virtual Machine (see --vmfile).
77 --force Do not prompt for user acknowledgement.
79 Options for Virtual Machine deployment:
81 --vm Set up a Virtual Machine, instead of plainly installing
82 to a partition or directory, to be combined with --target,
83 like: --vm --target /dev/mapper/your-vm-disk
84 --vmfile Like --vm, but install into a file (raw format).
85 Example: --vmfile --target /mnt/sda1/qemu.img
86 --vmsize <size> Use specified size for size of VM file (default: 2G).
87 Syntax as supported by qemu-img, like: --vmsize 3G
89 Configuration options:
91 -c, --config <file> Use specified configuration file, defaults to
92 /etc/debootstrap/config
93 -d, --confdir <path> Place of config files for debootstrap, defaults
95 --packages <file> Install packages defined in specified list file
96 instead of using /etc/debootstrap/packages.
97 --nopackages Skip installation of packages defined in
98 /etc/debootstrap/packages
99 --nokernel Skip installation of default kernel images.
100 --nointerfaces Do not copy /etc/network/interfaces from host system
102 (This option is automatically enabled when using --vmfile.)
103 --defaultinterfaces Install a default /etc/network/interfaces file (enabling
104 DHCP for eth0) instead of taking over config from host system.
105 --debconf <file> Pre-seed packages using specified pre-seed db file.
106 --grmlrepos Enable Grml's Debian repository (deb.grml.org).
107 --backportrepos Enable Debian's backports repository (backports.debian.org).
108 --keep_src_list Do not overwrite user provided apt sources.list.
109 --hostname <name> Hostname of Debian system.
110 --nopassword Do not prompt for the root password.
111 --password <pwd> Use specified password as password for user root.
112 --bootappend <line> Add specified appendline to kernel whilst booting.
113 --chroot-scripts <d> Execute chroot scripts from specified directory.
114 --pre-scripts <dir> Execute scripts from specified directory (before chroot-scripts).
115 --scripts <dir> Execute scripts from specified directory (after chroot-scripts).
119 -v, --verbose Increase verbosity.
120 --debug Execute in very verbose way.
121 -h, --help Print this usage information and exit.
122 -V, --version Show summary of options and exit.
124 Usage examples can be found in the grml-debootstrap manpage.
125 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
129 if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then
131 echo 'Please notice that this script requires root permissions!'
136 # early helper functions {{{
150 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
151 printf " ${GOOD}*${NORMAL} $*"
157 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
158 printf " ${BAD}*${NORMAL} $*\n" >&2
164 local retval="${1:-0}"
166 if [ $retval -gt 0 ]; then
167 printf " ${BAD}-> Failed (rc=${retval})${NORMAL}\n"
173 if [ "$(id -u 2>/dev/null)" != 0 ] ; then
174 echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1
181 which $arg >/dev/null 2>&1 || RC="$arg"
183 if [ -n "$RC" ] ; then
184 echo "$RC not installed"
190 # helper functions {{{
192 if [ -n "$CHROOT_VARIABLES" ] ; then
193 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
196 if [ -n "$STAGES" ] ; then
197 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
200 # Remove temporary mountpoint again
201 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
202 rmdir "$MNTPOINT" 2>/dev/null
205 # make sure $TARGET is not mounted when exiting grml-debootstrap
206 if [ -n "$MNTPOINT" ] ; then
207 if grep -q "$MNTPOINT" /proc/mounts ; then
208 # make sure nothing is left inside chroot so we can unmount it
209 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
210 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
212 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1
214 # ugly, but make sure we really don't leave anything (/proc /proc and
215 # /dev /dev are intended, trying to work around timing issues, see #657023)
216 for ARG in /sys /proc /proc /dev /dev ; do
217 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1
218 umount "$MNTPOINT"/$ARG >/dev/null 2>&1
221 if [ -n "$ISODIR" ] ; then
222 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1
225 if [ -n "$DIRECTORY" ] ; then
226 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
228 einfo "Unmounting $MNTPOINT"
233 if [ -n "$STAGES" ] ; then
234 echo -n "Removing stages directory ${STAGES}: "
235 rm -rf "$STAGES" && echo done
238 # remove directory only if we used the default with process id inside the name
239 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
240 einfo "Removing directory ${MNTPOINT}"
247 if [ -n "${ORIG_TARGET}" ] ; then
248 einfo "Removing loopback mount of file ${ORIG_TARGET}."
249 kpartx -d "${ORIG_TARGET}" ; eend $?
253 # we want to exit smoothly and clean:
258 [ -n "$1" ] && EXIT="$1" || EXIT="1"
259 [ -n "$2" ] && einfo "Notice: remove $STAGES/$2 to reexecute the stage"
263 trap bailout HUP INT QUIT TERM
265 # we want to execute all the functions only once, simple check for it:
267 if [ -n "$2" ] ; then
268 echo "$2" > "${STAGES}/${1}"
270 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
271 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
272 ewarn " To reexecute it clean up the according directory inside $STAGES" ; eend 0
278 # make sure we have what we need {{{
279 check4progs debootstrap || bailout 1
282 # source main configuration file {{{
283 if [ -r /etc/debootstrap/config ] ; then
284 . /etc/debootstrap/config
288 # cmdline handling {{{
289 # source external command line parameter-processing script
290 if [ -r ./cmdlineopts.clp ] ; then
292 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
293 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
295 eerror "Error: cmdline function file not found, exiting."
300 # == business-logic of command line parameter-processing
302 # source configuration file in <confdir> if supplied. {{{
303 [ "$_opt_confdir" ] && {
304 CONFFILES=$_opt_confdir
305 einfo "Using config files under $CONFFILES/."
306 if ! [ -r "$CONFFILES/config" ] ; then
307 eerror "Error: config file $CONFFILES/config not found."; eend 1; bailout 1
309 if ! . "$CONFFILES/config" ; then
310 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; bailout 1
312 # restore the command line parameter value
313 CONFFILES=$_opt_confdir
317 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
318 [ "$_opt_iso" ] && ISO=$_opt_iso
319 [ "$_opt_release" ] && RELEASE=$_opt_release
320 [ "$_opt_target" ] && TARGET=$_opt_target
321 [ "$_opt_vm" ] && VIRTUAL=1
322 [ "$_opt_vmfile" ] && VMFILE=1 && VIRTUAL=1
323 [ "$_opt_vmsize" ] && VMSIZE=$_opt_vmsize
324 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
325 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
326 [ "$_opt_interactive" ] && INTERACTIVE=1
327 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
328 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
329 [ "$_opt_packages_set" ] && PACKAGES='yes'
330 [ "$_opt_nopackages" ] && PACKAGES=''
331 [ "$_opt_debconf_set" ] && DEBCONF='yes'
332 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
333 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
334 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
335 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
336 [ "$_opt_grmlrepos" ] && GRMLREPOS='yes'
337 [ "$_opt_backportrepos" ] && BACKPORTREPOS='yes'
338 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
339 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
340 [ "$_opt_nopassword" ] && NOPASSWORD='yes'
341 [ "$_opt_defaultinterfaces" ] && DEFAULTINTERFACES="true"
342 [ "$_opt_nointerfaces" ] && NOINTERFACES="true"
343 [ "$_opt_nokernel" ] && NOKERNEL="true"
344 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
345 [ "$_opt_grub" ] && GRUB=$_opt_grub
346 [ "$_opt_arch" ] && ARCH=$_opt_arch
347 [ "$_opt_insecure" ] && echo "Warning: --insecure is deprecated, continuing anyway."
348 [ "$_opt_force" ] && FORCE=$_opt_force
349 [ "$_opt_verbose" ] && VERBOSE="-v"
350 [ "$_opt_debug" ] && DEBUG="true"
352 if [ "$DEBUG" = "true" ] ; then
356 [ "$_opt_help" ] && {
362 [ "$_opt_version" ] && {
363 einfo "$PN - version $VERSION"
364 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
370 # check for root permissions {{{
371 if ! check4root ; then
372 echo "For usage instructions please execute '$PN --help'."
377 # make sure we have what we need {{{
378 if [ -n "$VIRTUAL" ] ; then
379 check4progs kpartx mksh parted qemu-img || bailout 1
383 # source specified configuration file {{{
384 if [ -n "$CONFIGFILE" ] ; then
385 einfo "Reading specified config file $CONFIGFILE."
386 if ! . "$CONFIGFILE" ; then
387 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; bailout 1
392 # backwards compability checks {{{
393 if [ -n "$GROOT" ] ; then
394 eerror "Error: you seem to have \$GROOT configured."
395 eerror "This variable is no longer supported, please visit the"
396 eerror "grml-debootstrap documentation for details."
401 if echo "$GRUB" | grep -q '^hd' ; then
402 eerror "Error: this syntax for the grub configuration variable is no longer supported."
403 eerror "Please do not use hd... any longer but /dev/sdX instead."
412 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
413 Do you want to continue installing Debian using this frontend?" 0 0 || bailout 0
420 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
422 grep -v 'Extended$' | \
423 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
425 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
426 dialog --title "$PN" --trim \
427 --msgbox "Sorry, no partitions found. Please configure your
428 harddisks (see /proc/partitions) using a tool like fdisk,
429 cfdisk, gpart, gparted,..." 0 0
433 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
434 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet])"
437 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
438 --menu "Please select the target partition:" 0 0 0 \
440 [ $? -eq 0 ] || bailout 1
444 # ask for bootmanager {{{
445 prompt_for_bootmanager()
449 if echo "$TARGET" | grep -q "/dev/md" ; then
450 MBRPART="all disks of Software RAID $TARGET"
452 # figure out whole disk device
454 for device in /dev/disk/by-id/*
456 [ $(readlink -f $device) = ${TARGET} ] || continue
460 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
461 if [ -e "$MBRDISK" ]; then
462 MBRDISK=$(readlink -f $MBRDISK)
464 # fall back to old behaviour
465 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$//')
468 MBRPART="MBR of $MBRDISK"
471 for device in cciss/c0d0 sda hda; do
472 if [ "/dev/$device" != "${MBRDISK}" ]; then
473 grep -q $device /proc/partitions && \
474 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
477 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
481 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
482 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
483 mbr "install bootmanager into $MBRPART" \
484 nowhere "do not install bootmanager at all" \
485 ${ADDITIONAL_PARAMS})
486 [ $? -eq 0 ] || bailout 3
491 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
492 if echo "$TARGET" | grep -q "/dev/md" ; then
511 # ask for Debian release {{{
514 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='wheezy'
515 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
516 "Please enter the Debian release you would like to use for installation:" \
521 sid Debian/unstable)"
522 [ $? -eq 0 ] || bailout
526 # ask for hostname {{{
527 prompt_for_hostname()
529 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
530 "Please enter the hostname you would like to use for installation:" \
532 [ $? -eq 0 ] || bailout
536 # ask for password {{{
537 prompt_for_password()
539 if [ "$_opt_nopassword" ] ; then
540 einfo "Skip asking for root password as requested."
546 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
547 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
548 "Please enter the password for the root account:" 10 60)
549 [ $? -eq 0 ] || bailout
550 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
551 "Please enter the password for the root account again for \
552 confirmation:" 10 60)
553 [ $? -eq 0 ] || bailout
555 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
556 $(dialog --stdout --title "${PN}" --ok-label \
557 "Retry" --msgbox "Passwords do not match!" 10 60)
560 ROOTPASSWORD="$ROOTPW1"
564 # ask for Debian mirror {{{
567 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
569 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
570 --menu "Where do you want to install from?" 0 0 0 \
571 net "install via network (downloading from mirror)" \
572 local "install from local directory/mirror"
574 [ $? -eq 0 ] || bailout
576 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
577 [ -n "$MIRROR" ] || MIRROR='http://http.debian.net/debian'
578 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
579 "Please enter Debian mirror you would like to use for installing packages." \
581 [ $? -eq 0 ] || bailout
582 else # CHOOSE_MIRROR == local
583 [ -n "$ISO" ] || ISO='/mnt/mirror'
584 ISO="$(dialog --stdout --title "${PN}" --inputbox \
585 "Please enter directory name you would like to use for installing packages." \
587 [ $? -eq 0 ] || bailout
592 # software raid setup {{{
593 config_swraid_setup()
597 # Currently we support only raid1:
600 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
601 # --menu "Which RAID level do you want to use?" 0 0 0 \
602 # raid1 "Software RAID level 1" \
603 # raid5 "Software RAID level 5")
604 #[ $? -eq 0 ] || bailout 20
606 MD_LIST=$(for i in $(seq 0 9) ; do
607 awk '{print $4}' /proc/partitions | grep -q md$i || \
608 echo "/dev/md$i /dev/md$i"
611 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
612 --menu "Which device do you want to use for ${RAIDLEVEL}?
614 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 \
616 [ $? -eq 0 ] || bailout 20
618 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
620 grep -v 'Extended$' | \
621 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
622 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
623 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
624 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet]) off"
627 dialog --title "$PN" --separate-output \
628 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
629 $PARTITION_LIST 2>$TMPFILE
630 [ $? -eq 0 ] || bailout
632 SELECTED_PARTITIONS="$(cat $TMPFILE)"
635 for i in $(cat $TMPFILE) ; do
636 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
639 # force metadata version 0.90 for lenny so old grub can boot from this array.
641 if [ $RELEASE = "lenny" ]; then
642 METADATA_VERSION="-e0"
646 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
647 --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
649 if [ "$RC" = 0 ] ; then
650 dialog --title "$PN" --msgbox \
651 "Creating $TARGET was successful." 0 0
652 rm -f "$TMPFILE" "$ERRORFILE"
654 dialog --title "$PN" --msgbox \
655 "There was an error setting up $TARGET:
660 rm -f "$TMPFILE" "$ERRORFILE"
668 if dialog --stdout --title "$PN" \
669 --defaultno --yesno "Do you want to configure Software RAID?
671 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
677 # user should recheck his configuration {{{
678 # support full automatic installation:
680 dialog --timeout 10 --title "$PN" \
681 --yesno "Do you want to stop at this stage?
683 Notice: you are running ${PN} in non-interactive mode.
684 ${PN} will install Debian ${RELEASE} on ${TARGET}.
685 Last chance to quit. Timeout of 10 seconds running....
687 Do you want to stop now?" 0 0 2>/dev/null
691 # make sure the user is aware of the used configuration {{{
694 if [ -n "$AUTOINSTALL" ] ; then
695 if checkforrun ; then
696 eerror "Exiting as requested" ; eend 0
699 elif [ -n "$INTERACTIVE" ] ; then
701 INFOTEXT="Please recheck configuration before execution:
703 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
705 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
707 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
708 Using release: $RELEASE"
709 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
710 Using hostname: $HOSTNAME"
711 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
712 Using mirror: $MIRROR"
713 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
715 [ -n "$ARCH" ] && INFOTEXT="$INFOTEXT
720 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
722 dialog --title "$PN" --no-collapse \
723 --yesno "$INFOTEXT" 0 0
724 [ $? -eq 0 ] || bailout 0
726 else # if not running automatic installation display configuration and prompt for execution:
727 einfo "$PN [${VERSION}] - Please recheck configuration before execution:"
729 echo " Target: $TARGET"
731 # do not display if MNTPOINT is the default one
732 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
734 if [ -n "$VIRTUAL" ] ; then
735 echo " Install grub: yes"
737 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
740 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
741 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
742 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
743 [ -n "$ISO" ] && echo " Using ISO: $ISO"
744 [ -n "$ARCH" ] && echo " Using arch: $ARCH"
745 if [ -n "$VIRTUAL" ] ; then
746 echo " Deploying as Virtual Machine."
747 if [ -n "$VMSIZE" -a -n "$VMFILE" ]; then
748 echo " Using Virtual Disk file with size of ${VMSIZE}."
752 if [ ! -t 0 -a -z "$ROOTPASSWORD" -a -z "$NOPASSWORD" ] ; then
754 echo " You do not have a TTY allocated, your password will be shown in"
755 echo " plaintext on the terminal! If you are using SSH, try its -t option!"
759 echo " Important! Continuing will delete all data from ${TARGET}!"
761 if [ -n "$FORCE" ] ; then
762 einfo "Skip user acknowledgement as requested via --force option."
765 einfon "Is this ok for you? [y/N] "
767 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
768 eerror "Exiting as requested." ; eend 1
776 # interactive mode {{{
779 check4progs dialog || bailout 1
789 prompt_for_bootmanager
798 # run interactive mode if we didn't get the according configuration yet
799 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
800 # only target might be unset, so make sure the INTERACTIVE flag is set as well
806 # architecture setup {{{
807 if [ -n "$ARCH" ] ; then
808 ARCHCMD="--arch $ARCH"
809 ARCHINFO=" (${ARCH})"
811 ARCH="$(dpkg --print-architecture)"
812 ARCHCMD="--arch $ARCH"
813 ARCHINFO=" (${ARCH})"
817 # It is not possible to build amd64 on i686. {{{
818 CURRENT_ARCH="$(uname -m)"
819 if [ "$CURRENT_ARCH" != "x86_64" ] ; then
820 if [ "$ARCH" = "amd64" ] ; then
821 eerror "It is not possible to build amd64 on $CURRENT_ARCH." ; eend 1
829 # finally make sure at least $TARGET is set [the partition for the new system] {{{
830 if [ -n "$TARGET" ] ; then
831 SHORT_TARGET="${TARGET##*/}"
833 eerror "Please adjust $CONFFILES/config or..."
834 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
840 if [ -z "$STAGES" ] ; then
841 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
842 [ -d "$STAGES" ] || mkdir -p "$STAGES"
845 if [ -r "$STAGES"/grml-debootstrap ] ; then
846 if grep -q done $STAGES/grml-debootstrap ; then
847 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
848 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
853 # partition handling {{{
857 set_target_directory(){
858 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
864 # make sure we normalise the path to an absolute directory name so something like:
865 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
867 TARGET="$(readlink -f $TARGET)"
870 if [ -b "$TARGET" ] || [ -n "$VIRTUAL" ] ; then
877 # make sure we have the right syntax when using an iso image {{{
878 if [ -n "$ISO" ] ; then
891 # Debian ISOs do not contain signed Release files {{{
892 if [ -n "$ISO" ] ; then
893 DEBOOTSTRAP_OPT="$DEBOOTSTRAP_OPT --no-check-gpg"
897 # create filesystem {{{
899 if [ -n "$DIRECTORY" ] ; then
900 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
902 if grep -q "$TARGET" /proc/mounts ; then
903 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
907 if [ -n "$MKFS" ] ; then
908 einfo "Running $MKFS on $TARGET"
909 $MKFS $TARGET ; RC=$?
911 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
912 if ! echo "$MKFS" | grep -q "mkfs.ext" ; then
913 eerror "Not changing disk uuid for $TARGET because $MKFS doesn't seem to match for ext{2,3,4} file system"
917 einfo "Changing disk uuid for $TARGET to fixed (non-random) value using tune2fs"
918 tune2fs "$TARGET" -U 26ada0c0-1165-4098-884d-aafd2220c2c6
923 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
924 # will fail to detect the uuid in the chroot
925 if echo "$TARGET" | grep -q "/dev/md" ; then
926 blockdev --rereadpt "${TARGET}"
927 elif ! [ -n "$VIRTUAL" ] ; then
928 blockdev --rereadpt "${TARGET%%[0-9]*}"
930 # give the system 2 seconds, otherwise we might run into
931 # race conditions :-/
934 eval $(blkid -o udev $TARGET 2>/dev/null)
935 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
944 # modify filesystem settings {{{
946 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
947 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
954 # mount the new partition or if it's a directory do nothing at all {{{
956 if [ -n "$DIRECTORY" ] ; then
957 einfo "Running grml-debootstrap on a directory, nothing to mount."
959 if grep -q $TARGET /proc/mounts ; then
960 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
962 if ! [ -d "${MNTPOINT}" ] ; then
963 [ -n "$VIRTUAL" ] || mkdir -p "${MNTPOINT}"
965 einfo "Mounting $TARGET to $MNTPOINT"
967 mount -o rw,suid,dev $TARGET $MNTPOINT
971 if [ -n "$ISODIR" ] ; then
972 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
973 mkdir -p "$MNTPOINT/$ISODIR"
974 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
980 # prepare VM image for usage with debootstrap {{{
982 if [ -z "$VIRTUAL" ] ; then
983 return 0 # be quiet by intention
986 if [ -b "$TARGET" -a -n "$VMFILE" ] ; then
987 eerror "Error: specified virtual disk target ($TARGET) is an existing block device."
991 if [ ! -b "$TARGET" -a -z "$VMFILE" ] ; then
992 eerror "Error: specified virtual disk target ($TARGET) does not exist yet."
997 ORIG_TARGET="$TARGET" # store for later reuse
999 if [ -n "$VMFILE" ]; then
1000 qemu-img create -f raw "${TARGET}" "${VMSIZE}"
1002 echo 4 66 | /usr/share/grml-debootstrap/bootgrub.mksh -A | dd of="$TARGET" conv=notrunc
1003 dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
1004 if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then
1005 einfo "Adjusting disk signature to a fixed (non-random) value"
1006 MBRTMPFILE=$(mktemp)
1007 dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1
1008 echo -en "\x41\x41\x41\x41\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1
1009 dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc
1012 parted -s "${TARGET}" 'mkpart primary ext4 2M -1'
1014 # if dm-mod isn't available then kpartx will fail with
1015 # "Is device-mapper driver missing from kernel? [...]"
1016 if ! kpartx -av $TARGET >/dev/null 2>&1 || ! grep -q device-mapper /proc/misc >/dev/null 2>&1 ; then
1017 einfo "Device-mapper not ready yet, trying to load dm-mod module."
1018 modprobe dm-mod ; eend $?
1021 # make sure loop module is present
1022 if ! losetup -f >/dev/null 2>&1; then
1023 einfo "Can not find a usable loop device, retrying after loading loop module."
1025 if losetup -f >/dev/null 2>&1; then
1026 einfo "Found a usable loop device now, continuing."
1028 eerror "Error finding usable loop device" ; eend 1
1033 DEVINFO=$(kpartx -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
1034 if [ -z "${DEVINFO}" ] ; then
1035 eerror "Error setting up loopback device." ; eend 1
1039 # hopefully this always works as expected
1040 LOOP=$(echo ${DEVINFO} | sed 's/.* linear //; s/ [[:digit:]]*//') # '/dev/loop1'
1041 BLOCKDEV=$(echo "${DEVINFO}" | sed -e 's/.* (\(.*:.*\)).*/\1/') # '253:0'
1042 LOOP_PART="$(echo ${DEVINFO##add map } | sed 's/ .*//')" # '/dev/loop1p1'
1043 export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'
1045 blockdev --rereadpt "${LOOP}"
1047 if [ -z "$TARGET" ] ; then
1048 eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1
1054 # make VM image bootable and unmount it {{{
1056 if [ -z "${VIRTUAL}" ] ; then
1060 if ! mount "${TARGET}" "${MNTPOINT}" ; then
1061 eerror "Error: Mounting ${TARGET} failed, can not continue." ; eend 1
1065 einfo "Installing Grub as bootloader."
1066 mount -t proc none "${MNTPOINT}"/proc
1067 mount -t sysfs none "${MNTPOINT}"/sys
1068 mount --bind /dev "${MNTPOINT}"/dev
1070 mkdir -p "${MNTPOINT}/boot/grub"
1071 if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
1072 eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
1076 cp "${MNTPOINT}"/usr/lib/grub/i386-pc/* "${MNTPOINT}/boot/grub/"
1077 chroot "${MNTPOINT}" grub-mkimage -O i386-pc -p "(hd0,msdos1)/boot/grub" -o /tmp/core.img biosdisk part_msdos ext2
1078 dd if="${MNTPOINT}/tmp/core.img" of="${ORIG_TARGET}" conv=notrunc seek=4
1079 rm -f "${MNTPOINT}/tmp/core.img"
1081 einfo "Updating grub configuration file."
1082 if [ -n "$BOOT_APPEND" ] ; then
1083 sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" "${MNTPOINT}"/etc/default/grub
1085 chroot "${MNTPOINT}" update-grub
1087 umount "${MNTPOINT}"/proc
1088 umount "${MNTPOINT}"/sys
1089 umount "${MNTPOINT}"/dev
1091 einfo "Adjusting grub.cfg for successful boot sequence."
1092 # ugly but needed to boot grub acordingly
1093 sed -i "s;set root=.*;set root='(hd0,msdos1)';" "${MNTPOINT}"/boot/grub/grub.cfg
1094 sed -i "s;root=[^ ]\+;root=/dev/sda1;" "${MNTPOINT}"/boot/grub/grub.cfg
1096 umount "${MNTPOINT}"
1097 kpartx -d "${ORIG_TARGET}" >/dev/null
1101 # install main chroot {{{
1102 debootstrap_system() {
1103 if [ "$_opt_nodebootstrap" ]; then
1104 einfo "Skipping debootstrap as requested."
1108 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
1111 eerror "Error: $MNTPOINT not mounted, can not continue."
1115 if [ -n "$ISO" ] ; then
1116 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${ISO}"
1117 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
1118 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
1121 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}"
1122 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
1123 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
1127 if [ $RC -ne 0 ] ; then
1128 if [ -r "$MNTPOINT/debootstrap/debootstrap.log" ] && \
1129 [ -s "$MNTPOINT/debootstrap/debootstrap.log" ] ; then
1130 einfo "Presenting last ten lines of debootstrap.log:"
1131 tail -10 $MNTPOINT/debootstrap/debootstrap.log
1132 einfo "End of debootstrap.log"
1140 # prepare chroot via chroot-script {{{
1142 einfo "Preparing chroot system"
1144 # provide variables to chroot system
1145 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
1146 touch $CHROOT_VARIABLES
1147 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
1148 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
1149 [ -n "$ARCH" ] && echo "ARCH=\"$ARCH\"" >> $CHROOT_VARIABLES
1150 [ -n "$BACKPORTREPOS" ] && echo "BACKPORTREPOS=\"$BACKPORTREPOS\"" >> $CHROOT_VARIABLES
1151 [ -n "$CHROOT_SCRIPTS" ] && echo "CHROOT_SCRIPTS=\"$CHROOT_SCRIPTS\"" >> $CHROOT_VARIABLES
1152 [ -n "$CONFFILES" ] && echo "CONFFILES=\"$CONFFILES\"" >> $CHROOT_VARIABLES
1153 [ -n "$DEBCONF" ] && echo "DEBCONF=\"$DEBCONF\"" >> $CHROOT_VARIABLES
1154 [ -n "$DEBIAN_FRONTEND" ] && echo "DEBIAN_FRONTEND=\"$DEBIAN_FRONTEND\"" >> $CHROOT_VARIABLES
1155 [ -n "$DEBOOTSTRAP" ] && echo "DEBOOTSTRAP=\"$DEBOOTSTRAP\"" >> $CHROOT_VARIABLES
1156 [ -n "$DEFAULT_LOCALES" ] && echo "DEFAULT_LOCALES=\"$DEFAULT_LOCALES\"" >> $CHROOT_VARIABLES
1157 [ -n "$DEFAULT_LANGUAGE" ] && echo "DEFAULT_LANGUAGE=\"$DEFAULT_LANGUAGE\"" >> $CHROOT_VARIABLES
1158 [ -n "$EXTRAPACKAGES" ] && echo "EXTRAPACKAGES=\"$EXTRAPACKAGES\"" >> $CHROOT_VARIABLES
1159 [ -n "$FALLBACK_MIRROR" ] && echo "FALLBACK_MIRROR=\"$FALLBACK_MIRROR\"" >> $CHROOT_VARIABLES
1160 [ -n "$FORCE" ] && echo "FORCE=\"$FORCE\"" >> $CHROOT_VARIABLES
1161 [ -n "$GRMLREPOS" ] && echo "GRMLREPOS=\"$GRMLREPOS\"" >> $CHROOT_VARIABLES
1162 [ -n "$GRUB" ] && echo "GRUB=\"$GRUB\"" >> $CHROOT_VARIABLES
1163 [ -n "$HOSTNAME" ] && echo "HOSTNAME=\"$HOSTNAME\"" >> $CHROOT_VARIABLES
1164 [ -n "$INITRD" ] && echo "INITRD=\"$INITRD\"" >> $CHROOT_VARIABLES
1165 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=\"$INSTALL_NOTES\"" >> $CHROOT_VARIABLES
1166 [ -n "$ISODIR" ] && echo "ISODIR=\"$ISO\"" >> $CHROOT_VARIABLES
1167 [ -n "$ISO" ] && echo "ISO=\"$ISO\"" >> $CHROOT_VARIABLES
1168 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=\"$KEEP_SRC_LIST\"" >> $CHROOT_VARIABLES
1169 [ -n "$LOCALES" ] && echo "LOCALES=\"$LOCALES\"" >> $CHROOT_VARIABLES
1170 [ -n "$MIRROR" ] && echo "MIRROR=\"$MIRROR\"" >> $CHROOT_VARIABLES
1171 [ -n "$MKFS" ] && echo "MKFS=\"$MKFS\"" >> $CHROOT_VARIABLES
1172 [ -n "$NOPASSWORD" ] && echo "NOPASSWORD=\"true\"" >> $CHROOT_VARIABLES
1173 [ -n "$NOKERNEL" ] && echo "NOKERNEL=\"true\"" >> $CHROOT_VARIABLES
1174 [ -n "$PACKAGES" ] && echo "PACKAGES=\"$PACKAGES\"" >> $CHROOT_VARIABLES
1175 [ -n "$PRE_SCRIPTS" ] && echo "PRE_SCRIPTS=\"$PRE_SCRIPTS\"" >> $CHROOT_VARIABLES
1176 [ -n "$RECONFIGURE" ] && echo "RECONFIGURE=\"$RECONFIGURE\"" >> $CHROOT_VARIABLES
1177 [ -n "$RELEASE" ] && echo "RELEASE=\"$RELEASE\"" >> $CHROOT_VARIABLES
1178 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=\"$RM_APTCACHE\"" >> $CHROOT_VARIABLES
1179 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=\"$ROOTPASSWORD\"" >> $CHROOT_VARIABLES
1180 [ -n "$SCRIPTS" ] && echo "SCRIPTS=\"$SCRIPTS\"" >> $CHROOT_VARIABLES
1181 [ -n "$SECURE" ] && echo "SECURE=\"$SECURE\"" >> $CHROOT_VARIABLES
1182 [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=\"$SELECTED_PARTITIONS\"" >> $CHROOT_VARIABLES
1183 [ -n "$TARGET" ] && echo "TARGET=\"$TARGET\"" >> $CHROOT_VARIABLES
1184 [ -n "$UPGRADE_SYSTEM" ] && echo "UPGRADE_SYSTEM=\"$UPGRADE_SYSTEM\"" >> $CHROOT_VARIABLES
1185 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=\"$TARGET_UUID\"" >> $CHROOT_VARIABLES
1186 [ -n "$TIMEZONE" ] && echo "TIMEZONE=\"$TIMEZONE\"" >> $CHROOT_VARIABLES
1187 [ -n "$TUNE2FS" ] && echo "TUNE2FS=\"$TUNE2FS\"" >> $CHROOT_VARIABLES
1188 [ -n "$VMSIZE" ] && echo "VMSIZE=\"$VMSIZE\"" >> $CHROOT_VARIABLES
1190 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
1191 chmod 755 $MNTPOINT/bin/chroot-script
1192 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
1194 # make sure we have our files for later use via chroot-script
1195 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
1196 # make sure we adjust the configuration variables accordingly:
1197 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
1198 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
1199 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
1202 if [ -n "$INSTALL_NOTES" ] ; then
1203 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
1206 # package selection:
1207 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
1208 $MNTPOINT/etc/debootstrap/packages
1210 # debconf preseeding:
1211 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
1212 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
1213 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
1215 # copy scripts that should be executed inside the chroot:
1216 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
1217 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
1218 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
1219 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
1222 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
1223 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
1225 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
1227 # make sure we can access network [relevant for cdebootstrap]
1228 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
1230 # provide system's /etc/hosts to the target:
1231 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
1232 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
1235 # setup default locales
1236 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
1238 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
1239 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
1241 # copy any existing files to chroot
1242 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
1243 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
1244 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
1245 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
1246 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
1247 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
1248 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
1251 DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
1253 # Include files from /etc/network/interfaces.d when using
1254 # ifupdown v0.7.44 or newer:
1255 #source-directory /etc/network/interfaces.d
1258 iface lo inet loopback
1261 iface eth0 inet dhcp
1264 if [ -n "$NOINTERFACES" ] ; then
1265 einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0
1266 elif [ -n "$DEFAULT_INTERFACES" ] ; then
1267 einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options."
1268 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1270 elif [ -n "$VIRTUAL" ] ; then
1271 einfo "Setting up Virtual Machine, installing default /etc/network/interfaces"
1272 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1274 elif [ -r /etc/network/interfaces ] ; then
1275 einfo "Copying /etc/network/interfaces from host to target system"
1276 cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
1279 ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
1280 echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
1284 # install config file providing some example entries
1285 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
1286 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
1293 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
1294 execute_pre_scripts() {
1295 # make sure we have $MNTPOINT available for our scripts
1297 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
1298 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
1299 for script in ${pre_scripts}/* ; do
1300 if [ -x "$script" ] ; then
1301 einfo "Executing pre-script $script"
1309 # execute all scripts in /etc/debootstrap/scripts/ {{{
1311 # make sure we have $MNTPOINT available for our scripts
1313 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
1314 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
1315 for script in ${scripts}/* ; do
1316 if [ -x "$script" ] ; then
1317 einfo "Executing script $script"
1325 # execute chroot-script {{{
1327 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
1331 if ! [ -x "$MNTPOINT/bin/chroot-script" ] ; then
1332 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
1335 einfo "Executing chroot-script now"
1336 mount --bind /dev "$MNTPOINT"/dev
1337 if [ "$DEBUG" = "true" ] ; then
1338 chroot "$MNTPOINT" /bin/sh -x /bin/chroot-script ; RC=$?
1340 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
1342 umount "$MNTPOINT"/dev
1346 # finally get rid of chroot-script again, there's no good reason to
1347 # keep it on the installed system
1348 if grep -q GRML_CHROOT_SCRIPT_MARKER "${MNTPOINT}/bin/chroot-script" ; then
1349 einfo "Removing chroot-script again"
1350 rm -f "${MNTPOINT}/bin/chroot-script"
1353 einfo "Keeping chroot-script as string GRML_CHROOT_SCRIPT_MARKER could not be found"
1359 # unmount $MNTPOINT {{{
1362 # display installation notes:
1363 if [ -n "$INSTALL_NOTES" ] ; then
1364 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
1367 if [ -n "$ISODIR" ] ; then
1368 if grep -q "$ISODIR" /proc/mounts ; then
1369 einfo "Unmount $MNTPOINT/$ISODIR"
1370 umount "$MNTPOINT/$ISODIR"
1375 if grep -q "$MNTPOINT" /proc/mounts ; then
1376 if [ -n "$PARTITION" ] ; then
1377 einfo "Unmount $MNTPOINT"
1385 # execute filesystem check {{{
1387 if [ -n "$VIRTUAL" ] ; then
1388 einfo "Skipping filesystem check because we deploy a virtual machine."
1392 if [ "$FSCK" = 'yes' ] ; then
1393 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
1394 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
1401 # now execute all the functions {{{
1402 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
1403 preparechroot execute_pre_scripts chrootscript execute_scripts \
1404 umount_chroot finalize_vm fscktool ; do
1405 if stage "${i}" ; then
1406 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "$i"
1413 # end dialog of autoinstallation {{{
1414 if [ -n "$AUTOINSTALL" ] ; then
1415 if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1416 Automatically rebooting in 10 seconds.
1418 Choose Cancel to skip rebooting." 10 60 10 ; then
1419 noeject noprompt reboot
1422 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1426 ## END OF FILE #################################################################
1427 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=2