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: Don Apr 12 11:55:21 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"
62 if [ -r $STAGES/grml-debootstrap ] ; then
63 if grep -q done $STAGES/grml-debootstrap ; then
64 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
65 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
77 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
88 if [ -n "$ARCH" ] ; then
89 ARCHCMD="--arch $ARCH"
92 ARCH="$(dpkg --print-architecture)"
93 ARCHCMD="--arch $ARCH"
97 # provide variables to chroot system
100 " > /etc/debootstrap/variables
102 # make sure at least $TARGET is set [the partition for the new system]
103 if [ -z "$TARGET" ] ; then
104 eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
109 # helper functions {{{
110 # we want to exit smoothly and clean:
112 # make sure $TARGET is not mounted when exiting grml-debootstrap
113 if [ -n "$TARGET" ] ; then
114 if grep -q $TARGET /proc/mounts ; then
115 # make sure nothing is left inside chroot so we can unmount it
116 [ -x "$TARGET"/etc/init.d/ssh ] && "$TARGET"/etc/init.d/ssh stop
117 [ -x "$TARGET"/etc/init.d/mdadm ] && "$TARGET"/etc/init.d/mdadm stop
118 chroot "$TARGET" umount /sys 1>/dev/null 2>&1
119 chroot "$TARGET" umount /proc 1>/dev/null 2>&1
120 echo "Unmounting $TARGET"
124 [ -n "$1" ] && EXIT="$1" || EXIT="1"
127 trap bailout 1 2 3 15
129 # we want to execute all the functions only once, simple check for it:
131 if grep -q done "$STAGES/$1" 2>/dev/null ; then
132 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
135 echo "$2" > "$STAGES/$1"
141 # user should recheck his configuration {{{
142 einfo "$0 - Please recheck configuration before execution:"
145 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount-point: $MNTPOINT" ;; esac
146 [ -n "$GRUB" ] && echo " Install grub to: $GROOT / $GRUB"
147 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
149 einfon "Is this ok for you? [y/N] "
152 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
153 eerror "Exiting as requested." ; eend 1
158 # create filesystem {{{
160 if [ -n "$MKFS" ] ; then
161 einfo "Running $MKFS on $TARGET"
168 # modify filesystem settings {{{
170 if [ -n "$TUNE2FS" ] ; then
171 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
178 # mount the new partition or if it's a directory do nothing at all {{{
180 if [ -n "$DIRECTORY" ] ; then
181 einfo "Running grml-debootstrap on a directory, nothing to mount."
183 if grep -q $TARGET /proc/mounts ; then
184 eerror "$TARGET already mounted, exiting."
186 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
187 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
188 einfo "Mounting $TARGET to $MNTPOINT"
189 mount -o rw,suid,dev $TARGET $MNTPOINT
196 # install main chroot {{{
197 debootstrap_system() {
198 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using mirror $MIRROR"
199 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR
204 # prepare chroot via chroot-script {{{
206 einfo "Preparing chroot system"
207 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
208 chmod 755 $MNTPOINT/bin/chroot-script
209 mkdir $MNTPOINT/etc/debootstrap/
211 # make sure we have our files for later use via chroot-script
212 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
213 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
214 cp /etc/debootstrap/variables $MNTPOINT/etc/debootstrap/variables
216 # make sure we can access network [relevant for cdebootstrap]
217 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
219 # setup default locales
220 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
222 # copy any existing existing files to chroot
223 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
224 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
225 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
226 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
227 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
232 # execute chroot-script {{{
234 einfo "Executing chroot-script now"
235 chroot "$MNTPOINT" /bin/chroot-script
240 # install booloader grub {{{
242 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
243 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
245 einfo "Installing grub on ${GRUB}:"
246 grub-install --root-directory="$MNTPOINT" "(${GRUB})"
252 # unmount $MNTPOINRT {{{
254 if [ -n "$PARTITION" ] ; then
255 einfo "Unmount $MNTPOINT"
262 # execute filesystem check {{{
264 if [ "$FSCK" = 'yes' ] ; then
265 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
266 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
273 # now execute all the functions {{{
274 stage mkfs && mkfs && stage mkfs done || bailout
275 stage tunefs && tunefs && stage tunefs done || bailout
276 stage mount_target && mount_target && stage mount_target done || bailout
277 stage debootstrap_system && debootstrap_system && stage debootstrap_system done || bailout
278 stage preparechroot && preparechroot && stage preparechroot done || bailout
279 stage chrootscript && chrootscript && stage chrootscript done || bailout
280 stage grub_install && grub_install && stage grub_install done || bailout
281 stage umount_chroot && umount_chroot && stage umount_chroot done || bailout
282 stage fscktool && fscktool && stage fscktool done || bailout
286 echo done > $STAGES/grml-debootstrap
289 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
291 ## END OF FILE #################################################################
292 # vim: ai tw=100 expandtab foldmethod=marker