improve netdev, and add possibility to put no netdev
This commit is contained in:
parent
de44bbf565
commit
2997912cb8
1 changed files with 37 additions and 7 deletions
44
vm-start.sh
44
vm-start.sh
|
@ -37,9 +37,9 @@ OPTION available
|
|||
options=<option> additinal options to give to qemu. By default is
|
||||
-display gtk -vga qxl
|
||||
create_disk=<loc_disk> Def a create disk to boot on. Is necessary for using create, or need the variable INSTALLATION_DISK_LOCATION to be set.
|
||||
net=nat Add a nat connection to the vm. By default there is already one #TODO
|
||||
net=tap<tapInterface> Connect the vm to the tap interface <tapInterface>. Please use the script set-tap.sh as root to create the tap interface. #TODO
|
||||
net=none The vm will have no network interface #TODO
|
||||
net=nat:id Add a nat connection to the vm. By default there is already one.
|
||||
net=tap:<tapInterface> Connect the vm to the tap interface <tapInterface>. Please use the script set-tap.sh as root to create the tap interface. #TODO
|
||||
net=none The vm will have no network interface
|
||||
"
|
||||
|
||||
MAIN_LOCATION="$HOME/virtual_machine"
|
||||
|
@ -100,14 +100,18 @@ EOF
|
|||
}
|
||||
|
||||
start_the_vm() {
|
||||
|
||||
if [ "${network}" == "" ]
|
||||
then
|
||||
network="-net nic \
|
||||
-net user${FORWARD},hostname=${VMHOSTNAME}"
|
||||
fi
|
||||
|
||||
qemu-system-x86_64 \
|
||||
-enable-kvm \
|
||||
-cpu host \
|
||||
-smp "$NPROC" \
|
||||
-net nic \
|
||||
-net user"$FORWARD",hostname="$VMHOSTNAME" \
|
||||
-netdev user,id=id01,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
|
||||
-device virtio-net,netdev=id01 \
|
||||
$network \
|
||||
-m "$MEMORY" \
|
||||
-drive file="${MAIN_LOCATION}/${LOCATION}/${VMDRIVE}",index=2,id=maindrive,media=disk \
|
||||
$OPTION
|
||||
|
@ -195,6 +199,28 @@ set_uefi() {
|
|||
|
||||
}
|
||||
|
||||
set_net() {
|
||||
case "${1%:*}" in
|
||||
"nat")
|
||||
echo "ajout de l'interface ${1#*:}"
|
||||
network="${network} \
|
||||
-netdev user,id=${1#*:} \
|
||||
-device virtio-net,netdev=${1#*:}"
|
||||
;;
|
||||
"tap")
|
||||
echo "tap"
|
||||
;;
|
||||
"none")
|
||||
echo "no interface will be connected."
|
||||
network="-nic none"
|
||||
;;
|
||||
*)
|
||||
echo "type ${1%:*} not known, it should be either nat, tap or none" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
|
||||
# change active directory to became the one is stored vm-start. In case it is impossible, quit.
|
||||
|
@ -262,6 +288,10 @@ for (( i=3; i<=$#; i++)); do
|
|||
"create_disk")
|
||||
INSTALLATION_DISK_LOCATION="${!i#*=}"
|
||||
;;
|
||||
"net")
|
||||
param="${!i#*=}"
|
||||
set_net "${param}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in a new issue