Added guestfs example.
[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 if [ $(id -u) -eq 0 ]; then
17     echo "Don't run this script as root.  Read instructions in script first."
18     exit 1
19 fi
20
21 if [ ! -e vmlinuz -o ! -e guest-image ]; then
22     echo "Read instructions in script first."
23     exit 1
24 fi
25
26 ../febootstrap \
27     -i bash \
28     -i coreutils \
29     -i lvm2 \
30     -i ntfs-3g \
31     -i nfs-utils \
32     -i util-linux-ng \
33     -i MAKEDEV \
34     fedora-10 ./guestfs $1
35
36 echo -n "Before minimization: "; du -sh guestfs
37 ../febootstrap-minimize --all ./guestfs
38 echo -n "After minimization:  "; du -sh guestfs
39
40 # Create the /init which will scan for and enable all LVM volume groups.
41
42 ( cd guestfs && cat > init <<'__EOF__'
43 #!/bin/sh
44 PATH=/sbin:/usr/sbin:$PATH
45 MAKEDEV mem null port zero core full ram tty console fd \
46   hda hdb hdc hdd sda sdb sdc sdd loop sd
47 mount -t proc /proc /proc
48 mount -t sysfs /sys /sys
49 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
50 modprobe sata_nv pata_acpi ata_generic
51 lvm vgscan --ignorelockingfailure
52 lvm vgchange -ay --ignorelockingfailure
53 /bin/bash -i
54 __EOF__
55 chmod +x init
56 )
57
58 # Convert the filesystem to an initrd image.
59
60 ../febootstrap-to-initramfs ./guestfs > guestfs-initrd.img
61
62 # Now run qemu to boot this guestfs system.
63
64 qemu-system-$(arch) \
65   -m 128 \
66   -kernel vmlinuz -initrd guestfs-initrd.img \
67   -hda guest-image -boot c