-
Notifications
You must be signed in to change notification settings - Fork 7
/
build_diskimage.sh
executable file
·82 lines (67 loc) · 2.13 KB
/
build_diskimage.sh
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
#! /bin/sh
if [ -z "$TOPDIR" ] ; then
echo "you must define TOPDIR"
exit
fi
WHAT="$1"
if [ -z "$WHAT" ] ; then
echo "building 32 and 64 bit images"
WHAT="32 64"
fi
. $TOPDIR/settings.sh
# in case the loop device doesn't exist, we try to load the module
if ! [ -b $LOOP ] ; then
modprobe loop
sleep 5
fi
# if it still doesn't exist, we stop here before we cause damage
if ! [ -b $LOOP ] ; then
echo "$LOOP doesn't seem to exist - please check!"
exit 1
fi
oldpwd=`pwd`
for version in $WHAT
do
echo -n "Creating the $version bit system Ramdisk image.... "
IMAGE=$TOPDIR/cdtree/isolinux/sdisk${version}.img
echo "Initial Ramdisk contents will be $ISIZE KB"
# delete the existing ramdisk image, if there is one
rm -f $IMAGE
REALSIZE=$ISIZE
# create a file of REALSIZE
dd if=/dev/zero of=$TOPDIR/sdisk bs=1k count=$REALSIZE
# associate it with ${LOOP}
losetup ${LOOP} $TOPDIR/sdisk
# make an ext2 filesystem on it. We set the amount of unused space to 0%
# and turn down the number of inodes to save space. Note that we
# use the 4KB smaller ISIZE, for reiserfs compatibility.
mke2fs -q -i 16384 -m 0 ${LOOP} $ISIZE
# make sure we have $TOPDIR/loop2
[ -d $TOPDIR/loop2 ] || mkdir $TOPDIR/loop2
# we mount it...
mount ${LOOP} $TOPDIR/loop2
# ... and delete the lost+found directory
rm -rf $TOPDIR/loop2/lost+found
# then we copy the contents of our initrdtree to this filesystem
pushd $TOPDIR/loop2/
tar -xvpf $TOPDIR/root_tree${version}.tar.xz
cp $TOPDIR/hostkeys/* etc/ssh
cp -r $TOPDIR/xtras${version}/* . ||true
cp -r $TOPDIR/xtrasanyarch/* . ||true
popd
df $TOPDIR/loop2
# and unmount and divorce ${LOOP}
umount $TOPDIR/loop2
losetup -d ${LOOP}
# Now we have the image of the initial ramdisk in $TOPDIR/loopfiles/ramdisk. We
# compress this one and write the compressed image to the boot tree:
echo -n "Compressing the $version bit System Ramdisk image.... "
# delete any existing one
rm -f $IMAGE
# and gzip our initial ramdisk image and put it in the right place.
#gzip -9 -c $TOPDIR/sdisk > $IMAGE
bzip2 -c $TOPDIR/sdisk > $IMAGE
echo
rm -f $TOPDIR/sdisk
done
echo "done"