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.
55 Configuration options:
57 -c, --config <file> Use specified configuration file, defaults to
58 /etc/debootstrap/config
59 -d, --confdir <path> Place of config files for debootstrap, defaults
61 --packages <file> Install packages defined in specified list file.
62 --debconf <file> Pre-seed packages using specified 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 <d> Execute chroot scripts from specified directory.
68 --scripts <dir> Execute scripts from specified directory.
72 -v, --verbose Increase verbosity.
73 -h, --help Print this usage information and exit.
74 -V, --version Show summary of options and exit.
76 Usage examples can be found in the grml-debootstrap manpage.
77 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
81 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
83 echo 'Please notice that this script requires root permissions!'
88 # make sure we have what we need {{{
89 check4progs debootstrap dialog || exit 1
93 # source configuration file {{{
94 if [ -r /etc/debootstrap/config ] ; then
95 if [ -n "$CONFIGFILE" ] ; then
96 einfo "Using config file $CONFIGFILE."
97 if ! . "$CONFIGFILE" ; then
98 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
101 . /etc/debootstrap/config
106 # cmdline handling {{{
107 # source external command line parameter-processing script
108 if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
109 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
110 elif [ -r ./cmdlineopts.clp ] ; then
113 echo "Error: cmdline function file not found, exiting.">&2
117 # == business-logic of command line parameter-processing
119 # source configuration file in <confdir> if supplied. {{{
120 [ "$_opt_confdir" ] && {
121 CONFFILES=$_opt_confdir
122 einfo "Using config files under $CONFFILES/."
123 if ! [ -r "$CONFFILES/config" ] ; then
124 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
126 if ! . "$CONFFILES/config" ; then
127 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
129 # restore the command line parameter value
130 CONFFILES=$_opt_confdir
134 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
135 [ "$_opt_iso" ] && ISO=$_opt_iso
136 [ "$_opt_release" ] && RELEASE=$_opt_release
137 [ "$_opt_target" ] && TARGET=$_opt_target
138 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
139 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
140 [ "$_opt_interactive" ] && INTERACTIVE=1
141 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
142 [ "$_opt_packages_set" ] && PACKAGES='yes'
143 [ "$_opt_debconf_set" ] && DEBCONF='yes'
144 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
145 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
146 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
147 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
148 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
149 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
150 [ "$_opt_groot" ] && GROOT=$_opt_groot
151 [ "$_opt_grub" ] && GRUB=$_opt_grub
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/"
171 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
172 Do you want to continue installing Debian using this frontend?" 0 0
179 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
181 grep -v 'Extended$' | \
182 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; echo /dev/md*);
184 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
185 dialog --title "$PN" --trim \
186 --msgbox "Sorry, no partitions found. Please configure your
187 harddisks (see /proc/partitions) using a tool like fdisk,
188 cfdisk, gpart, gparted,..." 0 0
192 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
193 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
196 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
197 --menu "Please select the target partition:" 0 0 0 \
202 # ask for bootmanager {{{
203 prompt_for_bootmanager()
206 for device in sda hda; do
207 if [ /dev/$device != ${TARGET%[0-9]} ]; then
208 grep -q $device /proc/partitions && \
209 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
212 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
216 if echo $TARGET | grep -q "/dev/md" ; then
217 MBRPART="all disks of Software RAID $TARGET"
219 MBRPART="MBR of ${TARGET%[0-9]}"
222 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
223 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
224 mbr "install bootmanager into $MBRPART" \
225 partition "install bootmanager into partition $TARGET" \
226 nowhere "do not install bootmanager at all" \
227 ${ADDITIONAL_PARAMS})
228 [ $? -eq 0 ] || bailout 3
233 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
234 if echo $TARGET | grep -q "*md*" ; then
235 BOOT_PARTITION="${TARGET}"
237 BOOT_PARTITION="${TARGET%[0-9]}"
241 BOOT_PARTITION="$TARGET"
244 BOOT_PARTITION="/dev/hda"
247 BOOT_PARTITION="/dev/sda"
256 # ask for Debian release {{{
259 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
260 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
261 "Please enter the Debian release you would like to use for installation:" \
263 etch Debian/old-stable \
264 lenny Debian/stable \
265 squeeze 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 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
305 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
306 --menu "Where do you want to install from?" 0 0 0 \
307 net "install via network (downloading from mirror)" \
308 local "install from local directory/mirror"
311 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
312 [ -n "$MIRROR" ] || MIRROR='ftp://ftp.de.debian.org/debian'
313 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
314 "Please enter Debian mirror you would like to use for installing packages." \
316 else # CHROOT_VARIABLES == local
317 [ -n "$ISO" ] || ISO='/mnt/mirror'
318 ISO="$(dialog --stdout --title "${PN}" --inputbox \
319 "Please enter directory name you would like to use for installing packages." \
325 # get grub's syntax for /dev/ice {{{
326 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
328 if [ -z "$1" ] ; then
329 echo "Usage: grubdevice <device>">&2
334 device_map=/boot/grub/device.map
337 if ! [ -f "$device_map" ] ; then
338 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
341 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
342 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
343 -e 's%\(fd[0-9]*\)$%\1%' \
344 -e 's%/part[0-9]*$%/disc%' \
345 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
346 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
347 -e 's%.*/fd[0-9]*$%%' \
348 -e 's%.*/floppy/[0-9]*$%%' \
349 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
350 -e 's%.*c[0-7]d[0-9]*p*%%'`
351 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
354 /dev/[sh]d[a-z]) # we expect something like 'hd0'
357 *) # we expect something like 'hd0,0'
358 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
364 # software raid setup {{{
365 config_swraid_setup()
369 # Currently we support only raid1:
372 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
373 # --menu "Which RAID level do you want to use?" 0 0 0 \
374 # raid1 "Software RAID level 1" \
375 # raid5 "Software RAID level 5")
376 #[ $? -eq 0 ] || bailout 20
378 MD_LIST=$(for i in $(seq 0 9) ; do
379 awk '{print $4}' /proc/partitions | grep -q md$i || \
380 echo "/dev/md$i /dev/md$i"
383 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
384 --menu "Which device do you want to use for ${RAIDLEVEL}?
386 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 \
388 [ $? -eq 0 ] || bailout 20
390 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
392 grep -v 'Extended$' | \
393 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
394 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
395 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
396 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
399 dialog --title "$PN" --separate-output \
400 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
401 $PARTITION_LIST 2>$TMPFILE
403 SELECTED_PARTITIONS="$(cat $TMPFILE)"
406 for i in $(cat $TMPFILE) ; do
407 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
412 # TODO: better error handling?
413 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
414 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
418 if [ "$RC" = 0 ] ; then
419 dialog --title "$PN" --msgbox \
420 "Creating $TARGET was successful." 0 0
421 rm -f "$TMPFILE" "$ERRORFILE"
423 dialog --title "$PN" --msgbox \
424 "There was an error setting up $TARGET:
429 rm -f "$TMPFILE" "$ERRORFILE"
437 if dialog --stdout --title "$PN" \
438 --defaultno --yesno "Do you want to configure Software RAID?
440 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
446 # user should recheck his configuration {{{
447 # support full automatic installation:
449 dialog --timeout 10 --title "$PN" \
450 --yesno "Do you want to stop at this stage?
452 Notice: you are running ${PN} in non-interactive mode.
453 ${PN} will install Debian ${RELEASE} on ${TARGET}.
454 Last chance to quit. Timeout of 10 seconds running....
456 Do you want to stop now?" 0 0 2>/dev/null
459 # make sure the user is aware of the used configuration {{{
462 if [ -n "$AUTOINSTALL" ] ; then
463 if checkforrun ; then
464 eerror "Exiting as requested" ; eend 0
467 elif [ -n "$INTERACTIVE" ] ; then
469 INFOTEXT="Please recheck configuration before execution:
471 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
473 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
475 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
476 Using release: $RELEASE"
477 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
478 Using hostname $HOSTNAME"
479 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
480 Using mirror: $MIRROR"
481 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
486 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
488 dialog --title "$PN" --no-collapse \
489 --yesno "$INFOTEXT" 0 0
491 else # if not running automatic installation display configuration and prompt for execution:
492 einfo "$PN - Please recheck configuration before execution:"
494 echo " Target: $TARGET"
495 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
496 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
497 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
498 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
499 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
500 [ -n "$ISO" ] && echo " Using ISO: $ISO"
501 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
503 einfon "Is this ok for you? [y/N] "
505 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
506 eerror "Exiting as requested." ; eend 1
513 # interactive mode {{{
522 prompt_for_bootmanager
530 # use first disk of sw-raid for grub by default, install grub on
531 # all involved disks later on
532 if echo "$TARGET" | grep -q '/dev/md' ; then
533 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
534 # use hdX and not hdX,Y for $GRUB
535 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
536 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
537 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
538 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
541 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
542 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
548 # run interactive mode if we didn't get the according configuration yet
549 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
550 # only target might be unset, so make sure the INTERACTIVE flag is set as well
558 # finally make sure at least $TARGET is set [the partition for the new system] {{{
559 if [ -n "$TARGET" ] ; then
560 SHORT_TARGET="${TARGET##*/}"
562 eerror "Please adjust $CONFFILES/config or..."
563 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
569 if [ -z "$STAGES" ] ; then
570 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
571 [ -d "$STAGES" ] || mkdir -p "$STAGES"
574 if [ -r "$STAGES"/grml-debootstrap ] ; then
575 if grep -q done $STAGES/grml-debootstrap ; then
576 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
577 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
582 # partition handling {{{
591 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
603 # architecture setup {{{
604 if [ -n "$ARCH" ] ; then
605 ARCHCMD="--arch $ARCH"
606 ARCHINFO=" (${ARCH})"
608 ARCH="$(dpkg --print-architecture)"
609 ARCHCMD="--arch $ARCH"
610 ARCHINFO=" (${ARCH})"
614 # make sure we have the right syntax when using an iso image {{{
615 if [ -n "$ISO" ] ; then
628 # helper functions {{{
629 # we want to exit smoothly and clean:
631 # make sure $TARGET is not mounted when exiting grml-debootstrap
632 if [ -n "$MNTPOINT" ] ; then
633 if grep -q $MNTPOINT /proc/mounts ; then
634 # make sure nothing is left inside chroot so we can unmount it
635 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
636 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
637 # ugly, but make sure we really don't leav anything
638 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
639 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
640 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
641 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
642 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
644 if [ -n "$DIRECTORY" ] ; then
645 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
647 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
650 if [ -n "$STAGES" ] ; then
651 echo -n "Removing stages directory ${STAGES}: "
652 rm -rf "$STAGES" && echo done
655 # remove directory only if we used the default with process id inside the name
656 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
657 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
662 [ -n "$1" ] && EXIT="$1" || EXIT="1"
663 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
667 trap bailout HUP INT QUIT TERM
669 # we want to execute all the functions only once, simple check for it:
671 if [ -n "$2" ] ; then
672 echo "$2" > "${STAGES}/${1}"
674 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
675 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
677 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
684 # create filesystem {{{
686 if [ -n "$DIRECTORY" ] ; then
687 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
689 if grep -q "$TARGET" /proc/mounts ; then
690 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
694 if [ -n "$MKFS" ] ; then
695 einfo "Running $MKFS on $TARGET"
697 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
705 # modify filesystem settings {{{
707 if [ -n "$TUNE2FS" ] ; then
708 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
715 # mount the new partition or if it's a directory do nothing at all {{{
717 if [ -n "$DIRECTORY" ] ; then
718 einfo "Running grml-debootstrap on a directory, nothing to mount."
720 if grep -q $TARGET /proc/mounts ; then
721 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
723 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
724 einfo "Mounting $TARGET to $MNTPOINT"
725 mount -o rw,suid,dev $TARGET $MNTPOINT
729 if [ -n "$ISODIR" ] ; then
730 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
731 mkdir -p "$MNTPOINT/$ISODIR"
732 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
738 # install main chroot {{{
739 debootstrap_system() {
740 if ! grep -q "$MNTPOINT" /proc/mounts ; then
743 if [ "$_opt_nodebootstrap" ]; then
744 einfo "Skipping debootstrap as requested."
747 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
748 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
749 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
750 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
753 eerror "Error: $MNTPOINT not mounted, can not continue."
759 # prepare chroot via chroot-script {{{
761 einfo "Preparing chroot system"
763 # provide variables to chroot system
764 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
765 touch $CHROOT_VARIABLES
766 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
767 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
768 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
769 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
770 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
771 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
772 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
773 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
774 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
775 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
776 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
777 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
778 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
779 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
781 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
782 chmod 755 $MNTPOINT/bin/chroot-script
783 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
785 # make sure we have our files for later use via chroot-script
786 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
787 # make sure we adjust the configuration variables accordingly:
788 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
789 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
790 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
791 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
794 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
795 $MNTPOINT/etc/debootstrap/packages
797 # debconf preseeding:
798 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
799 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
800 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
802 # copy scripts that should be executed inside the chroot:
803 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
804 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
805 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
806 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
809 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
810 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
812 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
814 # make sure we can access network [relevant for cdebootstrap]
815 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
817 # provide system's /etc/hosts to the target:
818 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
819 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
822 # setup default locales
823 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
825 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
826 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
828 # copy any existing files to chroot
829 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
830 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
831 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
832 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
833 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
834 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
835 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
837 # copy local network setup to chroot
838 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
839 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
840 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
847 # execute all scripts in /etc/debootstrap/scripts/ {{{
849 # make sure we have $MNTPOINT available for our scripts
851 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
852 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
853 for script in ${scripts}/* ; do
854 if [ -x "$script" ] ; then
855 einfo "Executing script $script"
863 # execute chroot-script {{{
865 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
868 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
869 einfo "Executing chroot-script now"
870 chroot "$MNTPOINT" /bin/chroot-script
873 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
879 # install booloader grub {{{
881 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
882 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
883 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
884 for device in $SELECTED_PARTITIONS ; do
885 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
886 # GRUB="$(grubdevice ${TMPDEVICE})"
887 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
888 # GRUB=$(grubdevice $device)
889 GRUB="$(grubdevice ${device%%[0-9]})"
890 einfo "Installing grub on ${GRUB}:"
891 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
892 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
896 einfo "Installing grub on ${GRUB}:"
897 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
898 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
904 # unmount $MNTPOINRT {{{
906 if [ -n "$ISODIR" ] ; then
907 if grep -q "$ISODIR" /proc/mounts ; then
908 einfo "Unmount $MNTPOINT/$ISODIR"
909 umount "$MNTPOINT/$ISODIR"
914 if grep -q "$MNTPOINT" /proc/mounts ; then
915 if [ -n "$PARTITION" ] ; then
916 einfo "Unmount $MNTPOINT"
924 # execute filesystem check {{{
926 if [ "$FSCK" = 'yes' ] ; then
927 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
928 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
935 # now execute all the functions {{{
936 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
937 chrootscript execute_scripts grub_install umount_chroot \
939 if stage "${i}" ; then
940 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
946 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
947 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
949 # Remove temporary mountpoint again
950 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
951 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
955 # end dialog of autoinstallation {{{
956 if [ -n "$AUTOINSTALL" ] ; then
957 dialog --title "$PN" --msgbox \
958 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
960 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
964 ## END OF FILE #################################################################
965 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3