From 5c95bc4d9f5e292cda39860c3fd0cc711e542ced Mon Sep 17 00:00:00 2001 From: Cristiano Giuffrida Date: Sat, 28 Jun 2014 18:31:13 +0200 Subject: [PATCH] llvm: Add clientctl actions for external disk support. --- minix/llvm/clientctl | 91 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/minix/llvm/clientctl b/minix/llvm/clientctl index e8921d633..f97806dfd 100755 --- a/minix/llvm/clientctl +++ b/minix/llvm/clientctl @@ -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 < /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" -- 2.44.0