678d612b4ac1b56b8d7a73277c6f1722607ca5fc
[febootstrap.git] / examples / minimal-filesystem.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 # This creates a very minimal filesystem, just containing bash and a
12 # few command line utilities.  One of the joys of Fedora is that even
13 # this minimal install is still 200 MB ...
14
15 set -e
16
17 if [ $(id -u) -eq 0 ]; then
18     echo "Don't run this script as root.  Read instructions in script first."
19     exit 1
20 fi
21
22 if [ ! -e vmlinuz ]; then
23     echo "Read instructions in script first."
24     exit 1
25 fi
26
27 ../febootstrap -i bash -i coreutils fedora-10 ./minimal $1
28
29 # ... but let's minimize it aggressively.
30
31 echo -n "Before minimization: "; du -sh minimal
32 ../febootstrap-minimize --all --pack-executables ./minimal
33 echo -n "After minimization:  "; du -sh minimal
34
35 # Create the /init which is just a simple script to give users an
36 # interactive shell.
37
38 ( cd minimal && cat > init <<'__EOF__'
39 #!/bin/sh
40 echo; echo; echo
41 echo "Welcome to the minimal filesystem example"
42 echo; echo; echo
43 /bin/bash -i
44 __EOF__
45 chmod +x init
46 )
47
48 # Convert the filesystem to an initrd image.
49
50 ../febootstrap-to-initramfs ./minimal > minimal-initrd.img
51
52 # This is needed because of crappiness with qemu.
53
54 rm -f zero
55 dd if=/dev/zero of=zero bs=2048 count=1
56
57 # Now run qemu to boot this minimal system.
58
59 qemu-system-$(arch) \
60   -m 256 \
61   -kernel vmlinuz -initrd minimal-initrd.img \
62   -hda zero -boot c