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 --groot <device> Root device for usage in grub, corresponds with
51 \$TARGET in grub syntax, like hd0,0 for /dev/sda1.
52 --grub <device> Target for grub installation. Use grub syntax for
53 specifying, like hd0 for /dev/sda.
54 --arch <arch> Architecture to use. Currently only i386 and amd64
57 Configuration options:
59 -c, --config <file> Use specified configuration file, defaults to
60 /etc/debootstrap/config
61 -d, --confdir <path> Place of config files for debootstrap, defaults
63 --packages <file> Install packages defined in specified list file.
64 --debconf <file> Pre-seed packages using specified pre-seed db file.
65 --keep_src_list Do not overwrite user provided apt sources.list.
66 --hostname <name> Hostname of Debian system.
67 --password <pwd> Use specified password as password for user root.
68 --bootappend <line> Add specified appendline to kernel whilst booting.
69 --chroot-scripts <d> Execute chroot scripts from specified directory.
70 --scripts <dir> Execute scripts from specified 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 (at) 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_arch" ] && ARCH=$_opt_arch
155 [ "$_opt_verbose" ] && VERBOSE="-v"
157 [ "$_opt_help" ] && {
163 [ "$_opt_version" ] && {
164 einfo "$PN - version $VERSION"
165 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
174 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
175 Do you want to continue installing Debian using this frontend?" 0 0
182 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
184 grep -v 'Extended$' | \
185 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
187 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
188 dialog --title "$PN" --trim \
189 --msgbox "Sorry, no partitions found. Please configure your
190 harddisks (see /proc/partitions) using a tool like fdisk,
191 cfdisk, gpart, gparted,..." 0 0
195 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
196 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
199 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
200 --menu "Please select the target partition:" 0 0 0 \
205 # ask for bootmanager {{{
206 prompt_for_bootmanager()
210 if echo "$TARGET" | grep -q "/dev/md" ; then
211 MBRPART="all disks of Software RAID $TARGET"
213 # figure out whole disk device
215 for device in /dev/disk/by-id/*
217 [ $(readlink -f $device) = ${TARGET} ] || continue
221 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
222 if [ -e "$MBRDISK" ]; then
223 MBRDISK=$(readlink -f $MBRDISK)
225 # fall back to old behaviour
226 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$/')
229 MBRPART="MBR of $MBRDISK"
232 for device in cciss/c0d0 sda hda; do
233 if [ /dev/$device != ${MBRDISK} ]; then
234 grep -q $device /proc/partitions && \
235 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
238 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
242 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
243 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
244 mbr "install bootmanager into $MBRPART" \
245 partition "install bootmanager into partition $TARGET" \
246 nowhere "do not install bootmanager at all" \
247 ${ADDITIONAL_PARAMS})
248 [ $? -eq 0 ] || bailout 3
253 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
254 if echo "$TARGET" | grep -q "/dev/md" ; then
255 BOOT_PARTITION="$TARGET"
257 BOOT_PARTITION="$MBRDISK"
261 BOOT_PARTITION="$TARGET"
264 BOOT_PARTITION="/dev/hda"
267 BOOT_PARTITION="/dev/sda"
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 etch Debian/old-stable \
284 lenny Debian/stable \
285 squeeze Debian/testing \
286 sid Debian/unstable)"
290 # ask for hostname {{{
291 prompt_for_hostname()
293 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
294 "Please enter the hostname you would like to use for installation:" \
299 # ask for password {{{
300 prompt_for_password()
304 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
305 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
306 "Please enter the password for the root account:" 10 60)
307 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
308 "Please enter the password for the root account again for \
309 confirmation:" 10 60)
311 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
312 $(dialog --stdout --title "${PN}" --ok-label \
313 "Retry" --msgbox "Passwords do not match!" 10 60)
316 ROOTPASSWORD="$ROOTPW1"
320 # ask for Debian mirror {{{
323 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
325 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
326 --menu "Where do you want to install from?" 0 0 0 \
327 net "install via network (downloading from mirror)" \
328 local "install from local directory/mirror"
331 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
332 [ -n "$MIRROR" ] || MIRROR='ftp://ftp.de.debian.org/debian'
333 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
334 "Please enter Debian mirror you would like to use for installing packages." \
336 else # CHROOT_VARIABLES == local
337 [ -n "$ISO" ] || ISO='/mnt/mirror'
338 ISO="$(dialog --stdout --title "${PN}" --inputbox \
339 "Please enter directory name you would like to use for installing packages." \
345 # get grub's syntax for /dev/ice {{{
346 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
348 if [ -z "$1" ] ; then
349 echo "Usage: grubdevice <device>">&2
354 device_map=/boot/grub/device.map
357 if ! [ -f "$device_map" ] ; then
358 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
361 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
362 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
363 -e 's%\(fd[0-9]*\)$%\1%' \
364 -e 's%/part[0-9]*$%/disc%' \
365 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
366 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
367 -e 's%.*/fd[0-9]*$%%' \
368 -e 's%.*/floppy/[0-9]*$%%' \
369 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
370 -e 's%.*c[0-7]d[0-9]*p*%%'`
371 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
374 /dev/[sh]d[a-z]) # we expect something like 'hd0'
377 *) # we expect something like 'hd0,0'
378 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
384 # software raid setup {{{
385 config_swraid_setup()
389 # Currently we support only raid1:
392 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
393 # --menu "Which RAID level do you want to use?" 0 0 0 \
394 # raid1 "Software RAID level 1" \
395 # raid5 "Software RAID level 5")
396 #[ $? -eq 0 ] || bailout 20
398 MD_LIST=$(for i in $(seq 0 9) ; do
399 awk '{print $4}' /proc/partitions | grep -q md$i || \
400 echo "/dev/md$i /dev/md$i"
403 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
404 --menu "Which device do you want to use for ${RAIDLEVEL}?
406 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 \
408 [ $? -eq 0 ] || bailout 20
410 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
412 grep -v 'Extended$' | \
413 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
414 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
415 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
416 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
419 dialog --title "$PN" --separate-output \
420 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
421 $PARTITION_LIST 2>$TMPFILE
423 SELECTED_PARTITIONS="$(cat $TMPFILE)"
426 for i in $(cat $TMPFILE) ; do
427 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
432 # TODO: better error handling?
433 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
434 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
438 if [ "$RC" = 0 ] ; then
439 dialog --title "$PN" --msgbox \
440 "Creating $TARGET was successful." 0 0
441 rm -f "$TMPFILE" "$ERRORFILE"
443 dialog --title "$PN" --msgbox \
444 "There was an error setting up $TARGET:
449 rm -f "$TMPFILE" "$ERRORFILE"
457 if dialog --stdout --title "$PN" \
458 --defaultno --yesno "Do you want to configure Software RAID?
460 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
466 # user should recheck his configuration {{{
467 # support full automatic installation:
469 dialog --timeout 10 --title "$PN" \
470 --yesno "Do you want to stop at this stage?
472 Notice: you are running ${PN} in non-interactive mode.
473 ${PN} will install Debian ${RELEASE} on ${TARGET}.
474 Last chance to quit. Timeout of 10 seconds running....
476 Do you want to stop now?" 0 0 2>/dev/null
479 # make sure the user is aware of the used configuration {{{
482 if [ -n "$AUTOINSTALL" ] ; then
483 if checkforrun ; then
484 eerror "Exiting as requested" ; eend 0
487 elif [ -n "$INTERACTIVE" ] ; then
489 INFOTEXT="Please recheck configuration before execution:
491 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
493 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
495 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
496 Using release: $RELEASE"
497 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
498 Using hostname $HOSTNAME"
499 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
500 Using mirror: $MIRROR"
501 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
506 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
508 dialog --title "$PN" --no-collapse \
509 --yesno "$INFOTEXT" 0 0
511 else # if not running automatic installation display configuration and prompt for execution:
512 einfo "$PN - Please recheck configuration before execution:"
514 echo " Target: $TARGET"
516 # do not display if MNTPOINT is the default one
517 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
519 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
520 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
521 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
522 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
523 [ -n "$ISO" ] && echo " Using ISO: $ISO"
525 echo " Important! Continuing will delete all data from ${TARGET}!"
528 einfon "Is this ok for you? [y/N] "
530 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
531 eerror "Exiting as requested." ; eend 1
538 # interactive mode {{{
547 prompt_for_bootmanager
555 # use first disk of sw-raid for grub by default, install grub on
556 # all involved disks later on
557 if echo "$TARGET" | grep -q '/dev/md' ; then
558 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
559 # use hdX and not hdX,Y for $GRUB
560 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
561 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
562 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
563 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
566 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
567 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
573 # run interactive mode if we didn't get the according configuration yet
574 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
575 # only target might be unset, so make sure the INTERACTIVE flag is set as well
583 # finally make sure at least $TARGET is set [the partition for the new system] {{{
584 if [ -n "$TARGET" ] ; then
585 SHORT_TARGET="${TARGET##*/}"
587 eerror "Please adjust $CONFFILES/config or..."
588 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
594 if [ -z "$STAGES" ] ; then
595 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
596 [ -d "$STAGES" ] || mkdir -p "$STAGES"
599 if [ -r "$STAGES"/grml-debootstrap ] ; then
600 if grep -q done $STAGES/grml-debootstrap ; then
601 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
602 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
607 # partition handling {{{
616 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
628 # architecture setup {{{
629 if [ -n "$ARCH" ] ; then
630 ARCHCMD="--arch $ARCH"
631 ARCHINFO=" (${ARCH})"
633 ARCH="$(dpkg --print-architecture)"
634 ARCHCMD="--arch $ARCH"
635 ARCHINFO=" (${ARCH})"
639 # make sure we have the right syntax when using an iso image {{{
640 if [ -n "$ISO" ] ; then
653 # helper functions {{{
654 # we want to exit smoothly and clean:
656 # make sure $TARGET is not mounted when exiting grml-debootstrap
657 if [ -n "$MNTPOINT" ] ; then
658 if grep -q $MNTPOINT /proc/mounts ; then
659 # make sure nothing is left inside chroot so we can unmount it
660 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
661 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
662 # ugly, but make sure we really don't leav anything
663 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
664 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
665 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
666 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
667 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
669 if [ -n "$DIRECTORY" ] ; then
670 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
672 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
675 if [ -n "$STAGES" ] ; then
676 echo -n "Removing stages directory ${STAGES}: "
677 rm -rf "$STAGES" && echo done
680 # remove directory only if we used the default with process id inside the name
681 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
682 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
687 [ -n "$1" ] && EXIT="$1" || EXIT="1"
688 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
692 trap bailout HUP INT QUIT TERM
694 # we want to execute all the functions only once, simple check for it:
696 if [ -n "$2" ] ; then
697 echo "$2" > "${STAGES}/${1}"
699 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
700 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
702 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
709 # create filesystem {{{
711 if [ -n "$DIRECTORY" ] ; then
712 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
714 if grep -q "$TARGET" /proc/mounts ; then
715 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
719 if [ -n "$MKFS" ] ; then
720 einfo "Running $MKFS on $TARGET"
722 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
730 # modify filesystem settings {{{
732 if [ -n "$TUNE2FS" ] ; then
733 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
740 # mount the new partition or if it's a directory do nothing at all {{{
742 if [ -n "$DIRECTORY" ] ; then
743 einfo "Running grml-debootstrap on a directory, nothing to mount."
745 if grep -q $TARGET /proc/mounts ; then
746 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
748 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
749 einfo "Mounting $TARGET to $MNTPOINT"
750 mount -o rw,suid,dev $TARGET $MNTPOINT
754 if [ -n "$ISODIR" ] ; then
755 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
756 mkdir -p "$MNTPOINT/$ISODIR"
757 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
763 # install main chroot {{{
764 debootstrap_system() {
765 if [ "$_opt_nodebootstrap" ]; then
766 einfo "Skipping debootstrap as requested."
770 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
771 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
772 if [ -n "$MIRROR" ] ; then
773 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
775 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
779 eerror "Error: $MNTPOINT not mounted, can not continue."
785 # prepare chroot via chroot-script {{{
787 einfo "Preparing chroot system"
789 # provide variables to chroot system
790 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
791 touch $CHROOT_VARIABLES
792 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
793 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
794 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
795 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
796 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
797 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
798 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
799 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
800 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
801 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
802 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
803 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
804 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
805 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
807 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
808 chmod 755 $MNTPOINT/bin/chroot-script
809 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
811 # make sure we have our files for later use via chroot-script
812 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
813 # make sure we adjust the configuration variables accordingly:
814 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
815 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
816 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
817 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
820 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
821 $MNTPOINT/etc/debootstrap/packages
823 # debconf preseeding:
824 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
825 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
826 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
828 # copy scripts that should be executed inside the chroot:
829 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
830 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
831 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
832 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
835 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
836 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
838 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
840 # make sure we can access network [relevant for cdebootstrap]
841 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
843 # provide system's /etc/hosts to the target:
844 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
845 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
848 # setup default locales
849 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
851 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
852 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
854 # copy any existing files to chroot
855 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
856 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
857 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
858 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
859 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
860 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
861 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
863 # copy local network setup to chroot
864 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
865 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
866 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
873 # execute all scripts in /etc/debootstrap/scripts/ {{{
875 # make sure we have $MNTPOINT available for our scripts
877 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
878 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
879 for script in ${scripts}/* ; do
880 if [ -x "$script" ] ; then
881 einfo "Executing script $script"
889 # execute chroot-script {{{
891 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
894 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
895 einfo "Executing chroot-script now"
896 chroot "$MNTPOINT" /bin/chroot-script
899 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
905 # install booloader grub {{{
907 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
908 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
909 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
910 for device in $SELECTED_PARTITIONS ; do
911 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
912 # GRUB="$(grubdevice ${TMPDEVICE})"
913 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
914 # GRUB=$(grubdevice $device)
915 GRUB="$(grubdevice ${device%%[0-9]})"
916 einfo "Installing grub on ${GRUB}:"
917 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
918 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
922 einfo "Installing grub on ${GRUB}:"
923 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
924 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
930 # unmount $MNTPOINRT {{{
932 if [ -n "$ISODIR" ] ; then
933 if grep -q "$ISODIR" /proc/mounts ; then
934 einfo "Unmount $MNTPOINT/$ISODIR"
935 umount "$MNTPOINT/$ISODIR"
940 if grep -q "$MNTPOINT" /proc/mounts ; then
941 if [ -n "$PARTITION" ] ; then
942 einfo "Unmount $MNTPOINT"
950 # execute filesystem check {{{
952 if [ "$FSCK" = 'yes' ] ; then
953 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
954 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
961 # now execute all the functions {{{
962 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
963 chrootscript execute_scripts grub_install umount_chroot \
965 if stage "${i}" ; then
966 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
972 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
973 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
975 # Remove temporary mountpoint again
976 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
977 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
981 # end dialog of autoinstallation {{{
982 if [ -n "$AUTOINSTALL" ] ; then
983 dialog --title "$PN" --msgbox \
984 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
986 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
990 ## END OF FILE #################################################################
991 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3