• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# The following is a synthesis of info in:
3#
4#  http://vmsplice.net/~stefan/stefanha-kernel-recipes-2015.pdf
5#  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/README
6#
7KBASE=../../linux
8#APPEND="console=ttyS0"
9
10function die {
11    echo "$*"
12    exit 1
13}
14
15pushd ..
16make || die "failed to make libcap tree"
17popd
18
19# Assumes desired make *config (eg. make defconfig) is already done.
20pushd $KBASE
21pwd
22make V=1 all || die "failed to build kernel: $0"
23popd
24
25HERE=$(/bin/pwd)
26
27cat > fs.conf <<EOF
28file /init test-init.sh 0755 0 0
29dir /etc 0755 0 0
30file /etc/passwd test-passwd 0444 0 0
31dir /lib 0755 0 0
32dir /proc 0755 0 0
33dir /dev 0755 0 0
34dir /sys 0755 0 0
35dir /sbin 0755 0 0
36file /sbin/busybox /usr/sbin/busybox 0755 0 0
37dir /bin 0755 0 0
38file /bin/myprompt test-prompt.sh 0755 0 0
39file /bin/bash test-bash.sh 0755 0 0
40dir /usr 0755 0 0
41dir /usr/bin 0755 0 0
42dir /root 0755 0 0
43file /root/quicktest.sh $HERE/../progs/quicktest.sh 0755 0 0
44file /root/setcap $HERE/../progs/setcap 0755 0 0
45file /root/getcap $HERE/../progs/getcap 0755 0 0
46file /root/capsh $HERE/../progs/capsh 0755 0 0
47file /root/getpcaps $HERE/../progs/getpcaps 0755 0 0
48EOF
49
50COMMANDS="ls ln cp id pwd mkdir rmdir cat rm sh mount umount chmod less"
51for f in $COMMANDS; do
52    echo slink /bin/$f /sbin/busybox 0755 0 0 >> fs.conf
53done
54
55UCOMMANDS="id cut"
56for f in $UCOMMANDS; do
57    echo slink /usr/bin/$f /sbin/busybox 0755 0 0 >> fs.conf
58done
59
60$KBASE/usr/gen_init_cpio fs.conf | gzip -9 > initramfs.img
61
62KERNEL=$KBASE/arch/x86_64/boot/bzImage
63
64qemu-system-$(uname -m) -m 1024 \
65		   -kernel $KERNEL \
66		   -initrd initramfs.img \
67		   -append "$APPEND"
68