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: Mon Nov 06 23:48:26 CET 2006 [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 [ "$UID" != 0 ]; then
28 echo 1>&2 "${RED}Error: please run this script with uid 0 (root).${NORMAL}" ; exit 1
33 if [[ $DEBUG -gt 0 ]]; 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 - delete grml-installation from /mnt/external1:
86 $PROGRAMNAME uninstall /mnt/external1
88 For more information take a look at http://wiki.grml.org/doku.php?id=usb
89 Report bugs, send wishes and feedback to the grml team:
90 http://grml.org/bugs/ - contact (at) grml.org
96 Installing grml to $DEVICE should have been successful!
100 Use the usb cheatcode on bootprompt if you experience any problems with
101 booting grml via usb/firewire, so boot with 'grml scandelay' on bootprompt.
102 This adds a 'sleep' while trying to access the usb-stick and the module
103 should have enough time to access it. Using scandeleay=seconds is possible
104 as well, use 'grml scandelay=20' to wait 20 seconds before trying to access
105 the external device with grml on it.
107 Also make sure you have tested all available modes of USB-boot in
108 the BIOS of your computer. Often found as USB-HDD, USB-FDD and
109 USB-ZIP in the bootmenu.
111 Take a look at http://wiki.grml.org/doku.php?id=usb for more information."
115 echo "${BLUE}$PROGRAMNAME ${VERSION}${NORMAL} - install grml-system to usb-device"
120 echo "Warning: make sure that your usb-device is preformated with vfat.
121 If not please run it e.g. via: mkfs.vfat -F 16 -v /dev/sda1"
126 if grep ${DEVICE} /proc/mounts ; then
127 echo echo 1>&2 "${WHITE}${DEVICE} already mounted${NORMAL}"
129 echo -n "Mounting ${DEVICE}: "
130 debugit "debug: mount $DEVICE"
131 mount $DEVICE && echo "${WHITE}done${NORMAL}" || bailout
136 echo -n "Mounting ${ISO} to ${TMPMNT}: "
137 debugit "debug: mount -o loop ${ISO} ${TMPMNT}"
138 if mount -o loop "${ISO}" ${TMPMNT} ; then
139 echo "${WHITE}done${NORMAL}"
141 echo 1>&2 "${RED}Problem? You got an error saying 'mount: could not find any free loop device'?
142 Possible solution: losetup -d /dev/loop/0${NORMAL}"
148 echo -n "Unmounting ${DEVICE} and ${TMPMNT}."
154 echo -n "Installing data from ${ISO} to ${DEVICE} (will take some time): "
155 debugit "debug: cp -dR --preserve=mode,timestamps ${TMPMNT}/* ${DEVICE}"
156 debugit "debug: mv ${DEVICE}/boot/isolinux/* ${DEVICE}/"
157 if cp -dR --preserve=mode,timestamps ${TMPMNT}/* ${DEVICE} ; then
158 echo "# filelist of $PROGRAMNAME on $(date) using $ISO on ${DEVICE}:" > $DEVICE/grml2hd.filelist
159 find ${TMPMNT} -type f | grep -v isolinux | sed 's#^/mnt/test/##' | tr A-Z a-z >> $DEVICE/grml2hd.filelist && \
160 find ${DEVICE}/boot/isolinux -type f | sed 's#.*isolinux/##' | tr A-Z a-z >> $DEVICE/grml2hd.filelist && \
161 mv ${DEVICE}/boot/isolinux/* ${DEVICE}/ && \
162 rmdir ${DEVICE}/boot/isolinux && \
163 rmdir ${DEVICE}/boot/
164 sync && echo "${WHITE}done${NORMAL}"
172 DEV=$(echo ${DEVICE%/})
173 TMPDEV=$(grep ${DEV} /etc/fstab | awk '{print $1}')
174 SYSDEV=$(echo ${TMPDEV%/})
175 echo -n "Running syslinux on ${SYSDEV}: "
176 debugit "debug: syslinux ${SYSDEV}"
177 syslinux ${SYSDEV} && echo "${WHITE}done${NORMAL}" || echo 1>&2 "${RED}Problem when running syslinux?
178 Try to call it manually via 'syslinux /dev/sda1' if you installed grml to /dev/sda1'${NORMAL}"
184 trap bailout 1 2 3 15
186 if [[ $# != 2 ]]; then
190 if [ -n "$UNINSTALL" ] ; then
191 echo "${BLUE}$PROGRAMNAME - ${VERSION}"
192 echo "${BLUE}Uninstalling grml from ${DEVICE} based on ${DEVICE}/grml2hd.filelist.${NORMAL}"
193 if mount_device ; then
194 if [ -f ${DEVICE}/grml2hd.filelist ] ; then
195 for file in `cat $DEVICE/grml2hd.filelist | grep -v '^#'` ; do
196 echo -n "removing ${file} on ${DEVICE}: "
197 rm ${DEVICE}/${file} && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
199 echo -n "removing directory grml/images/ on ${DEVICE}: "
200 rmdir ${DEVICE}/grml/images/ && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
201 echo -n "removing directory grml/ on ${DEVICE}: "
202 rmdir ${DEVICE}/grml && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
203 echo -n "removing filelist grml2hd.filelist on ${DEVICE}: "
204 rm ${DEVICE}/grml2hd.filelist && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
205 echo -n "Unmounting ${DEVICE}:"
206 umount $DEVICE && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
208 echo 1>&2 "${RED}File ${DEVICE}/grml2hd.filelist not found. I have nothing to delete therefor. Exiting.${NORMAL}"
223 ## END OF FILE #################################################################
224 # vim:foldmethod=marker