f487f502991932b5c9bdc483c6c52718a998d25f
[febootstrap.git] / examples / guestfs-test.sh
1 #!/bin/sh -
2
3 # Before running, make sure 'vmlinuz' in this examples directory is a
4 # bootable Linux kernel or a symlink to one.  You can just use any
5 # kernel out of the /boot directory for this.
6 #
7 # eg:
8 # cd examples
9 # ln -s /boot/vmlinuz-NNN vmlinuz
10 #
11 # Also make 'guest-image' be a symlink to a virtual machine disk image.
12
13 # This is a realistic example for 'libguestfs', which contains a
14 # selection of command-line tools, LVM, NTFS and an NFS server.
15
16 set -e
17
18 if [ $(id -u) -eq 0 ]; then
19     echo "Don't run this script as root.  Read instructions in script first."
20     exit 1
21 fi
22
23 if [ ! -e vmlinuz -o ! -e guest-image ]; then
24     echo "Read instructions in script first."
25     exit 1
26 fi
27
28 ../febootstrap \
29     -i bash \
30     -i coreutils \
31     -i lvm2 \
32     -i ntfs-3g \
33     -i nfs-utils \
34     -i util-linux-ng \
35     -i MAKEDEV \
36     fedora-10 ./guestfs $1
37
38 echo -n "Before minimization: "; du -sh guestfs
39 ../febootstrap-minimize --all ./guestfs
40 echo -n "After minimization:  "; du -sh guestfs
41
42 # Create the /init which will scan for and enable all LVM volume groups.
43
44 ( cd guestfs && cat > init <<'__EOF__'
45 #!/bin/sh
46 PATH=/sbin:/usr/sbin:$PATH
47 MAKEDEV mem null port zero core full ram tty console fd \
48   hda hdb hdc hdd sda sdb sdc sdd loop sd
49 mount -t proc /proc /proc
50 mount -t sysfs /sys /sys
51 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
52 modprobe sata_nv pata_acpi ata_generic
53 lvm vgscan --ignorelockingfailure
54 lvm vgchange -ay --ignorelockingfailure
55 /bin/bash -i
56 __EOF__
57 chmod +x init
58 )
59
60 # Convert the filesystem to an initrd image.
61
62 ../febootstrap-to-initramfs ./guestfs > guestfs-initrd.img
63
64 # Now run qemu to boot this guestfs system.
65
66 qemu-system-$(arch) \
67   -m 256 \
68   -kernel vmlinuz -initrd guestfs-initrd.img \
69   -hda guest-image -boot c