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
25 GRML_LIVE_EDITOR=${VISUAL:-${EDITOR:-vi}}
27 # source core functions {{{
28 if ! [ -r /etc/grml/lsb-functions ] || ! [ -r /etc/grml/script-functions ] ; then
29 echo "Error: could not read /etc/grml/lsb-functions and/or /etc/grml/script-functions." >&2
30 echo "Error: $0 can run only in Grml live session. Exiting." >&2
34 . /etc/grml/lsb-functions
35 . /etc/grml/script-functions
39 echo "Error: $0 can run only in Grml live session. Exiting." >&2
43 # make sure we have what we need {{{
44 if check4progs mkisofs >/dev/null 2>&1 ; then
48 if check4progs genisoimage >/dev/null 2>&1 ; then
52 if [ -z "$MKISO" ] ; then
53 echo "Error: neither mkisofs nor genisoimage available. Exiting." >&2
57 check4progs stat || exit 1
59 # allow overriding via environment:
60 if [ -z "$MKSQUASHFS" ] ; then
61 if which mksquashfs >/dev/null 2>&1 ; then
64 echo "Error: mksquashfs is not available. Exiting." >&2
72 echo "$0 - version $VERSION
74 Usage: $0 destination.iso
75 destination.iso should point to a path that is on a hard disk,
76 you might want to mount some swap partitions or swap files
77 first, because grml-live-remaster will need a lot ot RAM.
79 Please report bugs and feature requests: http://grml.org/bugs/" >&2
83 if [ ! -d /remaster ]; then
84 mkdir -p /remaster/chroot /remaster/tmp /remaster/cdrom
85 mount -t tmpfs tmpfs /remaster/tmp
86 echo "#:# edit the following two lines to change the boot message" \
88 echo "#:#" >>/remaster/msg
89 if [ -r /live/image/boot/isolinux/boot.msg ] ; then
90 sed 1,2d /live/image/boot/isolinux/boot.msg >>/remaster/msg
92 sed 1,2d /live/image/boot.msg >>/remaster/msg
96 SQUASHFS_FILE="$(find /live/image/live -name \*.squashfs | head -1)"
97 if ! grep -q "/remaster/cdrom squashfs" /proc/mounts ; then
98 mount -t squashfs "$SQUASHFS_FILE" /remaster/cdrom -o ro,loop
101 if ! grep -q "aufs /remaster/chroot" /proc/mounts ; then
102 mount -t aufs aufs /remaster/chroot -o br:/remaster/tmp=rw:/remaster/cdrom=rr
105 for i in dev proc root sys tmp; do
106 mount --bind /$i /remaster/chroot/$i
109 echo "Now edit the contents of the live CD in this chrooted shell:"
110 chroot /remaster/chroot
112 for i in dev proc root sys tmp; do
113 umount /remaster/chroot/$i
116 ${GRML_LIVE_EDITOR} /remaster/msg
118 [ -d /remaster/iso ] || mkdir /remaster/iso
120 for i in /live/image/*; do
121 if [ ! $i = /live/image/live ]; then
122 cp -R $i /remaster/iso
126 if [ -r /remaster/iso/boot/isolinux/boot.msg ] ; then
127 rm /remaster/iso/boot/isolinux/boot.msg
130 # make sure we support usb sticks as well:
131 if [ -d /live/image/boot/isolinux ] ; then
132 BOOTSTUFF=/live/image/boot/isolinux
134 BOOTSTUFF=/live/image
137 [ -d /remaster/iso/boot/isolinux ] || mkdir -p /remaster/iso/boot/isolinux
139 sed 3,4d "${BOOTSTUFF}"/boot.msg \
140 >/remaster/iso/boot/isolinux/boot.msg
141 sed 1,2d /remaster/msg >>/remaster/iso/boot/isolinux/boot.msg
143 mkdir /remaster/iso/live
144 $MKSQUASHFS /remaster/chroot /remaster/iso/live/"$(basename $SQUASHFS_FILE)"
145 umount /remaster/chroot /remaster/cdrom
147 if [ -f /remaster/iso/boot/isolinux/isolinux.bin ] ; then
148 ISOLINUX=boot/isolinux/isolinux.bin
149 ISOLINUX_BOOTCAT=boot/isolinux/boot.cat
151 ISOLINUX=isolinux.bin
152 ISOLINUX_BOOTCAT=boot.cat
155 $MKISO -b $ISOLINUX -no-emul-boot -c $ISOLINUX_BOOTCAT \
156 -boot-info-table -boot-load-size 4 -no-pad \
157 -l -r -J -o "$1" /remaster/iso
158 # pad for partition table
159 siz=$($getfilesize "$1")
160 cyls=$((siz / 512 / 32 / 16 + 1)) # C=$cyls H=16 S=32 (= 256 KiB units)
161 siz=$((cyls * 16 * 32 * 512)) # size after padding
162 dd if=/dev/zero bs=1 count=1 seek=$((siz - 1)) of="$1" 2>/dev/null
165 # here is the place where we could apply bootgrub.mksh
168 echo "ISO generation complete:"
170 echo "If you want to customize your ISO, just call grml-live-remaster again."
172 ## END OF FILE #################################################################
173 # vim: ai filetype=sh expandtab