-i create raw image
-a all, run steps -g, -c, -r, -i
-l clean up vm
- -n don't use ramfs
+ -s speed up execution using ramfs
Some options are mutualy exclusive.
EOF
}
echo "Creating VM with VDI in ramfs..."
- # create ramfs
-# sudo mount -t ramfs ramfs -o mode=1777 ramfs
-# cp setup.iso ramfs/
+ if [ $option_ramfs -eq 1 ]; then
+ local vdi_file=ramfs/rescuesys.vdi
+ local iso_file=ramfs/setup.iso
+ # create ramfs
+ sudo mount -t ramfs ramfs -o mode=1777 ramfs
+ cp setup.iso ramfs/
+ else
+ local vdi_file=rescuesys.vdi
+ local iso_file=setup.iso
+ fi
# create and configure VM
VBoxManage createvm --name rescuesys --register > /dev/null
VBoxManage modifyvm rescuesys --memory 1024 --acpi on --boot1 disk --boot2\
- dvd --vram 12 --cpus $(nproc)
+ dvd --vram 12 --cpus $(getconf _NPROCESSORS_ONLN)
VBoxManage modifyvm rescuesys --nic1 nat --nictype1 82540EM\
--cableconnected1 on
VBoxManage modifyvm rescuesys --ostype Ubuntu_64
VBoxManage modifyvm rescuesys --ioapic on
-# VBoxManage createhd --filename ramfs/rescuesys.vdi --size 3814 > /dev/null
- VBoxManage createhd --filename rescuesys.vdi --size 3814 > /dev/null
+ VBoxManage createhd --filename $vdi_file --size 3814 > /dev/null
VBoxManage storagectl rescuesys --name SATA --add sata --hostiocache on
-# VBoxManage storageattach rescuesys --storagectl SATA --port 0 --device 0\
-# --type hdd --medium ramfs/rescuesys.vdi
-# VBoxManage storageattach rescuesys --storagectl SATA --port 1 --device 0\
-# --type dvddrive --medium ramfs/setup.iso
VBoxManage storageattach rescuesys --storagectl SATA --port 0 --device 0\
- --type hdd --medium rescuesys.vdi
+ --type hdd --medium $vdi_file
VBoxManage storageattach rescuesys --storagectl SATA --port 1 --device 0\
- --type dvddrive --medium setup.iso
+ --type dvddrive --medium $iso_file
}
run_VM()
echo "Creating image..."
rm -f rescuesys.img
-# VBoxManage clonehd ramfs/rescuesys.vdi rescuesys.img --format RAW >\
-# /dev/null
- VBoxManage clonehd rescuesys.vdi rescuesys.img --format RAW >\
- /dev/null
+ if [ $option_ramfs -eq 1 ]; then
+ local vdi_file=ramfs/rescuesys.vdi
+ else
+ local vdi_file=rescuesys.vdi
+ fi
+ VBoxManage clonehd $vdi_file rescuesys.img --format RAW > /dev/null
adapt_image
}
set -e
}
-action_other=
-action_generate_iso=
-action_create_VM=
-action_run_VM=
-action_create_image=
-action_all=
-action_cleanup=
-option_noramfs=
+action_other=0
+action_generate_iso=0
+action_create_VM=0
+action_run_VM=0
+action_create_image=0
+action_all=0
+action_cleanup=0
+option_ramfs=0
-while getopts "hgcrialn" opt; do
+while getopts "hgcrials" opt; do
case $opt in
h)
usage
l)
action_cleanup=1
;;
+ s)
+ option_ramfs=1
+ ;;
*)
usage
exit 1
[ -z "$1" ] && { usage; exit 0; }
-if [ $action_all && $action_other ] || [ $action_cleanup && $action_other ] ||\
- [ $action_all && $action_cleanup ]; then
+if (($action_all&&$action_other)) || (($action_cleanup&&$action_other)) ||\
+ (($action_all&&$action_cleanup)); then
usage
exit 1
fi
+
+[ $action_cleanup -eq 1 ] && { cleanup; exit 0; }
+[ $action_all -eq 1 ] && { generate_iso; create_VM; run_VM; create_image;\
+ exit 0; }
+
+[ $action_generate_iso -eq 1 ] && generate_iso
+[ $action_create_VM -eq 1 ] && create_VM
+[ $action_run_VM -eq 1 ] && run_VM
+[ $action_create_image -eq 1 ] && create_image
+
+exit 0