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
14 prog_real=`readlink -f -- $0`
16 MNTPOINT="/mnt/debootstrap.$$"
18 # inside the chroot system locales might not be available, so use minimum:
22 # make sure interactive mode is only executed when
23 # using an empty configuration file or option --interactive
27 # source core functions {{{
28 . /etc/grml/lsb-functions
29 . /etc/grml/script-functions
34 echo "$PN - wrapper around debootstrap for installing Debian
40 -m, --mirror=URL Mirror which should be used for apt-get/aptitude.
41 -i, --iso=mnt Mountpoint where a Debian ISO is mounted to, for use
42 instead of fetching packages from a mirror.
43 -r, --release=name Release of new Debian system (default: stable).
44 -t, --target=target Target partition (/dev/...) or directory.
45 -p, --mntpoint=mnt Mountpoint used for mounting the target system.
46 --debopt=params Extra parameters passed to the debootstrap.
47 --interactive Use interactive mode (frontend).
48 --nodebootstrap Skip debootstrap, only do configuration to the target.
50 Configuration options:
53 -c, --config=file Use specified configuration file, defaults to
54 /etc/debootstrap/config
55 -d, --confdir=path Place of config files for debootstrap, defaults to
57 --packages[=f] Install packages defined in <confdir>/packages. Option
58 arg: alternative package list file.
59 --debconf[=f] Pre-seed packages using <confdir>/debconf-selections.
60 Option arg: alternative 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.
65 --bootappend=line Add specified appendline to kernel whilst booting.
66 --groot=device Root device for usage in grub, corresponds with
67 $TARGET in grub syntax, like hd0,0 for /dev/sda1.
68 --grub=device Target for grub installation. Use grub syntax for
69 specifying, like hd0 for /dev/sda.
73 -v, --verbose Increase verbosity.
74 -h, --help Print this usage information and exit.
75 -V, --version Show summary of options and exit.
77 Send bugreports to the grml-team: bugs@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
110 # == business-logic of command line parameter-processing
112 # source configuration file in <confdir> if supplied. {{{
113 [ "$_opt_confdir" ] && {
114 CONFFILES=$_opt_confdir
115 einfo "Using config files under $CONFFILES/."
116 if ! [ -r "$CONFFILES/config" ] ; then
117 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
119 if ! . "$CONFFILES/config" ; then
120 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
125 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
126 [ "$_opt_iso" ] && ISO=$_opt_iso
127 [ "$_opt_release" ] && RELEASE=$_opt_release
128 [ "$_opt_target" ] && TARGET=$_opt_target
129 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
130 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
131 [ "$_opt_interactive" ] && INTERACTIVE=1
132 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
133 [ "$_opt_packages_set" ] && PACKAGES='yes'
134 [ "$_opt_debconf_set" ] && DEBCONF='yes'
135 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
136 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
137 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
138 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
139 [ "$_opt_groot" ] && GROOT=$_opt_groot
140 [ "$_opt_grub" ] && GRUB=$_opt_grub
141 [ "$_opt_verbose" ] && VERBOSE="-v"
143 [ "$_opt_help" ] && {
149 [ "$_opt_version" ] && {
150 einfo "$PN - version $VERSION"
151 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
160 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
161 Do you want to continue installing Debian using this frontend?" 0 0
168 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
170 grep -v 'Extended$' | \
171 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
173 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
174 dialog --title "$PN" --trim \
175 --msgbox "Sorry, no partitions found. Please configure your
176 harddisks (see /proc/partitions) using a tool like fdisk,
177 cfdisk, gpart, gparted,..." 0 0
181 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
182 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
185 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
186 --menu "Please select the target partition:" 0 0 0 \
191 # ask for bootmanager {{{
192 prompt_for_bootmanager()
195 for device in sda hda; do
196 if [ /dev/$device != ${TARGET%[0-9]} ]; then
197 grep -q $device /proc/partitions && \
198 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
201 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
205 if echo $TARGET | grep -q "/dev/md" ; then
206 MBRPART="all disks of Software RAID $TARGET"
208 MBRPART="MBR of ${TARGET%[0-9]}"
211 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
212 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
213 mbr "install bootmanager into $MBRPART" \
214 partition "install bootmanager into partition $TARGET" \
215 nowhere "do not install bootmanager at all" \
216 ${ADDITIONAL_PARAMS})
217 [ $? -eq 0 ] || bailout 3
222 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
223 if echo $TARGET | grep -q "*md*" ; then
224 BOOT_PARTITION="${TARGET}"
226 BOOT_PARTITION="${TARGET%[0-9]}"
230 BOOT_PARTITION="$TARGET"
233 BOOT_PARTITION="/dev/hda"
236 BOOT_PARTITION="/dev/sda"
245 # ask for Debian release {{{
248 RELEASE="$(dialog --stdout --title "${PN}" --default-item etch --menu \
249 "Please enter the Debian release you would like to use for installation:" \
252 lenny Debian/testing \
253 sid Debian/unstable)"
257 # ask for hostname {{{
258 prompt_for_hostname()
260 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
261 "Please enter the hostname you would like to use for installation:" \
266 # ask for password {{{
267 prompt_for_password()
271 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
272 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
273 "Please enter the password for the root account:" 10 60)
274 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
275 "Please enter the password for the root account again for \
276 confirmation:" 10 60)
278 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
279 $(dialog --stdout --title "${PN}" --ok-label \
280 "Retry" --msgbox "Passwords do not match!" 10 60)
283 ROOTPASSWORD="$ROOTPW1"
287 # ask for Debian mirror {{{
290 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
291 "Please enter Debian mirror you would like to use for installing packages." \
292 0 0 http://ftp.de.debian.org/debian)"
296 # get grub's syntax for /dev/ice {{{
297 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
299 if [ -z "$1" ] ; then
300 echo "Usage: grubdevice <device>">&2
305 device_map=/boot/grub/device.map
308 if ! [ -f "$device_map" ] ; then
309 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
312 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
313 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
314 -e 's%\(fd[0-9]*\)$%\1%' \
315 -e 's%/part[0-9]*$%/disc%' \
316 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
317 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
318 -e 's%.*/fd[0-9]*$%%' \
319 -e 's%.*/floppy/[0-9]*$%%' \
320 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
321 -e 's%.*c[0-7]d[0-9]*p*%%'`
322 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
325 /dev/[sh]d[a-z]) # we expect something like 'hd0'
328 *) # we expect something like 'hd0,0'
329 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
335 # software raid setup {{{
336 config_swraid_setup()
340 # Currently we support only raid1:
343 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
344 # --menu "Which RAID level do you want to use?" 0 0 0 \
345 # raid1 "Software RAID level 1" \
346 # raid5 "Software RAID level 5")
347 #[ $? -eq 0 ] || bailout 20
349 MD_LIST=$(for i in $(seq 0 9) ; do
350 awk '{print $4}' /proc/partitions | grep -q md$i || \
351 echo "/dev/md$i /dev/md$i"
354 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
355 --menu "Which device do you want to use for ${RAIDLEVEL}?
357 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 \
359 [ $? -eq 0 ] || bailout 20
361 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
363 grep -v 'Extended$' | \
364 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
365 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
366 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
367 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
370 dialog --title "$PN" --separate-output \
371 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
372 $PARTITION_LIST 2>$TMPFILE
374 SELECTED_PARTITIONS="$(cat $TMPFILE)"
377 for i in $(cat $TMPFILE) ; do
378 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
383 # TODO: better error handling?
384 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
385 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
389 if [ "$RC" = 0 ] ; then
390 dialog --title "$PN" --msgbox \
391 "Creating $TARGET was successful." 0 0
392 rm -f "$TMPFILE" "$ERRORFILE"
394 dialog --title "$PN" --msgbox \
395 "There was an error setting up $TARGET:
400 rm -f "$TMPFILE" "$ERRORFILE"
408 if dialog --stdout --title "$PN" \
409 --defaultno --yesno "Do you want to configure Software RAID?
411 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
417 # make sure the user is aware of the used configuration {{{
420 if [ -n "$AUTOINSTALL" ] ; then
421 if checkforrun ; then
422 eerror "Exiting as requested" ; eend 0
425 elif [ -n "$INTERACTIVE" ] ; then
427 INFOTEXT="Please recheck configuration before execution:
429 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
431 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
433 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
434 Using release: $RELEASE"
435 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
436 Using hostname $HOSTNAME"
437 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
438 Using mirror: $MIRROR"
442 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
444 dialog --title "$PN" --no-collapse \
445 --yesno "$INFOTEXT" 0 0
447 else # if not running automatic installation display configuration and prompt for execution:
448 einfo "$PN - Please recheck configuration before execution:"
450 echo " Target: $TARGET"
451 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
452 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
453 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
454 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
455 [ -n "$ISO" ] && echo " Using iso: $ISO"
456 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
458 einfon "Is this ok for you? [y/N] "
460 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
461 eerror "Exiting as requested." ; eend 1
468 # interactive mode {{{
475 # do not prompt for partition dialog if swraid has been configured already
476 [ -n "$TARGET" ] || prompt_for_target
478 prompt_for_bootmanager
486 # use first disk of sw-raid for grub by default, install grub on
487 # all involved disks later on
488 if echo "$TARGET" | grep -q '/dev/md' ; then
489 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
490 # use hdX and not hdX,Y for $GRUB
491 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
492 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
493 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
494 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
497 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
498 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
506 # run interactive mode if we didn't get the according configuration yet
507 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
508 # only target might be unset, so make sure the INTERACTIVE flag is set as well
514 # finally make sure at least $TARGET is set [the partition for the new system] {{{
515 if [ -n "$TARGET" ] ; then
516 SHORT_TARGET="${TARGET##*/}"
518 eerror "Please adjust $CONFFILES/config or..."
519 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
525 if [ -z "$STAGES" ] ; then
526 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
527 [ -d "$STAGES" ] || mkdir -p "$STAGES"
530 if [ -r "$STAGES"/grml-debootstrap ] ; then
531 if grep -q done $STAGES/grml-debootstrap ; then
532 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
533 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
538 # partition handling {{{
547 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
559 # architecture setup {{{
560 if [ -n "$ARCH" ] ; then
561 ARCHCMD="--arch $ARCH"
562 ARCHINFO=" (${ARCH})"
564 ARCH="$(dpkg --print-architecture)"
565 ARCHCMD="--arch $ARCH"
566 ARCHINFO=" (${ARCH})"
570 # make sure we have the right syntax when using an iso image {{{
571 if [ -n "$ISO" ] ; then
584 # helper functions {{{
585 # we want to exit smoothly and clean:
587 # make sure $TARGET is not mounted when exiting grml-debootstrap
588 if [ -n "$MNTPOINT" ] ; then
589 if grep -q $MNTPOINT /proc/mounts ; then
590 # make sure nothing is left inside chroot so we can unmount it
591 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
592 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
593 # ugly, but make sure we really don't leav anything
594 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
595 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
596 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
597 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
598 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
599 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
601 if [ -n "$STAGES" ] ; then
602 echo -n "Removing stages directory ${STAGES}: "
603 rm -rf "$STAGES" && echo done
606 # remove directory only if we used the default with process id inside the name
607 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
608 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
613 [ -n "$1" ] && EXIT="$1" || EXIT="1"
614 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
618 trap bailout HUP INT QUIT TERM
620 # we want to execute all the functions only once, simple check for it:
622 if [ -n "$2" ] ; then
623 echo "$2" > "${STAGES}/${1}"
625 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
626 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
628 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
635 # user should recheck his configuration {{{
636 # support full automatic installation:
638 dialog --timeout 10 --title "$PN" \
639 --yesno "Do you want to stop at this stage?
641 Notice: you are running ${PN} in non-interactive mode.
642 ${PN} will install Debian ${RELEASE} on ${TARGET}.
643 Last chance to quit. Timeout of 10 seconds running....
645 Do you want to stop now?" 0 0 2>/dev/null
648 # create filesystem {{{
650 if [ -n "$MKFS" ] ; then
651 einfo "Running $MKFS on $TARGET"
653 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
659 # modify filesystem settings {{{
661 if [ -n "$TUNE2FS" ] ; then
662 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
669 # mount the new partition or if it's a directory do nothing at all {{{
671 if [ -n "$DIRECTORY" ] ; then
672 einfo "Running grml-debootstrap on a directory, nothing to mount."
674 if grep -q $TARGET /proc/mounts ; then
675 eerror "$TARGET already mounted, exiting."
677 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
678 einfo "Mounting $TARGET to $MNTPOINT"
679 mount -o rw,suid,dev $TARGET $MNTPOINT
683 if [ -n "$ISODIR" ] ; then
684 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
685 mkdir -p "$MNTPOINT/$ISODIR"
686 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
692 # install main chroot {{{
693 debootstrap_system() {
694 if ! grep -q $MNTPOINT /proc/mounts ; then
697 if [ "$_opt_nodebootstrap" ]; then
698 einfo "Skipping debootstrap as requested."
701 if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then
702 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
703 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
704 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
707 eerror "Error: $MNTPOINT not mounted, can not continue."
713 # prepare chroot via chroot-script {{{
715 einfo "Preparing chroot system"
717 # provide variables to chroot system
718 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
719 touch $CHROOT_VARIABLES
720 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
721 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
722 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
723 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
724 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
725 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
726 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
727 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
728 [ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> $CHROOT_VARIABLES
729 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
730 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
731 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
732 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
733 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
735 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
736 chmod 755 $MNTPOINT/bin/chroot-script
737 mkdir $MNTPOINT/etc/debootstrap/
739 # make sure we have our files for later use via chroot-script
740 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
741 # make sure we adjust the configuration variables accordingly:
742 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
743 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
744 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
745 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
747 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
748 $MNTPOINT/etc/debootstrap/packages
749 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
750 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
751 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
753 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
754 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
756 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
758 # make sure we can access network [relevant for cdebootstrap]
759 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
761 # provide system's /etc/hosts to the target:
762 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
763 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
764 sed -i "s#127.0.0.1 .*#127.0.0.1 localhost $HOSTNAME#" /etc/hosts
767 # setup default locales
768 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
770 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
771 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
773 # copy any existing files to chroot
774 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
775 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
776 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
777 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
778 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
779 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
780 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
782 # copy local network setup to chroot
783 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
784 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
785 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
792 # execute chroot-script {{{
794 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
797 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
798 einfo "Executing chroot-script now"
799 chroot "$MNTPOINT" /bin/chroot-script
802 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
808 # install booloader grub {{{
810 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
811 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
812 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
813 for device in $SELECTED_PARTITIONS ; do
814 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
815 # GRUB="$(grubdevice ${TMPDEVICE})"
816 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
817 # GRUB=$(grubdevice $device)
818 GRUB="$(grubdevice ${device%%[0-9]})"
819 einfo "Installing grub on ${GRUB}:"
820 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
821 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
825 einfo "Installing grub on ${GRUB}:"
826 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
827 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
833 # unmount $MNTPOINRT {{{
835 if [ -n "$ISODIR" ] ; then
836 if grep -q "$ISODIR" /proc/mounts ; then
837 einfo "Unmount $MNTPOINT/$ISODIR"
838 umount "$MNTPOINT/$ISODIR"
842 if grep -q "$MNTPOINT" /proc/mounts ; then
843 if [ -n "$PARTITION" ] ; then
844 einfo "Unmount $MNTPOINT"
852 # execute filesystem check {{{
854 if [ "$FSCK" = 'yes' ] ; then
855 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
856 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
863 # now execute all the functions {{{
864 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
865 chrootscript grub_install umount_chroot fscktool ; do
866 if stage "${i}" ; then
867 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
873 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
874 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
876 # Remove temporary mountpoint again
877 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
878 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
882 # end dialog of autoinstallation {{{
883 if [ -n "$AUTOINSTALL" ] ; then
884 dialog --title "$PN" --msgbox \
885 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
887 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
891 ## END OF FILE #################################################################
892 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3