2 # Filename: grml-bootstrap
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
15 MNTPOINT="/mnt/debootstrap.$$"
17 # inside the chroot system locales might not be available, so use minimum:
21 # make sure interactive mode is only executed when
22 # using an empty configuration file or option --interactive
26 # source core functions {{{
27 . /etc/grml/lsb-functions
28 . /etc/grml/script-functions
33 echo "$PN - wrapper around debootstrap for installing Debian
39 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
40 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
41 instead of fetching packages from a mirror.
42 -r, --release <name> Release of new Debian system (default: lenny).
43 -t, --target <target> Target partition (/dev/...) or directory where the
44 system should be installed to.
45 -p, --mntpoint <mnt> Mountpoint used for mounting the target system,
46 has no effect if -t is given and represents a directory.
47 --debopt <params> Extra parameters passed to the debootstrap command.
48 --interactive Use interactive mode (frontend).
49 --nodebootstrap Skip debootstrap, only do configuration to the target.
50 --grub <device> Target for grub installation. Usage example: /dev/sda
51 --arch <arch> Architecture to use. Currently only i386 is supported.
53 Configuration options:
55 -c, --config <file> Use specified configuration file, defaults to
56 /etc/debootstrap/config
57 -d, --confdir <path> Place of config files for debootstrap, defaults
59 --packages <file> Install packages defined in specified list file.
60 --debconf <file> Pre-seed packages using specified pre-seed db file.
61 --keep_src_list Do not overwrite user provided apt sources.list.
62 --hostname <name> Hostname of Debian system.
63 --password <pwd> Use specified password as password for user root.
64 --bootappend <line> Add specified appendline to kernel whilst booting.
65 --chroot-scripts <d> Execute chroot scripts from specified directory.
66 --scripts <dir> Execute scripts from specified directory.
70 -v, --verbose Increase verbosity.
71 -h, --help Print this usage information and exit.
72 -V, --version Show summary of options and exit.
74 Usage examples can be found in the grml-debootstrap manpage.
75 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
79 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
81 echo 'Please notice that this script requires root permissions!'
86 # make sure we have what we need {{{
87 check4progs debootstrap dialog || exit 1
91 # source configuration file {{{
92 if [ -r /etc/debootstrap/config ] ; then
93 if [ -n "$CONFIGFILE" ] ; then
94 einfo "Using config file $CONFIGFILE."
95 if ! . "$CONFIGFILE" ; then
96 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
99 . /etc/debootstrap/config
104 # cmdline handling {{{
105 # source external command line parameter-processing script
106 if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
107 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
108 elif [ -r ./cmdlineopts.clp ] ; then
111 echo "Error: cmdline function file not found, exiting.">&2
115 # == business-logic of command line parameter-processing
117 # source configuration file in <confdir> if supplied. {{{
118 [ "$_opt_confdir" ] && {
119 CONFFILES=$_opt_confdir
120 einfo "Using config files under $CONFFILES/."
121 if ! [ -r "$CONFFILES/config" ] ; then
122 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
124 if ! . "$CONFFILES/config" ; then
125 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
127 # restore the command line parameter value
128 CONFFILES=$_opt_confdir
132 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
133 [ "$_opt_iso" ] && ISO=$_opt_iso
134 [ "$_opt_release" ] && RELEASE=$_opt_release
135 [ "$_opt_target" ] && TARGET=$_opt_target
136 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
137 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
138 [ "$_opt_interactive" ] && INTERACTIVE=1
139 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
140 [ "$_opt_packages_set" ] && PACKAGES='yes'
141 [ "$_opt_debconf_set" ] && DEBCONF='yes'
142 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
143 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
144 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
145 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
146 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
147 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
148 [ "$_opt_grub" ] && GRUB=$_opt_grub
149 [ "$_opt_arch" ] && ARCH=$_opt_arch
150 [ "$_opt_verbose" ] && VERBOSE="-v"
152 [ "$_opt_help" ] && {
158 [ "$_opt_version" ] && {
159 einfo "$PN - version $VERSION"
160 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
169 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
170 Do you want to continue installing Debian using this frontend?" 0 0
177 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
179 grep -v 'Extended$' | \
180 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
182 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
183 dialog --title "$PN" --trim \
184 --msgbox "Sorry, no partitions found. Please configure your
185 harddisks (see /proc/partitions) using a tool like fdisk,
186 cfdisk, gpart, gparted,..." 0 0
190 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
191 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
194 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
195 --menu "Please select the target partition:" 0 0 0 \
200 # ask for bootmanager {{{
201 prompt_for_bootmanager()
205 if echo "$TARGET" | grep -q "/dev/md" ; then
206 MBRPART="all disks of Software RAID $TARGET"
208 # figure out whole disk device
210 for device in /dev/disk/by-id/*
212 [ $(readlink -f $device) = ${TARGET} ] || continue
216 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
217 if [ -e "$MBRDISK" ]; then
218 MBRDISK=$(readlink -f $MBRDISK)
220 # fall back to old behaviour
221 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$/')
224 MBRPART="MBR of $MBRDISK"
227 for device in cciss/c0d0 sda hda; do
228 if [ /dev/$device != ${MBRDISK} ]; then
229 grep -q $device /proc/partitions && \
230 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
233 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
237 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
238 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
239 mbr "install bootmanager into $MBRPART" \
240 partition "install bootmanager into partition $TARGET" \
241 nowhere "do not install bootmanager at all" \
242 ${ADDITIONAL_PARAMS})
243 [ $? -eq 0 ] || bailout 3
248 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
249 if echo "$TARGET" | grep -q "/dev/md" ; then
251 if [ -n "$SELECTED_PARTITIONS" ] ; then
252 GRUB=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
276 # ask for Debian release {{{
279 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
280 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
281 "Please enter the Debian release you would like to use for installation:" \
283 lenny Debian/stable \
284 squeeze Debian/testing \
285 sid Debian/unstable)"
289 # ask for hostname {{{
290 prompt_for_hostname()
292 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
293 "Please enter the hostname you would like to use for installation:" \
298 # ask for password {{{
299 prompt_for_password()
303 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
304 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
305 "Please enter the password for the root account:" 10 60)
306 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
307 "Please enter the password for the root account again for \
308 confirmation:" 10 60)
310 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
311 $(dialog --stdout --title "${PN}" --ok-label \
312 "Retry" --msgbox "Passwords do not match!" 10 60)
315 ROOTPASSWORD="$ROOTPW1"
319 # ask for Debian mirror {{{
322 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
324 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
325 --menu "Where do you want to install from?" 0 0 0 \
326 net "install via network (downloading from mirror)" \
327 local "install from local directory/mirror"
330 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
331 [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
332 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
333 "Please enter Debian mirror you would like to use for installing packages." \
335 else # CHROOT_VARIABLES == local
336 [ -n "$ISO" ] || ISO='/mnt/mirror'
337 ISO="$(dialog --stdout --title "${PN}" --inputbox \
338 "Please enter directory name you would like to use for installing packages." \
344 # software raid setup {{{
345 config_swraid_setup()
349 # Currently we support only raid1:
352 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
353 # --menu "Which RAID level do you want to use?" 0 0 0 \
354 # raid1 "Software RAID level 1" \
355 # raid5 "Software RAID level 5")
356 #[ $? -eq 0 ] || bailout 20
358 MD_LIST=$(for i in $(seq 0 9) ; do
359 awk '{print $4}' /proc/partitions | grep -q md$i || \
360 echo "/dev/md$i /dev/md$i"
363 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
364 --menu "Which device do you want to use for ${RAIDLEVEL}?
366 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 \
368 [ $? -eq 0 ] || bailout 20
370 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
372 grep -v 'Extended$' | \
373 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
374 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
375 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
376 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
379 dialog --title "$PN" --separate-output \
380 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
381 $PARTITION_LIST 2>$TMPFILE
383 SELECTED_PARTITIONS="$(cat $TMPFILE)"
386 for i in $(cat $TMPFILE) ; do
387 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
392 # TODO: better error handling?
393 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
394 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
398 if [ "$RC" = 0 ] ; then
399 dialog --title "$PN" --msgbox \
400 "Creating $TARGET was successful." 0 0
401 rm -f "$TMPFILE" "$ERRORFILE"
403 dialog --title "$PN" --msgbox \
404 "There was an error setting up $TARGET:
409 rm -f "$TMPFILE" "$ERRORFILE"
417 if dialog --stdout --title "$PN" \
418 --defaultno --yesno "Do you want to configure Software RAID?
420 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
426 # user should recheck his configuration {{{
427 # support full automatic installation:
429 dialog --timeout 10 --title "$PN" \
430 --yesno "Do you want to stop at this stage?
432 Notice: you are running ${PN} in non-interactive mode.
433 ${PN} will install Debian ${RELEASE} on ${TARGET}.
434 Last chance to quit. Timeout of 10 seconds running....
436 Do you want to stop now?" 0 0 2>/dev/null
439 # make sure the user is aware of the used configuration {{{
442 if [ -n "$AUTOINSTALL" ] ; then
443 if checkforrun ; then
444 eerror "Exiting as requested" ; eend 0
447 elif [ -n "$INTERACTIVE" ] ; then
449 INFOTEXT="Please recheck configuration before execution:
451 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
453 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
455 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
456 Using release: $RELEASE"
457 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
458 Using hostname $HOSTNAME"
459 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
460 Using mirror: $MIRROR"
461 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
466 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
468 dialog --title "$PN" --no-collapse \
469 --yesno "$INFOTEXT" 0 0
471 else # if not running automatic installation display configuration and prompt for execution:
472 einfo "$PN - Please recheck configuration before execution:"
474 echo " Target: $TARGET"
476 # do not display if MNTPOINT is the default one
477 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
479 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
480 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
481 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
482 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
483 [ -n "$ISO" ] && echo " Using ISO: $ISO"
485 echo " Important! Continuing will delete all data from ${TARGET}!"
488 einfon "Is this ok for you? [y/N] "
490 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
491 eerror "Exiting as requested." ; eend 1
498 # interactive mode {{{
507 prompt_for_bootmanager
518 # run interactive mode if we didn't get the according configuration yet
519 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
520 # only target might be unset, so make sure the INTERACTIVE flag is set as well
528 # finally make sure at least $TARGET is set [the partition for the new system] {{{
529 if [ -n "$TARGET" ] ; then
530 SHORT_TARGET="${TARGET##*/}"
532 eerror "Please adjust $CONFFILES/config or..."
533 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
539 if [ -z "$STAGES" ] ; then
540 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
541 [ -d "$STAGES" ] || mkdir -p "$STAGES"
544 if [ -r "$STAGES"/grml-debootstrap ] ; then
545 if grep -q done $STAGES/grml-debootstrap ; then
546 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
547 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
552 # partition handling {{{
561 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
572 # architecture setup {{{
573 if [ -n "$ARCH" ] ; then
574 ARCHCMD="--arch $ARCH"
575 ARCHINFO=" (${ARCH})"
577 ARCH="$(dpkg --print-architecture)"
578 ARCHCMD="--arch $ARCH"
579 ARCHINFO=" (${ARCH})"
583 # make sure we have the right syntax when using an iso image {{{
584 if [ -n "$ISO" ] ; then
597 # helper functions {{{
598 # we want to exit smoothly and clean:
600 # make sure $TARGET is not mounted when exiting grml-debootstrap
601 if [ -n "$MNTPOINT" ] ; then
602 if grep -q $MNTPOINT /proc/mounts ; then
603 # make sure nothing is left inside chroot so we can unmount it
604 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
605 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
606 # ugly, but make sure we really don't leav anything
607 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
608 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
609 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
610 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
611 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
613 if [ -n "$DIRECTORY" ] ; then
614 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
616 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
619 if [ -n "$STAGES" ] ; then
620 echo -n "Removing stages directory ${STAGES}: "
621 rm -rf "$STAGES" && echo done
624 # remove directory only if we used the default with process id inside the name
625 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
626 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
631 [ -n "$1" ] && EXIT="$1" || EXIT="1"
632 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
636 trap bailout HUP INT QUIT TERM
638 # we want to execute all the functions only once, simple check for it:
640 if [ -n "$2" ] ; then
641 echo "$2" > "${STAGES}/${1}"
643 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
644 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
646 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
653 # create filesystem {{{
655 if [ -n "$DIRECTORY" ] ; then
656 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
658 if grep -q "$TARGET" /proc/mounts ; then
659 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
663 if [ -n "$MKFS" ] ; then
664 einfo "Running $MKFS on $TARGET"
665 $MKFS $TARGET ; RC=$?
667 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
668 # will fail to detect the uuid in the chroot
669 blockdev --rereadpt "${TARGET%%[0-9]*}"
670 # give the system 2 seconds, otherwise we might run into
671 # race conditions :-/
674 eval $(blkid -o udev $TARGET 2>/dev/null)
675 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
684 # modify filesystem settings {{{
686 if [ -n "$TUNE2FS" ] ; then
687 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
694 # mount the new partition or if it's a directory do nothing at all {{{
696 if [ -n "$DIRECTORY" ] ; then
697 einfo "Running grml-debootstrap on a directory, nothing to mount."
699 if grep -q $TARGET /proc/mounts ; then
700 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
702 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
703 einfo "Mounting $TARGET to $MNTPOINT"
704 mount -o rw,suid,dev $TARGET $MNTPOINT
708 if [ -n "$ISODIR" ] ; then
709 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
710 mkdir -p "$MNTPOINT/$ISODIR"
711 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
717 # install main chroot {{{
718 debootstrap_system() {
719 if [ "$_opt_nodebootstrap" ]; then
720 einfo "Skipping debootstrap as requested."
724 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
725 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
726 if [ -n "$MIRROR" ] ; then
727 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
729 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
733 eerror "Error: $MNTPOINT not mounted, can not continue."
739 # prepare chroot via chroot-script {{{
741 einfo "Preparing chroot system"
743 # provide variables to chroot system
744 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
745 touch $CHROOT_VARIABLES
746 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
747 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
748 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
749 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
750 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
751 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=$INSTALL_NOTES" >> $CHROOT_VARIABLES
752 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
753 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
754 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
755 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
756 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
757 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
758 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
759 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
761 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
762 chmod 755 $MNTPOINT/bin/chroot-script
763 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
765 # make sure we have our files for later use via chroot-script
766 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
767 # make sure we adjust the configuration variables accordingly:
768 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
769 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
770 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
773 if [ -n "$INSTALL_NOTES" ] ; then
774 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
778 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
779 $MNTPOINT/etc/debootstrap/packages
781 # debconf preseeding:
782 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
783 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
784 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
786 # copy scripts that should be executed inside the chroot:
787 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
788 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
789 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
790 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
793 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
794 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
796 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
798 # make sure we can access network [relevant for cdebootstrap]
799 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
801 # provide system's /etc/hosts to the target:
802 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
803 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
806 # setup default locales
807 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
809 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
810 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
812 # copy any existing files to chroot
813 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
814 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
815 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
816 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
817 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
818 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
819 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
821 # copy local network setup to chroot
822 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
823 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
824 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
831 # execute all scripts in /etc/debootstrap/scripts/ {{{
833 # make sure we have $MNTPOINT available for our scripts
835 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
836 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
837 for script in ${scripts}/* ; do
838 if [ -x "$script" ] ; then
839 einfo "Executing script $script"
847 # execute chroot-script {{{
849 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
853 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
854 einfo "Executing chroot-script now"
855 mount --bind /dev "$MNTPOINT"/dev
856 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
857 umount "$MNTPOINT"/dev
860 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
866 # install booloader grub {{{
868 if [ -z "$GRUB" ] ; then
869 echo "Notice: \$GRUB not defined, will not install grub therefore."
873 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
874 for device in $SELECTED_PARTITIONS ; do
875 GRUB="${device%%[0-9]}"
876 einfo "Installing grub on ${GRUB}:"
877 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
878 $GRUBINSTALL --root-directory="$MNTPOINT" "$GRUB"
882 einfo "Installing grub on ${GRUB}:"
883 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
884 $GRUBINSTALL --root-directory="$MNTPOINT" "$GRUB"
890 # unmount $MNTPOINT {{{
893 # display installation notes:
894 if [ -n "$INSTALL_NOTES" ] ; then
895 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
898 if [ -n "$ISODIR" ] ; then
899 if grep -q "$ISODIR" /proc/mounts ; then
900 einfo "Unmount $MNTPOINT/$ISODIR"
901 umount "$MNTPOINT/$ISODIR"
906 if grep -q "$MNTPOINT" /proc/mounts ; then
907 if [ -n "$PARTITION" ] ; then
908 einfo "Unmount $MNTPOINT"
916 # execute filesystem check {{{
918 if [ "$FSCK" = 'yes' ] ; then
919 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
920 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
927 # now execute all the functions {{{
928 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
929 chrootscript execute_scripts grub_install umount_chroot \
931 if stage "${i}" ; then
932 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
938 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
939 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
941 # Remove temporary mountpoint again
942 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
943 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
947 # end dialog of autoinstallation {{{
948 if [ -n "$AUTOINSTALL" ] ; then
949 dialog --title "$PN" --msgbox \
950 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
952 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
956 ## END OF FILE #################################################################
957 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3