2 # Filename: grml-live-remaster
3 # Purpose: remaster a grml from the live cd
4 # Authors: grml-team (grml.org),
5 # (c) Michael Schierl <schierlm@gmx.de>,
6 # (c) Michael Prokop <mika@grml.org>,
7 # (c) Thorsten Glaser <tg@mirbsd.org>
8 # Bug-Reports: see http://grml.org/bugs/
9 # License: This file is licensed under the GPL v2 or any later version.
10 ################################################################################
12 # this script currently lacks LOTS of error checking code... any help welcome...
13 ################################################################################
15 # define function getfilesize before "set -e"
16 if stat --help >/dev/null 2>&1; then
17 getfilesize='stat -c %s' # GNU stat
19 getfilesize='stat -f %z' # BSD stat
22 set -e # exit on any error
24 if [ -d /live/image/boot/ ] ; then # until Grml versions <=2012.XX
25 LIVE_PATH_MAIN='/live/image'
26 LIVE_PATH_BOOT='/live/image/boot/'
27 else # for Grml versions >=2013.XX
28 LIVE_PATH_MAIN='/lib/live/mount/medium/'
29 LIVE_PATH_BOOT='/lib/live/mount/medium/boot/'
33 GRML_LIVE_EDITOR=${VISUAL:-${EDITOR:-vi}}
35 # source core functions {{{
36 if ! [ -r /etc/grml/lsb-functions ] || ! [ -r /etc/grml/script-functions ] ; then
37 echo "Error: could not read /etc/grml/lsb-functions and/or /etc/grml/script-functions." >&2
38 echo "Error: $0 can run only in Grml live session. Exiting." >&2
42 . /etc/grml/lsb-functions
43 . /etc/grml/script-functions
47 echo "Error: $0 can run only in Grml live session. Exiting." >&2
51 # make sure we have what we need {{{
52 if check4progs mkisofs >/dev/null 2>&1 ; then
56 if check4progs genisoimage >/dev/null 2>&1 ; then
60 if [ -z "$MKISO" ] ; then
61 echo "Error: neither mkisofs nor genisoimage available. Exiting." >&2
65 check4progs stat || exit 1
67 # allow overriding via environment:
68 if [ -z "$MKSQUASHFS" ] ; then
69 if which mksquashfs >/dev/null 2>&1 ; then
72 echo "Error: mksquashfs is not available. Exiting." >&2
80 echo "$0 - version $VERSION
82 Usage: $0 destination.iso
83 destination.iso should point to a path that is on a hard disk,
84 you might want to mount some swap partitions or swap files
85 first, because grml-live-remaster will need a lot ot RAM.
87 Please report bugs and feature requests: http://grml.org/bugs/" >&2
91 if [ ! -d /remaster ]; then
92 mkdir -p /remaster/chroot /remaster/tmp /remaster/cdrom
93 mount -t tmpfs tmpfs /remaster/tmp
94 echo "#:# edit the following two lines to change the boot message" \
96 echo "#:#" >>/remaster/msg
97 if [ -r ${LIVE_PATH_BOOT}/isolinux/boot.msg ] ; then
98 sed 1,2d ${LIVE_PATH_BOOT}/isolinux/boot.msg >>/remaster/msg
102 SQUASHFS_FILE="$(find ${LIVE_PATH_MAIN}/live -name \*.squashfs | head -1)"
103 if ! grep -q "/remaster/cdrom squashfs" /proc/mounts ; then
104 mount -t squashfs "$SQUASHFS_FILE" /remaster/cdrom -o ro,loop
107 if ! grep -q "aufs /remaster/chroot" /proc/mounts ; then
108 mount -t aufs aufs /remaster/chroot -o br:/remaster/tmp=rw:/remaster/cdrom=rr
111 for i in dev proc root sys tmp; do
112 mount --bind /$i /remaster/chroot/$i
115 echo "Now edit the contents of the live CD in this chrooted shell:"
116 chroot /remaster/chroot
118 for i in dev proc root sys tmp; do
119 umount /remaster/chroot/$i
122 ${GRML_LIVE_EDITOR} /remaster/msg
124 [ -d /remaster/iso ] || mkdir /remaster/iso
126 for i in ${LIVE_PATH_MAIN}/*; do
127 if [ ! $i = ${LIVE_PATH_MAIN}/live ]; then
128 cp -R $i /remaster/iso
132 if [ -r /remaster/iso/boot/isolinux/boot.msg ] ; then
133 rm /remaster/iso/boot/isolinux/boot.msg
136 # make sure we support usb sticks as well:
137 if [ -d ${LIVE_PATH_BOOT}/isolinux ] ; then
138 BOOTSTUFF=${LIVE_PATH_BOOT}/isolinux
140 BOOTSTUFF=${LIVE_PATH_MAIN}
143 [ -d /remaster/iso/boot/isolinux ] || mkdir -p /remaster/iso/boot/isolinux
145 sed 3,4d "${BOOTSTUFF}"/boot.msg \
146 >/remaster/iso/boot/isolinux/boot.msg
147 sed 1,2d /remaster/msg >>/remaster/iso/boot/isolinux/boot.msg
149 mkdir /remaster/iso/live
150 $MKSQUASHFS /remaster/chroot /remaster/iso/live/"$(basename $SQUASHFS_FILE)"
151 umount /remaster/chroot /remaster/cdrom
153 if [ -f /remaster/iso/boot/isolinux/isolinux.bin ] ; then
154 ISOLINUX=boot/isolinux/isolinux.bin
155 ISOLINUX_BOOTCAT=boot/isolinux/boot.cat
157 ISOLINUX=isolinux.bin
158 ISOLINUX_BOOTCAT=boot.cat
161 $MKISO -b $ISOLINUX -no-emul-boot -c $ISOLINUX_BOOTCAT \
162 -boot-info-table -boot-load-size 4 -no-pad \
163 -l -r -J -o "$1" /remaster/iso
164 # pad for partition table
165 siz=$($getfilesize "$1")
166 cyls=$((siz / 512 / 32 / 16 + 1)) # C=$cyls H=16 S=32 (= 256 KiB units)
167 siz=$((cyls * 16 * 32 * 512)) # size after padding
168 dd if=/dev/zero bs=1 count=1 seek=$((siz - 1)) of="$1" 2>/dev/null
171 # here is the place where we could apply bootgrub.mksh
174 echo "ISO generation complete:"
176 echo "If you want to customize your ISO, just call grml-live-remaster again."
178 ## END OF FILE #################################################################
179 # vim: ai filetype=sh expandtab