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