1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#!/bin/bash -e
#
# mkus-iso - add Sugar and activities to Ubuntu installation media
#
# input: ubuntu-14.04.2-desktop-amd64.iso
#
# output: olpc-ubuntu-sugar-14.04.2-desktop-amd64.iso
#
# Based on oem-config-remaster, this script adds the Sugar desktop and
# activities to the live filesystem on the installation media, by
# reading the filesystem, using APT to install packages, and then
# writing a new filesystem.
#
# Ubuntu installation media is described in the ubiquity source
# package. The media is an ISOHYBRID MBR ISO9660 filesystem which
# contains a file with a squashfs live filesystem. The former is
# created by ubiquity using xorriso. The latter is created by
# ubiquity-casper using mksquashfs.
#
#
# Naming convention for mount point directories
#
# cd_* the outer iso9660 bootable filesystem
# fs_* the inner squashfs live filesystem made by ubiquity-casper
#
# {cd,fs}_ro the unchanged original
# {cd,fs}_rw a backing filesystem (writes to the aufs are made here)
# {cd,fs} an aufs filesystem to which we will make changes
#
# check for missing dependencies
MISSING=0
for program in xorriso mksquashfs; do
if ! which $program >/dev/null; then
if [ $MISSING == 0 ]; then
echo "$(basename $0): please install the dependencies below and retry"
fi
echo "$(basename $0): missing $program"
MISSING=1
fi
done
if [ $MISSING == 1 ]; then
exit 1
fi
# installation media from upstream project
INPUT=ubuntu-14.04.2-desktop-amd64.iso
# directory to work in
TEMPDIR=/tmp/us
# output media
OUTPUT=olpc-ubuntu-sugar-14.04.2-desktop-amd64-$(date +%s).iso
if [ -f ~/.mkus-iso.conf ]; then
. ~/.mkus-iso.conf
fi
# process options and arguments
while [ ! -z "$1" ]; do
case "$1" in
--output)
shift
OUTPUT=$1
shift
;;
--tmpdir)
shift
TMPDIR=$1
shift
;;
*)
INPUT=$1
shift
;;
esac
done
# check for missing input file
if [ ! -r $INPUT ]; then
echo "$(basename $0): input installation media image not found"
exit 1
fi
# canonicalise file paths
INPUT=$(readlink -f $INPUT)
OUTPUT=$(readlink -f $OUTPUT)
# create temporary directory
mkdir -p $TEMPDIR
cd $TEMPDIR
# warning: make no further persistent changes to current working directory
# functions
mount_kernelfs()
{
mount -t sysfs sysfs fs/sys
mount -t proc proc fs/proc
mount -t devtmpfs devfs fs/dev
mount -t devpts devpts fs/dev/pts
}
umount_kernelfs()
{
umount fs/dev/pts
umount fs/dev
umount fs/proc
umount fs/sys
}
disable_forks()
{
# https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/430224
# http://blogs.balabit.com/2011/01/21/using-upstart-in-a-chroot/
mv fs/sbin/initctl fs/sbin/initctl.REAL
ln -s /bin/true fs/sbin/initctl
mv fs/sbin/start-stop-daemon fs/sbin/start-stop-daemon.REAL
cat >fs/sbin/start-stop-daemon<<EOF
#!/bin/sh
echo
echo "Warning: fake start-stop-daemon called, doing nothing"
echo "\$*"
echo
EOF
chmod 755 fs/sbin/start-stop-daemon
}
enable_forks()
{
mv fs/sbin/start-stop-daemon.REAL fs/sbin/start-stop-daemon
rm fs/sbin/initctl
mv fs/sbin/initctl.REAL fs/sbin/initctl
}
cleanup() {
set +e
[ -d fs/proc/1 ] && umount_kernelfs
for directory in fs fs_rw fs_ro cd cd_rw cd_ro; do
if [ -e "$directory" ]; then
umount $directory
rmdir $directory
fi
done
}
trap cleanup EXIT HUP INT QUIT TERM
# mount the installation media
mkdir -p cd_ro
mount -o loop,ro $INPUT cd_ro
# set up a copy-on-write filesystem for new installation media
mkdir -p cd_rw
mount -t tmpfs tmpfs cd_rw
mkdir -p cd
mount -t aufs -o br=cd_rw:cd_ro none cd
# mount the live filesystem
mkdir -p fs_ro
mount -o loop,ro cd_ro/casper/filesystem.squashfs fs_ro
# set up a copy-on-write filesystem for the live filesystem
mkdir -p fs_rw
mount -t tmpfs tmpfs fs_rw
mkdir -p fs
mount -t aufs -o br=fs_rw:fs_ro none fs
# save the sources list
cp fs/etc/apt/sources.list .
# change the sources list to local proxy and add our public archive
cat > fs/etc/apt/sources.list <<EOF
deb http://us.archive.ubuntu.com/ubuntu/ trusty main universe multiverse restricted
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates main universe multiverse restricted
deb http://security.ubuntu.com/ubuntu/ trusty-security main universe multiverse restricted
deb [trusted=yes] http://dev.laptop.org/pub/us trusty main
EOF
# duplicate local cache of archive metadata to save time
cp -pr /var/lib/apt/lists fs/var/lib/apt/
# ensure name resolver can work
# (is overwritten by resolvconf on installer boot)
cp /etc/resolv.conf fs/etc/
# update package list and install packages
mount_kernelfs
disable_forks
chroot fs ln -s /proc/mounts /etc/mtab
chroot fs apt-get update
chroot fs apt-get --assume-yes install olpc-activities \
virtualbox-guest-utils \
olpc-powerd- git- fakeroot- consolekit-
enable_forks
umount_kernelfs
# restore sources.list and add our public archive
cp sources.list fs/etc/apt/
echo 'deb [trusted=yes] http://dev.laptop.org/pub/us trusty main' >> \
fs/etc/apt/sources.list
rm sources.list
# FIXME: is not effective, ubiquity removes it,
# try to use d-i oem-config/repository from oem-config-remaster
# FIXME: answer some bootloader and installer questions ahead of time
# path to files associated with this script
#PF=$(dirname $0)
#cp $PF/ks.preseed cd/
#cp $PF/ks.cfg cd/
#cp $PF/boot/grub/grub.cfg cd/boot/grub/
#cp $PF/isolinux/txt.cfg cd/isolinux/
# regenerate squashfs
( chroot fs dpkg-query -W ) > cd/casper/filesystem.manifest
rm cd/casper/filesystem.squashfs
mksquashfs fs cd/casper/filesystem.squashfs
# build image
# derived from https://bugs.launchpad.net/ubuntu-cdimage/+bug/1298894/comments/17
xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 -V Ubuntu\ 14.04.2\ LTS\ amd64 -o $OUTPUT -isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus cd
cleanup
|