Created
April 14, 2017 15:39
-
-
Save nacika-ins/dbb2cb3feb4845ec35f50871c04aba1a to your computer and use it in GitHub Desktop.
kvm make instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage | |
#------------------------------------------------------------ | |
# ./mk_ws.sh --name hoge --port 8882 | |
args=$(getopt -l "name:" -l "port:" -o "n:" -o "p:" -- "$@") | |
eval set -- "$args" | |
while [ $# -ge 1 ]; do | |
case "$1" in | |
--) | |
# No more options left. | |
shift | |
break | |
;; | |
-n|--name) | |
NAME="$2" | |
shift | |
;; | |
-p|--port) | |
PORT="$2" | |
shift | |
;; | |
-h) | |
echo "Display some help" | |
exit 0 | |
;; | |
esac | |
shift | |
done | |
echo "名前: $NAME" | |
echo "ポート: $PORT" | |
echo "以上の内容で作成します。よろしいですか? [y/N]" | |
read ANSWER;ANSWER=`echo $ANSWER | tr y Y | tr -d '[\[\]]'` | |
case $ANSWER in | |
Y* ) ;; | |
* ) echo "終了しました";exit ;; | |
esac | |
# イメージファイル作成 | |
qemu-img create -f qcow2 /home/vm/vms/${NAME}.img 20G | |
# インスタンスの作成 | |
virt-install \ | |
--connect qemu:///system \ | |
--name=${NAME} \ | |
--connect=qemu:///system \ | |
--ram=2048 \ | |
--vcpu=2 \ | |
--os-type=linux \ | |
--hvm \ | |
--os-variant=ubuntuprecise \ | |
--disk path=/home/vm/vms/${NAME}.img,size=20,format=qcow2 \ | |
--cdrom=/home/vm/templates/FreeBSD-10.0-RELEASE-amd64-dvd1.iso \ | |
--network bridge=virbr0 \ | |
--graphics vnc,port=${PORT},listen=127.0.0.1,keymap=ja | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment