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.
44 -p, --mntpoint <mnt> Mountpoint used for mounting the target system.
45 --debopt <params> Extra parameters passed to the debootstrap command.
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 <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_groot" ] && GROOT=$_opt_groot
149 [ "$_opt_grub" ] && GRUB=$_opt_grub
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}'; echo /dev/md*);
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()
204 for device in sda hda; do
205 if [ /dev/$device != ${TARGET%[0-9]} ]; then
206 grep -q $device /proc/partitions && \
207 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
210 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
214 if echo $TARGET | grep -q "/dev/md" ; then
215 MBRPART="all disks of Software RAID $TARGET"
217 MBRPART="MBR of ${TARGET%[0-9]}"
220 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
221 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
222 mbr "install bootmanager into $MBRPART" \
223 partition "install bootmanager into partition $TARGET" \
224 nowhere "do not install bootmanager at all" \
225 ${ADDITIONAL_PARAMS})
226 [ $? -eq 0 ] || bailout 3
231 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
232 if echo $TARGET | grep -q "*md*" ; then
233 BOOT_PARTITION="${TARGET}"
235 BOOT_PARTITION="${TARGET%[0-9]}"
239 BOOT_PARTITION="$TARGET"
242 BOOT_PARTITION="/dev/hda"
245 BOOT_PARTITION="/dev/sda"
254 # ask for Debian release {{{
257 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
258 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
259 "Please enter the Debian release you would like to use for installation:" \
261 etch Debian/old-stable \
262 lenny Debian/stable \
263 squeeze Debian/testing \
264 sid Debian/unstable)"
268 # ask for hostname {{{
269 prompt_for_hostname()
271 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
272 "Please enter the hostname you would like to use for installation:" \
277 # ask for password {{{
278 prompt_for_password()
282 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
283 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
284 "Please enter the password for the root account:" 10 60)
285 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
286 "Please enter the password for the root account again for \
287 confirmation:" 10 60)
289 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
290 $(dialog --stdout --title "${PN}" --ok-label \
291 "Retry" --msgbox "Passwords do not match!" 10 60)
294 ROOTPASSWORD="$ROOTPW1"
298 # ask for Debian mirror {{{
301 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
303 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
304 --menu "Where do you want to install from?" 0 0 0 \
305 net "install via network (downloading from mirror)" \
306 local "install from local directory/mirror"
309 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
310 [ -n "$MIRROR" ] || MIRROR='ftp://ftp.de.debian.org/debian'
311 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
312 "Please enter Debian mirror you would like to use for installing packages." \
314 else # CHROOT_VARIABLES == local
315 [ -n "$ISO" ] || ISO='/mnt/mirror'
316 ISO="$(dialog --stdout --title "${PN}" --inputbox \
317 "Please enter directory name you would like to use for installing packages." \
323 # get grub's syntax for /dev/ice {{{
324 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
326 if [ -z "$1" ] ; then
327 echo "Usage: grubdevice <device>">&2
332 device_map=/boot/grub/device.map
335 if ! [ -f "$device_map" ] ; then
336 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
339 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
340 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
341 -e 's%\(fd[0-9]*\)$%\1%' \
342 -e 's%/part[0-9]*$%/disc%' \
343 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
344 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
345 -e 's%.*/fd[0-9]*$%%' \
346 -e 's%.*/floppy/[0-9]*$%%' \
347 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
348 -e 's%.*c[0-7]d[0-9]*p*%%'`
349 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
352 /dev/[sh]d[a-z]) # we expect something like 'hd0'
355 *) # we expect something like 'hd0,0'
356 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
362 # software raid setup {{{
363 config_swraid_setup()
367 # Currently we support only raid1:
370 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
371 # --menu "Which RAID level do you want to use?" 0 0 0 \
372 # raid1 "Software RAID level 1" \
373 # raid5 "Software RAID level 5")
374 #[ $? -eq 0 ] || bailout 20
376 MD_LIST=$(for i in $(seq 0 9) ; do
377 awk '{print $4}' /proc/partitions | grep -q md$i || \
378 echo "/dev/md$i /dev/md$i"
381 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
382 --menu "Which device do you want to use for ${RAIDLEVEL}?
384 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 \
386 [ $? -eq 0 ] || bailout 20
388 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
390 grep -v 'Extended$' | \
391 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
392 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
393 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
394 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
397 dialog --title "$PN" --separate-output \
398 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
399 $PARTITION_LIST 2>$TMPFILE
401 SELECTED_PARTITIONS="$(cat $TMPFILE)"
404 for i in $(cat $TMPFILE) ; do
405 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
410 # TODO: better error handling?
411 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
412 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
416 if [ "$RC" = 0 ] ; then
417 dialog --title "$PN" --msgbox \
418 "Creating $TARGET was successful." 0 0
419 rm -f "$TMPFILE" "$ERRORFILE"
421 dialog --title "$PN" --msgbox \
422 "There was an error setting up $TARGET:
427 rm -f "$TMPFILE" "$ERRORFILE"
435 if dialog --stdout --title "$PN" \
436 --defaultno --yesno "Do you want to configure Software RAID?
438 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
444 # user should recheck his configuration {{{
445 # support full automatic installation:
447 dialog --timeout 10 --title "$PN" \
448 --yesno "Do you want to stop at this stage?
450 Notice: you are running ${PN} in non-interactive mode.
451 ${PN} will install Debian ${RELEASE} on ${TARGET}.
452 Last chance to quit. Timeout of 10 seconds running....
454 Do you want to stop now?" 0 0 2>/dev/null
457 # make sure the user is aware of the used configuration {{{
460 if [ -n "$AUTOINSTALL" ] ; then
461 if checkforrun ; then
462 eerror "Exiting as requested" ; eend 0
465 elif [ -n "$INTERACTIVE" ] ; then
467 INFOTEXT="Please recheck configuration before execution:
469 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
471 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
473 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
474 Using release: $RELEASE"
475 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
476 Using hostname $HOSTNAME"
477 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
478 Using mirror: $MIRROR"
479 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
484 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
486 dialog --title "$PN" --no-collapse \
487 --yesno "$INFOTEXT" 0 0
489 else # if not running automatic installation display configuration and prompt for execution:
490 einfo "$PN - Please recheck configuration before execution:"
492 echo " Target: $TARGET"
493 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
494 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
495 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
496 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
497 [ -n "$ISO" ] && echo " Using ISO: $ISO"
498 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
500 einfon "Is this ok for you? [y/N] "
502 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
503 eerror "Exiting as requested." ; eend 1
510 # interactive mode {{{
519 prompt_for_bootmanager
527 # use first disk of sw-raid for grub by default, install grub on
528 # all involved disks later on
529 if echo "$TARGET" | grep -q '/dev/md' ; then
530 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
531 # use hdX and not hdX,Y for $GRUB
532 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
533 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
534 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
535 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
538 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
539 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
545 # run interactive mode if we didn't get the according configuration yet
546 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
547 # only target might be unset, so make sure the INTERACTIVE flag is set as well
555 # finally make sure at least $TARGET is set [the partition for the new system] {{{
556 if [ -n "$TARGET" ] ; then
557 SHORT_TARGET="${TARGET##*/}"
559 eerror "Please adjust $CONFFILES/config or..."
560 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
566 if [ -z "$STAGES" ] ; then
567 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
568 [ -d "$STAGES" ] || mkdir -p "$STAGES"
571 if [ -r "$STAGES"/grml-debootstrap ] ; then
572 if grep -q done $STAGES/grml-debootstrap ; then
573 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
574 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
579 # partition handling {{{
588 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
600 # architecture setup {{{
601 if [ -n "$ARCH" ] ; then
602 ARCHCMD="--arch $ARCH"
603 ARCHINFO=" (${ARCH})"
605 ARCH="$(dpkg --print-architecture)"
606 ARCHCMD="--arch $ARCH"
607 ARCHINFO=" (${ARCH})"
611 # make sure we have the right syntax when using an iso image {{{
612 if [ -n "$ISO" ] ; then
625 # helper functions {{{
626 # we want to exit smoothly and clean:
628 # make sure $TARGET is not mounted when exiting grml-debootstrap
629 if [ -n "$MNTPOINT" ] ; then
630 if grep -q $MNTPOINT /proc/mounts ; then
631 # make sure nothing is left inside chroot so we can unmount it
632 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
633 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
634 # ugly, but make sure we really don't leav anything
635 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
636 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
637 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
638 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
639 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
641 if [ -n "$DIRECTORY" ] ; then
642 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
644 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
647 if [ -n "$STAGES" ] ; then
648 echo -n "Removing stages directory ${STAGES}: "
649 rm -rf "$STAGES" && echo done
652 # remove directory only if we used the default with process id inside the name
653 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
654 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
659 [ -n "$1" ] && EXIT="$1" || EXIT="1"
660 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
664 trap bailout HUP INT QUIT TERM
666 # we want to execute all the functions only once, simple check for it:
668 if [ -n "$2" ] ; then
669 echo "$2" > "${STAGES}/${1}"
671 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
672 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
674 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
681 # create filesystem {{{
683 if [ -n "$DIRECTORY" ] ; then
684 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
686 if grep -q "$TARGET" /proc/mounts ; then
687 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
691 if [ -n "$MKFS" ] ; then
692 einfo "Running $MKFS on $TARGET"
694 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
702 # modify filesystem settings {{{
704 if [ -n "$TUNE2FS" ] ; then
705 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
712 # mount the new partition or if it's a directory do nothing at all {{{
714 if [ -n "$DIRECTORY" ] ; then
715 einfo "Running grml-debootstrap on a directory, nothing to mount."
717 if grep -q $TARGET /proc/mounts ; then
718 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
720 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
721 einfo "Mounting $TARGET to $MNTPOINT"
722 mount -o rw,suid,dev $TARGET $MNTPOINT
726 if [ -n "$ISODIR" ] ; then
727 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
728 mkdir -p "$MNTPOINT/$ISODIR"
729 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
735 # install main chroot {{{
736 debootstrap_system() {
737 if ! grep -q $MNTPOINT /proc/mounts ; then
740 if [ "$_opt_nodebootstrap" ]; then
741 einfo "Skipping debootstrap as requested."
744 if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then
745 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
746 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
747 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
750 eerror "Error: $MNTPOINT not mounted, can not continue."
756 # prepare chroot via chroot-script {{{
758 einfo "Preparing chroot system"
760 # provide variables to chroot system
761 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
762 touch $CHROOT_VARIABLES
763 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
764 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
765 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
766 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
767 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
768 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
769 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
770 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
771 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
772 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
773 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
774 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
775 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
776 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
778 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
779 chmod 755 $MNTPOINT/bin/chroot-script
780 mkdir $MNTPOINT/etc/debootstrap/
782 # make sure we have our files for later use via chroot-script
783 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
784 # make sure we adjust the configuration variables accordingly:
785 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
786 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
787 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
788 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
791 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
792 $MNTPOINT/etc/debootstrap/packages
794 # debconf preseeding:
795 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
796 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
797 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
799 # copy scripts that should be executed inside the chroot:
800 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
801 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
802 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
803 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
806 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
807 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
809 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
811 # make sure we can access network [relevant for cdebootstrap]
812 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
814 # provide system's /etc/hosts to the target:
815 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
816 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
819 # setup default locales
820 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
822 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
823 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
825 # copy any existing files to chroot
826 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
827 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
828 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
829 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
830 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
831 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
832 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
834 # copy local network setup to chroot
835 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
836 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
837 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
844 # execute all scripts in /etc/debootstrap/scripts/ {{{
846 # make sure we have $MNTPOINT available for our scripts
848 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
849 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
850 for script in ${scripts}/* ; do
851 if [ -x "$script" ] ; then
852 einfo "Executing script $script"
860 # execute chroot-script {{{
862 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
865 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
866 einfo "Executing chroot-script now"
867 chroot "$MNTPOINT" /bin/chroot-script
870 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
876 # install booloader grub {{{
878 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
879 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
880 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
881 for device in $SELECTED_PARTITIONS ; do
882 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
883 # GRUB="$(grubdevice ${TMPDEVICE})"
884 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
885 # GRUB=$(grubdevice $device)
886 GRUB="$(grubdevice ${device%%[0-9]})"
887 einfo "Installing grub on ${GRUB}:"
888 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
889 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
893 einfo "Installing grub on ${GRUB}:"
894 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
895 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
901 # unmount $MNTPOINRT {{{
903 if [ -n "$ISODIR" ] ; then
904 if grep -q "$ISODIR" /proc/mounts ; then
905 einfo "Unmount $MNTPOINT/$ISODIR"
906 umount "$MNTPOINT/$ISODIR"
911 if grep -q "$MNTPOINT" /proc/mounts ; then
912 if [ -n "$PARTITION" ] ; then
913 einfo "Unmount $MNTPOINT"
921 # execute filesystem check {{{
923 if [ "$FSCK" = 'yes' ] ; then
924 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
925 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
932 # now execute all the functions {{{
933 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
934 chrootscript execute_scripts grub_install umount_chroot \
936 if stage "${i}" ; then
937 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
943 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
944 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
946 # Remove temporary mountpoint again
947 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
948 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
952 # end dialog of autoinstallation {{{
953 if [ -n "$AUTOINSTALL" ] ; then
954 dialog --title "$PN" --msgbox \
955 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
957 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
961 ## END OF FILE #################################################################
962 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3