/
create_and_boot_vm.sh
48 lines (38 loc) · 1.41 KB
/
create_and_boot_vm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
vmname="pxe_ks_linux"
VBoxManage controlvm ${vmname} acpipowerbutton
VBoxManage controlvm ${vmname} poweroff
dir="${HOME}/VirtualBox VMs/${vmname}"
# cpu & memory
cpu=2
cpuexecutioncap=100
mem=$(( 1024 * 2 ))
disk=$(( 1024 * 15 ))
VBoxManage unregistervm ${vmname}
rm -rf "${dir}"
mkdir -p "${dir}"
VBoxManage unregistervm --delete ${vmname}
VBoxManage createvm --name ${vmname} --ostype RedHat_64 --register
VBoxManage modifyvm ${vmname} --cpus ${cpu}
VBoxManage modifyvm ${vmname} --cpuexecutioncap ${cpuexecutioncap}
VBoxManage modifyvm ${vmname} --memory ${mem}
VBoxManage modifyvm ${vmname} --vram 64
VBoxManage modifyvm ${vmname} --graphicscontroller vmsvga
VBoxManage modifyvm ${vmname} --boot1 dvd --boot2 disk --boot3 net --boot4 none
# network
VBoxManage modifyvm ${vmname} --nic1 nat
VBoxManage modifyvm ${vmname} --nic2 intnet
VBoxManage modifyvm ${vmname} --intnet2 "mynetwork"
# storage
# controller
VBoxManage storagectl ${vmname} --name SATA --add sata --controller IntelAHCI
# disk
VBoxManage closemedium disk "${dir}/${vmname}.vdi" --delete
VBoxManage createmedium disk --filename "${dir}/${vmname}.vdi" --size ${disk} --format VDI
# attach
VBoxManage storageattach ${vmname} --storagectl SATA --port 0 --type hdd --medium "${dir}/${vmname}.vdi"
# controller
VBoxManage storagectl ${vmname} --name IDE --add ide --controller PIIX4 --hostiocache on
# run
VBoxManage startvm ${vmname} --type headless
exit