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: stable).
43 -t, --target=target Target partition (/dev/...) or directory.
44 -p, --mntpoint=mnt Mountpoint used for mounting the target system.
45 --debopt=params Extra parameters passed to the debootstrap.
46 --interactive Use interactive mode (frontend).
47 --nodebootstrap Skip debootstrap, only do configuration to the target.
48 --groot=device Root device for usage in grub, corresponds with
49 \$TARGET in grub syntax, like hd0,0 for /dev/sda1.
50 --grub=device Target for grub installation. Use grub syntax for
51 specifying, like hd0 for /dev/sda.
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[=f] Install packages defined in <confdir>/packages.
60 Option arg: alternative package list file.
61 --debconf[=f] Pre-seed packages using <confdir>/debconf-selections.
62 Option arg: alternative pre-seed db file.
63 --keep_src_list Do not overwrite user provided apt sources.list.
64 --hostname=name Hostname of Debian system.
65 --password=pwd Use specified password as password for user root.
66 --bootappend=line Add specified appendline to kernel whilst booting.
67 --chroot-scripts[=f] Execute scripts from <confdir>/chroot-scripts/
68 Option arg: alternative chroot-scripts directory.
69 --scripts[=d] Execute scripts from <confdir>/scripts/.
70 Option arg: alternative scripts directory.
74 -v, --verbose Increase verbosity.
75 -h, --help Print this usage information and exit.
76 -V, --version Show summary of options and exit.
78 Usage examples can be found in the grml-debootstrap manpage.
79 Send bugreports to the grml-team: bugs@grml.org || http://grml.org/bugs/
83 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
85 echo 'Please notice that this script requires root permissions!'
90 # make sure we have what we need {{{
91 check4progs debootstrap dialog || exit 1
95 # source configuration file {{{
96 if [ -r /etc/debootstrap/config ] ; then
97 if [ -n "$CONFIGFILE" ] ; then
98 einfo "Using config file $CONFIGFILE."
99 if ! . "$CONFIGFILE" ; then
100 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
103 . /etc/debootstrap/config
108 # cmdline handling {{{
109 # source external command line parameter-processing script
110 if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
111 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
112 elif [ -r ./cmdlineopts.clp ] ; then
115 echo "Error: cmdline function file not found, exiting.">&2
119 # == business-logic of command line parameter-processing
121 # source configuration file in <confdir> if supplied. {{{
122 [ "$_opt_confdir" ] && {
123 CONFFILES=$_opt_confdir
124 einfo "Using config files under $CONFFILES/."
125 if ! [ -r "$CONFFILES/config" ] ; then
126 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
128 if ! . "$CONFFILES/config" ; then
129 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
131 # restore the command line parameter value
132 CONFFILES=$_opt_confdir
136 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
137 [ "$_opt_iso" ] && ISO=$_opt_iso
138 [ "$_opt_release" ] && RELEASE=$_opt_release
139 [ "$_opt_target" ] && TARGET=$_opt_target
140 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
141 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
142 [ "$_opt_interactive" ] && INTERACTIVE=1
143 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
144 [ "$_opt_packages_set" ] && PACKAGES='yes'
145 [ "$_opt_debconf_set" ] && DEBCONF='yes'
146 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
147 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
148 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
149 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
150 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
151 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
152 [ "$_opt_groot" ] && GROOT=$_opt_groot
153 [ "$_opt_grub" ] && GRUB=$_opt_grub
154 [ "$_opt_verbose" ] && VERBOSE="-v"
156 [ "$_opt_help" ] && {
162 [ "$_opt_version" ] && {
163 einfo "$PN - version $VERSION"
164 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
173 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
174 Do you want to continue installing Debian using this frontend?" 0 0
181 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
183 grep -v 'Extended$' | \
184 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
186 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
187 dialog --title "$PN" --trim \
188 --msgbox "Sorry, no partitions found. Please configure your
189 harddisks (see /proc/partitions) using a tool like fdisk,
190 cfdisk, gpart, gparted,..." 0 0
194 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
195 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
198 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
199 --menu "Please select the target partition:" 0 0 0 \
204 # ask for bootmanager {{{
205 prompt_for_bootmanager()
208 for device in sda hda; do
209 if [ /dev/$device != ${TARGET%[0-9]} ]; then
210 grep -q $device /proc/partitions && \
211 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
214 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
218 if echo $TARGET | grep -q "/dev/md" ; then
219 MBRPART="all disks of Software RAID $TARGET"
221 MBRPART="MBR of ${TARGET%[0-9]}"
224 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
225 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
226 mbr "install bootmanager into $MBRPART" \
227 partition "install bootmanager into partition $TARGET" \
228 nowhere "do not install bootmanager at all" \
229 ${ADDITIONAL_PARAMS})
230 [ $? -eq 0 ] || bailout 3
235 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
236 if echo $TARGET | grep -q "*md*" ; then
237 BOOT_PARTITION="${TARGET}"
239 BOOT_PARTITION="${TARGET%[0-9]}"
243 BOOT_PARTITION="$TARGET"
246 BOOT_PARTITION="/dev/hda"
249 BOOT_PARTITION="/dev/sda"
258 # ask for Debian release {{{
261 RELEASE="$(dialog --stdout --title "${PN}" --default-item etch --menu \
262 "Please enter the Debian release you would like to use for installation:" \
265 lenny Debian/testing \
266 sid Debian/unstable)"
270 # ask for hostname {{{
271 prompt_for_hostname()
273 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
274 "Please enter the hostname you would like to use for installation:" \
279 # ask for password {{{
280 prompt_for_password()
284 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
285 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
286 "Please enter the password for the root account:" 10 60)
287 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
288 "Please enter the password for the root account again for \
289 confirmation:" 10 60)
291 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
292 $(dialog --stdout --title "${PN}" --ok-label \
293 "Retry" --msgbox "Passwords do not match!" 10 60)
296 ROOTPASSWORD="$ROOTPW1"
300 # ask for Debian mirror {{{
303 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
304 "Please enter Debian mirror you would like to use for installing packages." \
305 0 0 http://ftp.de.debian.org/debian)"
309 # get grub's syntax for /dev/ice {{{
310 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
312 if [ -z "$1" ] ; then
313 echo "Usage: grubdevice <device>">&2
318 device_map=/boot/grub/device.map
321 if ! [ -f "$device_map" ] ; then
322 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
325 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
326 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
327 -e 's%\(fd[0-9]*\)$%\1%' \
328 -e 's%/part[0-9]*$%/disc%' \
329 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
330 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
331 -e 's%.*/fd[0-9]*$%%' \
332 -e 's%.*/floppy/[0-9]*$%%' \
333 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
334 -e 's%.*c[0-7]d[0-9]*p*%%'`
335 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
338 /dev/[sh]d[a-z]) # we expect something like 'hd0'
341 *) # we expect something like 'hd0,0'
342 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
348 # software raid setup {{{
349 config_swraid_setup()
353 # Currently we support only raid1:
356 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
357 # --menu "Which RAID level do you want to use?" 0 0 0 \
358 # raid1 "Software RAID level 1" \
359 # raid5 "Software RAID level 5")
360 #[ $? -eq 0 ] || bailout 20
362 MD_LIST=$(for i in $(seq 0 9) ; do
363 awk '{print $4}' /proc/partitions | grep -q md$i || \
364 echo "/dev/md$i /dev/md$i"
367 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
368 --menu "Which device do you want to use for ${RAIDLEVEL}?
370 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 \
372 [ $? -eq 0 ] || bailout 20
374 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
376 grep -v 'Extended$' | \
377 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
378 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
379 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
380 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
383 dialog --title "$PN" --separate-output \
384 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
385 $PARTITION_LIST 2>$TMPFILE
387 SELECTED_PARTITIONS="$(cat $TMPFILE)"
390 for i in $(cat $TMPFILE) ; do
391 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
396 # TODO: better error handling?
397 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
398 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
402 if [ "$RC" = 0 ] ; then
403 dialog --title "$PN" --msgbox \
404 "Creating $TARGET was successful." 0 0
405 rm -f "$TMPFILE" "$ERRORFILE"
407 dialog --title "$PN" --msgbox \
408 "There was an error setting up $TARGET:
413 rm -f "$TMPFILE" "$ERRORFILE"
421 if dialog --stdout --title "$PN" \
422 --defaultno --yesno "Do you want to configure Software RAID?
424 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
430 # make sure the user is aware of the used configuration {{{
433 if [ -n "$AUTOINSTALL" ] ; then
434 if checkforrun ; then
435 eerror "Exiting as requested" ; eend 0
438 elif [ -n "$INTERACTIVE" ] ; then
440 INFOTEXT="Please recheck configuration before execution:
442 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
444 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
446 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
447 Using release: $RELEASE"
448 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
449 Using hostname $HOSTNAME"
450 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
451 Using mirror: $MIRROR"
455 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
457 dialog --title "$PN" --no-collapse \
458 --yesno "$INFOTEXT" 0 0
460 else # if not running automatic installation display configuration and prompt for execution:
461 einfo "$PN - Please recheck configuration before execution:"
463 echo " Target: $TARGET"
464 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
465 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
466 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
467 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
468 [ -n "$ISO" ] && echo " Using iso: $ISO"
469 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
471 einfon "Is this ok for you? [y/N] "
473 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
474 eerror "Exiting as requested." ; eend 1
481 # interactive mode {{{
488 # do not prompt for partition dialog if swraid has been configured already
489 [ -n "$TARGET" ] || prompt_for_target
491 prompt_for_bootmanager
499 # use first disk of sw-raid for grub by default, install grub on
500 # all involved disks later on
501 if echo "$TARGET" | grep -q '/dev/md' ; then
502 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
503 # use hdX and not hdX,Y for $GRUB
504 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
505 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
506 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
507 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
510 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
511 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
519 # run interactive mode if we didn't get the according configuration yet
520 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
521 # only target might be unset, so make sure the INTERACTIVE flag is set as well
527 # finally make sure at least $TARGET is set [the partition for the new system] {{{
528 if [ -n "$TARGET" ] ; then
529 SHORT_TARGET="${TARGET##*/}"
531 eerror "Please adjust $CONFFILES/config or..."
532 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
538 if [ -z "$STAGES" ] ; then
539 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
540 [ -d "$STAGES" ] || mkdir -p "$STAGES"
543 if [ -r "$STAGES"/grml-debootstrap ] ; then
544 if grep -q done $STAGES/grml-debootstrap ; then
545 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
546 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
551 # partition handling {{{
560 # 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
612 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
614 if [ -n "$STAGES" ] ; then
615 echo -n "Removing stages directory ${STAGES}: "
616 rm -rf "$STAGES" && echo done
619 # remove directory only if we used the default with process id inside the name
620 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
621 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
626 [ -n "$1" ] && EXIT="$1" || EXIT="1"
627 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
631 trap bailout HUP INT QUIT TERM
633 # we want to execute all the functions only once, simple check for it:
635 if [ -n "$2" ] ; then
636 echo "$2" > "${STAGES}/${1}"
638 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
639 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
641 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
648 # user should recheck his configuration {{{
649 # support full automatic installation:
651 dialog --timeout 10 --title "$PN" \
652 --yesno "Do you want to stop at this stage?
654 Notice: you are running ${PN} in non-interactive mode.
655 ${PN} will install Debian ${RELEASE} on ${TARGET}.
656 Last chance to quit. Timeout of 10 seconds running....
658 Do you want to stop now?" 0 0 2>/dev/null
661 # create filesystem {{{
663 if [ -n "$MKFS" ] ; then
664 einfo "Running $MKFS on $TARGET"
666 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
672 # modify filesystem settings {{{
674 if [ -n "$TUNE2FS" ] ; then
675 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
682 # mount the new partition or if it's a directory do nothing at all {{{
684 if [ -n "$DIRECTORY" ] ; then
685 einfo "Running grml-debootstrap on a directory, nothing to mount."
687 if grep -q $TARGET /proc/mounts ; then
688 eerror "$TARGET already mounted, exiting."
690 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
691 einfo "Mounting $TARGET to $MNTPOINT"
692 mount -o rw,suid,dev $TARGET $MNTPOINT
696 if [ -n "$ISODIR" ] ; then
697 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
698 mkdir -p "$MNTPOINT/$ISODIR"
699 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
705 # install main chroot {{{
706 debootstrap_system() {
707 if ! grep -q $MNTPOINT /proc/mounts ; then
710 if [ "$_opt_nodebootstrap" ]; then
711 einfo "Skipping debootstrap as requested."
714 if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then
715 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
716 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
717 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
720 eerror "Error: $MNTPOINT not mounted, can not continue."
726 # prepare chroot via chroot-script {{{
728 einfo "Preparing chroot system"
730 # provide variables to chroot system
731 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
732 touch $CHROOT_VARIABLES
733 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
734 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
735 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
736 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
737 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
738 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
739 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
740 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
741 [ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> $CHROOT_VARIABLES
742 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
743 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
744 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
745 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
746 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
748 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
749 chmod 755 $MNTPOINT/bin/chroot-script
750 mkdir $MNTPOINT/etc/debootstrap/
752 # make sure we have our files for later use via chroot-script
753 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
754 # make sure we adjust the configuration variables accordingly:
755 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
756 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
757 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
758 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
761 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
762 $MNTPOINT/etc/debootstrap/packages
764 # debconf preseeding:
765 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
766 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
767 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
769 # copy scripts that should be executed inside the chroot:
770 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot_scripts/}
771 [ -f $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && \
772 cp -a $VERBOSE $_opt_chroot_scripts $MNTPOINT/etc/debootstrap/
774 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
775 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
777 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
779 # make sure we can access network [relevant for cdebootstrap]
780 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
782 # provide system's /etc/hosts to the target:
783 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
784 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
785 sed -i "s#127.0.0.1 .*#127.0.0.1 localhost $HOSTNAME#" /etc/hosts
788 # setup default locales
789 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
791 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
792 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
794 # copy any existing files to chroot
795 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
796 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
797 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
798 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
799 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
800 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
801 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
803 # copy local network setup to chroot
804 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
805 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
806 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
813 # execute all scripts in /etc/debootstrap/scripts/ {{{
815 if [ -f $_opt_scripts -a "$SCRIPTS" = 'yes' ] ; then
816 for script in /etc/debootstrap/scripts/* ; do
817 if [ -x "$script" ] ; then
818 einfo "Executing script $script"
826 # execute chroot-script {{{
828 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
831 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
832 einfo "Executing chroot-script now"
833 chroot "$MNTPOINT" /bin/chroot-script
836 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
842 # install booloader grub {{{
844 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
845 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
846 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
847 for device in $SELECTED_PARTITIONS ; do
848 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
849 # GRUB="$(grubdevice ${TMPDEVICE})"
850 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
851 # GRUB=$(grubdevice $device)
852 GRUB="$(grubdevice ${device%%[0-9]})"
853 einfo "Installing grub on ${GRUB}:"
854 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
855 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
859 einfo "Installing grub on ${GRUB}:"
860 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
861 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
867 # unmount $MNTPOINRT {{{
869 if [ -n "$ISODIR" ] ; then
870 if grep -q "$ISODIR" /proc/mounts ; then
871 einfo "Unmount $MNTPOINT/$ISODIR"
872 umount "$MNTPOINT/$ISODIR"
876 if grep -q "$MNTPOINT" /proc/mounts ; then
877 if [ -n "$PARTITION" ] ; then
878 einfo "Unmount $MNTPOINT"
886 # execute filesystem check {{{
888 if [ "$FSCK" = 'yes' ] ; then
889 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
890 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
897 # now execute all the functions {{{
898 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
899 chrootscript execute_scripts grub_install umount_chroot \
901 if stage "${i}" ; then
902 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
908 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
909 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
911 # Remove temporary mountpoint again
912 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
913 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
917 # end dialog of autoinstallation {{{
918 if [ -n "$AUTOINSTALL" ] ; then
919 dialog --title "$PN" --msgbox \
920 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
922 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
926 ## END OF FILE #################################################################
927 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3