qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [SCRIPT] make_root.sh


From: Rusty Russell
Subject: [Qemu-devel] [SCRIPT] make_root.sh
Date: Thu, 10 Jul 2003 19:35:02 +1000

OK, Debian fans!

Here's my script to make a Debian qemu root image, for use as -hda.

You will need debootstrap, sharutils and sfdisk installed, and to
run this as root.  It takes at least 90MB to fit the base Debian,
unfortunately.  Also, my script is naive and needs twice the size of
the image temporarily.

Example use:

$ sudo ./make_root.sh 200 sid http://proxy:10000/debian qemu
....
$ ./vl -snapshot -hda qemu bzImage root=/dev/hda1 ide1=noprobe ide2=noprobe 
ide3=noprobe ide4=noprobe ide5=noprobe

Feedback and patches welcome!
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#! /bin/sh -e
# Script to make a debian root image.

if [ $# -ne 4 ]; then
    echo Usage: "%s size-in-MB distrib deburl image" >&2
    echo "eg %s 150 sid http://proxy:10000/debian qemu" >&2
    exit 1
fi

SIZE=$1
DISTRO=$2
URL=$3
IMAGE=$4

if [ $SIZE -lt 110 ]; then
    echo 'Size must be at least 110 megabytes (Debian takes 90)' >&2
    exit 1
fi

cleanup()
{
    echo Cleaning up... >&2
    umount /tmp/mount.$$ || true
    rm -f $IMAGE.ext2 $IMAGE
}

trap cleanup EXIT

HEADS=16
SECTORS=63
# 512 bytes in a sector: cancel the 512 with one of the 1024s...
CYLINDERS=$(( $SIZE * 1024 * 2 / ($HEADS * $SECTORS) ))

# Create a filesystem: one track for partition table.
dd bs=$(($SECTORS * 512)) if=/dev/zero of=$IMAGE.ext2 count=$(($CYLINDERS * 
$HEADS - 1))
mke2fs -q -m1 -F $IMAGE.ext2

# Mount it.
mkdir /tmp/mount.$$
mount -o loop $IMAGE.ext2 /tmp/mount.$$

# Do debian install on it.
debootstrap 
--exclude=syslinux,at,exim,mailx,libstdc++2.10-glibc2.2,mbr,setserial,fdutils,info,ipchains,lilo,pcmcia-cs,ppp,pppoe,pppoeconf,pppconfig
 $DISTRO /tmp/mount.$$ $URL

# Final configuration.
cat > /tmp/mount.$$/etc/fstab <<EOF
# # /dev/hda1 / ext2 errors=remount-ro 0 1
proc /proc proc defaults 0 0
EOF

# Console on ttyS0, not tty1, and no other gettys.
sed 's,1:2345:respawn:/sbin/getty 38400 tty1,1:2345:respawn:/sbin/getty 38400 
ttyS0,' < /tmp/mount.$$/etc/inittab | sed 's,^.:23:respawn.*,,' > 
/tmp/mount.$$/etc/inittab.new
mv /tmp/mount.$$/etc/inittab.new /tmp/mount.$$/etc/inittab

# Set hostname to base of image name.
basename $IMAGE > /tmp/mount.$$/etc/hostname

# Remove ones we can remove.
chroot /tmp/mount.$$ /usr/bin/dpkg --remove console-tools console-data 
base-config

umount /tmp/mount.$$

# Create file with partition table.
uudecode -o- << "EOF" | gunzip > $IMAGE
begin 664 partition-table.gz
M'XL("*_<##\"`W!A<G1I=&EO;BUT86)L90#LT#$-`"`0!,&']D6A`D6XP1T&
M"%B@))FIMKGF(OA9C;%;EENYZO.Z3P\"````!P``__\:!0````#__QH%````
M`/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%
M`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#_
M_QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0``
M``#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:
M!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````
M__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`
M````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__
M&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%````
M`/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%
M`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#_
M_QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0``
M``#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:
M!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`````
M__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__&@4`
M````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%`````/__
M&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%````
M`/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#__QH%
M`````/__&@4`````__\:!0````#__QH%`````/__&@4`````__\:!0````#_
M_QH%`````/__&@4`````__\:!0````#__QH%`````/address@hidden&_
&<address@hidden
`
end
EOF
cat $IMAGE.ext2 >> $IMAGE
rm $IMAGE.ext2

# Repartition so one partition covers entire disk.
echo '63,' | sfdisk -uS -H$HEADS -S$SECTORS -C$CYLINDERS $IMAGE

trap "" EXIT

echo Done.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]