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: Sun May 25 01:37:43 CEST 2008 [mika]
8 ################################################################################
23 if ! [ -x "$(which syslinux)" ] ; then
24 echo "${RED}Error: syslinux is not available. Please install it before running this script.${NORMAL}" >&2; exit 2
27 if [ "$(id -u)" != 0 ]; then
28 echo "${RED}Error: please run this script with uid 0 (root).${NORMAL}" >&2 ; exit 1
33 if [ -n "$DEBUG" ]; then
44 if [ "$1" = "uninstall" ] ; then
56 [ -n "$TMPMNT" ] || TMPMNT='/mnt/test/'
57 [ -d "$TMPMNT" ] || mkdir -p $TMPMNT
60 # helper functions {{{
63 echo "Exiting - umounting /mnt/test and $DEVICE"
64 umount $TMPMNT 2>/dev/null
65 umount $DEVICE 2>/dev/null
71 echo 1>&2 "$PROGRAMNAME $VERSION - install grml-system to usb-device
73 This program installs a grml-iso to an usb-device to be able to boot
74 from usb. Make sure you have a grml-iso, syslinux (just run
75 'apt-get install syslinux' on Debian-based systems) and root access.
78 $PROGRAMNAME grml.iso /mount/point
80 Notice: /mount/point is the mountpoint set up for your USB device in /etc/fstab
81 /mount/point should not be mounted at the time running $PROGRAMNAME
83 Usage example - install grml-small to usb-device on /mnt/usb-sdb1:
84 $PROGRAMNAME grml_1.1.iso /mnt/usb-sdb1
86 Usage example - install currently running grml to usb-device on /mnt/usb-sdb1:
87 $PROGRAMNAME /live/image /mnt/usb-sdb1
89 Usage example - delete grml-installation from /mnt/usb-sdb1:
90 $PROGRAMNAME uninstall /mnt/usb-sdb1
92 For more information take a look at http://wiki.grml.org/doku.php?id=usb
93 Report bugs, send wishes and feedback to the grml team:
94 http://grml.org/bugs/ - contact (at) grml.org
100 Installing grml to $DEVICE should have been successful!
102 Please take a look at http://wiki.grml.org/doku.php?id=usb
103 for more information or if you have problems with booting from usb."
107 echo "$PROGRAMNAME ${VERSION} - install grml-system to usb-device"
112 DEV=$(echo ${DEVICE%/})
113 TMPDEV=$(grep "[[:space:]]${DEV}[[:space:]]" /etc/fstab | grep -vh '^[[:space:]]*#' | awk '{print $1}')
114 SYSDEV=$(echo ${TMPDEV%/})
115 if [ -x /lib/udev/vol_id ] ; then
116 /lib/udev/vol_id $SYSDEV | grep -q 'FS_TYPE=vfat' || VFAT=1
117 /lib/udev/vol_id $SYSDEV | grep -q 'ID_FS_VERSION=FAT16' || VFAT=1
121 if [ -n "$VFAT" ] ; then
122 echo 'WARNING: make sure that your usb-device is preformated with vfat.'
123 echo "Format your device (erases all data) via: mkfs.vfat -F 16 -v $SYSDEV"
129 if grep -q ${DEVICE} /proc/mounts ; then
130 echo "Notice: ${WHITE}${DEVICE} already mounted - continuing anyway${NORMAL}" >&2
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 "${RED}Problem? You got an error saying 'mount: could not find any free loop device'?
151 Possible solution: losetup -d /dev/loop/0${NORMAL}" >&2
157 echo -n "Unmounting ${DEVICE} and ${TMPMNT}: "
159 umount ${DEVICE} && echo "done" || echo "failed"
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}/"
167 if cp -dR --preserve=mode,timestamps ${TMPMNT}/* ${DEVICE} ; then
168 echo "# filelist of $PROGRAMNAME on $(date) using $ISO on ${DEVICE}:" > $DEVICE/grml2usb.filelist
170 find ${TMPMNT} -type f | sed "s#${TMPMNT}##" | \
171 sed "s#boot/## ; s#isolinux/## ; s#.*initrd.gz#initrd.gz# ; s#.*linux26#linux26#" | \
172 tr A-Z a-z >> $DEVICE/grml2usb.filelist
174 # make sure we have a valid syslinux.cfg, if not use isolinux.cfg as base
175 if ! [ -f "${DEVICE}"/boot/isolinux/syslinux.cfg ] ; then
176 cp ${DEVICE}/boot/isolinux/isolinux.cfg ${DEVICE}/boot/isolinux/syslinux.cfg && \
177 echo 'syslinux.cfg' >> $DEVICE/grml2usb.filelist
180 if mv ${DEVICE}/boot/isolinux/* ${DEVICE}/ ; then
181 rmdir ${DEVICE}/boot/isolinux
183 echo boot >> $DEVICE/grml2usb.filelist
185 # syslinux creates a file named ldlinux.sys:
186 echo "ldlinux.sys" >> ${DEVICE}/grml2usb.filelist
188 if ! [ -r ${DEVICE}/live/filesystem.module ] ; then
191 GRML_NAME=$(cat ${DEVICE}/live/filesystem.module)
192 GRML_NAME=${GRML_NAME%%.squashfs}
193 GRML_NAME="$(echo $GRML_NAME | tr -d ',./;\- ')"
196 KERNEL=$(find ${TMPMNT}/boot/ -maxdepth 2 -name linux26)
197 INITRD=$(find ${TMPMNT}/boot/ -maxdepth 2 -name initrd.gz)
200 */boot/${GRML_NAME}/linux26*) mv ${DEVICE}/boot/${GRML_NAME}/linux26 ${DEVICE}/
205 */boot/${GRML_NAME}/initrd.gz*) mv ${DEVICE}/boot/${GRML_NAME}/initrd.gz ${DEVICE}/
209 if [ -d "${DEVICE}"/boot/addons ] ; then
210 [ -d "${DEVICE}/addons" ] || mkdir ${DEVICE}/addons
211 mv ${DEVICE}/boot/addons/* ${DEVICE}/addons/
214 if [ -d "${DEVICE}"/boot/grub ] ; then
215 [ -d "${DEVICE}/grub" ] || mkdir ${DEVICE}/grub
216 mv ${DEVICE}/boot/grub/* ${DEVICE}/grub/
219 rmdir ${DEVICE}/boot 2>/dev/null
221 sync && echo "${WHITE}done${NORMAL}"
229 DEV=$(echo ${DEVICE%/})
230 TMPDEV=$(grep "[[:space:]]${DEV}[[:space:]]" /etc/fstab | grep -vh '^[[:space:]]*#' | awk '{print $1}')
231 SYSDEV=$(echo ${TMPDEV%/})
232 echo -n "Running syslinux on ${SYSDEV}: "
233 debugit "debug: syslinux ${SYSDEV}"
235 if syslinux ${SYSDEV} ; then
236 echo "${WHITE}done${NORMAL}"
238 echo "${RED}Problem when running syslinux?" >&2
239 echo "Try to call it manually via 'syslinux $SYSDEV' if you installed grml to ${SYSDEV}${NORMAL}" >&2
247 trap bailout 1 2 3 15
249 if [ "$#" != 2 ]; then
253 if [ -n "$UNINSTALL" ] ; then
254 echo "$PROGRAMNAME - ${VERSION}"
257 echo -n "Are you sure you want to erase all grml related data on ${DEVICE}? [y/N] "
259 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
260 echo "Exiting as requested."
264 echo "Uninstalling grml from ${DEVICE} based on ${DEVICE}/grml2usb.filelist${NORMAL}"
265 if mount_device ; then
266 if ! [ -f "${DEVICE}"/grml2usb.filelist ] ; then
267 echo "${RED}File ${DEVICE}/grml2usb.filelist not found."
268 echo "I have nothing to delete therefor. Exiting.${NORMAL}"
272 for file in $(grep -v '^#' "${DEVICE}/grml2usb.filelist") ; do
273 if [ -f "${DEVICE}/${file}" ] ; then
274 echo -n "removing file ${file} on ${DEVICE}: "
275 rm ${DEVICE}/${file} && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
279 for dir in $(grep -v '^#' "${DEVICE}/grml2usb.filelist" | sed 's#/.*##' | sort -u) ; do
280 if [ -d "${DEVICE}/$dir" ] ; then
281 echo -n "removing directory ${dir} on ${DEVICE}: "
282 rmdir "${DEVICE}/${dir}"/* 2>/dev/null
283 rmdir "${DEVICE}/${dir}" && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
287 echo -n "removing filelist grml2usb.filelist on ${DEVICE}: "
288 rm ${DEVICE}/grml2usb.filelist && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
292 echo -n "Unmounting ${DEVICE}: "
293 umount $DEVICE && echo "${WHITE}done${NORMAL}" || echo "${RED}error${NORMAL}"
308 ## END OF FILE #################################################################
309 # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=3