2
###############################################################################
4
## Copyright (C) International Business Machines Corp., 2005
5
## Author(s): Daniel Stekloff <dsteklof@us.ibm.com>
7
## This program is free software; you can redistribute it and/or modify
8
## it under the terms of the GNU General Public License as published by
9
## the Free Software Foundation; under version 2 of the License.
11
## This program is distributed in the hope that it will be useful,
12
## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
## GNU General Public License for more details.
16
## You should have received a copy of the GNU General Public License
17
## along with this program; if not, write to the Free Software
18
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
###############################################################################
31
if [ -e "$IMAGE" ]; then
34
if [ -e "$LCONF" ]; then
49
Command creates a hvm guest disk image for xm-test.
54
-d|--dvrdir <name> Directory where to find network driver
55
to use for disk image.
56
-i|--image <name> Image name to create.
57
-k|--kernel <name> Kernel name to use for disk image.
58
-n|--netdrv <name> Network driver name to use for disk image.
59
-r|--rootfs <image> Rootfs image to use for disk image.
61
This script defaults to using the 8139too.ko driver for network tests.
62
If a dvrdir isn't added on the command-line, it will look in
63
/lib/modules/ directory relating to the supplied kernel. If the
64
network driver is built into the kernel, you can specify the key word
65
"builtin" with the -d option and the script will continue.
67
Note: Many network drivers rely upon mii.ko. This script will look
68
for that module in the same location as the network driver, either
69
for the kernel or the location used with the -d option.
74
function check_dependencies()
76
which lilo > /dev/null 2>&1
78
die "$PROGNAME requires lilo version 22.7+ to be installed."
80
local pass="$( lilo -V | cut -f3 -d " " | awk -F "." '
82
if ($1 >= 22 && $2 >= 7)
87
if [ $pass = "false" ]; then
88
die "$PROGNAME requires lilo version 22.7+ to be installed."
92
function initialize_globals()
94
PROGNAME="create_disk_image"
100
LOOPD="" # Loop device for entire disk image
101
LOOPP="" # Loop device for ext partition
103
MNT="/tmp/$PROGNAME-mnt"
107
CYLINDERS=$(($SIZE/$SECTORS/$HEADS*2))
108
BSIZE=$(($SIZE-$SECTORS))
109
OFFSET=$(($SECTORS*512))
112
function get_options()
114
while [ $# -gt 0 ]; do
153
for i in `seq 0 7`; do
154
losetup /dev/loop$i > /dev/null 2>&1
155
if [ $? -ne 0 ]; then
161
die "No free loopback devices."
164
function losetup_image()
169
# If offset, then associate with it
170
if [ $# -eq 1 ]; then
171
losetup -o $1 $loop $IMAGE
176
if [ $? -ne 0 ]; then
177
die "Failed to losetup $IMAGE to $loop."
180
echo "Associated $IMAGE with $loop"
183
function create_disk_image()
185
dd bs=1024 count=$SIZE of=$IMAGE if=/dev/zero
187
fdisk -b 512 -C $CYLINDERS -H $HEADS -S $SECTORS "$IMAGE" > /dev/null 2>&1 << EOF
199
function makefs_image()
201
mke2fs -N 24 -b 1024 $LOOPP $BSIZE
203
if [ $? -ne 0 ]; then
204
die "mke2fs $LOOPP failed."
208
function dd_rootfs_to_image()
210
if [ ! "$ROOTFS" ]; then
211
die "Must specify rootfs image to use."
214
dd if="$ROOTFS" of="$LOOPP" > /dev/null 2>&1
215
if [ $? -ne 0 ]; then
216
die "Failed to dd $ROOTFS to $LOOPP."
219
# Resize fs to use full partition
222
if [ $? -ne 0 ]; then
223
die "Failed to resize rootfs on $LOOPP."
227
function get_kernel()
229
# look in /boot for an existing kernel
230
local -a kernels=( `ls /boot | grep vmlinuz` )
233
for k in ${kernels[@]}; do
240
echo "Using kernel $KERNEL"
247
function copy_kernel_to_image()
249
if [ ! "$KERNEL" ]; then
250
get_kernel || die "Couldn't find a kernel to use."
255
cp "$KERNEL" "$MNT/boot"
258
function copy_netdriver_to_image()
260
local kernel=`basename $KERNEL`
261
local kversion=$( echo $kernel | sed 's/^vmlinuz-//' )
262
local fdir="/lib/modules/$kversion/kernel/drivers/net"
264
mkdir "$MNT/lib/modules"
265
if [ -e "$DRVDIR" ]; then
266
if [ -e "$DRVDIR/$NETDRV" ]; then
267
cp $DRVDIR/mii.ko $MNT/lib/modules
268
cp $DRVDIR/$NETDRV $MNT/lib/modules
270
die "Failed to find $NETDRV at $DRVDIR."
272
elif [ -e "$fdir/$NETDRV" ]; then
273
cp $fdir/mii.ko $MNT/lib/modules
274
cp $fdir/$NETDRV $MNT/lib/modules
276
die "Xm-test requires at minimum the 8139too.ko driver to run."
279
# Make sure that modules will be installed
280
if [ -e "$MNT/etc/init.d/rcS" ]; then
281
echo "insmod /lib/modules/mii.ko" >> $MNT/etc/init.d/rcS
282
echo "insmod /lib/modules/$NETDRV" >> $MNT/etc/init.d/rcS
284
die "Failed to add insmod command to rcS file on image."
288
function lilo_image()
290
local kernel=`basename $KERNEL`
305
image=$MNT/boot/$kernel
306
append="root=0301 console=tty0 console=ttyS0"
311
) > "/$MNT/boot/$LCONF"
314
function install_lilo()
316
lilo -C "$MNT/boot/$LCONF"
317
if [ $? -ne 0 ]; then
318
die "Failed to install $MNT/boot/$LCONF."
322
function add_getty_to_inittab()
324
local itab=$MNT/etc/inittab
326
if [ -e "$itab" ]; then
327
echo "# Start getty on serial line" >> $itab
328
echo "S0:12345:respawn:/sbin/getty ttyS0" >> $itab
341
# Get the first free loop device
343
LOOPD="/dev/loop$ldev"
346
# Now associate where the partition will go
348
LOOPP="/dev/loop$ldev"
349
losetup_image $LOOPP $OFFSET
355
if [ -e "$MNT" ]; then
360
if [ $? -ne 0 ]; then
361
die "Failed to create temporary mount point $MNT."
364
mount "$LOOPP" "$MNT";
365
if [ $? -ne 0 ]; then
366
die "Failed to mount $LOOPP on $MNT."
370
if [ ! "$DRVDIR" = "builtin" ]; then
371
copy_netdriver_to_image
373
#add_getty_to_inittab