llvm: Add clientctl actions for external disk support.

This commit is contained in:
Cristiano Giuffrida 2014-06-28 18:31:13 +02:00 committed by Lionel Sambuc
parent 3bfef65a9a
commit 5c95bc4d9f

View file

@ -1,24 +1,99 @@
#!/bin/bash
set -o errexit
mode=$1
shift || mode="no_action"
ROOT=../..
IMAGE=$( readlink -f $ROOT/minix_x86.img)
IMAGE=$( readlink -f $ROOT/minix_x86.img )
DISK=$( readlink -f $ROOT/minix_x86.disk )
RC=$( readlink -f $ROOT/minix_x86.rc )
HYPER=${HYPER:-}
DISK_SIZE=${DISK_SIZE:-1024}
DISK_MNT=${DISK_MNT:-/media/minix-disk}
function rc_create {
cat <<EOF
#!/bin/sh
set -o errexit
mkdir /ext
mount -t ext2 /dev/c0d1 /ext
if [ -f /ext/etc/rc ]; then
sh /ext/etc/rc
fi
EOF
}
function rc_ext_default_create {
cat <<EOF
#!/bin/sh
echo "/ext/etc/rc: /ext mounted correctly."
EOF
}
function disk_mount {
local mnt=$1
echo "* Mounting ${DISK} to $mnt..."
[ -d $mnt ] || sudo mkdir -p $mnt
umountdisk &> /dev/null || true
sudo mount -o loop $DISK $mnt
}
function disk_umount {
echo "* Unmounting ${DISK}..."
sudo umount $DISK
}
function disk_build {
local size=$1
local tmp_mnt=$( mktemp -d /tmp/clientctl-XXXXX )
echo "* Building ${size} MB disk image..."
dd if=/dev/zero of=$DISK bs=1M count=$size
mkfs -t ext2 -i 4096 -b 4096 -F $DISK
echo "* Setting up /ext/etc/rc file executed at startup..."
rc_create > $RC
disk_mount $tmp_mnt
[ -d $tmp_mnt/etc ] || mkdir -p $tmp_mnt/etc
rc_ext_default_create > $tmp_mnt/etc/rc
disk_umount
rm -rf $tmp_mnt
}
case "$mode" in
'buildimage')
(cd $ROOT && CREATE_IMAGE_ONLY=1 releasetools/x86_hdimage.sh)
;;
'builddisk')
rm -f $DISK
disk_build $DISK_SIZE
;;
'mountdisk')
disk_mount $DISK_MNT
;;
'umountdisk')
disk_umount
;;
'run')
if which kvm > /dev/null; then
hypervisor=kvm
elif [ -e /dev/kvm ]; then
hypervisor="qemu-system-i386 --enable-kvm"
else
hypervisor=qemu-system-i386
if [ "$HYPER" == "" ]; then
if which kvm2 > /dev/null; then
HYPER=kvm
elif [ -e /dev/kvm ]; then
HYPER="qemu-system-i386 --enable-kvm"
else
HYPER=qemu-system-i386
fi
fi
(cd ../../../obj.i386/destdir.i386/multiboot && $hypervisor -nographic -kernel kernel -append "console=tty00 rootdevname=c0d0p1" -initrd "mod01_ds,mod02_rs,mod03_pm,mod04_sched,mod05_vfs,mod06_memory,mod07_tty,mod08_mfs,mod09_vm,mod10_pfs,mod11_init" -hda $IMAGE)
opts="-hda $IMAGE"
[ ! -f $DISK ] || opts="$opts -hdb $DISK"
(cd ../../../obj.i386/destdir.i386/multiboot && $HYPER -nographic -kernel kernel -append "console=tty00 rootdevname=c0d0p1" -initrd "mod01_ds,mod02_rs,mod03_pm,mod04_sched,mod05_vfs,mod06_memory,mod07_tty,mod08_mfs,mod09_vm,mod10_pfs,mod11_init" $opts)
;;
*)
echo "Invalid action: $mode"