Internet Windows Android

Getting started with VirtualBox (for dummies). Getting Started with VirtualBox (for Dummies) Accelerating the launch of programs in virtualbox

Getting Started with VirtualBox
(for Dummies)

2014.12.12. |

Recently, in Getting Started with VMware Workstation, I covered the basics of working with a VMware virtual machine, hoping to show that working with virtual machines is simple and rewarding. VMware is good for everyone, but it has one drawback - it is paid and not cheap. Today I want to talk about a free alternative to VMWare - the VirtualBox virtual machine.

I will use VirtualBox 4.3.20 for Windows and the ubuntu-12.04 guest operating system as an example. And I will install and configure all this in the Window 7 host operating system.

1. Install the VirtualBox 4.3.20 for Windows virtual machine.

The most convenient way is to download the virtual machine distribution kit from the official site “www.virtualbox.org”, from the page https://www.virtualbox.org/wiki/Downloads. There you will find all the latest versions of the virtual machine for most of the popular operating systems. I am downloading for Windows operating system (Figure 1).

The distribution kit of VirtualBox 4.3.20 for Windows is presented as a single executable file VirtualBox-4.3.20-96997-Win.exe with a volume of 105 MB.

After launching the executable file, a window opens informing about the preparation for the start of the installation of the program (Figure 2).

After a few seconds, the Installation Assistant window will open. To start the installation, click the "Next" button. After that, the window for selecting the volume and location of installation will open (Figure 3).

By default, you will be prompted to install all the components of the virtual machine, I do not recommend disabling the installation of any components unnecessarily, since all of them will be needed even with minimal use of the virtual machine. Also, by default, it will be offered to install the program in the "Programs Files \ Oracle \ VirtualBox \" folder and here I will not change anything. To proceed to the next stage of the installation, press the "Next" button.

In the window that opens (Figure 4), the basic settings for starting the virtual machine will be offered:

Create a shortcut on the desktop;
- create a shortcut in the quick launch bar;
- register the Virtual Box file extensions in the operating system.

Of these settings, I will leave the first and third, but this is a matter of taste and habit.

To continue the installation, click "Next", after which a window will open (Figure 5) warning that during the installation process the network connection will be terminated. To avoid data loss, it is advisable to assure the operation of applications using a network connection and wait until all data has been downloaded from the network.

The network connection will be interrupted for just a few seconds and then will be automatically restored, so feel free to click the "Yes" button to proceed to the next stage of preparation for installation. The window that opens (Figure 6) informs you that all the necessary preparations for installing the program have been made and you can proceed with the installation. To start the installation, click the "Install" button and you will see a window showing the installation process (Figure 7).

During the installation process, the operating system will ask for confirmation to allow the installation of USB channel controllers for the virtual machine (Figure 8), network adapters (Figure 9) and network services (Figure 10).

For convenient work with the virtual machine, it is desirable to be able to access the USB controllers and work with the network, therefore, we agree with the installation of these components.

After the installation is completed, a window will open on the screen informing about this long-awaited event (Figure 11). Click the Finish button to complete the installation and proceed to creating and configuring the virtual machine.

2. We create a virtual machine.

Well, let's get down to creating a virtual machine. It won't be any more difficult than installing VirtualBox. And so, we launch VirtualBox and the main program window opens in front of us (Figure 12).

To create a virtual machine, press the button or select the menu item: "Machine-> create" or press the key combination Ctrl + N. In the window that opens (Figure 13), set the name of the virtual system, the type and version of the guest operating system.

My virtual machine will be named "VM". Since I decided to use ubuntu-12.04 as a guest, the guest type will be Linux and the version will be Ubuntu (32 bit). After setting the required parameters, click "Next".

In the window that opens (Figure 14), select the size of the RAM allocated for the virtual machine.

In most cases, the default 512 MB of memory is sufficient. If you have little RAM, then this size can be reduced, but do not set it too low, as this may affect the performance of the virtual machine. If necessary, if you need to run resource-intensive applications in a virtual machine, the amount of allocated RAM can be increased. After choosing the amount of RAM, click "Next".

In the next window (Figure 15), you need to select the virtual hard disk with which the virtual machine will work.

There are two options: choose a ready-made one or create a new one. Since we are just starting to work with VirtualBox, we do not have the already created virtual hard disks, so we select "Create a new virtual hard disk" and click "Create".

In the window that opens (Figure 16), click, first of all, on the "Hide details" button. In this version of VirtualBox, there is an error in the translation or the name of this button, and when you click the "Hide details" button, a window with detailed settings for the created virtual hard disk is displayed.

After clicking the "Hide details" button, a window with advanced hard disk settings opens (Figure 17).

First of all, we select the type of virtual hard disk. To ensure compatibility with other virtualization programs, it is possible to create virtual hard disks of several types, for example, VMDK hard disks can be used with VMware virtual machines.

Since the purpose of this article is to give basic skills in working with a VirtualBox virtual machine, I will choose the type of virtual disk VDI - the format of hard disks designed to work with VirtualBox virtual machines.

WARNING: Make sure you have enough space on your hard disk to create a virtual hard disk before you start creating it.

To create a virtual female disk, click "Create". Then a window will open illustrating the process of creating a hard disk (Figure 18). This may take a few minutes.

The created virtual disk is an ordinary file in the host operating system with the name and VDI extension you specified. This file can be moved, copied, transferred to another computer. For example, if you need to work with the same virtual machine at home and in the office, you can transfer a hard disk file on a flash drive and work at home and in the office with the same virtual machine.

After creating the virtual hard disk, a new virtual machine will appear in the main window of the VirtualBox program, ready to use (Figure 19). All that remains is to install the guest operating system on it.

3. Install the guest operating system.

The installation of the guest operating system will start automatically after the first start of the virtual machine. And so, we start the virtual machine by pressing the button. After a few seconds, a window will open (Figure 20), in which you will be asked to specify the path to the boot disk or the boot disk image.

I will install the operating system from the boot disk image (ubuntu-12.04-oem-i386.iso) downloaded by RuTracker.org in advance. To select the boot disk image, press the button and in the window that opens (Figure 21) select the ubuntu-12.04-oem-i386.iso file, press the "open" button and to start installing the operating system in the window (Figure 20), press the "Continue" button.

Immediately after pressing the button, the virtual machine will start (Figure 22) and after a few seconds the installation of the guest operating system will automatically start. During the installation of the operating system, you will see prompts designed to make it easier to work with the virtual machine.

The installation of the guest operating system will proceed in exactly the same way as when installing this operating system on a real computer or on a VMWare virtual machine. Since I have already described the process of installing a similar operating system in the article "Getting Started with VMware Workstation", in the section on installing a guest operating system, I will not repeat myself and will go straight to describing the basics of working with a virtual machine.

4. Basic operations with a virtual machine.

4.1. Running a virtual machine

Start the virtualization program VirtualBox. The main program window will open on the screen (Figure 23).

If in the left part of the window that opens, in the list of available virtual machines, there is no one you need, then select the menu item:

Machine-> Add

In the file manager that opens, select the virtual machine you need (file with permission .vbox) and click the "open" button. The selected virtual machine will appear in the list of available virtual machines on the left side of the main VirtualBox window.

In the list of virtual machines in the window (Figure 23), select the one you need. I will select a virtual machine named "VM" and start the selected virtual machine in one of the following ways:

By clicking the button at the top of the window, under the "Edit" menu;
- by selecting a menu item: Machine-> Run.

After starting the virtual machine, if its state was saved, the state of the virtual machine will be automatically restored and you can continue working as if you had not turned off the virtual machine. If the state of the virtual machine was not saved, then the installed guest system will start, similar to the launch of the operating system when a real computer is turned on.

4.2. Pause the virtual machine.

It is often necessary to temporarily leave the workplace. If at this moment a certain program is running and you cannot miss any important moment in the process of this program, then VirtualBox provides the ability to temporarily suspend the operation of the virtual machine. To do this, select the menu item: Machine-> Suspend and the virtual machine will automatically pause. To resume work, select the menu item again: Machine-> Suspend.

Naturally, you can shutdown the stateful virtual machine and then restart the virtual machine, but this takes much longer. If setting to pause takes a split second, then saving the state can take several tens of seconds. If you often have to be distracted, then it is much more convenient to pause.

4.3. Shutting down the virtual machine.

There are several ways to shut down the virtual machine:

1. Click the shutdown button in the upper right corner of the window (Figure 24). In the menu that opens (Figure 25), select one of the following items:

- "Save Machine State", which saves the machine state and then shuts down the virtual machine. The next time you start the virtual machine, the state of the virtual machine will be automatically restored and work will continue as if you had not turned off the virtual machine.

- "Send shutdown signal", this will open the shutdown window, the appearance of which depends on the operating system used. Using this window, you will be able to shut down the guest operating system in a regular manner, and after the guest operating system is shut down, the virtual machine will shut down automatically.

- "Turn off the car." This action is equivalent to de-energizing a real machine.

I would like to draw your attention to the fact that in the version of VirtualBox used in this program, regardless of your choice in the operating system shutdown window, a few seconds after selecting "Send shutdown signal" the virtual machine turns off.

2. Shut down the guest operating system in a regular way provided by the guest operating system, and the virtual machine will automatically shut down after the guest operating system is shut down.

3. Select a menu item: Machine -> Send Ctrl-Alt-Del, in this case, the actions of the virtual machine will be similar to the action of a real computer when the keyboard keys of the same name are pressed, i.e. the task manager will start, the appearance of which depends on the operating system used. Using the Task Manager, it will be possible to shut down the entire guest operating system or individual threads. After the guest operating system is shut down, the virtual machine will shut down automatically.

4. Select a menu item: Machine -> reboot, after which a window will open (Figure 26), warning about the loss of all unsaved data in applications running in the guest operating system, if you continue to reboot. If you click the "Restart" button, then the further actions of the virtual machine will be similar to the actions of a personal computer when you click the "Restart" button on the "system manager".

5. Select the menu item: Machine-> shut down, this will open the shutdown window, the appearance of which depends on the operating system used. Using this window, you will be able to shut down the guest operating system in a regular manner, and after the guest operating system and the system are shut down, the virtual machine will shut down automatically.

I would like to draw your attention to the fact that in the version of VirtualBox used in this program, regardless of your choice in the shutdown window of the operating system, in a few seconds after selecting the menu item "Machine-> shut down", the virtual machine is shutting down.

4.4. Connecting removable devices to a virtual machine.

Let's consider the connection of removable devices using the example of connecting and disconnecting a USB drive.

To connect a USB storage, select the menu item: Devices-> USB Devices and in the list that opens (Figure 27) select the USB device you need. In my case, the USB drive was identified as "Generic Mass Storage".

After selecting the "Generic Mass Storage" menu item, the USB storage will be connected as if you had connected a flash drive to a real computer, and in the list (Figure 27) the selected device will be marked with a check mark. Further actions are determined by the operating system you are using. To disconnect the USB storage, uncheck the checkbox in the same menu. As you can see, everything is very simple.

ATTENTION! When a removable device is connected to a virtual machine, it is disabled in the host operating system, which may result in the loss of unsaved data. Therefore, before connecting a removable device to a virtual machine, make sure that you do not perform any actions with it in the host operating system.

4.5. Switching between host and guest operating systems.

When working in a virtual machine, the keyboard and mouse are "captured", that is, all keystrokes or mouse actions are processed by the virtual machine and ignored in the host operating system. In order to switch to work with the host operating system, you must press the "Host" key or a combination of keys. For different versions of virtual machines and depending on their settings, the "Host" key may be different, but the name of the key is displayed in the lower right corner of the virtual machine window (Figure 28).

When you press this key, the processing of all events from the keyboard and mouse will again be processed by the host operating system. In order to return to work with the virtual machine, you just need to click with the mouse anywhere in the ritual machine window.

This is quite enough to start working with a virtual machine, and in the future, if you like the new tool, and you will certainly like it, you can easily explore all its capabilities, and I will try to help you in one of the following articles.


From time to time you have to work with virtual machines in VirtualBox, but you are absolutely not satisfied with the speed of their work? In this article we will try to tell you how to speed up VirtualBox!

Whether you are a software developer or web designer or a tech geek interested in new products, the slow operation of a virtual machine is not to anyone's liking. One of the popular virtual machines, and also free, is Oracle Virtualbox.

Speed ​​up VirtualBox

We will tell you how to make virtual operating systems work faster in it later.

Components for your server or PC

The most powerful argument in the fast operation of the OS in Virtualbox is high-performance components. For more or less comfortable work, you will need:

  • Intel Core i5 processor, equivalent or better
  • RAM from 8 GB
  • SSD or HDD with enough free memory (One OS installed at least 8 GB)

On slower hardware, you can't get VirtualBox to run fast, no matter what you do.

Configuring UEFI / BIOS

Modern Intel and AMD processors have the ability to hardware virtualization, enabling this option in can significantly speed up the operation of the VirtualBox virtual machine. This requires the Intel VT-x or AMD-V options to be enabled.

Configuring VirtualBox

Now let's look at the options that should be enabled or changed in VirtualBox to speed up the virtual machine.

Location of virtual machines

If your computer has more than one disk (HDD or SSD), then the very initial setting that should be changed is the "default folder for machines". It is necessary to perform this setting because, during the operation of individual programs and the OS, they can cause delays in the disk subsystem, so that this does not happen, it is necessary to place the "virtual machines" on another disk.

Better yet, if it is an SSD drive. The only thing worth paying attention to is that you should not specify an external drive, as the read / write speed will be much lower than from internal disks.

To set the "default folder" you need to select "File" in the panel and go to the "General" tab.

Settings when creating virtual machines

When creating a virtual machine, pay attention to the following parameters:


Configuring virtual machine settings

After the virtual hard disk has been created, you can configure it to allocate some resources to the OS.

Section "System"

In the "System" section, the "Processor" tab, check the box next to "Enable PAE / NX" if you have provided more than 4 GB to the virtual system.

Specify the acceptable number of processor cores.

In the "Acceleration" tab, enable hardware virtualization by checking the "Enable VT-x / AMD-V" and "Enable Nested Paging" checkboxes.

In the drop-down list "Paravirtualization interface" specify:

  • Hyper-V - for Windows
  • KVM - for operating systems on the Linux kernel (Ubuntu, Fedora, OpenSuse, Mint, Debian)

Display section

In the "Display" section, check the box next to "Acceleration: Enable 3D acceleration", if you are using Windows, then also check "Enable 2D acceleration".

Set the maximum amount of video memory. It is worth noting here that from the VirtualBox interface, you cannot specify the amount of video memory over 128 MB, to specify more (up to 256 MB), follow these steps:


Section "Media"

In the "Media" section, select the virtual SATA controller on which the virtual machine will be installed (or is already installed) and check the box next to "I / O caching"

After installing the virtual system

After you install the operating system in the virtual machine, you should immediately connect the guest OS add-ons and install the "drivers" for virtual Windows or Linux and reboot the system.

What else can speed up VirtualBox?

If you have followed all the steps that we wrote above, then the following steps will help you to increase the performance of the virtual system:


Still have questions? Write them in the comments, tell us what you did or vice versa!

That's all! Read more articles and instructions in the section. Stay with the site, it will be even more interesting further!

February 1, 2013 at 07:28 PM

Some features of using virtual machines for beginners

  • Virtualization

Virtual machines such as Virtualbox are used to emulate virtual hardware and run multiple operating systems on a computer. The better your CPU and the more RAM you have, the faster the virtual machines on your computer will run.
Here are some tips to help you save time when setting up your virtual machines for the first time. This will be useful for working with VirtualBox, VMware, Parallels, or any other virtual machines.

Be sure to install the VirtualBox Guest OS or VMware Tools add-ons

After installing the guest operating system in the virtual machine, the first thing to do is to install the virtual machine software - "Guest OS Add-ons for VirtualBox" or VMware Tools for VMware. "These packages include special drivers to help your guest operating system work faster on using the hardware of your main machine.

Installing the package is simple - in VirtualBox, after booting up the guest operating system, click the Devices menu button and select "Install Guest Additions". If you are using VMware, select “Install VMware Tools” from the Virtual Machine menu. Follow the onscreen instructions to complete the installation - if you are using Windows as your guest operating system, this will be the same as installing any other application.

Make sure you have the latest Guest Additions - if you see a notification that an update is available for Guest Additions or VMware Tools, you must install it.

Creating a fixed size disks on initial setup

When creating a virtual machine, you can create two different types of virtual disks. By default, the program usually suggests using dynamically allocated disks that grow along with the space occupied by the guest OS.

For example, if you create a new VM with a dynamically allocated disk with a maximum size of 30 GB, it will not take up to 30 GB of hard disk space right away. After installing the operating system and programs, the disk may only take up to 10 GB. As files are added to the virtual disk, it will expand to a maximum size of 30 GB.

This can be convenient - each virtual machine will not take up unreasonable amount of space on your hard disk. However, this is slower than creating a fixed disk size (a disk with pre-allocated space). When you create a fixed size disk, the entire 30 GB will be used immediately on your computer.

There is a trade-off here - a fixed disk size takes up more hard disk space, but works faster with a virtual hard disk. You will also get rid of file fragmentation - space will be occupied by a large block instead of adding smaller chunks all over the disk.

Exclude the virtual machines directory in your antivirus

Your antivirus can scan virtual machine files as they are accessed, slowing performance. Antivirus will not be able to detect a virus inside a virtual machine running on your guest operating system, so this check only does harm.

To speed up the process, you can add your virtual machine directory to the antivirus author's exclusion list. Once it is listed, your antivirus will ignore all files in that directory.

Allocate more memory

Virtual machines love a lot of virtual memory. Microsoft recommends 2GB RAM for 64-bit Windows 7, and this recommendation applies to Windows 7 x32 as well when running in a virtual machine. If you are running large applications in a virtual machine, you can allocate more than 2GB of RAM.

You can allocate more RAM in the settings dialog of your virtual machine (the virtual machine must be turned off to do this). If your computer does not have enough memory to comfortably work with a virtual machine, you may notice a very large decrease in computer performance when using the paging file on your hard disk.

Allocate more processors

If you have a computer with multiple processors or cores, you can allocate additional processors for your virtual machine from the VM settings window. A VM with a dual-core (or quad-core) processor will be more responsive.

If you are going to install an OS of the MS-Windows family and in the future, so that you can use more kernels during installation, specify 2 kernels in order to install the correct HAL, after installation you can turn off the machine and set 1 kernel by default for everyday use. But for the future, you can always add kernels without uninstalling the OS. Linux VM can dynamically detect any number of cores when the OS boots.

Adjust video settings

Fine-tuning video settings and allocating more video memory will also help improve the speed of your virtual machine. For example, enabling 2D acceleration in VirtualBox improves video playback in virtual machines, enabling 3D acceleration will allow you to use some 3D applications.

By and large, you need to minimize the use of 3D for example Windows 7 - by disabling Aero.

Make sure Intel VT-x or AMD-V features are enabled

Intel VT-x and AMD-V are special processor extensions that improve virtualization speed. Newer Intel and AMD processors usually include these features. However, some computers do not automatically enable VT-x or AMD-V - you will have to enable this setting in your computer's BIOS.

To determine if your Intel processor supports the Intel VT extension, use the utilities that display the system information. If your processor supports this feature, but the option is not available in your virtual machine, you must enable this feature in your computer's BIOS. This option is usually enabled by default on motherboards with AMD processors.

Place the virtual machine files on a different disk

Disk performance can limit the speed of your virtual machine. Placing virtual machine files on a separate physical disk or not on the system disk can improve performance. Your virtual machine and system will not be able to concurrently read and write from the same disk.

However, you do not have to start the virtual machine from an external disk (USB) - it will be much slower.

  1. Allocating additional processors is rarely a good idea. Use 1 CPU for desktop OS.
  2. Try not to use graphical hypervisors for server operating systems.
  3. Do not allocate more cores to a running VM than there are on your computer.

I need to run a software system designed to be installed as a device on a separate machine. To save energy, I plan to run the system in a virtual machine instead.

The host is a standard Linux box with a SysV-Init system, the guest is a heavily modified Linux and I would rather not change it any further. VirtualBox is used in OSE version.

I already figured out how to start the virtual VBoxManager startvm when the host boots ( Edit: this is done as mentioned below by VBoxManager startvm using VBoxManager startvm command), but how can I gracefully close the VM? Any script running on the host will have to wait for the guest to completely disconnect.

Can anyone suggest what a view of a service file should look like, for example?

10 Solutions collect form web for “How to Automatically Start and Shut Down VirtualBox Machines?”

Have you tried acpipowerbutton from this command set?

VBoxManage controlvm |pause | resume | reset | poweroff | savestate | acpipowerbutton | acpisleepbutton |

Edit after reading comments:

You can use acpid or other acpi utilities to make it graceful. Also, can you provide more information on how to shutdown the machine at this time?

A normal shutdown would not wait for unfinished jobs, the time delay might be too long.

I am assuming you are not using a window manager, so try this tool.

I just saw this demon. You may find this helpful.

Instead of coding it yourself, consider using Vagrant, which is built for creating and managing virtual machine instances. The documentation is great and I suggest you check it out rather than trying to roll it yourself.

The long and short of this is that you create a simple control file and then run vagrant up to run as many instances of VirtualBox as you want. You can use vagrant ssh to log into hosts and vagrant halt to shut down the host (no interruption). vagrant destroy will get rid of these cases.

It supports Puppet, Ansible or Chef rendering and allows you to control most of the exposed VBox settings.

I have a similar application like you, with one difference: I need to reboot the system and restore from a snapshot.

What interests you is headless mode .

I have several such services, so I use the following script:

VBox_StopRestoreStart.sh

#! / bin / bash if [-z "$ 1"]; then echo "Usage: $ 0 VMNAME_or_UUID" exit 1 fi set -x VBoxManage controlvm "$ 1" poweroff #enforce turnoff VBoxManage snapshot "$ 1" restorecurrent #retore state VBoxManage showvminfo "$ 1" | grep State #display state to ensure VBoxHeadless -s "$ 1" #run in headless mode in background

how can I gracefully close the VM?

If you want to gracefully shutdown the VM, you have two options, depending on your application:

  • Emulate the shutdown button or "sleep button" and prepare the VM to respond to it (to close gracefully)
    • VBoxManage controlvm |acpipowerbutton
    • VBoxManage controlvm |acpisleepbutton
  • Save the state of the virtual machine for later recovery
    • VBoxManage controlvm |savestate

ADVICE. You may find useful:

  • VBoxManage list vms - list of available vms
  • rdesktop IP-ADDR: 3389 or rdesktop-vrdp IP-ADDR: 3389 - when you want to use the GUI (even remotely) when running in headless mode: VBoxHeadless -s |
  • VBoxManage startvm - start with GUI for local debugging

Related chapter of the VirtualBox manual: Chapter 7. Remote Virtual Machines - Step by Step: Creating a Virtual Machine on a Headless Server

PS If you are interested in fully featured solutions already implemented, OpenStack seems like an interesting choice.

View the documentation for managing the VirtualBox virtual machine at http://www.virtualbox.org/manual/ch08.html

Use VBoxManage list vms command to list virtual machines

To start the virtual machine, use the VBoxManage startvm command

Use VBoxManage controlvm to manage VM

controlvm controlvm allows you to change the state of the virtual machine that is currently running. You can specify the following:

VBoxManage controlvm pause temporarily puts the virtual machine on hold without permanently changing its state. The VM window will be grayed out to indicate that the virtual machine is currently suspended. (This is equivalent to selecting Pause from the Machine menu of the GUI.)

Use VBoxManage controlvm resume to undo the previous pause command. (This is equivalent to selecting Resume from the Machine menu of the GUI.)

VBoxManage controlvm reset has the same effect on a virtual machine as clicking the Reset button on a real computer: a cold reboot of the virtual machine, which will reboot again and load the guest operating system. The state of the virtual machine is not saved in advance and data may be lost. (This is equivalent to selecting Reset from the Machine GUI menu.)

VBoxManage controlvm poweroff has the same effect on a virtual machine as pulling the power cable on a real computer. Again, the state of the virtual machine is not pre-saved and data can be lost. (This is equivalent to selecting Close from the Machine GUI menu, or clicking the close button and then selecting Shut Down Machine from the dialog box.)

After that, the state of the virtual machine will be disabled.

How about sending a command via ssh from host to guest?

I'm not sure if it works and if you can check the machine status after that or get something like exit status, but it should be clean at least.

For a systemd based system, you can try this.

Step # 1: create a service file

Description = VBox Virtual Machine% i Service Requires = systemd-modules-load.service After = systemd-modules-load.service User = user Group = vboxusers ExecStart = / usr / bin / VBoxHeadless -s% i ExecStop = / usr / bin / VBoxManage controlvm% i savestate WantedBy = multi-user.target as Description = VBox Virtual Machine% i Service Requires = systemd-modules-load.service After = systemd-modules-load.service User = user Group = vboxusers ExecStart = / usr / bin / VBoxHeadless -s% i ExecStop = / usr / bin / VBoxManage controlvm% i savestate WantedBy = multi-user.target

Step # 2: Include the service file

$ sudo systemctl enable [email protected] _name.service
  • systemd / Services - ArchLinux Wiki
  • Auto start VirtualBox virtual machines in Archlinux using Systemd

My solution: in this shellscript "root" is the invoker and "theuser" is the owner of "thevm"

I know the vms have run out when the output of the VBoxManage list runningvms command returns an empty string.

Start () (su -c "VBoxHeadless --startvm thevm" -s / bin / bash theuser & # maybe another vbox command) stop () (su -c "VBoxManage controlvm thevm acpipowerbutton" -s / bin / bash theuser # maybe another vbox command while ["` su -c "VBoxManage list runningvms" -s / bin / bash theuser` "! =" "] do echo waiting for VMs to shutdown sleep 3 done) ...

Maybe this will help as part of the solution.

VBoxManage list runningvms | tr -s "\" (""% ("| cut -d"% "-f3 | while read uuid; do VBoxManage controlvm $ uuid savestate; done

Probably a stupid question, but why don't you go into your guest house and disconnect from there?

Unless you have a compelling reason not to install sshd and access the VM via VBox, I would go for a script that just issues ssh shutdown -h now. To be honest, I would create a script for each machine that properly shuts it down and does some checks while it is running.

Just package the script /etc/init.d/shutdown_vm that calls the other one from the host, the call will block until it's ready. This process (as described) adds the linux dependency on the guest, but removes the VBox dependency on the host.

Cut to the chase: you don't need to go to the VBox to turn off the machine, if you have some means of accessing it (like ssh), then the OS will always have some means to do this (enabling this is of course different)

To start vm:

VBoxManage startvm VMNAME --type headless

To stop vm:

VBoxManage controlvm VMNAME savestate

List of all running vm "s.