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: Die Apr 10 10:51:26 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 # cmdline handling {{{
28 einfo "$0 - wrapper around debootstrap for installing plain Debian via grml"
29 einfo "Adjust /etc/debootstrap/config and invoke $0 afterwards."
34 einfo "$0 version $VERSION"
35 einfo "Send bug reports to Michael Prokop <mika@grml.org>."
42 # without config file it won't work {{{
43 if [ -r /etc/debootstrap/config ] ; then
44 . /etc/debootstrap/config
46 eerror "/etc/debootstrap/config could not be read, exiting." ; eend 1
51 # set/check variables {{{
53 # inside the chroot system the locales might not be available, so use minimum:
57 if [ -z "$STAGES" ] ; then
58 STAGES='/etc/debootstrap/stages'
59 [ -d "$STAGES" ] || mkdir -p "$STAGES"
70 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
81 if [ -n "$ARCH" ] ; then
82 ARCHCMD="--arch $ARCH"
85 ARCH="$(dpkg --print-architecture)"
86 ARCHCMD="--arch $ARCH"
90 # make sure at least $TARGET is set [the partition for the new system]
91 if [ -z "$TARGET" ] ; then
92 eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
97 # helper functions {{{
98 # we want to exit smoothly and clean:
100 # make sure $TARGET is not mounted when exiting grml-debootstrap
101 if [ -n "$TARGET" ] ; then
102 if grep -q $TARGET /proc/mounts ; then
103 # make sure nothing is left inside chroot so we can unmount it
104 [ -x "$TARGET"/etc/init.d/ssh ] && "$TARGET"/etc/init.d/ssh stop
105 [ -x "$TARGET"/etc/init.d/mdadm ] && "$TARGET"/etc/init.d/mdadm stop
106 chroot "$TARGET" umount /sys 1>/dev/null 2>&1
107 chroot "$TARGET" umount /proc 1>/dev/null 2>&1
108 echo "Unmounting $TARGET"
112 [ -n "$1" ] && EXIT="$1" || EXIT="1"
115 trap bailout 1 2 3 15
117 # we want to execute all the functions only once, simple check for it:
119 if grep -q done "$STAGES/$1" 2>/dev/null ; then
120 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
123 echo "$2" > "$STAGES/$1"
129 # user should recheck his configuration {{{
130 einfo "$0 - Please recheck configuration before execution:"
133 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount-point: $MNTPOINT" ;; esac
134 [ -n "$GRUB" ] && echo " Install grub to: $GROOT / $GRUB"
135 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
137 einfon "Is this ok for you? [y/N] "
140 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
141 eerror "Exiting as requested." ; eend 1
146 # create filesystem {{{
148 if [ -n "$MKFS" ] ; then
149 einfo "Running $MKFS on $TARGET"
156 # modify filesystem settings {{{
158 if [ -n "$TUNE2FS" ] ; then
159 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
166 # mount the new partition or if it's a directory do nothing at all {{{
168 if [ -n "$DIRECTORY" ] ; then
169 einfo "Running grml-debootstrap on a directory, nothing to mount."
171 if grep -q $TARGET /proc/mounts ; then
172 eerror "$TARGET already mounted, exiting."
174 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
175 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
176 einfo "Mounting $TARGET to $MNTPOINT"
177 mount -o rw,suid,dev $TARGET $MNTPOINT
184 # install main chroot {{{
185 debootstrap_system() {
186 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using mirror $MIRROR"
187 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR
192 # prepare chroot via chroot-script {{{
194 einfo "Preparing chroot system"
195 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
196 chmod 755 $MNTPOINT/bin/chroot-script
197 mkdir $MNTPOINT/etc/debootstrap/
199 # make sure we have our files for later use via chroot-script
200 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
201 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
203 # make sure we can access network [relevant for cdebootstrap]
204 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
206 # setup default locales
207 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
209 # copy any existing existing files to chroot
210 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
211 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
212 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
213 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
214 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
219 # execute chroot-script {{{
221 einfo "Executing chroot-script now"
222 chroot "$MNTPOINT" /bin/chroot-script
227 # install booloader grub {{{
229 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
230 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
232 einfo "Installing grub on ${GRUB}:"
233 grub-install --root-directory="$MNTPOINT" "(${GRUB})"
239 # unmount $MNTPOINRT {{{
241 if [ -n "$PARTITION" ] ; then
242 einfo "Unmount $MNTPOINT"
249 # execute filesystem check {{{
251 if [ "$FSCK" = 'yes' ] ; then
252 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
253 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
260 # now execute all the functions {{{
261 stage mkfs && mkfs && stage mkfs done
262 stage tunefs && tunefs && stage tunefs done
263 stage mount_target && mount_target && stage mount_target done
264 stage debootstrap_system && debootstrap_system && stage debootstrap_system done
265 stage preparechroot && preparechroot && stage preparechroot done
266 stage chrootscript && chrootscript && stage chrootscript done
267 stage grub_install && grub_install && stage grub_install done
268 stage umount_chroot && umount_chroot && stage umount_chroot done
269 stage fscktool && fscktool && stage fscktool done
272 # finally remove stages on main system so grml-deboostrap can be reexecuted {{{
276 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
278 ## END OF FILE #################################################################
279 # vim: ai tw=80 expandtab foldmethod=marker