2 # Filename: grml-bootstrap
3 # Purpose: wrapper around debootstrap for installing plain Debian via grml
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
8 # http://www.debian.org/releases/stable/i386/index.html.en
10 set -e # exit on any error
15 MNTPOINT="/mnt/debootstrap.$$"
17 # inside the chroot system locales might not be available, so use minimum:
21 # make sure interactive mode is only executed when
22 # using an empty configuration file or option --interactive
26 # source core functions {{{
27 . /etc/grml/lsb-functions
28 . /etc/grml/script-functions
33 echo "$PN - wrapper around debootstrap for installing Debian
39 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
40 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
41 instead of fetching packages from a mirror.
42 -r, --release <name> Release of new Debian system (default: lenny).
43 -t, --target <target> Target partition (/dev/...) or directory where the
44 system should be installed to.
45 -p, --mntpoint <mnt> Mountpoint used for mounting the target system,
46 has no effect if -t is given and represents a directory.
47 --debopt <params> Extra parameters passed to the debootstrap command.
48 --interactive Use interactive mode (frontend).
49 --nodebootstrap Skip debootstrap, only do configuration to the target.
50 --groot <device> Root device for usage in grub, corresponds with
51 \$TARGET in grub syntax, like hd0,0 for /dev/sda1.
52 --grub <device> Target for grub installation. Use grub syntax for
53 specifying, like hd0 for /dev/sda.
54 --arch <arch> Architecture to use. Currently only i386 is supported.
56 Configuration options:
58 -c, --config <file> Use specified configuration file, defaults to
59 /etc/debootstrap/config
60 -d, --confdir <path> Place of config files for debootstrap, defaults
62 --packages <file> Install packages defined in specified list file.
63 --debconf <file> Pre-seed packages using specified pre-seed db file.
64 --keep_src_list Do not overwrite user provided apt sources.list.
65 --hostname <name> Hostname of Debian system.
66 --password <pwd> Use specified password as password for user root.
67 --bootappend <line> Add specified appendline to kernel whilst booting.
68 --chroot-scripts <d> Execute chroot scripts from specified directory.
69 --scripts <dir> Execute scripts from specified directory.
73 -v, --verbose Increase verbosity.
74 -h, --help Print this usage information and exit.
75 -V, --version Show summary of options and exit.
77 Usage examples can be found in the grml-debootstrap manpage.
78 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
82 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
84 echo 'Please notice that this script requires root permissions!'
89 # make sure we have what we need {{{
90 check4progs debootstrap dialog || exit 1
94 # source configuration file {{{
95 if [ -r /etc/debootstrap/config ] ; then
96 if [ -n "$CONFIGFILE" ] ; then
97 einfo "Using config file $CONFIGFILE."
98 if ! . "$CONFIGFILE" ; then
99 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
102 . /etc/debootstrap/config
107 # cmdline handling {{{
108 # source external command line parameter-processing script
109 if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
110 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
111 elif [ -r ./cmdlineopts.clp ] ; then
114 echo "Error: cmdline function file not found, exiting.">&2
118 # == business-logic of command line parameter-processing
120 # source configuration file in <confdir> if supplied. {{{
121 [ "$_opt_confdir" ] && {
122 CONFFILES=$_opt_confdir
123 einfo "Using config files under $CONFFILES/."
124 if ! [ -r "$CONFFILES/config" ] ; then
125 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
127 if ! . "$CONFFILES/config" ; then
128 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
130 # restore the command line parameter value
131 CONFFILES=$_opt_confdir
135 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
136 [ "$_opt_iso" ] && ISO=$_opt_iso
137 [ "$_opt_release" ] && RELEASE=$_opt_release
138 [ "$_opt_target" ] && TARGET=$_opt_target
139 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
140 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
141 [ "$_opt_interactive" ] && INTERACTIVE=1
142 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
143 [ "$_opt_packages_set" ] && PACKAGES='yes'
144 [ "$_opt_debconf_set" ] && DEBCONF='yes'
145 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
146 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
147 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
148 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
149 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
150 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
151 [ "$_opt_groot" ] && GROOT=$_opt_groot
152 [ "$_opt_grub" ] && GRUB=$_opt_grub
153 [ "$_opt_arch" ] && ARCH=$_opt_arch
154 [ "$_opt_verbose" ] && VERBOSE="-v"
156 [ "$_opt_help" ] && {
162 [ "$_opt_version" ] && {
163 einfo "$PN - version $VERSION"
164 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
173 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
174 Do you want to continue installing Debian using this frontend?" 0 0
181 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
183 grep -v 'Extended$' | \
184 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
186 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
187 dialog --title "$PN" --trim \
188 --msgbox "Sorry, no partitions found. Please configure your
189 harddisks (see /proc/partitions) using a tool like fdisk,
190 cfdisk, gpart, gparted,..." 0 0
194 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
195 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
198 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
199 --menu "Please select the target partition:" 0 0 0 \
204 # ask for bootmanager {{{
205 prompt_for_bootmanager()
209 if echo "$TARGET" | grep -q "/dev/md" ; then
210 MBRPART="all disks of Software RAID $TARGET"
212 # figure out whole disk device
214 for device in /dev/disk/by-id/*
216 [ $(readlink -f $device) = ${TARGET} ] || continue
220 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
221 if [ -e "$MBRDISK" ]; then
222 MBRDISK=$(readlink -f $MBRDISK)
224 # fall back to old behaviour
225 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$/')
228 MBRPART="MBR of $MBRDISK"
231 for device in cciss/c0d0 sda hda; do
232 if [ /dev/$device != ${MBRDISK} ]; then
233 grep -q $device /proc/partitions && \
234 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
237 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
241 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
242 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
243 mbr "install bootmanager into $MBRPART" \
244 partition "install bootmanager into partition $TARGET" \
245 nowhere "do not install bootmanager at all" \
246 ${ADDITIONAL_PARAMS})
247 [ $? -eq 0 ] || bailout 3
252 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
253 if echo "$TARGET" | grep -q "/dev/md" ; then
254 BOOT_PARTITION="$TARGET"
256 BOOT_PARTITION="$MBRDISK"
260 BOOT_PARTITION="$TARGET"
263 BOOT_PARTITION="/dev/hda"
266 BOOT_PARTITION="/dev/sda"
275 # ask for Debian release {{{
278 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
279 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
280 "Please enter the Debian release you would like to use for installation:" \
282 etch Debian/old-stable \
283 lenny Debian/stable \
284 squeeze Debian/testing \
285 sid Debian/unstable)"
289 # ask for hostname {{{
290 prompt_for_hostname()
292 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
293 "Please enter the hostname you would like to use for installation:" \
298 # ask for password {{{
299 prompt_for_password()
303 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
304 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
305 "Please enter the password for the root account:" 10 60)
306 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
307 "Please enter the password for the root account again for \
308 confirmation:" 10 60)
310 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
311 $(dialog --stdout --title "${PN}" --ok-label \
312 "Retry" --msgbox "Passwords do not match!" 10 60)
315 ROOTPASSWORD="$ROOTPW1"
319 # ask for Debian mirror {{{
322 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
324 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
325 --menu "Where do you want to install from?" 0 0 0 \
326 net "install via network (downloading from mirror)" \
327 local "install from local directory/mirror"
330 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
331 [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
332 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
333 "Please enter Debian mirror you would like to use for installing packages." \
335 else # CHROOT_VARIABLES == local
336 [ -n "$ISO" ] || ISO='/mnt/mirror'
337 ISO="$(dialog --stdout --title "${PN}" --inputbox \
338 "Please enter directory name you would like to use for installing packages." \
344 # get grub's syntax for /dev/ice {{{
345 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
347 if [ -z "$1" ] ; then
348 echo "Usage: grubdevice <device>">&2
356 if which grub >/dev/null 2>&1 ; then
357 echo 'quit' | grub --device-map="$device_map" >/dev/null 2>&1
358 elif which grub-mkdevicemap >/dev/null 2>&1 ; then
359 grub-mkdevicemap --device-map="$device_map" >/dev/null 2>&1
361 echo "Error: neither grub nor grub-mkdevicemap command found." >&2
365 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
366 tmp_disk=$(echo "$device" | sed -e 's%\(\(s\|h\|v\|xv\)d[a-z]\)[0-9]*$%\1%' \
367 -e 's%\(fd[0-9]*\)$%\1%' \
368 -e 's%/part[0-9]*$%/disc%' \
369 -e 's%\(c[0-7]d[0-9]*\).*$%\1%' \
370 -e 's%\(mmcblk[0-9]d[0-9]*\).*$%\1%' \
371 -e 's%\(/mapper/mpath[0-9]\+\)-part[0-9]\+$%\1%')
372 tmp_part=$(echo "$device" | sed -e 's%.*/\(s\|h\|v\|xv\)d[a-z]\([0-9]*\)$%\2%' \
373 -e 's%.*/fd[0-9]*$%%' \
374 -e 's%.*/floppy/[0-9]*$%%' \
375 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
376 -e 's%.*c[0-7]d[0-9]*p*%%' \
377 -e 's%.*mmcblk[0-9]d[0-9]*p%%' \
378 -e 's%.*/mapper/mpath[0-9]\+-part\([0-9]\+\)%\1%')
379 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
381 if [ -z "$tmp_drive" ]; then
382 echo "Error: $device does not have any corresponding BIOS drive." >&2
387 /dev/[sh]d[a-z]) # we expect something like 'hd0'
390 *) # we expect something like 'hd0,0'
391 echo "$tmp_drive" | sed "s%$%,$(expr $tmp_part - 1)%" # FIXME => md0
398 # software raid setup {{{
399 config_swraid_setup()
403 # Currently we support only raid1:
406 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
407 # --menu "Which RAID level do you want to use?" 0 0 0 \
408 # raid1 "Software RAID level 1" \
409 # raid5 "Software RAID level 5")
410 #[ $? -eq 0 ] || bailout 20
412 MD_LIST=$(for i in $(seq 0 9) ; do
413 awk '{print $4}' /proc/partitions | grep -q md$i || \
414 echo "/dev/md$i /dev/md$i"
417 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
418 --menu "Which device do you want to use for ${RAIDLEVEL}?
420 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 \
422 [ $? -eq 0 ] || bailout 20
424 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
426 grep -v 'Extended$' | \
427 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
428 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
429 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
430 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
433 dialog --title "$PN" --separate-output \
434 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
435 $PARTITION_LIST 2>$TMPFILE
437 SELECTED_PARTITIONS="$(cat $TMPFILE)"
440 for i in $(cat $TMPFILE) ; do
441 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
446 # TODO: better error handling?
447 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
448 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
452 if [ "$RC" = 0 ] ; then
453 dialog --title "$PN" --msgbox \
454 "Creating $TARGET was successful." 0 0
455 rm -f "$TMPFILE" "$ERRORFILE"
457 dialog --title "$PN" --msgbox \
458 "There was an error setting up $TARGET:
463 rm -f "$TMPFILE" "$ERRORFILE"
471 if dialog --stdout --title "$PN" \
472 --defaultno --yesno "Do you want to configure Software RAID?
474 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
480 # user should recheck his configuration {{{
481 # support full automatic installation:
483 dialog --timeout 10 --title "$PN" \
484 --yesno "Do you want to stop at this stage?
486 Notice: you are running ${PN} in non-interactive mode.
487 ${PN} will install Debian ${RELEASE} on ${TARGET}.
488 Last chance to quit. Timeout of 10 seconds running....
490 Do you want to stop now?" 0 0 2>/dev/null
493 # make sure the user is aware of the used configuration {{{
496 if [ -n "$AUTOINSTALL" ] ; then
497 if checkforrun ; then
498 eerror "Exiting as requested" ; eend 0
501 elif [ -n "$INTERACTIVE" ] ; then
503 INFOTEXT="Please recheck configuration before execution:
505 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
507 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
509 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
510 Using release: $RELEASE"
511 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
512 Using hostname $HOSTNAME"
513 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
514 Using mirror: $MIRROR"
515 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
520 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
522 dialog --title "$PN" --no-collapse \
523 --yesno "$INFOTEXT" 0 0
525 else # if not running automatic installation display configuration and prompt for execution:
526 einfo "$PN - Please recheck configuration before execution:"
528 echo " Target: $TARGET"
530 # do not display if MNTPOINT is the default one
531 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
533 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
534 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
535 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
536 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
537 [ -n "$ISO" ] && echo " Using ISO: $ISO"
539 echo " Important! Continuing will delete all data from ${TARGET}!"
542 einfon "Is this ok for you? [y/N] "
544 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
545 eerror "Exiting as requested." ; eend 1
552 # interactive mode {{{
561 prompt_for_bootmanager
569 # use first disk of sw-raid for grub by default, install grub on
570 # all involved disks later on
571 if echo "$TARGET" | grep -q '/dev/md' ; then
572 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
573 # use hdX and not hdX,Y for $GRUB
574 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
575 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
576 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
579 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
580 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
586 # run interactive mode if we didn't get the according configuration yet
587 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
588 # only target might be unset, so make sure the INTERACTIVE flag is set as well
596 # finally make sure at least $TARGET is set [the partition for the new system] {{{
597 if [ -n "$TARGET" ] ; then
598 SHORT_TARGET="${TARGET##*/}"
600 eerror "Please adjust $CONFFILES/config or..."
601 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
607 if [ -z "$STAGES" ] ; then
608 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
609 [ -d "$STAGES" ] || mkdir -p "$STAGES"
612 if [ -r "$STAGES"/grml-debootstrap ] ; then
613 if grep -q done $STAGES/grml-debootstrap ; then
614 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
615 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
620 # partition handling {{{
629 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
641 # architecture setup {{{
642 if [ -n "$ARCH" ] ; then
643 ARCHCMD="--arch $ARCH"
644 ARCHINFO=" (${ARCH})"
646 ARCH="$(dpkg --print-architecture)"
647 ARCHCMD="--arch $ARCH"
648 ARCHINFO=" (${ARCH})"
652 # make sure we have the right syntax when using an iso image {{{
653 if [ -n "$ISO" ] ; then
666 # helper functions {{{
667 # we want to exit smoothly and clean:
669 # make sure $TARGET is not mounted when exiting grml-debootstrap
670 if [ -n "$MNTPOINT" ] ; then
671 if grep -q $MNTPOINT /proc/mounts ; then
672 # make sure nothing is left inside chroot so we can unmount it
673 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
674 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
675 # ugly, but make sure we really don't leav anything
676 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
677 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
678 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
679 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
680 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
682 if [ -n "$DIRECTORY" ] ; then
683 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
685 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
688 if [ -n "$STAGES" ] ; then
689 echo -n "Removing stages directory ${STAGES}: "
690 rm -rf "$STAGES" && echo done
693 # remove directory only if we used the default with process id inside the name
694 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
695 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
700 [ -n "$1" ] && EXIT="$1" || EXIT="1"
701 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
705 trap bailout HUP INT QUIT TERM
707 # we want to execute all the functions only once, simple check for it:
709 if [ -n "$2" ] ; then
710 echo "$2" > "${STAGES}/${1}"
712 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
713 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
715 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
722 # create filesystem {{{
724 if [ -n "$DIRECTORY" ] ; then
725 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
727 if grep -q "$TARGET" /proc/mounts ; then
728 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
732 if [ -n "$MKFS" ] ; then
733 einfo "Running $MKFS on $TARGET"
735 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
743 # modify filesystem settings {{{
745 if [ -n "$TUNE2FS" ] ; then
746 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
753 # mount the new partition or if it's a directory do nothing at all {{{
755 if [ -n "$DIRECTORY" ] ; then
756 einfo "Running grml-debootstrap on a directory, nothing to mount."
758 if grep -q $TARGET /proc/mounts ; then
759 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
761 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
762 einfo "Mounting $TARGET to $MNTPOINT"
763 mount -o rw,suid,dev $TARGET $MNTPOINT
767 if [ -n "$ISODIR" ] ; then
768 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
769 mkdir -p "$MNTPOINT/$ISODIR"
770 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
776 # install main chroot {{{
777 debootstrap_system() {
778 if [ "$_opt_nodebootstrap" ]; then
779 einfo "Skipping debootstrap as requested."
783 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
784 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
785 if [ -n "$MIRROR" ] ; then
786 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
788 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
792 eerror "Error: $MNTPOINT not mounted, can not continue."
798 # prepare chroot via chroot-script {{{
800 einfo "Preparing chroot system"
802 # provide variables to chroot system
803 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
804 touch $CHROOT_VARIABLES
805 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
806 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
807 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
808 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
809 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
810 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
811 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
812 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
813 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
814 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
815 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
816 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
817 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
818 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
820 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
821 chmod 755 $MNTPOINT/bin/chroot-script
822 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
824 # make sure we have our files for later use via chroot-script
825 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
826 # make sure we adjust the configuration variables accordingly:
827 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
828 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
829 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
830 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
833 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
834 $MNTPOINT/etc/debootstrap/packages
836 # debconf preseeding:
837 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
838 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
839 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
841 # copy scripts that should be executed inside the chroot:
842 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
843 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
844 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
845 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
848 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
849 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
851 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
853 # make sure we can access network [relevant for cdebootstrap]
854 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
856 # provide system's /etc/hosts to the target:
857 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
858 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
861 # setup default locales
862 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
864 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
865 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
867 # copy any existing files to chroot
868 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
869 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
870 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
871 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
872 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
873 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
874 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
876 # copy local network setup to chroot
877 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
878 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
879 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
886 # execute all scripts in /etc/debootstrap/scripts/ {{{
888 # make sure we have $MNTPOINT available for our scripts
890 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
891 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
892 for script in ${scripts}/* ; do
893 if [ -x "$script" ] ; then
894 einfo "Executing script $script"
902 # execute chroot-script {{{
904 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
907 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
908 einfo "Executing chroot-script now"
909 chroot "$MNTPOINT" /bin/chroot-script
912 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
918 # install booloader grub {{{
920 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
921 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
922 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
923 for device in $SELECTED_PARTITIONS ; do
924 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
925 # GRUB="$(grubdevice ${TMPDEVICE})"
926 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
927 # GRUB=$(grubdevice $device)
928 GRUB="$(grubdevice ${device%%[0-9]})"
929 einfo "Installing grub on ${GRUB}:"
930 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
931 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
935 einfo "Installing grub on ${GRUB}:"
936 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
937 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
943 # unmount $MNTPOINRT {{{
945 if [ -n "$ISODIR" ] ; then
946 if grep -q "$ISODIR" /proc/mounts ; then
947 einfo "Unmount $MNTPOINT/$ISODIR"
948 umount "$MNTPOINT/$ISODIR"
953 if grep -q "$MNTPOINT" /proc/mounts ; then
954 if [ -n "$PARTITION" ] ; then
955 einfo "Unmount $MNTPOINT"
963 # execute filesystem check {{{
965 if [ "$FSCK" = 'yes' ] ; then
966 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
967 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
974 # now execute all the functions {{{
975 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
976 chrootscript execute_scripts grub_install umount_chroot \
978 if stage "${i}" ; then
979 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
985 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
986 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
988 # Remove temporary mountpoint again
989 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
990 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
994 # end dialog of autoinstallation {{{
995 if [ -n "$AUTOINSTALL" ] ; then
996 dialog --title "$PN" --msgbox \
997 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
999 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1003 ## END OF FILE #################################################################
1004 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3