3 # Purpose: install grml-system to usb-device
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: Fre Mär 16 16:04:18 CET 2007 [mika]
8 ################################################################################
23 if ! [ -x "$(which syslinux)" ] ; then
24 echo 1>&2 "${RED}Error: syslinux is not available. Please install it before running this script.${NORMAL}" ; exit 2
27 if [ "$(id -u)" != 0 ]; then
28 echo 1>&2 "${RED}Error: please run this script with uid 0 (root).${NORMAL}" ; exit 1
33 if [ -n "$DEBUG" ]; then
44 if [ "$1" = "uninstall" ] ; then
55 [ -n "$TMPMNT" ] || TMPMNT='/mnt/test'
56 [ -d "$TMPMNT" ] || mkdir -p $TMPMNT
59 # helper functions {{{
62 echo "Exiting - umounting /mnt/test and $DEVICE"
63 umount /mnt/test 2>/dev/null
64 umount $DEVICE 2>/dev/null
70 echo 1>&2 "${BLUE}$PROGRAMNAME $VERSION${NORMAL} - install grml-system to usb-device
72 This program installs a grml-iso to an usb-device to be able to boot
73 from usb. Make sure you have a grml-iso, syslinux (just run
74 'apt-get install syslinux' on debian-systems) and root access.
77 $PROGRAMNAME grml.iso /mount/point
79 Notice: /mount/point is the mountpoint set up for your USB device in /etc/fstab
80 /mount/point should not be mounted at the time running $PROGRAMNAME
82 Usage example - install grml-small to usb-device on /mnt/external1:
83 $PROGRAMNAME grml_small_0.2.iso /mnt/external1
85 Usage example - install currently running grml to usb-device on /mnt/external1:
86 $PROGRAMNAME /cdrom /mnt/external1
88 Usage example - delete grml-installation from /mnt/external1:
89 $PROGRAMNAME uninstall /mnt/external1
91 For more information take a look at http://wiki.grml.org/doku.php?id=usb
92 Report bugs, send wishes and feedback to the grml team:
93 http://grml.org/bugs/ - contact (at) grml.org
99 Installing grml to $DEVICE should have been successful!
103 Use the usb cheatcode on bootprompt if you experience any problems with
104 booting grml via usb/firewire, so boot with 'grml scandelay' on bootprompt.
105 This adds a 'sleep' while trying to access the usb-stick and the module
106 should have enough time to access it. Using scandeleay=seconds is possible
107 as well, use 'grml scandelay=20' to wait 20 seconds before trying to access
108 the external device with grml on it.
110 Also make sure you have tested all available modes of USB-boot in
111 the BIOS of your computer. Often found as USB-HDD, USB-FDD and
112 USB-ZIP in the bootmenu.
114 Take a look at http://wiki.grml.org/doku.php?id=usb for more information."
118 echo "${BLUE}$PROGRAMNAME ${VERSION}${NORMAL} - install grml-system to usb-device"
123 echo "Warning: make sure that your usb-device is preformated with vfat.
124 If not please run it e.g. via: mkfs.vfat -F 16 -v /dev/sda1"
129 if grep ${DEVICE} /proc/mounts ; then
130 echo echo 1>&2 "${WHITE}${DEVICE} already mounted${NORMAL}"
132 echo -n "Mounting ${DEVICE}: "
133 debugit "debug: mount $DEVICE"
134 mount $DEVICE && echo "${WHITE}done${NORMAL}" || bailout
139 echo -n "Mounting ${ISO} to ${TMPMNT}: "
140 local mount_opts_="-o loop"
143 elif [ -b $ISO ]; then
146 debugit "debug: mount $mount_opts_ ${ISO} ${TMPMNT}"
147 if mount $mount_opts_ "${ISO}" ${TMPMNT} ; then
148 echo "${WHITE}done${NORMAL}"
150 echo 1>&2 "${RED}Problem? You got an error saying 'mount: could not find any free loop device'?
151 Possible solution: losetup -d /dev/loop/0${NORMAL}"
157 echo -n "Unmounting ${DEVICE} and ${TMPMNT}."
163 echo -n "Installing data from ${ISO} to ${DEVICE} (will take some time): "
164 debugit "debug: cp -dR --preserve=mode,timestamps ${TMPMNT}/* ${DEVICE}"
165 debugit "debug: mv ${DEVICE}/boot/isolinux/* ${DEVICE}/"
166 if cp -dR --preserve=mode,timestamps ${TMPMNT}/* ${DEVICE} ; then
167 echo "# filelist of $PROGRAMNAME on $(date) using $ISO on ${DEVICE}:" > $DEVICE/grml2hd.filelist
168 find ${TMPMNT} -type f | grep -v isolinux | sed 's#^/mnt/test/##' | tr A-Z a-z >> $DEVICE/grml2hd.filelist && \
169 find ${DEVICE}/boot/isolinux -type f | sed 's#.*isolinux/##' | tr A-Z a-z >> $DEVICE/grml2hd.filelist && \
170 mv ${DEVICE}/boot/isolinux/* ${DEVICE}/ && \
171 rmdir ${DEVICE}/boot/isolinux && \
172 rmdir ${DEVICE}/boot/
173 sync && echo "${WHITE}done${NORMAL}"
181 DEV=$(echo ${DEVICE%/})
182 TMPDEV=$(grep ${DEV} /etc/fstab | awk '{print $1}')
183 SYSDEV=$(echo ${TMPDEV%/})
184 echo -n "Running syslinux on ${SYSDEV}: "
185 debugit "debug: syslinux ${SYSDEV}"
186 syslinux ${SYSDEV} && echo "${WHITE}done${NORMAL}" || echo 1>&2 "${RED}Problem when running syslinux?
187 Try to call it manually via 'syslinux /dev/sda1' if you installed grml to /dev/sda1'${NORMAL}"
193 trap bailout 1 2 3 15
195 if [ "$#" != 2 ]; then
199 if [ -n "$UNINSTALL" ] ; then
200 echo "${BLUE}$PROGRAMNAME - ${VERSION}"
201 echo "${BLUE}Uninstalling grml from ${DEVICE} based on ${DEVICE}/grml2hd.filelist.${NORMAL}"
202 if mount_device ; then
203 if [ -f ${DEVICE}/grml2hd.filelist ] ; then
204 for file in `cat $DEVICE/grml2hd.filelist | grep -v '^#'` ; do
205 echo -n "removing ${file} on ${DEVICE}: "
206 rm ${DEVICE}/${file} && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
208 echo -n "removing directory grml/images/ on ${DEVICE}: "
209 rmdir ${DEVICE}/grml/images/ && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
210 echo -n "removing directory grml/ on ${DEVICE}: "
211 rmdir ${DEVICE}/grml && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
212 echo -n "removing filelist grml2hd.filelist on ${DEVICE}: "
213 rm ${DEVICE}/grml2hd.filelist && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
214 echo -n "Unmounting ${DEVICE}:"
215 umount $DEVICE && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
217 echo 1>&2 "${RED}File ${DEVICE}/grml2hd.filelist not found. I have nothing to delete therefor. Exiting.${NORMAL}"
232 ## END OF FILE #################################################################
233 # vim:foldmethod=marker