diff options
| author | Marc Vertes <mvertes@free.fr> | 2021-03-19 22:27:11 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2021-03-19 22:27:11 +0100 |
| commit | a8e3586e9b691c2a25b5f2e50a2761d5fcad18f8 (patch) | |
| tree | ec26001917a7cf009b18271972c03c9094d7dfc5 /bin/vm | |
| parent | d86227be78743b71c713a7ce6267cfcea73f6582 (diff) | |
update
Diffstat (limited to 'bin/vm')
| -rwxr-xr-x | bin/vm | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -8,6 +8,7 @@ vm_version='vm-0.1' # - DONE: fetch, build and install vftool in .vm/vftool # - DONE: setup a config file per VM # - creation of hdd image +# - import iso, kernel, initrd from existing vm # - script install from CDROM iso: # - setup system, including static IP address # - setup user account from host @@ -20,13 +21,31 @@ export LC_ALL=C IFS=' ' add() { - usage 'add name' 'Add a new VM' && return + usage 'add [Options] name' 'Add a new VM' && return + while getopts :c:p:s: opt; do + case $opt in + c|k|p|s) eval "$opt=$OPTARG";; + *) Opth=1 add; exit ;; + esac + done + shift $((OPTIND - 1)) + [ -d "$dir/$1" ] && die "vm $1 already exists in $dir/$1" init_alpine || die "could not init alpine iso" mkdir -p "$dir/$1" && cd "$dir/$1" || die "add $1 failed" - pwd + hdd=${p-$1.raw} + [ -f "$hdd" ] || dd if=/dev/zero of=$hdd bs=1 count=0 seek=${s-32g} 2>/dev/null + echo "hdd=\"$hdd\"" > config + [ "$c" ] && { + [ -d "../$c" ] || die "invalid directory: $dir/$c" + iso=$(getconf "$c" iso) + [ "$iso" ] && echo "iso=\"../$c/$iso\"" >> config + cp "../$c/vmlinux" "../$c/initrd" . + } } +getconf() { awk -F '=' -v k="$2" '$1 == k {print $2}' "$dir/$1/config"; } + console() { usage 'console name' 'Attach a console to a VM' && return [ "$1" ] || die 'console: name is missing' @@ -128,6 +147,7 @@ start() { cd "$dir/$1" || die "start $1 failed" [ -f vftool.pid ] && die "Error: process $(cat vftool.pid) is active or $PWD/vftool.pid should be removed" start_vm & + [ "$attach" ] && sleep 1 && vm console $1 } start_vm() ( @@ -139,8 +159,8 @@ start_vm() ( "$dir/vftool" \ -k vmlinux \ -i initrd \ - ${iso+-c "$iso"} \ ${hdd+-d "$hdd"} \ + ${iso+-c "$iso"} \ ${cpu+-p "$cpu"} \ ${ram+-m "$ram"} \ ${arg+-m "$arg"} \ |
