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 --grub <device> Target for grub installation. Usage example: /dev/sda
51 --arch <arch> Architecture to use. Currently only i386 is supported.
52 --filesystem <fs> Filesystem that should be used when target is a partition.
53 --insecure Do not download and check Release file signatures.
55 Configuration options:
57 -c, --config <file> Use specified configuration file, defaults to
58 /etc/debootstrap/config
59 -d, --confdir <path> Place of config files for debootstrap, defaults
61 --packages <file> Install packages defined in specified list file.
62 --nopackages Skip installation of packages defined in
63 /etc/debootstrap/packages
64 --debconf <file> Pre-seed packages using specified pre-seed db file.
65 --keep_src_list Do not overwrite user provided apt sources.list.
66 --hostname <name> Hostname of Debian system.
67 --password <pwd> Use specified password as password for user root.
68 --bootappend <line> Add specified appendline to kernel whilst booting.
69 --chroot-scripts <d> Execute chroot scripts from specified directory.
70 --pre-scripts <dir> Execute scripts from specified directory (before chroot-scripts).
71 --scripts <dir> Execute scripts from specified directory (after chroot-scripts).
75 -v, --verbose Increase verbosity.
76 -h, --help Print this usage information and exit.
77 -V, --version Show summary of options and exit.
79 Usage examples can be found in the grml-debootstrap manpage.
80 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
84 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
86 echo 'Please notice that this script requires root permissions!'
91 # make sure we have what we need {{{
92 check4progs debootstrap dialog || exit 1
96 # source configuration file {{{
97 if [ -r /etc/debootstrap/config ] ; then
98 if [ -n "$CONFIGFILE" ] ; then
99 einfo "Using config file $CONFIGFILE."
100 if ! . "$CONFIGFILE" ; then
101 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
104 . /etc/debootstrap/config
109 # cmdline handling {{{
110 # source external command line parameter-processing script
111 if [ -r ./cmdlineopts.clp ] ; then
113 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
114 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
116 echo "Error: cmdline function file not found, exiting.">&2
120 # == business-logic of command line parameter-processing
122 # source configuration file in <confdir> if supplied. {{{
123 [ "$_opt_confdir" ] && {
124 CONFFILES=$_opt_confdir
125 einfo "Using config files under $CONFFILES/."
126 if ! [ -r "$CONFFILES/config" ] ; then
127 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
129 if ! . "$CONFFILES/config" ; then
130 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
132 # restore the command line parameter value
133 CONFFILES=$_opt_confdir
137 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
138 [ "$_opt_iso" ] && ISO=$_opt_iso
139 [ "$_opt_release" ] && RELEASE=$_opt_release
140 [ "$_opt_target" ] && TARGET=$_opt_target
141 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
142 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
143 [ "$_opt_interactive" ] && INTERACTIVE=1
144 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
145 [ "$_opt_filesystem" ] && MKFS="mkfs.$_opt_filesystem"
146 [ "$_opt_packages_set" ] && PACKAGES='yes'
147 [ "$_opt_nopackages" ] && PACKAGES=''
148 [ "$_opt_debconf_set" ] && DEBCONF='yes'
149 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
150 [ "$_opt_pre_scripts_set" ] && PRE_SCRIPTS='yes'
151 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
152 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
153 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
154 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
155 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
156 [ "$_opt_grub" ] && GRUB=$_opt_grub
157 [ "$_opt_arch" ] && ARCH=$_opt_arch
158 [ "$_opt_insecure" ] && SECURE='false'
159 [ "$_opt_verbose" ] && VERBOSE="-v"
161 [ "$_opt_help" ] && {
167 [ "$_opt_version" ] && {
168 einfo "$PN - version $VERSION"
169 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
175 # backwards compability checks {{{
176 if [ -n "$GROOT" ] ; then
177 echo "Error: you seem to have \$GROOT configured." >&2
178 echo "This variable is no longer supported, please visit the" >&2
179 echo "grml-debootstrap documentation for details." >&2
183 if echo "$GRUB" | grep -q '^hd' ; then
184 echo "Error: this syntax for the grub configuration variable is no longer supported." >&2
185 echo "Please do not use hd... any longer but /dev/sdX instead." >&2
193 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
194 Do you want to continue installing Debian using this frontend?" 0 0
201 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
203 grep -v 'Extended$' | \
204 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
206 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
207 dialog --title "$PN" --trim \
208 --msgbox "Sorry, no partitions found. Please configure your
209 harddisks (see /proc/partitions) using a tool like fdisk,
210 cfdisk, gpart, gparted,..." 0 0
214 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
215 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet])"
218 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
219 --menu "Please select the target partition:" 0 0 0 \
224 # ask for bootmanager {{{
225 prompt_for_bootmanager()
229 if echo "$TARGET" | grep -q "/dev/md" ; then
230 MBRPART="all disks of Software RAID $TARGET"
232 # figure out whole disk device
234 for device in /dev/disk/by-id/*
236 [ $(readlink -f $device) = ${TARGET} ] || continue
240 [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
241 if [ -e "$MBRDISK" ]; then
242 MBRDISK=$(readlink -f $MBRDISK)
244 # fall back to old behaviour
245 MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$//')
248 MBRPART="MBR of $MBRDISK"
251 for device in cciss/c0d0 sda hda; do
252 if [ /dev/$device != ${MBRDISK} ]; then
253 grep -q $device /proc/partitions && \
254 ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
257 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
261 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
262 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
263 mbr "install bootmanager into $MBRPART" \
264 nowhere "do not install bootmanager at all" \
265 ${ADDITIONAL_PARAMS})
266 [ $? -eq 0 ] || bailout 3
271 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
272 if echo "$TARGET" | grep -q "/dev/md" ; then
274 if [ -n "$SELECTED_PARTITIONS" ] ; then
275 GRUB=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
296 # ask for Debian release {{{
299 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
300 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
301 "Please enter the Debian release you would like to use for installation:" \
303 lenny Debian/stable \
304 squeeze Debian/testing \
305 sid Debian/unstable)"
309 # ask for hostname {{{
310 prompt_for_hostname()
312 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
313 "Please enter the hostname you would like to use for installation:" \
318 # ask for password {{{
319 prompt_for_password()
323 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
324 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
325 "Please enter the password for the root account:" 10 60)
326 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
327 "Please enter the password for the root account again for \
328 confirmation:" 10 60)
330 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
331 $(dialog --stdout --title "${PN}" --ok-label \
332 "Retry" --msgbox "Passwords do not match!" 10 60)
335 ROOTPASSWORD="$ROOTPW1"
339 # ask for Debian mirror {{{
342 [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
344 CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
345 --menu "Where do you want to install from?" 0 0 0 \
346 net "install via network (downloading from mirror)" \
347 local "install from local directory/mirror"
350 if [ "$CHOOSE_MIRROR" = 'net' ] ; then
351 [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
352 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
353 "Please enter Debian mirror you would like to use for installing packages." \
355 else # CHROOT_VARIABLES == local
356 [ -n "$ISO" ] || ISO='/mnt/mirror'
357 ISO="$(dialog --stdout --title "${PN}" --inputbox \
358 "Please enter directory name you would like to use for installing packages." \
364 # software raid setup {{{
365 config_swraid_setup()
369 # Currently we support only raid1:
372 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
373 # --menu "Which RAID level do you want to use?" 0 0 0 \
374 # raid1 "Software RAID level 1" \
375 # raid5 "Software RAID level 5")
376 #[ $? -eq 0 ] || bailout 20
378 MD_LIST=$(for i in $(seq 0 9) ; do
379 awk '{print $4}' /proc/partitions | grep -q md$i || \
380 echo "/dev/md$i /dev/md$i"
383 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
384 --menu "Which device do you want to use for ${RAIDLEVEL}?
386 Notice: activated devices will not be listed for security reasons. Anyway, please make sure the selected device is not in use already!" 0 0 0 \
388 [ $? -eq 0 ] || bailout 20
390 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
392 grep -v 'Extended$' | \
393 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
394 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
395 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
396 echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet]) off"
399 dialog --title "$PN" --separate-output \
400 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
401 $PARTITION_LIST 2>$TMPFILE
403 SELECTED_PARTITIONS="$(cat $TMPFILE)"
406 for i in $(cat $TMPFILE) ; do
407 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
412 # TODO: better error handling?
413 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
414 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
418 if [ "$RC" = 0 ] ; then
419 dialog --title "$PN" --msgbox \
420 "Creating $TARGET was successful." 0 0
421 rm -f "$TMPFILE" "$ERRORFILE"
423 dialog --title "$PN" --msgbox \
424 "There was an error setting up $TARGET:
429 rm -f "$TMPFILE" "$ERRORFILE"
437 if dialog --stdout --title "$PN" \
438 --defaultno --yesno "Do you want to configure Software RAID?
440 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
446 # user should recheck his configuration {{{
447 # support full automatic installation:
449 dialog --timeout 10 --title "$PN" \
450 --yesno "Do you want to stop at this stage?
452 Notice: you are running ${PN} in non-interactive mode.
453 ${PN} will install Debian ${RELEASE} on ${TARGET}.
454 Last chance to quit. Timeout of 10 seconds running....
456 Do you want to stop now?" 0 0 2>/dev/null
459 # make sure the user is aware of the used configuration {{{
462 if [ -n "$AUTOINSTALL" ] ; then
463 if checkforrun ; then
464 eerror "Exiting as requested" ; eend 0
467 elif [ -n "$INTERACTIVE" ] ; then
469 INFOTEXT="Please recheck configuration before execution:
471 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
473 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
475 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
476 Using release: $RELEASE"
477 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
478 Using hostname $HOSTNAME"
479 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
480 Using mirror: $MIRROR"
481 [ -n "$ISO" ] && INFOTEXT="$INFOTEXT
486 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
488 dialog --title "$PN" --no-collapse \
489 --yesno "$INFOTEXT" 0 0
491 else # if not running automatic installation display configuration and prompt for execution:
492 einfo "$PN - Please recheck configuration before execution:"
494 echo " Target: $TARGET"
496 # do not display if MNTPOINT is the default one
497 case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo " Mount point: $MNTPOINT" ;; esac
499 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
500 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
501 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
502 [ -n "$HOSTNAME" ] && echo " Using hostname: $HOSTNAME"
503 [ -n "$ISO" ] && echo " Using ISO: $ISO"
505 echo " Important! Continuing will delete all data from ${TARGET}!"
508 einfon "Is this ok for you? [y/N] "
510 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
511 eerror "Exiting as requested." ; eend 1
518 # interactive mode {{{
527 prompt_for_bootmanager
538 # run interactive mode if we didn't get the according configuration yet
539 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
540 # only target might be unset, so make sure the INTERACTIVE flag is set as well
548 # finally make sure at least $TARGET is set [the partition for the new system] {{{
549 if [ -n "$TARGET" ] ; then
550 SHORT_TARGET="${TARGET##*/}"
552 eerror "Please adjust $CONFFILES/config or..."
553 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
559 if [ -z "$STAGES" ] ; then
560 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
561 [ -d "$STAGES" ] || mkdir -p "$STAGES"
564 if [ -r "$STAGES"/grml-debootstrap ] ; then
565 if grep -q done $STAGES/grml-debootstrap ; then
566 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
567 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
572 # partition handling {{{
576 set_target_directory(){
577 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
584 # make sure we normalise the path to an absolute directory name so something like:
585 # mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
587 TARGET="$(readlink -f $TARGET)"
590 if [ -b "$TARGET" ] ; then
597 # architecture setup {{{
598 if [ -n "$ARCH" ] ; then
599 ARCHCMD="--arch $ARCH"
600 ARCHINFO=" (${ARCH})"
602 ARCH="$(dpkg --print-architecture)"
603 ARCHCMD="--arch $ARCH"
604 ARCHINFO=" (${ARCH})"
610 if [ "$SECURE" = 'yes' ] ; then
611 if [ -e '/etc/apt/trusted.gpg' ] ; then
612 KEYRING="--keyring /etc/apt/trusted.gpg"
614 eerror "Could not find /etc/apt/trusted.gpg."
617 ewarn "Not checking Release signatures!"
621 # make sure we have the right syntax when using an iso image {{{
622 if [ -n "$ISO" ] ; then
635 # helper functions {{{
636 # we want to exit smoothly and clean:
638 # make sure $TARGET is not mounted when exiting grml-debootstrap
639 if [ -n "$MNTPOINT" ] ; then
640 if grep -q $MNTPOINT /proc/mounts ; then
641 # make sure nothing is left inside chroot so we can unmount it
642 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
643 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
644 # ugly, but make sure we really don't leave anything (/proc /proc is intended)
645 for ARG in /sys -a /proc /proc ; do
646 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true
648 umount "$MNTPOINT"/dev >/dev/null 2>&1 || true
650 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1 || true
652 if [ -n "$DIRECTORY" ] ; then
653 einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
655 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
658 if [ -n "$STAGES" ] ; then
659 echo -n "Removing stages directory ${STAGES}: "
660 rm -rf "$STAGES" && echo done
663 # remove directory only if we used the default with process id inside the name
664 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
665 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
670 [ -n "$1" ] && EXIT="$1" || EXIT="1"
671 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
675 trap bailout HUP INT QUIT TERM
677 # we want to execute all the functions only once, simple check for it:
679 if [ -n "$2" ] ; then
680 echo "$2" > "${STAGES}/${1}"
682 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
683 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
685 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
692 # create filesystem {{{
694 if [ -n "$DIRECTORY" ] ; then
695 einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
697 if grep -q "$TARGET" /proc/mounts ; then
698 eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
702 if [ -n "$MKFS" ] ; then
703 einfo "Running $MKFS on $TARGET"
704 $MKFS $TARGET ; RC=$?
706 # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
707 # will fail to detect the uuid in the chroot
708 blockdev --rereadpt "${TARGET%%[0-9]*}"
709 # give the system 2 seconds, otherwise we might run into
710 # race conditions :-/
713 eval $(blkid -o udev $TARGET 2>/dev/null)
714 [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
723 # modify filesystem settings {{{
725 if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
726 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
733 # mount the new partition or if it's a directory do nothing at all {{{
735 if [ -n "$DIRECTORY" ] ; then
736 einfo "Running grml-debootstrap on a directory, nothing to mount."
738 if grep -q $TARGET /proc/mounts ; then
739 ewarn "$TARGET already mounted, continuing anyway." ; eend 0
741 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
742 einfo "Mounting $TARGET to $MNTPOINT"
743 mount -o rw,suid,dev $TARGET $MNTPOINT
747 if [ -n "$ISODIR" ] ; then
748 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
749 mkdir -p "$MNTPOINT/$ISODIR"
750 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
756 # install main chroot {{{
757 debootstrap_system() {
758 if [ "$_opt_nodebootstrap" ]; then
759 einfo "Skipping debootstrap as requested."
763 if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
764 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
765 if [ -n "$MIRROR" ] ; then
766 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
767 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
769 einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
770 $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
774 eerror "Error: $MNTPOINT not mounted, can not continue."
780 # prepare chroot via chroot-script {{{
782 einfo "Preparing chroot system"
784 # provide variables to chroot system
785 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
786 touch $CHROOT_VARIABLES
787 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
788 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
789 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
790 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
791 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
792 [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=$INSTALL_NOTES" >> $CHROOT_VARIABLES
793 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
794 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
795 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
796 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
797 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
798 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
799 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
800 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
801 [ -n "$RM_APTCACHE" ] && echo "RM_APTCACHE=$RM_APTCACHE" >> $CHROOT_VARIABLES
803 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
804 chmod 755 $MNTPOINT/bin/chroot-script
805 [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
807 # make sure we have our files for later use via chroot-script
808 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
809 # make sure we adjust the configuration variables accordingly:
810 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
811 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
812 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
815 if [ -n "$INSTALL_NOTES" ] ; then
816 [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
820 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
821 $MNTPOINT/etc/debootstrap/packages
823 # debconf preseeding:
824 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
825 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
826 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
828 # copy scripts that should be executed inside the chroot:
829 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
830 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
831 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
832 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
835 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
836 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
838 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
840 # make sure we can access network [relevant for cdebootstrap]
841 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
843 # provide system's /etc/hosts to the target:
844 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
845 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
848 # setup default locales
849 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
851 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
852 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
854 # copy any existing files to chroot
855 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
856 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
857 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
858 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
859 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
860 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
861 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
863 # copy local network setup to chroot
864 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
865 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
866 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
869 # install config file providing some example entries
870 if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
871 cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
878 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
879 execute_pre_scripts() {
880 # make sure we have $MNTPOINT available for our scripts
882 if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
883 [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
884 for script in ${pre_scripts}/* ; do
885 if [ -x "$script" ] ; then
886 einfo "Executing pre-script $script"
894 # execute all scripts in /etc/debootstrap/scripts/ {{{
896 # make sure we have $MNTPOINT available for our scripts
898 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
899 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
900 for script in ${scripts}/* ; do
901 if [ -x "$script" ] ; then
902 einfo "Executing script $script"
910 # execute chroot-script {{{
912 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
916 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
917 einfo "Executing chroot-script now"
918 mount --bind /dev "$MNTPOINT"/dev
919 chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
920 umount "$MNTPOINT"/dev
923 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
929 # install booloader grub {{{
931 if [ -z "$GRUB" ] ; then
932 echo "Notice: \$GRUB not defined, will not install grub therefore."
936 if ! [ -x "$(which grub-install)" ] ; then
937 echo "Error: grub-install not available. (Error while installing grub package?)"
941 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
942 for device in $SELECTED_PARTITIONS ; do
943 GRUB="${device%%[0-9]}"
944 einfo "Installing grub on ${GRUB}:"
945 grub-install --no-floppy --root-directory="$MNTPOINT" "$GRUB"
949 einfo "Installing grub on ${GRUB}:"
950 grub-install --no-floppy --root-directory="$MNTPOINT" "$GRUB"
956 # unmount $MNTPOINT {{{
959 # display installation notes:
960 if [ -n "$INSTALL_NOTES" ] ; then
961 [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
964 if [ -n "$ISODIR" ] ; then
965 if grep -q "$ISODIR" /proc/mounts ; then
966 einfo "Unmount $MNTPOINT/$ISODIR"
967 umount "$MNTPOINT/$ISODIR"
972 if grep -q "$MNTPOINT" /proc/mounts ; then
973 if [ -n "$PARTITION" ] ; then
974 einfo "Unmount $MNTPOINT"
982 # execute filesystem check {{{
984 if [ "$FSCK" = 'yes' ] ; then
985 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
986 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
993 # now execute all the functions {{{
994 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
995 execute_pre_scripts chrootscript execute_scripts grub_install umount_chroot \
997 if stage "${i}" ; then
998 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
1004 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
1005 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
1007 # Remove temporary mountpoint again
1008 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
1009 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
1013 # end dialog of autoinstallation {{{
1014 if [ -n "$AUTOINSTALL" ] ; then
1015 dialog --title "$PN" --msgbox \
1016 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
1018 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1022 ## END OF FILE #################################################################
1023 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3