]> Zhao Yanbai Git Server - minix.git/commitdiff
llvm: Add clientctl actions for external disk support.
authorCristiano Giuffrida <giuffrida@cs.vu.nl>
Sat, 28 Jun 2014 16:31:13 +0000 (18:31 +0200)
committerLionel Sambuc <lionel@minix3.org>
Mon, 28 Jul 2014 15:06:11 +0000 (17:06 +0200)
minix/llvm/clientctl

index e8921d633b8989ea7d912da454c7bce83c41a8e8..f97806dfdb939c5a636e69149fb1815f8f93ce7a 100755 (executable)
@@ -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"