2 # Filename: grml-bootstrap
3 # Purpose: wrapper around debootstrap for installing plain Debian via grml
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
8 # http://www.debian.org/releases/stable/i386/index.html.en
10 set -e # exit on any error
15 MNTPOINT="/mnt/debootstrap.$$"
17 # inside the chroot system locales might not be available, so use minimum:
21 # make sure interactive mode is only executed when
22 # using an empty configuration file or option --interactive
26 # source core functions {{{
27 . /etc/grml/lsb-functions
28 . /etc/grml/script-functions
33 echo "$PN - wrapper around debootstrap for installing Debian
39 -m, --mirror=URL Mirror which should be used for apt-get/aptitude.
40 -i, --iso=mnt Mountpoint where a Debian ISO is mounted to, for use
41 instead of fetching packages from a mirror.
42 -r, --release=name Release of new Debian system (default: stable).
43 -t, --target=target Target partition (/dev/...) or directory.
44 -p, --mntpoint=mnt Mountpoint used for mounting the target system.
45 --debopt=params Extra parameters passed to the debootstrap.
46 --interactive Use interactive mode (frontend).
47 --nodebootstrap Skip debootstrap, only do configuration to the target.
49 Configuration options:
52 -c, --config=file Use specified configuration file, defaults to
53 /etc/debootstrap/config
54 -d, --confdir=path Place of config files for debootstrap, defaults to
56 --packages[=f] Install packages defined in <confdir>/packages. Option
57 arg: alternative package list file.
58 --debconf[=f] Pre-seed packages using <confdir>/debconf-selections.
59 Option arg: alternative pre-seed db file.
60 --keep_src_list Do not overwrite user provided apt sources.list.
61 --hostname=name Hostname of Debian system.
62 --password=pwd Use specified password as password for user root.
64 --bootappend=line Add specified appendline to kernel whilst booting.
65 --groot=device Root device for usage in grub, corresponds with
66 $TARGET in grub syntax, like hd0,0 for /dev/sda1.
67 --grub=device Target for grub installation. Use grub syntax for
68 specifying, like hd0 for /dev/sda.
72 -v, --verbose Increase verbosity.
73 -h, --help Print this usage information and exit.
74 -V, --version Show summary of options and exit.
76 Send bugreports to the grml-team: bugs@grml.org || http://grml.org/bugs/
80 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
82 echo 'Please notice that this script requires root permissions!'
87 # make sure we have what we need {{{
88 check4progs debootstrap dialog || exit 1
92 # source configuration file {{{
93 if [ -r /etc/debootstrap/config ] ; then
94 if [ -n "$CONFIGFILE" ] ; then
95 einfo "Using config file $CONFIGFILE."
96 if ! . "$CONFIGFILE" ; then
97 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
100 . /etc/debootstrap/config
105 # cmdline handling {{{
106 # source external command line parameter-processing script
107 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
109 # == business-logic of command line parameter-processing
111 # source configuration file in <confdir> if supplied. {{{
112 [ "$_opt_confdir" ] && {
113 CONFFILES=$_opt_confdir
114 einfo "Using config files under $CONFFILES/."
115 if ! [ -r "$CONFFILES/config" ] ; then
116 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
118 if ! . "$CONFFILES/config" ; then
119 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
121 # restore the command line parameter value
122 CONFFILES=$_opt_confdir
126 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
127 [ "$_opt_iso" ] && ISO=$_opt_iso
128 [ "$_opt_release" ] && RELEASE=$_opt_release
129 [ "$_opt_target" ] && TARGET=$_opt_target
130 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
131 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
132 [ "$_opt_interactive" ] && INTERACTIVE=1
133 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
134 [ "$_opt_packages_set" ] && PACKAGES='yes'
135 [ "$_opt_debconf_set" ] && DEBCONF='yes'
136 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
137 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
138 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
139 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
140 [ "$_opt_groot" ] && GROOT=$_opt_groot
141 [ "$_opt_grub" ] && GRUB=$_opt_grub
142 [ "$_opt_verbose" ] && VERBOSE="-v"
144 [ "$_opt_help" ] && {
150 [ "$_opt_version" ] && {
151 einfo "$PN - version $VERSION"
152 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
161 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
162 Do you want to continue installing Debian using this frontend?" 0 0
169 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
171 grep -v 'Extended$' | \
172 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
174 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
175 dialog --title "$PN" --trim \
176 --msgbox "Sorry, no partitions found. Please configure your
177 harddisks (see /proc/partitions) using a tool like fdisk,
178 cfdisk, gpart, gparted,..." 0 0
182 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
183 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
186 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
187 --menu "Please select the target partition:" 0 0 0 \
192 # ask for bootmanager {{{
193 prompt_for_bootmanager()
196 for device in sda hda; do
197 if [ /dev/$device != ${TARGET%[0-9]} ]; then
198 grep -q $device /proc/partitions && \
199 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
202 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
206 if echo $TARGET | grep -q "/dev/md" ; then
207 MBRPART="all disks of Software RAID $TARGET"
209 MBRPART="MBR of ${TARGET%[0-9]}"
212 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
213 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
214 mbr "install bootmanager into $MBRPART" \
215 partition "install bootmanager into partition $TARGET" \
216 nowhere "do not install bootmanager at all" \
217 ${ADDITIONAL_PARAMS})
218 [ $? -eq 0 ] || bailout 3
223 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
224 if echo $TARGET | grep -q "*md*" ; then
225 BOOT_PARTITION="${TARGET}"
227 BOOT_PARTITION="${TARGET%[0-9]}"
231 BOOT_PARTITION="$TARGET"
234 BOOT_PARTITION="/dev/hda"
237 BOOT_PARTITION="/dev/sda"
246 # ask for Debian release {{{
249 RELEASE="$(dialog --stdout --title "${PN}" --default-item etch --menu \
250 "Please enter the Debian release you would like to use for installation:" \
253 lenny Debian/testing \
254 sid Debian/unstable)"
258 # ask for hostname {{{
259 prompt_for_hostname()
261 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
262 "Please enter the hostname you would like to use for installation:" \
267 # ask for password {{{
268 prompt_for_password()
272 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
273 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
274 "Please enter the password for the root account:" 10 60)
275 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
276 "Please enter the password for the root account again for \
277 confirmation:" 10 60)
279 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
280 $(dialog --stdout --title "${PN}" --ok-label \
281 "Retry" --msgbox "Passwords do not match!" 10 60)
284 ROOTPASSWORD="$ROOTPW1"
288 # ask for Debian mirror {{{
291 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
292 "Please enter Debian mirror you would like to use for installing packages." \
293 0 0 http://ftp.de.debian.org/debian)"
297 # get grub's syntax for /dev/ice {{{
298 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
300 if [ -z "$1" ] ; then
301 echo "Usage: grubdevice <device>">&2
306 device_map=/boot/grub/device.map
309 if ! [ -f "$device_map" ] ; then
310 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
313 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
314 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
315 -e 's%\(fd[0-9]*\)$%\1%' \
316 -e 's%/part[0-9]*$%/disc%' \
317 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
318 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
319 -e 's%.*/fd[0-9]*$%%' \
320 -e 's%.*/floppy/[0-9]*$%%' \
321 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
322 -e 's%.*c[0-7]d[0-9]*p*%%'`
323 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
326 /dev/[sh]d[a-z]) # we expect something like 'hd0'
329 *) # we expect something like 'hd0,0'
330 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
336 # software raid setup {{{
337 config_swraid_setup()
341 # Currently we support only raid1:
344 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
345 # --menu "Which RAID level do you want to use?" 0 0 0 \
346 # raid1 "Software RAID level 1" \
347 # raid5 "Software RAID level 5")
348 #[ $? -eq 0 ] || bailout 20
350 MD_LIST=$(for i in $(seq 0 9) ; do
351 awk '{print $4}' /proc/partitions | grep -q md$i || \
352 echo "/dev/md$i /dev/md$i"
355 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
356 --menu "Which device do you want to use for ${RAIDLEVEL}?
358 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 \
360 [ $? -eq 0 ] || bailout 20
362 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
364 grep -v 'Extended$' | \
365 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
366 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
367 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
368 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
371 dialog --title "$PN" --separate-output \
372 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
373 $PARTITION_LIST 2>$TMPFILE
375 SELECTED_PARTITIONS="$(cat $TMPFILE)"
378 for i in $(cat $TMPFILE) ; do
379 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
384 # TODO: better error handling?
385 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
386 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
390 if [ "$RC" = 0 ] ; then
391 dialog --title "$PN" --msgbox \
392 "Creating $TARGET was successful." 0 0
393 rm -f "$TMPFILE" "$ERRORFILE"
395 dialog --title "$PN" --msgbox \
396 "There was an error setting up $TARGET:
401 rm -f "$TMPFILE" "$ERRORFILE"
409 if dialog --stdout --title "$PN" \
410 --defaultno --yesno "Do you want to configure Software RAID?
412 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
418 # make sure the user is aware of the used configuration {{{
421 if [ -n "$AUTOINSTALL" ] ; then
422 if checkforrun ; then
423 eerror "Exiting as requested" ; eend 0
426 elif [ -n "$INTERACTIVE" ] ; then
428 INFOTEXT="Please recheck configuration before execution:
430 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
432 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
434 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
435 Using release: $RELEASE"
436 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
437 Using hostname $HOSTNAME"
438 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
439 Using mirror: $MIRROR"
443 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
445 dialog --title "$PN" --no-collapse \
446 --yesno "$INFOTEXT" 0 0
448 else # if not running automatic installation display configuration and prompt for execution:
449 einfo "$PN - Please recheck configuration before execution:"
451 echo " Target: $TARGET"
452 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
453 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
454 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
455 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
456 [ -n "$ISO" ] && echo " Using iso: $ISO"
457 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
459 einfon "Is this ok for you? [y/N] "
461 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
462 eerror "Exiting as requested." ; eend 1
469 # interactive mode {{{
476 # do not prompt for partition dialog if swraid has been configured already
477 [ -n "$TARGET" ] || prompt_for_target
479 prompt_for_bootmanager
487 # use first disk of sw-raid for grub by default, install grub on
488 # all involved disks later on
489 if echo "$TARGET" | grep -q '/dev/md' ; then
490 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
491 # use hdX and not hdX,Y for $GRUB
492 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
493 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
494 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
495 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
498 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
499 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
507 # run interactive mode if we didn't get the according configuration yet
508 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
509 # only target might be unset, so make sure the INTERACTIVE flag is set as well
515 # finally make sure at least $TARGET is set [the partition for the new system] {{{
516 if [ -n "$TARGET" ] ; then
517 SHORT_TARGET="${TARGET##*/}"
519 eerror "Please adjust $CONFFILES/config or..."
520 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
526 if [ -z "$STAGES" ] ; then
527 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
528 [ -d "$STAGES" ] || mkdir -p "$STAGES"
531 if [ -r "$STAGES"/grml-debootstrap ] ; then
532 if grep -q done $STAGES/grml-debootstrap ; then
533 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
534 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
539 # partition handling {{{
548 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
560 # architecture setup {{{
561 if [ -n "$ARCH" ] ; then
562 ARCHCMD="--arch $ARCH"
563 ARCHINFO=" (${ARCH})"
565 ARCH="$(dpkg --print-architecture)"
566 ARCHCMD="--arch $ARCH"
567 ARCHINFO=" (${ARCH})"
571 # make sure we have the right syntax when using an iso image {{{
572 if [ -n "$ISO" ] ; then
585 # helper functions {{{
586 # we want to exit smoothly and clean:
588 # make sure $TARGET is not mounted when exiting grml-debootstrap
589 if [ -n "$MNTPOINT" ] ; then
590 if grep -q $MNTPOINT /proc/mounts ; then
591 # make sure nothing is left inside chroot so we can unmount it
592 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
593 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
594 # ugly, but make sure we really don't leav anything
595 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
596 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
597 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
598 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
599 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
600 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
602 if [ -n "$STAGES" ] ; then
603 echo -n "Removing stages directory ${STAGES}: "
604 rm -rf "$STAGES" && echo done
607 # remove directory only if we used the default with process id inside the name
608 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
609 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
614 [ -n "$1" ] && EXIT="$1" || EXIT="1"
615 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
619 trap bailout HUP INT QUIT TERM
621 # we want to execute all the functions only once, simple check for it:
623 if [ -n "$2" ] ; then
624 echo "$2" > "${STAGES}/${1}"
626 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
627 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
629 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
636 # user should recheck his configuration {{{
637 # support full automatic installation:
639 dialog --timeout 10 --title "$PN" \
640 --yesno "Do you want to stop at this stage?
642 Notice: you are running ${PN} in non-interactive mode.
643 ${PN} will install Debian ${RELEASE} on ${TARGET}.
644 Last chance to quit. Timeout of 10 seconds running....
646 Do you want to stop now?" 0 0 2>/dev/null
649 # create filesystem {{{
651 if [ -n "$MKFS" ] ; then
652 einfo "Running $MKFS on $TARGET"
654 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
660 # modify filesystem settings {{{
662 if [ -n "$TUNE2FS" ] ; then
663 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
670 # mount the new partition or if it's a directory do nothing at all {{{
672 if [ -n "$DIRECTORY" ] ; then
673 einfo "Running grml-debootstrap on a directory, nothing to mount."
675 if grep -q $TARGET /proc/mounts ; then
676 eerror "$TARGET already mounted, exiting."
678 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
679 einfo "Mounting $TARGET to $MNTPOINT"
680 mount -o rw,suid,dev $TARGET $MNTPOINT
684 if [ -n "$ISODIR" ] ; then
685 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
686 mkdir -p "$MNTPOINT/$ISODIR"
687 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
693 # install main chroot {{{
694 debootstrap_system() {
695 if ! grep -q $MNTPOINT /proc/mounts ; then
698 if [ "$_opt_nodebootstrap" ]; then
699 einfo "Skipping debootstrap as requested."
702 if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then
703 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
704 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
705 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
708 eerror "Error: $MNTPOINT not mounted, can not continue."
714 # prepare chroot via chroot-script {{{
716 einfo "Preparing chroot system"
718 # provide variables to chroot system
719 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
720 touch $CHROOT_VARIABLES
721 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
722 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
723 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
724 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
725 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
726 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
727 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
728 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
729 [ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> $CHROOT_VARIABLES
730 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
731 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
732 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
733 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
734 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
736 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
737 chmod 755 $MNTPOINT/bin/chroot-script
738 mkdir $MNTPOINT/etc/debootstrap/
740 # make sure we have our files for later use via chroot-script
741 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
742 # make sure we adjust the configuration variables accordingly:
743 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
744 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
745 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
746 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
748 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
749 $MNTPOINT/etc/debootstrap/packages
750 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
751 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
752 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
754 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
755 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
757 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
759 # make sure we can access network [relevant for cdebootstrap]
760 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
762 # provide system's /etc/hosts to the target:
763 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
764 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
765 sed -i "s#127.0.0.1 .*#127.0.0.1 localhost $HOSTNAME#" /etc/hosts
768 # setup default locales
769 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
771 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
772 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
774 # copy any existing files to chroot
775 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
776 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
777 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
778 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
779 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
780 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
781 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
783 # copy local network setup to chroot
784 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
785 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
786 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
793 # execute chroot-script {{{
795 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
798 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
799 einfo "Executing chroot-script now"
800 chroot "$MNTPOINT" /bin/chroot-script
803 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
809 # install booloader grub {{{
811 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
812 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
813 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
814 for device in $SELECTED_PARTITIONS ; do
815 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
816 # GRUB="$(grubdevice ${TMPDEVICE})"
817 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
818 # GRUB=$(grubdevice $device)
819 GRUB="$(grubdevice ${device%%[0-9]})"
820 einfo "Installing grub on ${GRUB}:"
821 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
822 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
826 einfo "Installing grub on ${GRUB}:"
827 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
828 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
834 # unmount $MNTPOINRT {{{
836 if [ -n "$ISODIR" ] ; then
837 if grep -q "$ISODIR" /proc/mounts ; then
838 einfo "Unmount $MNTPOINT/$ISODIR"
839 umount "$MNTPOINT/$ISODIR"
843 if grep -q "$MNTPOINT" /proc/mounts ; then
844 if [ -n "$PARTITION" ] ; then
845 einfo "Unmount $MNTPOINT"
853 # execute filesystem check {{{
855 if [ "$FSCK" = 'yes' ] ; then
856 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
857 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
864 # now execute all the functions {{{
865 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
866 chrootscript grub_install umount_chroot fscktool ; do
867 if stage "${i}" ; then
868 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
874 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
875 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
877 # Remove temporary mountpoint again
878 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
879 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
883 # end dialog of autoinstallation {{{
884 if [ -n "$AUTOINSTALL" ] ; then
885 dialog --title "$PN" --msgbox \
886 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
888 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
892 ## END OF FILE #################################################################
893 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3