aboutsummaryrefslogtreecommitdiff
path: root/vm.sh
blob: 997246473ff5005ba95d10340798b5c063a06e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

function run
{
    st qemu-system-x86_64 \
		-kernel "$BIND/$KERNEL_NAME" \
		-initrd "$BIND/$INITFS_NAME" \
		-append "console=ttyS0" -nographic
}

function initramfs
{
    IMG="$(pwd)/$1"
    DIR="${IMG%.*}"

    mkdir -p $DIR

    # get busybox things
    install -D $(which busybox) $DIR/bin/busybox
    ln -sf busybox $DIR/bin/sh
    ln -sf busybox $DIR/bin/dmesg
    ln -sf busybox $DIR/bin/mount
    # ln -sf busybox $DIR/bin/bash

    # copy the things
    mkdir -p $DIR/usr/
    cp -r $BIND/* $DIR/usr/

    rm -f $DIR/usr/kernel*      # no need for the kernel
    rm -f $DIR/usr/*.img        # no need for the initramfs
    rm -rf $DIR/usr/initramfs   # no need for the initramfs

    # copy the script and the bin
    cp $2 $DIR/init
    chmod +x $DIR/init

    # make image and delete folder
    (cd $DIR; find . | cpio -H newc -o | gzip > $IMG)
    rm -rf $DIR
}

function kernel
{
    sudo cp /boot/vmlinuz-linux-lts $1
}

$1 $2 $3