Trying to make a series of scripts to make original state of VM drives but the if gets skipped
#!/bin/bash
file_a="../bin/wind7.vdi"
file_b="../VirtualBox VMs/Wind7/Wind7.vdi"
if -e $file_a ]; then
echo "backup vm drive exists ... deleting it"
rm $file_a
fi
echo Backing up "$file_b" to "$file_a"
cp "$file_b" ./
The script is in my home/me/bin folder as is the backup copies
I get file or directory does not exist but it is present in both source and destination so I should have gotten the backup vm exists … deleting followed by it doing the copy process.
This seems to work First time I ran the script it didn’t delete the existing file first, so I had two identical files in the destination folder. Ran it a second time and third time and in each of the other attempts was left with just one which was correct.
I use a similar script to create my VM if it doesn’t exist and do all the define stuff using virtualbox 4.3.x which the documentation says will place the files into VirtualBox VMs/vmname but when i use the script it creates the Wind7.vdi in /home/me and everything else in
VirtualBox VMs/vmname/Wind7.vbox.prev & Wind7.vbox. Using the exact same command in a terminal from /home/me/bin and the
Wind7.vdi goes where it is supposed to go (VirtualBox VMs/Wind7/Wind7.vdi
Looked but couldn’t find a way to explicitely set where it is to put the .vdi image file. Trying to run the script from with-in the VirtualBox folder does not work … it exists with access denied even as root.
Here is what i am proposing as a script to create and set-up a template to create a vm for windows 7 should i need to quickly re-install it fresh. Seems to work but many settings I have not tackled yet. The idea is that using a script to back-up a working
VM I can quickly restore along with all the programs using a restore script and if that doesn’t fix things use this script to re-insatll the OS fresh and use a batch file with-in the virtual windows 7 to re-install all software.
#!/bin/bash
if -d "$home/Virtualbox VMs/Wind7" ]; then
echo "Can not create a VM twice pls run $home/bin/Killwin7.sh and try again"
else
# Create a virtual machine for win7
echo "create and register wind7 vm"
/usr/bin/VBoxManage createvm --name Wind7 --register
#In the above command, “createvm” is used to create a virtual machine and “–name“ defines
#the name of the #virtual machine. It will create virtual machine called “Wind7.vbox” in home folder
#under “VirtualBox VMs/Wind7/Wind7.vbox”
# Create a virtual disk for guest installation
echo "make virtual disk"
#Now, create the hard disk image for the virtual machine using the below command
/usr/bin/VBoxManage createhd --filename "$home/VirtualBox VM/Wind7/Wind7.vdi" --size 50000 --variant standard
#In the above command, “createhd” is used to create hard disk image and “–filename” is used to specify the
# virtual machine’s name, for which the hard disk image is created. Here, “–size” denotes the size of the
#hard disk image. The size is always given in MB. Here we have specified 50Gb.
#Now set the OS type.
echo "OS Type is windows 7 64bit"
/usr/bin/VBoxManage modifyvm Wind7 --ostype windows7_64
#Now, set the memory size for the virtual OS
echo "Memory size set to 2MB"
/usr/bin/VBoxManage modifyvm Wind7 --memory 2048
# “–memory <size>” is used to set the RAM size for the virtual machine.
# Create a Storage controller for the harddisk
#Now create a storage controller for the virtual machine.
echo "add ide controller"
/usr/bin/VBoxManage storagectl Wind7 --name "IDE Controller" --add ide --controller PIIX4 --bootable on
#Here,
# storagectl <name> define what machine to set as being changed.
# –name <name> specifies the name of the storage controller that needs to be created
# –add <options> defines the type of system bus [ide|sata|scsi|floppy]
# –controller <options> type of chipset [LsiLogic|LSILogicSAS|BusLogic|IntelAhci|PIIX3|PIIX4/ICH6| I82078]
# –bootable <on/off>” defines whether this controller is bootable or not.
# /usr/bin/VBoxManage storagectl Wind7 --name SATA --add sata --controller IntelAhci --bootable on
#Using the above command, a storage controller called SATA has been created.
# Attach virtual disk to virtual guest
echo "attach virtual disk to ide"
#/usr/bin/VBoxManage storageattach Wind7 --storagectl SATA --port 0 --device 0 --type hdd --medium "filename"
/usr/bin/VBoxManage storageattach Wind7 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "$home/Virtual VMs/Wind7/Wind7.vdi"
#Here
# storageattach <name> says we are attaching to machine Wind7
# –storagectl <name> define the name of the storage controller to be attached ie 'SATA'
# –port <number> define the number of storage controller’s port
# –device <number>” define the number of the port’s device
# –type <options> type of the drive [dvddrive | hdd | fdd]
# –medium <options> defines the hard disk image as [none|emptydrive|<uuid>|<filename>]
#*Note: If you decide to specify the filename, then specify the full path where it is located.
#Example: “/home/user/Wind7.vdi”
# Attach the ISO operating image to be installed
echo "attach Windows iso image"
/usr/bin/VBoxManage storageattach Wind7 --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium Win_7_x64.ISO
#Here
# storageattach <name> says we are attaching to machine Wind7
# –storagectl <name> define the name of the storage controller to be attached ie 'IDE'
# –port <number> define the number of storage controller’s port
# –device <number>” define the number of the port’s device
# –type <options> type of the drive [dvddrive | hdd | fdd]
# –medium <options> defines the hard disk image as <filename>]
# medium of ISO image as DVD drive. This medium can be closed after installing the virtual OS(Wind7).
# “filename“– Example: “/home/<user>/bin/windows7_64.iso”
#Next, add some features like audio, 3d acceleration, network, etc,.
#One of the most important command in VBoxManage is “modifyvm“. Using “modifyvm”, one can modify many
#features in virtual machine like changing the memory size, name of the Virtual Machine, OS type and many
#more. The name of the virtual machine has to be specified inorder to modify it.
VBoxManage modifyvm Wind7 --vram 18 --accelerate3d off --audio pulse --audiocontroller ac97
#Here
# –vram <size> is 18MB for graphics card
# –accelerate3d <on/off>” is set off (on requires guest additions).
# –audio <options> are one of [none|null|oss|alsa|pulse].
# –audiocontroller <options> are one of [ac97 | hda | sb16].
# Modify settings needed before it starts for the first time
echo "Modifying settings..."
/usr/bin/VBoxManage modifyvm Wind7 --description "Windows 7 Professional"
/usr/bin/VBoxManage modifyvm Wind7 --acpi on
/usr/bin/VBoxManage modifyvm Wind7 --ioapc on
/usr/bin/VBoxManage modifyvm Wind7 --cpus 2
/usr/bin/VBoxManage modifyvm Wind7 --pae off
/usr/bin/VBoxManage modifyvm Wind7 --longmode on
/usr/bin/VBoxManage modifyvm Wind7 --nestedpaging on
/usr/bin/VBoxManage modifyvm Wind7 --largepages off
/usr/bin/VBoxManage modifyvm Wind7 --vtxvpid on
/usr/bin/VBoxManage modifyvm Wind7 --vtxux on
/usr/bin/VBoxManage modifyvm Wind7 --boot1 dvd
/usr/bin/VBoxManage modifyvm Wind7 --boot2 disk
/usr/bin/VBoxManage modifyvm Wind7 --clipboard bidirectional
/usr/bin/VBoxManage modifyvm Wind7 --audio none|null|oss|alsa|pulse]
/usr/bin/VBoxManage modifyvm Wind7 --audiocontroller ac97|hda|sb16]
/usr/bin/VBoxManage modifyvm Wind7 --draganddrop disabled|hosttoguest
#/usr/bin/VBoxManage modifyvm Wind7 --groups <group>, ...]
#/usr/bin/VBoxManage modifyvm Wind7 --iconfile <filename>]
#/usr/bin/VBoxManage modifyvm Wind7 --pagefusion on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --hpet on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --triplefaultreset on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --hwvirtex on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --synthcpu on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --cpuidset <leaf> <eax> <ebx> <ecx> <edx>]
#/usr/bin/VBoxManage modifyvm Wind7 --cpuidremove <leaf>]
#/usr/bin/VBoxManage modifyvm Wind7 --cpuidremoveall]
#/usr/bin/VBoxManage modifyvm Wind7 --hardwareuuid <uuid>]
#/usr/bin/VBoxManage modifyvm Wind7 --cpuhotplug on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --plugcpu <id>]
#/usr/bin/VBoxManage modifyvm Wind7 --unplugcpu <id>]
#/usr/bin/VBoxManage modifyvm Wind7 --cpuexecutioncap <1-100>]
#/usr/bin/VBoxManage modifyvm Wind7 --rtcuseutc on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --graphicscontroller none|vboxvga|vmsvga]
#/usr/bin/VBoxManage modifyvm Wind7 --monitorcount <number>]
#/usr/bin/VBoxManage modifyvm Wind7 --accelerate2dvideo on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --firmware bios|efi|efi32|efi64]
#/usr/bin/VBoxManage modifyvm Wind7 --chipset ich9|piix3]
#/usr/bin/VBoxManage modifyvm Wind7 --bioslogofadein on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --bioslogofadeout on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --bioslogodisplaytime <msec>]
#/usr/bin/VBoxManage modifyvm Wind7 --bioslogoimagepath <imagepath>]
#/usr/bin/VBoxManage modifyvm Wind7 --biosbootmenu disabled|menuonly|messageandmenu]
#/usr/bin/VBoxManage modifyvm Wind7 --biossystemtimeoffset <msec>]
#/usr/bin/VBoxManage modifyvm Wind7 --biospxedebug on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --boot<1-4> none|floppy|dvd|disk|net>]
#/usr/bin/VBoxManage modifyvm Wind7 --nic<1-N> none|null|nat|bridged|intnet|hostonly|
# generic|natnetwork]
#/usr/bin/VBoxManage modifyvm Wind7 --nictype<1-N> Am79C970A|Am79C973|
# 82540EM|82543GC|82545EM|virtio]
#/usr/bin/VBoxManage modifyvm Wind7 --cableconnected<1-N> on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --nictrace<1-N> on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --nictracefile<1-N> <filename>]
#/usr/bin/VBoxManage modifyvm Wind7 --nicproperty<1-N> name=[value]]
#/usr/bin/VBoxManage modifyvm Wind7 --nicspeed<1-N> <kbps>]
#/usr/bin/VBoxManage modifyvm Wind7 --nicbootprio<1-N> <priority>]
#/usr/bin/VBoxManage modifyvm Wind7 --nicpromisc<1-N> deny|allow-vms|allow-all]
#/usr/bin/VBoxManage modifyvm Wind7 --nicbandwidthgroup<1-N> none|<name>]
#/usr/bin/VBoxManage modifyvm Wind7 --bridgeadapter<1-N> none|<devicename>]
#/usr/bin/VBoxManage modifyvm Wind7 --hostonlyadapter<1-N> none|<devicename>]
#/usr/bin/VBoxManage modifyvm Wind7 --intnet<1-N> <network name>]
#/usr/bin/VBoxManage modifyvm Wind7 --nat-network<1-N> <network name>]
#/usr/bin/VBoxManage modifyvm Wind7 --nicgenericdrv<1-N> <driver>
#/usr/bin/VBoxManage modifyvm Wind7 --natnet<1-N> <network>|default]
#/usr/bin/VBoxManage modifyvm Wind7 --natsettings<1-N> <mtu>],<socksnd>],
#/usr/bin/VBoxManage modifyvm Wind7 <sockrcv>],<tcpsnd>],
#/usr/bin/VBoxManage modifyvm Wind7 <tcprcv>]]
#/usr/bin/VBoxManage modifyvm Wind7 --natpf<1-N> <rulename>],tcp|udp,<hostip>],
# <hostport>,<guestip>],<guestport>]
#/usr/bin/VBoxManage modifyvm Wind7 --natpf<1-N> delete <rulename>]
#/usr/bin/VBoxManage modifyvm Wind7 --nattftpprefix<1-N> <prefix>]
#/usr/bin/VBoxManage modifyvm Wind7 --nattftpfile<1-N> <file>]
#/usr/bin/VBoxManage modifyvm Wind7 --nattftpserver<1-N> <ip>]
#/usr/bin/VBoxManage modifyvm Wind7 --natbindip<1-N> <ip>
#/usr/bin/VBoxManage modifyvm Wind7 --natdnspassdomain<1-N> on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --natdnsproxy<1-N> on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --natdnshostresolver<1-N> on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --nataliasmode<1-N> default|[log],[proxyonly],
#/usr/bin/VBoxManage modifyvm Wind7 sameports]]
#/usr/bin/VBoxManage modifyvm Wind7 --macaddress<1-N> auto|<mac>]
#/usr/bin/VBoxManage modifyvm Wind7 --mouse ps2|usb|usbtablet|usbmultitouch]
#/usr/bin/VBoxManage modifyvm Wind7 --keyboard ps2|usb
#/usr/bin/VBoxManage modifyvm Wind7 --uart<1-N> off|<I/O base> <IRQ>]
#/usr/bin/VBoxManage modifyvm Wind7 --uartmode<1-N> disconnected|
# server <pipe>|
# client <pipe>|
# file <file>|
# <devicename>]
#/usr/bin/VBoxManage modifyvm Wind7 --lpt<1-N> off|<I/O base> <IRQ>]
#/usr/bin/VBoxManage modifyvm Wind7 --lptmode<1-N> <devicename>]
#/usr/bin/VBoxManage modifyvm Wind7 --guestmemoryballoon <balloonsize in MB>]
#/usr/bin/VBoxManage modifyvm Wind7 --vrde on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeextpack default|<name>
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeproperty <name=[value]>]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeport <hostport>]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeaddress <hostip>]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeauthtype null|external|guest]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdeauthlibrary default|<name>
#/usr/bin/VBoxManage modifyvm Wind7 --vrdemulticon on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdereusecon on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdevideochannel on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --vrdevideochannelquality <percent>]
#/usr/bin/VBoxManage modifyvm Wind7 --usb on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --usbehci on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --snapshotfolder default|<path>]
#/usr/bin/VBoxManage modifyvm Wind7 --teleporter on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --teleporterport <port>]
#/usr/bin/VBoxManage modifyvm Wind7 --teleporteraddress <address|empty>
#/usr/bin/VBoxManage modifyvm Wind7 --teleporterpassword <password>]
#/usr/bin/VBoxManage modifyvm Wind7 --teleporterpasswordfile <file>|stdin]
#/usr/bin/VBoxManage modifyvm Wind7 --tracing-enabled on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --tracing-config <config-string>]
#/usr/bin/VBoxManage modifyvm Wind7 --tracing-allow-vm-access on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --usbcardreader on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --autostart-enabled on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --autostart-delay <seconds>]
#/usr/bin/VBoxManage modifyvm Wind7 --vcpenabled on|off]
#/usr/bin/VBoxManage modifyvm Wind7 --vcpscreens <display>],...
#/usr/bin/VBoxManage modifyvm Wind7 --vcpfile <filename>]
#/usr/bin/VBoxManage modifyvm Wind7 --vcpwidth <width>]
#/usr/bin/VBoxManage modifyvm Wind7 --vcpheight <height>]
#/usr/bin/VBoxManage modifyvm Wind7 --vcprate <rate>]
#/usr/bin/VBoxManage modifyvm Wind7 --vcpfps <fps>]
#/usr/bin/VBoxManage modifyvm Wind7 --defaultfrontend default|<name>]
# uncomment next line to allow networking of Windows 7
echo "skip netowrking"
# /usr/bin/VBoxManage modifyvm Wind7 --nic1 bridged --cableconnected1 on --nictrace off
# open the new vm for win7 and start the software install
echo "skip run of new vm"
# /usr/bin/VBoxManage startvm Wind7
# Need to remove the installation dvd after install finishes
# VBoxManage modifyvm Wind7 --dvd none
ls "$home/VirtualBox VMs"
fi
You can build your scripts from scratch,
Or, if you’d be interested in using a system of pre-configured scripts to create, invoke, shutdown and otherwise manage virtual machines (including VBox) I’d recommend the widely used Vagrant
Note that Vagrant is very technology and platform agnostic. You can use Vagrant on a variety of hardware and OS to manage practically any virtualization technology that exists. And, it’s all scripts.
Interesting read but some of the functionality seems missing. The problem I have had is trying to coach a non-computer person 3000 miles away who is constantly having me try to walk her through fixing windows due to slowdowns and suspected malware and viruses issues. I am creating two identical machines and sending one to her set-up hopefully to be easy to fix. Under my plan the original script will allow me to pre set up 3 windows versions linked to shared data and under control of linux and virtualbox. In theory at least two scripts save<version>.sh and load<version>.sh will handle backup and restore of the full windows version inclusive of installed apps should she get infected with malware or viruses. And if all else fails she can use the kill<version> script to remove the
VM and Make<version> script to create a new clean version and the installapps.bat from within the version to re-install all the apps.
With a lot of help from this forum (not this particular section) I have managed to create video’s to walk her through using linux, and windows versions running under virtualbox which I hope will reduce the learning curve.
I just need to be sure the scripts all do as intended. loadvm / savevm / killvm so far work now Makevm was working but I have to check why some of my changes stopped it from working. Of note, Windows 7 and above do not tollerate anything that might suggest a hardware change after install so that is why I am trying to make sure vbox settings are 100% before an install attempt.
The scenario and your objectives are fairly common for virtualization in general, and there are published solutions.
But, let’s fine tune (propose alternatives) to some of your procedures to reduce complexity and improve efficiency for both yourself and your non-computer person.
The first major recommendation is to either instruct her or provide a script that clones an existing Guest. Once cloned, a near exact copy is the backup and is created if needed. The only difference whenever a clone is created are the networking (MAC address primarily) and hostname (because you shouldn’t have two machines with the same name on your network if you happen to launch both Guests at once). All other VBox Guest properties(options) are identical, so in theory if the original Guest has network connectivity, then any clones will connect exactly the same way.
The advantage of cloning instead of creating and sending/downloading entirely new Guests (aka Appliances) is to avoid all those file transfers. As long as you have cloned a Guest, nearly all your copes of the Guest are entirely disposable (just delete) and its replacement running within seconds with the simple push of a button.
So, although you didn’t give any examples of what kinds of problems you want to have fixed, let’s say one day she notices things are slow and maybe specific things aren’t working properly. Instead of trying to figure out what happened, she might simply delete that Guest and fire up one of the clones she’s made. She might have a choice of clones that were made yesterday, the week before, when you first sent her the original Guest appliance.
You may also ask “What if I want to modify the Guest?” That’s scriptable, either within openSUSE using install scripts like what I’ve posted in various Wiki articles I’ve written, or externally using something like Vagrant (Yes, Vagrant can push modifications easily from outside the Guest).
All of the above can be managed within Virtualbox manager, or if you wish by command line(VBox has its own scripting language for VBox management). Or, if you prefer to use Vagrant, a lot of functionality is packaged into solutions. This is a personal decision which to use. And, everything you’ve described in your last post if you want to continue that approach is definitely in Vagrant for VBox Guest setup in your proposed network and management.
Last note… Be aware that MS has licensing issues related to creating copies of Windows, although many of Microsoft’s own have recommended just doing what you need if you’re adhering to the spirit of the license you’d likely be breaking the letter of the agreement. If I were doing this on a large scale (not just one close person), I’d likely call up MS licensing to get a clarification for this particular use and if it sounds acceptable, ask that the interpretation be sent to me in an email… Because MS licensing is so convoluted the next person might have an entirely different interpretation. So, it’s important to get something in writing.
@TSU
I have been dealing with her issues for 15 years at least and with each new windows the problems multiply. I am not breaking license issue since making a drive copy that cannot be run without replacing the original is in their EULA. Virtualbox clones do specifically violate licensing since you could create or modify them to run as two instances. Habits are hard to break and even my approach has an inherant flaw. Say she gets a virus and chooses to either delete the wrong clone thus killing her alternate working copy leaving her with just the infected one, or… in my method chooses the save-script instead of the load-script she again ends with an infected copy.
The kill-script totally removes the previous install and Make-script initiates a clean fresh install preconfigured to work with her only needing to present her license key at the appropiate time and because it is preconfigured with all settings right, she will not face the dreaded windows7, 8, 9, or 10 bugs that see even a change in the number of drives, or usb devices etc as being a new piece of hardware. What she has already found with windows 7 on her other laptop is that each time attaches and removes her external back-up drive it counts as one of her 7 allowed hardware changes. Upon the seventh re-attach of the same drive she gets “this version of windows is not genuine” and a box asking her to call Microsoft for a resolve. She did that once and they told her she had to re-install with a new license key for $35. Next time she just re-installed using her recovery disc. I can see it being an issue if the motherboard or harddisk (which would require re-install or migrate) but not for hotplug devices like externals, flashcards, mice, and printers. In my tests I found making changes to the virtual machine also causes problems unless you set-up USB and drives before the install and never change them. example: I configure one open USB port and one USB set to vender of the external hdd and windows 7 does not complain if the drives are on or off the system BUT define them after you have installed windows and it counts as a hardware change everytime you attach and dettach the devices.
On the EULA note, when you install ms windows you have the option to make recovery discs for the purpose of recovering your system should you have an issue. In our case we just made an iso of the disc to be used to recover her system. <br><br>What bothered me about virtualbox snapshots is they were far to easy to mistakingly restore the wrong one, also I noted that a merge feature could be invoked which in the case of a virus would carry the virus from version to version (not what we intend to do). Clones work fine in theory but as you said there is the same ELUA license issue. With a clone you can have more than one copy
>running which is a clear problem. Vagrant was interesting but then I realized that I would be defining everything I did in my script into theirs, then adding programs to both machines to run the scripts and adding a layer of heavy learning for her at her end if she runs into trouble…
Yup,
I only mentioned the MS licensing issue as something to consider (and you’ve seemed to consider it).
As I suggested, MS has a varying approach to following licensing to the letter and even interpreting the letter. So, sometimes MS might consider the practical objective and that the User is trying to best be consistent with the spirit (not promoting piracy), but sometimes some badass guy could still require a strict interpretation. And, it’s recognized that depending on the Windows version, certain virtualization practices did not exist common today were not recognized when that Windows EULA was created.
So, thankfully FOSS generally has fewer issues to deal with. Although there are other types of licenses, the main ones we use are GPLv2 and GPLv3.
If the scripts you use fulfill your needs, go for it.