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 ################################################################################
8 # http://www.debian.org/releases/stable/i386/index.html.en
10 set -e # exit on any error
14 VERSION="$(dpkg --list $PN 2>/dev/null| awk '/^i/ {print $3}')"
15 VERSION="${VERSION:-unknown}"
16 MNTPOINT="/mnt/debootstrap.$$"
18 # inside the chroot system locales might not be available, so use minimum:
22 # make sure interactive mode is only executed when
23 # using an empty configuration file or option --interactive
27 # source core functions {{{
28 . /etc/grml/lsb-functions
29 . /etc/grml/script-functions
34 echo "$PN - wrapper around debootstrap for installing Debian
40 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
41 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
42 instead of fetching packages from a mirror.
43 -r, --release <name> Release of new Debian system (default: lenny).
44 -t, --target <target> Target partition (/dev/...) or directory where the
45 system should be installed to.
46 -p, --mntpoint <mnt> Mountpoint used for mounting the target system,
47 has no effect if -t is given and represents a directory.
48 --debopt <params> Extra parameters passed to the debootstrap command.
49 --interactive Use interactive mode (frontend).
50 --nodebootstrap Skip debootstrap, only do configuration to the target.
51 --grub <device> Target for grub installation. Usage example: /dev/sda
52 --arch <arch> Architecture to use. Currently only i386 is supported.
53 --filesystem <fs> Filesystem that should be used when target is a partition.
54 --insecure Do not download and check Release file signatures.
56 Configuration options:
58 -c, --config <file> Use specified configuration file, defaults to
59 /etc/debootstrap/config
60 -d, --confdir <path> Place of config files for debootstrap, defaults
62 --packages <file> Install packages defined in specified list file.
63 --nopackages Skip installation of packages defined in
64 /etc/debootstrap/packages
65 --debconf <file> Pre-seed packages using specified pre-seed db file.
66 --keep_src_list Do not overwrite user provided apt sources.list.
67 --hostname <name> Hostname of Debian system.
68 --password <pwd> Use specified password as password for user root.
69 --bootappend <line> Add specified appendline to kernel whilst booting.
70 --chroot-scripts <d> Execute chroot scripts from specified directory.
71 --pre-scripts <dir> Execute scripts from specified directory (before chroot-scripts).
72 --scripts <dir> Execute scripts from specified directory (after chroot-scripts).
76 -v, --verbose Increase verbosity.
77 -h, --help Print this usage information and exit.
78 -V, --version Show summary of options and exit.
80 Usage examples can be found in the grml-debootstrap manpage.
81 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
85 if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then
87 echo 'Please notice that this script requires root permissions!'
92 # make sure we have what we need {{{
93 check4progs debootstrap dialog || exit 1
96 # source main configuration file {{{
97 if [ -r /etc/debootstrap/config ] ; then
98 . /etc/debootstrap/config
102 # cmdline handling {{{
103 # source external command line parameter-processing script
104 if [ -r ./cmdlineopts.clp ] ; then
106 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
107 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
109 echo "Error: cmdline function file not found, exiting.">&2
113 # == business-logic of command line parameter-processing
115 # source configuration file in <confdir> if supplied. {{{
116 [ "$_opt_confdir" ] && {
117 CONFFILES=$_opt_confdir
118 einfo "Using config files under $CONFFILES/."
119 if ! [ -r "$CONFFILES/config" ] ; then
120 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
122 if ! . "$CONFFILES/config" ; then
123 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
125 # restore the command line parameter value
126 CONFFILES=$_opt_confdir
130 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
131 [ "$_opt_iso" ] && ISO=$_opt_iso
132 [ "$_opt_release" ] && RELEASE=$_opt_release
133 [ "$_opt_target" ] && TARGET=$_opt_target
134 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
135 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
136 [ "$_opt_interactive" ] && INTERACTIVE=1
137 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
138 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
139 [ "$_opt_packages_set" ] && PACKAGES='yes'
140 [ "$_opt_nopackages" ] && PACKAGES=''
141 [ "$_opt_debconf_set" ] && DEBCONF='yes'
142 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
143 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
144 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
145 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
146 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
147 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
148 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
149 [ "$_opt_grub" ] && GRUB=$_opt_grub
150 [ "$_opt_arch" ] && ARCH=$_opt_arch
151 [ "$_opt_insecure" ] && SECURE='false'
152 [ "$_opt_verbose" ] && VERBOSE="-v"
154 [ "$_opt_help" ] && {
160 [ "$_opt_version" ] && {
161 einfo "$PN - version $VERSION"
162 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
168 # check for root permissions {{{
169 if ! check4root ; then
170 echo "For usage instructions please execute '$PN --help'."
175 # source specified configuration file {{{
176 if [ -n "$CONFIGFILE" ] ; then
177 einfo "Reading specified config file $CONFIGFILE."
178 if ! . "$CONFIGFILE" ; then
179 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
184 # backwards compability checks {{{
185 if [ -n "$GROOT" ] ; then
186 echo "Error: you seem to have \$GROOT configured." >&2
187 echo "This variable is no longer supported, please visit the" >&2
188 echo "grml-debootstrap documentation for details." >&2
192 if echo "$GRUB" | grep -q '^hd' ; then
193 echo "Error: this syntax for the grub configuration variable is no longer supported." >&2
194 echo "Please do not use hd... any longer but /dev/sdX instead." >&2
202 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
203 Do you want to continue installing Debian using this frontend?" 0 0
210 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
212 grep -v 'Extended$' | \
213 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
215 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
216 dialog --title "$PN" --trim \
217 --msgbox "Sorry, no partitions found. Please configure your
218 harddisks (see /proc/partitions) using a tool like fdisk,
219 cfdisk, gpart, gparted,..." 0 0
223 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
224 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet])"
227 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
228 --menu "Please select the target partition:" 0 0 0 \
233 # ask for bootmanager {{{
234 prompt_for_bootmanager()
238 if echo "$TARGET" | grep -q "/dev/md" ; then
239 MBRPART="all disks of Software RAID $TARGET"
241 # figure out whole disk device
243 for device in /dev/disk/by-id/*
245 [ $(readlink -f $device) = ${TARGET} ] || continue
249 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
250 if [ -e "$MBRDISK" ]; then
251 MBRDISK=$(readlink -f $MBRDISK)
253 # fall back to old behaviour
254 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$//')
257 MBRPART="MBR of $MBRDISK"
260 for device in cciss/c0d0 sda hda; do
261 if [ /dev/$device != ${MBRDISK} ]; then
262 grep -q $device /proc/partitions && \
263 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
266 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
270 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
271 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
272 mbr "install bootmanager into $MBRPART" \
273 nowhere "do not install bootmanager at all" \
274 ${ADDITIONAL_PARAMS})
275 [ $? -eq 0 ] || bailout 3
280 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
281 if echo "$TARGET" | grep -q "/dev/md" ; then
283 if [ -n "$SELECTED_PARTITIONS" ] ; then
284 GRUB=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
305 # ask for Debian release {{{
308 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='squeeze'
309 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
310 "Please enter the Debian release you would like to use for installation:" \
312 lenny Debian/old-stable \
313 squeeze Debian/stable \
314 wheezy Debian/testing \
315 sid Debian/unstable)"
319 # ask for hostname {{{
320 prompt_for_hostname()
322 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
323 "Please enter the hostname you would like to use for installation:" \
328 # ask for password {{{
329 prompt_for_password()
333 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
334 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
335 "Please enter the password for the root account:" 10 60)
336 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
337 "Please enter the password for the root account again for \
338 confirmation:" 10 60)
340 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
341 $(dialog --stdout --title "${PN}" --ok-label \
342 "Retry" --msgbox "Passwords do not match!" 10 60)
345 ROOTPASSWORD="$ROOTPW1"
349 # ask for Debian mirror {{{
352 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
354 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
355 --menu "Where do you want to install from?" 0 0 0 \
356 net "install via network (downloading from mirror)" \
357 local "install from local directory/mirror"
360 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
361 [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
362 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
363 "Please enter Debian mirror you would like to use for installing packages." \
365 else # CHOOSE_MIRROR == local
366 [ -n "$ISO" ] || ISO='/mnt/mirror'
367 ISO="$(dialog --stdout --title "${PN}" --inputbox \
368 "Please enter directory name you would like to use for installing packages." \
374 # software raid setup {{{
375 config_swraid_setup()
379 # Currently we support only raid1:
382 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
383 # --menu "Which RAID level do you want to use?" 0 0 0 \
384 # raid1 "Software RAID level 1" \
385 # raid5 "Software RAID level 5")
386 #[ $? -eq 0 ] || bailout 20
388 MD_LIST=$(for i in $(seq 0 9) ; do
389 awk '{print $4}' /proc/partitions | grep -q md$i || \
390 echo "/dev/md$i /dev/md$i"
393 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
394 --menu "Which device do you want to use for ${RAIDLEVEL}?
396 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 \
398 [ $? -eq 0 ] || bailout 20
400 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
402 grep -v 'Extended$' | \
403 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
404 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
405 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
406 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet]) off"
409 dialog --title "$PN" --separate-output \
410 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
411 $PARTITION_LIST 2>$TMPFILE
413 SELECTED_PARTITIONS="$(cat $TMPFILE)"
416 for i in $(cat $TMPFILE) ; do
417 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
420 # force metadata version 0.90 for lenny so old grub can boot from this array.
422 if [ $RELEASE = "lenny" ]; then
423 METADATA_VERSION="-e0"
428 # TODO: better error handling?
429 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
430 --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
434 if [ "$RC" = 0 ] ; then
435 dialog --title "$PN" --msgbox \
436 "Creating $TARGET was successful." 0 0
437 rm -f "$TMPFILE" "$ERRORFILE"
439 dialog --title "$PN" --msgbox \
440 "There was an error setting up $TARGET:
445 rm -f "$TMPFILE" "$ERRORFILE"
453 if dialog --stdout --title "$PN" \
454 --defaultno --yesno "Do you want to configure Software RAID?
456 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
462 # user should recheck his configuration {{{
463 # support full automatic installation:
465 dialog --timeout 10 --title "$PN" \
466 --yesno "Do you want to stop at this stage?
468 Notice: you are running ${PN} in non-interactive mode.
469 ${PN} will install Debian ${RELEASE} on ${TARGET}.
470 Last chance to quit. Timeout of 10 seconds running....
472 Do you want to stop now?" 0 0 2>/dev/null
475 # make sure the user is aware of the used configuration {{{
478 if [ -n "$AUTOINSTALL" ] ; then
479 if checkforrun ; then
480 eerror "Exiting as requested" ; eend 0
483 elif [ -n "$INTERACTIVE" ] ; then
485 INFOTEXT="Please recheck configuration before execution:
487 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
489 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
491 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
492 Using release: $RELEASE"
493 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
494 Using hostname $HOSTNAME"
495 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
496 Using mirror: $MIRROR"
497 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
502 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
504 dialog --title "$PN" --no-collapse \
505 --yesno "$INFOTEXT" 0 0
507 else # if not running automatic installation display configuration and prompt for execution:
508 einfo "$PN - Please recheck configuration before execution:"
510 echo " Target: $TARGET"
512 # do not display if MNTPOINT is the default one
513 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
515 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
516 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
517 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
518 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
519 [ -n "$ISO" ] && echo " Using ISO: $ISO"
521 echo " Important! Continuing will delete all data from ${TARGET}!"
524 einfon "Is this ok for you? [y/N] "
526 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
527 eerror "Exiting as requested." ; eend 1
534 # interactive mode {{{
545 prompt_for_bootmanager
554 # run interactive mode if we didn't get the according configuration yet
555 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
556 # only target might be unset, so make sure the INTERACTIVE flag is set as well
564 # finally make sure at least $TARGET is set [the partition for the new system] {{{
565 if [ -n "$TARGET" ] ; then
566 SHORT_TARGET="${TARGET##*/}"
568 eerror "Please adjust $CONFFILES/config or..."
569 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
575 if [ -z "$STAGES" ] ; then
576 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
577 [ -d "$STAGES" ] || mkdir -p "$STAGES"
580 if [ -r "$STAGES"/grml-debootstrap ] ; then
581 if grep -q done $STAGES/grml-debootstrap ; then
582 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
583 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
588 # partition handling {{{
592 set_target_directory(){
593 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
600 # make sure we normalise the path to an absolute directory name so something like:
601 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
603 TARGET="$(readlink -f $TARGET)"
606 if [ -b "$TARGET" ] ; then
613 # architecture setup {{{
614 if [ -n "$ARCH" ] ; then
615 ARCHCMD="--arch $ARCH"
616 ARCHINFO=" (${ARCH})"
618 ARCH="$(dpkg --print-architecture)"
619 ARCHCMD="--arch $ARCH"
620 ARCHINFO=" (${ARCH})"
626 if [ "$SECURE" = 'yes' ] ; then
627 if [ -e '/etc/apt/trusted.gpg' ] ; then
628 KEYRING="--keyring /etc/apt/trusted.gpg"
630 eerror "Could not find /etc/apt/trusted.gpg."
633 ewarn "Not checking Release signatures!"
637 # make sure we have the right syntax when using an iso image {{{
638 if [ -n "$ISO" ] ; then
651 # helper functions {{{
652 # we want to exit smoothly and clean:
654 # make sure $TARGET is not mounted when exiting grml-debootstrap
655 if [ -n "$MNTPOINT" ] ; then
656 if grep -q $MNTPOINT /proc/mounts ; then
657 # make sure nothing is left inside chroot so we can unmount it
658 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
659 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
660 # ugly, but make sure we really don't leave anything (/proc /proc is intended)
661 for ARG in /sys /proc /proc ; do
662 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true
664 umount "$MNTPOINT"/dev >/dev/null 2>&1 || true
666 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1 || true
668 if [ -n "$DIRECTORY" ] ; then
669 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
671 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
674 if [ -n "$STAGES" ] ; then
675 echo -n "Removing stages directory ${STAGES}: "
676 rm -rf "$STAGES" && echo done
679 # remove directory only if we used the default with process id inside the name
680 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
681 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
686 [ -n "$1" ] && EXIT="$1" || EXIT="1"
687 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
691 trap bailout HUP INT QUIT TERM
693 # we want to execute all the functions only once, simple check for it:
695 if [ -n "$2" ] ; then
696 echo "$2" > "${STAGES}/${1}"
698 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
699 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
701 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
708 # create filesystem {{{
710 if [ -n "$DIRECTORY" ] ; then
711 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
713 if grep -q "$TARGET" /proc/mounts ; then
714 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
718 if [ -n "$MKFS" ] ; then
719 einfo "Running $MKFS on $TARGET"
720 $MKFS $TARGET ; RC=$?
722 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
723 # will fail to detect the uuid in the chroot
724 if echo "$TARGET" | grep -q "/dev/md" ; then
725 blockdev --rereadpt "${TARGET}"
727 blockdev --rereadpt "${TARGET%%[0-9]*}"
729 # give the system 2 seconds, otherwise we might run into
730 # race conditions :-/
733 eval $(blkid -o udev $TARGET 2>/dev/null)
734 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
743 # modify filesystem settings {{{
745 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
746 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
753 # mount the new partition or if it's a directory do nothing at all {{{
755 if [ -n "$DIRECTORY" ] ; then
756 einfo "Running grml-debootstrap on a directory, nothing to mount."
758 if grep -q $TARGET /proc/mounts ; then
759 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
761 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
762 einfo "Mounting $TARGET to $MNTPOINT"
763 mount -o rw,suid,dev $TARGET $MNTPOINT
767 if [ -n "$ISODIR" ] ; then
768 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
769 mkdir -p "$MNTPOINT/$ISODIR"
770 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
776 # install main chroot {{{
777 debootstrap_system() {
778 if [ "$_opt_nodebootstrap" ]; then
779 einfo "Skipping debootstrap as requested."
783 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
784 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
785 if [ -n "$MIRROR" ] ; then
786 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
787 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
789 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
790 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
794 eerror "Error: $MNTPOINT not mounted, can not continue."
800 # prepare chroot via chroot-script {{{
802 einfo "Preparing chroot system"
804 # provide variables to chroot system
805 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
806 touch $CHROOT_VARIABLES
807 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
808 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
809 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
810 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
811 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
812 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=$INSTALL_NOTES" >> $CHROOT_VARIABLES
813 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
814 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
815 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
816 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
817 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
818 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=$RM_APTCACHE" >> $CHROOT_VARIABLES
819 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
820 [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=$SELECTED_PARTITIONS" >> $CHROOT_VARIABLES
821 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
822 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
824 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
825 chmod 755 $MNTPOINT/bin/chroot-script
826 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
828 # make sure we have our files for later use via chroot-script
829 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
830 # make sure we adjust the configuration variables accordingly:
831 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
832 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
833 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
836 if [ -n "$INSTALL_NOTES" ] ; then
837 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
841 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
842 $MNTPOINT/etc/debootstrap/packages
844 # debconf preseeding:
845 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
846 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
847 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
849 # copy scripts that should be executed inside the chroot:
850 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
851 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
852 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
853 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
856 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
857 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
859 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
861 # make sure we can access network [relevant for cdebootstrap]
862 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
864 # provide system's /etc/hosts to the target:
865 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
866 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
869 # setup default locales
870 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
872 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
873 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
875 # copy any existing files to chroot
876 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
877 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
878 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
879 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
880 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
881 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
882 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
884 # copy local network setup to chroot
885 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
886 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
887 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
890 # install config file providing some example entries
891 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
892 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
899 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
900 execute_pre_scripts() {
901 # make sure we have $MNTPOINT available for our scripts
903 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
904 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
905 for script in ${pre_scripts}/* ; do
906 if [ -x "$script" ] ; then
907 einfo "Executing pre-script $script"
915 # execute all scripts in /etc/debootstrap/scripts/ {{{
917 # make sure we have $MNTPOINT available for our scripts
919 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
920 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
921 for script in ${scripts}/* ; do
922 if [ -x "$script" ] ; then
923 einfo "Executing script $script"
931 # execute chroot-script {{{
933 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
937 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
938 einfo "Executing chroot-script now"
939 mount --bind /dev "$MNTPOINT"/dev
940 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
941 umount "$MNTPOINT"/dev
944 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
950 # unmount $MNTPOINT {{{
953 # display installation notes:
954 if [ -n "$INSTALL_NOTES" ] ; then
955 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
958 if [ -n "$ISODIR" ] ; then
959 if grep -q "$ISODIR" /proc/mounts ; then
960 einfo "Unmount $MNTPOINT/$ISODIR"
961 umount "$MNTPOINT/$ISODIR"
966 if grep -q "$MNTPOINT" /proc/mounts ; then
967 if [ -n "$PARTITION" ] ; then
968 einfo "Unmount $MNTPOINT"
976 # execute filesystem check {{{
978 if [ "$FSCK" = 'yes' ] ; then
979 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
980 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
987 # now execute all the functions {{{
988 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
989 execute_pre_scripts chrootscript execute_scripts umount_chroot \
991 if stage "${i}" ; then
992 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
998 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
999 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
1001 # Remove temporary mountpoint again
1002 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
1003 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
1007 # end dialog of autoinstallation {{{
1008 if [ -n "$AUTOINSTALL" ] ; then
1009 if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1010 Automatically rebooting in 10 seconds.
1012 Choose Cancel to skip rebooting." 10 60 10 ; then
1013 noeject noprompt reboot
1016 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1020 ## END OF FILE #################################################################
1021 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3