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 . /etc/grml/lsb-functions
29 . /etc/grml/script-functions
32 # make sure we have what we need {{{
33 check4progs mkisofs mksquashfs stat || exit 1
37 if [ x"$1" == x ]; then
38 echo "$0 - version $VERSION"
40 echo "Usage: $0 destination.iso"
41 echo " destination.iso should point to a path that is on a hard disk,"
42 echo " you might want to mount some swap partitions or swap files"
43 echo " first, because grml-live-remaster will need a lot ot RAM."
45 echo "Please report bugs and feature requests: http://grml.org/bugs/"
49 if [ ! -d /remaster ]; then
50 mkdir -p /remaster/chroot /remaster/tmp /remaster/cdrom
51 mount -t tmpfs tmpfs /remaster/tmp
52 echo "#:# edit the following two lines to change the boot message" \
54 echo "#:#" >>/remaster/msg
55 if [ -r /live/image/boot/isolinux/boot.msg ] ; then
56 sed 1,2d /live/image/boot/isolinux/boot.msg >>/remaster/msg
58 sed 1,2d /live/image/boot.msg >>/remaster/msg
62 SQUASHFS_FILE="$(find /live/image/live -name \*.squashfs | head -1)"
63 if ! grep -q "/remaster/cdrom squashfs" /proc/mounts ; then
64 mount -t squashfs "$SQUASHFS_FILE" /remaster/cdrom -o ro,loop
67 if ! grep -q "aufs /remaster/chroot" /proc/mounts ; then
68 mount -t aufs aufs /remaster/chroot -o br:/remaster/tmp=rw:/remaster/cdrom=rr
71 for i in dev proc root sys tmp; do
72 mount --bind /$i /remaster/chroot/$i
75 echo "Now edit the contents of the live CD in this chrooted shell:"
76 chroot /remaster/chroot
78 for i in dev proc root sys tmp; do
79 umount /remaster/chroot/$i
82 ${GRML_LIVE_EDITOR} /remaster/msg
84 [ -d /remaster/iso ] || mkdir /remaster/iso
86 for i in /live/image/*; do
87 if [ ! $i == /live/image/live ]; then
88 cp -R $i /remaster/iso
92 if [ -r /remaster/iso/boot/isolinux/boot.msg ] ; then
93 rm /remaster/iso/boot/isolinux/boot.msg
96 # make sure we support usb sticks as well:
97 if [ -d /live/image/boot/isolinux ] ; then
98 BOOTSTUFF=/live/image/boot/isolinux
100 BOOTSTUFF=/live/image
103 [ -d /remaster/iso/boot/isolinux ] || mkdir -p /remaster/iso/boot/isolinux
105 sed 3,4d "${BOOTSTUFF}"/boot.msg \
106 >/remaster/iso/boot/isolinux/boot.msg
107 sed 1,2d /remaster/msg >>/remaster/iso/boot/isolinux/boot.msg
109 mkdir /remaster/iso/live
110 mksquashfs /remaster/chroot /remaster/iso/live/"$(basename $SQUASHFS_FILE)"
111 umount /remaster/chroot /remaster/cdrom
113 if [ -f /remaster/iso/boot/isolinux/isolinux.bin ] ; then
114 ISOLINUX=boot/isolinux/isolinux.bin
115 ISOLINUX_BOOTCAT=boot/isolinux/boot.cat
117 ISOLINUX=isolinux.bin
118 ISOLINUX_BOOTCAT=boot.cat
121 mkisofs -b $ISOLINUX -no-emul-boot -c $ISOLINUX_BOOTCAT \
122 -boot-info-table -boot-load-size 4 -no-pad \
123 -l -r -J -o "$1" /remaster/iso
124 # pad for partition table
125 siz=$($getfilesize "$1")
126 cyls=$((siz / 512 / 32 / 16 + 1)) # C=$cyls H=16 S=32 (= 256 KiB units)
127 siz=$((cyls * 16 * 32 * 512)) # size after padding
128 dd if=/dev/zero bs=1 count=1 seek=$((siz - 1)) of="$1" 2>/dev/null
131 # here is the place where we could apply bootgrub.mksh
134 echo "ISO generation complete:"
136 echo "If you want to customize your ISO, just call grml-live-remaster again."
138 ## END OF FILE #################################################################
139 # vim: ai filetype=sh expandtab