Use febootstrap-run properly.
[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 create_init ()
45 {
46   cat > /init <<'__EOF__'
47 #!/bin/sh
48 PATH=/sbin:/usr/sbin:$PATH
49 MAKEDEV mem null port zero core full ram tty console fd \
50   hda hdb hdc hdd sda sdb sdc sdd loop sd
51 mount -t proc /proc /proc
52 mount -t sysfs /sys /sys
53 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
54 modprobe sata_nv pata_acpi ata_generic
55 lvm vgscan --ignorelockingfailure
56 lvm vgchange -ay --ignorelockingfailure
57 /bin/bash -i
58 __EOF__
59   chmod +x init
60 }
61 export -f create_init
62 ../febootstrap-run ./guestfs -- bash -c create_init
63
64 # Convert the filesystem to an initrd image.
65
66 ../febootstrap-to-initramfs ./guestfs > guestfs-initrd.img
67
68 # Now run qemu to boot this guestfs system.
69
70 qemu-system-$(arch) \
71   -m 256 \
72   -kernel vmlinuz -initrd guestfs-initrd.img \
73   -hda guest-image -boot c