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 # Latest change: Sam Okt 06 18:01:53 CEST 2007 [mika]
8 ################################################################################
9 # http://www.debian.org/releases/stable/i386/index.html.en
11 set -e # exit on any error
15 # source core functions {{{
16 . /etc/grml/lsb-functions
17 . /etc/grml/script-functions
20 # make sure we have what we need {{{
21 check4progs debootstrap || exit 1
25 # without config file it won't work {{{
26 if [ -r /etc/debootstrap/config ] ; then
27 . /etc/debootstrap/config
29 eerror "/etc/debootstrap/config could not be read, exiting." ; eend 1
34 # cmdline handling {{{
36 einfo "$0 - version $VERSION"
37 echo " A wrapper around debootstrap for installing plain Debian via grml"
39 einfo "Usage: $0 [options]"
40 echo " Adjust /etc/debootstrap/config and invoke $0 afterwards or use the cmdline option:"
42 einfo "Valid options:"
44 -h|--help Print this usage information and exit.
45 -v|--version Show summary of options and exit.
47 -t|--target <target> Target partition (/dev/...) or directory.
48 -r|--release <release> Specify release of new Debian system. Supported relases: sarge, etch, lenny and sid.
49 -m|--mirror <URL> Specify mirror which should be used for apt-get/aptitude.
50 -i|--iso <mnt> Specify mountpoint where Debian ISO is mounted to (instead of using mirror)
51 -p|--mntpoint <mnt> Specify mountpoint that should be used for mounting the target system.
52 --groot <device> Specify root device for usage in grub (corresponds with \$TARGET).
53 --grub <device> Where do you want to install grub to? Use grub syntax for specifying.
54 --password <pwd> Use specified password as password for user root. Use with caution.
55 --boot_append <appendline> Add specified appendline to kernel whilst booting
60 while [ "$#" -gt "0" ] ; do
63 einfo "$0 - version $VERSION"
64 einfo "Send bug reports to Michael Prokop <mika@grml.org>."
99 [ -n "$MIRROR" ] && unset MIRROR
108 eerror "Syntax error."
117 # set/check variables {{{
119 # inside the chroot system the locales might not be available, so use minimum:
123 if [ -z "$STAGES" ] ; then
124 STAGES='/etc/debootstrap/stages'
125 [ -d "$STAGES" ] || mkdir -p "$STAGES"
128 if [ -r "$STAGES"/grml-debootstrap ] ; then
129 if grep -q done $STAGES/grml-debootstrap ; then
130 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
131 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
143 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
154 if [ -n "$ARCH" ] ; then
155 ARCHCMD="--arch $ARCH"
156 ARCHINFO=" (${ARCH})"
158 ARCH="$(dpkg --print-architecture)"
159 ARCHCMD="--arch $ARCH"
160 ARCHINFO=" (${ARCH})"
163 # make sure we have the right syntax when using an iso image
164 if [ -n "$ISO" ] ; then
176 # provide variables to chroot system
177 touch /etc/debootstrap/variables
178 chmod 600 /etc/debootstrap/variables # make sure nobody except root can read it
179 [ -n "$ARCH" ] && echo "ARCH=$ARCH" > /etc/debootstrap/variables
180 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> /etc/debootstrap/variables
181 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> /etc/debootstrap/variables
182 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> /etc/debootstrap/variables
183 [ -n "$ISO" ] && echo "ISO=$ISO" >> /etc/debootstrap/variables
184 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> /etc/debootstrap/variables
185 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> /etc/debootstrap/variables
186 [ -n "$MIRROR" ] && echo "CHROOTMIRROR=$MIRROR" >> /etc/debootstrap/variables
187 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> /etc/debootstrap/variables
189 # make sure at least $TARGET is set [the partition for the new system]
190 if [ -z "$TARGET" ] ; then
191 eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
196 # helper functions {{{
197 # we want to exit smoothly and clean:
199 # make sure $TARGET is not mounted when exiting grml-debootstrap
200 if [ -n "$MNTPOINT" ] ; then
201 if grep -q $MNTPOINT /proc/mounts ; then
202 # make sure nothing is left inside chroot so we can unmount it
203 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
204 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
205 # ugly, but make sure we really don't leav anything
206 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
207 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
208 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
209 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
210 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
211 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
214 [ -n "$1" ] && EXIT="$1" || EXIT="1"
215 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
218 trap bailout 1 2 3 15
220 # we want to execute all the functions only once, simple check for it:
222 if [ -n "$2" ] ; then
223 echo "$2" > "$STAGES/$1"
225 elif grep -q done "$STAGES/$1" 2>/dev/null ; then
226 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
228 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
235 # user should recheck his configuration {{{
236 # support full automatic installation:
238 dialog --timeout 10 --title "$0" \
239 --yesno "Do you want to stop at this stage?
241 Notice: you are running grml-debootstrap in non-interactive mode.
242 grml-debootstrap will install Debian ${RELEASE} on ${TARGET}.
243 Last chance to quit. Timeout of 10 seconds running....
245 Do you want to stop now?" 0 0 2>/dev/null
248 if [ -n "$AUTOINSTALL" ] ; then
249 if checkforrun ; then
250 eerror "Exiting as requested" ; eend 0
253 else # if not running automatic installation display configuration and prompt for execution:
254 einfo "$0 - Please recheck configuration before execution:"
256 echo " Target: $TARGET"
257 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount-point: $MNTPOINT" ;; esac
258 [ -n "$GRUB" ] && echo " Install grub to: $GROOT / $GRUB"
259 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
260 [ -n "$ISO" ] && echo " Using iso: $ISO"
261 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
263 einfon "Is this ok for you? [y/N] "
265 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
266 eerror "Exiting as requested." ; eend 1
272 # create filesystem {{{
274 if [ -n "$MKFS" ] ; then
275 einfo "Running $MKFS on $TARGET"
282 # modify filesystem settings {{{
284 if [ -n "$TUNE2FS" ] ; then
285 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
292 # mount the new partition or if it's a directory do nothing at all {{{
294 if [ -n "$DIRECTORY" ] ; then
295 einfo "Running grml-debootstrap on a directory, nothing to mount."
297 if grep -q $TARGET /proc/mounts ; then
298 eerror "$TARGET already mounted, exiting."
300 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
301 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
302 einfo "Mounting $TARGET to $MNTPOINT"
303 mount -o rw,suid,dev $TARGET $MNTPOINT
307 if [ -n "$ISODIR" ] ; then
308 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
309 mkdir -p "$MNTPOINT/$ISODIR"
310 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
316 # install main chroot {{{
317 debootstrap_system() {
318 if ! grep -q $MNTPOINT /proc/mounts ; then
321 if grep -q $MNTPOINT /proc/mounts ; then
322 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
323 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR || \
324 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $ISO
327 eerror "Error: $MNTPOINT not mounted, can not continue."
333 # prepare chroot via chroot-script {{{
335 einfo "Preparing chroot system"
336 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
337 chmod 755 $MNTPOINT/bin/chroot-script
338 mkdir $MNTPOINT/etc/debootstrap/
340 # make sure we have our files for later use via chroot-script
341 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
342 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
343 cp /etc/debootstrap/variables $MNTPOINT/etc/debootstrap/variables
345 cp -a /etc/debootstrap/extrapackages/ $MNTPOINT/etc/debootstrap/
347 # make sure we can access network [relevant for cdebootstrap]
348 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
350 # setup default locales
351 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
353 # copy any existing existing files to chroot
354 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
355 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
356 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
357 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
358 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
363 # execute chroot-script {{{
365 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
368 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
369 einfo "Executing chroot-script now"
370 chroot "$MNTPOINT" /bin/chroot-script
373 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
379 # install booloader grub {{{
381 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
382 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
384 einfo "Installing grub on ${GRUB}:"
385 [ -x /usr/sbin/grub-install ] && GRUBINSTALL=/usr/sbin/grub-install || GRUBINSTALL=/sbin/grub-install
386 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
392 # unmount $MNTPOINRT {{{
394 if [ -n "$ISODIR" ] ; then
395 if grep -q "$ISODIR" /proc/mounts ; then
396 einfo "Unmount $MNTPOINT/$ISODIR"
397 umount "$MNTPOINT/$ISODIR"
401 if grep -q "$MNTPOINT" /proc/mounts ; then
402 if [ -n "$PARTITION" ] ; then
403 einfo "Unmount $MNTPOINT"
411 # execute filesystem check {{{
413 if [ "$FSCK" = 'yes' ] ; then
414 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
415 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
422 # now execute all the functions {{{
423 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
424 chrootscript grub_install umount_chroot fscktool ; do
426 $i && stage $i done || bailout 2 "i"
432 echo done > $STAGES/grml-debootstrap
435 if [ -n "$AUTOINSTALL" ] ; then
436 dialog --title "$0" --msgbox \
437 "Finished execution of ${0}.
438 Enjoy your Debian system." 6 60
440 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
443 ## END OF FILE #################################################################
444 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3