Setup virtualboxhost71 » Historie » Revision 1
Revision 1/2
| Weiter »
Jeremias Keihsler, 17.09.2024 07:38
Install Procedure for VirtualBox 7.1¶
Requirements¶
To install VirtualBox you will need the following:- a installed and supported operating system (e.g. CentOS 9.x)
- root-access
- a fast internet connection
- EPEL
- VirtualBox - Repo
Preliminary Note¶
This procedure is based on a documentation supplied by www.proclos.com.
You may also find additional information at- http://wiki.centos.org/HowTos/Virtualization/VirtualBox/
- https://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-rhel/
Install Virtual Box¶
Install DKMS¶
Install Dynamic Kernel Module System: (automatically installs appropriate kernel modules per
selected version)
dnf install binutils kernel-devel kernel-headers libgomp make patch gcc glibc-headers glibc-devel dkms
Install VirtualBox¶
dnf install VirtualBox-7.1
Rebuild kernel modules with following command:
/usr/lib/virtualbox/vboxdrv.sh setup
Setup vboxusers¶
The Linux installers create the system user group vboxusers during installation. Any system user who is going to use USB devices from VirtualBox guests must be a member of that group. A user can be made a member of the group vboxusers through the GUI user/group management or at the command line with
usermod -a -G vboxusers username
Note that adding an active user to that group will require that user to log out and back in again. This should be done manually after successful installation of the package.
Start virtual box.¶
GNOME-Menu->Applications->System Tools->Oracle VM VirtualBox
Install VirtualBox-Extension¶
Download the extension from the virtualbox homepage www.virtualbox.org.
Add the extension (VirtualBox 6.0.x Oracle VM VirtualBox Extension Pack) using Preferences->Extensions->Add
. This extension is needed to attach usb devices to the guest machines and to be
able to connect to guest machines using WindowsRemote Desktop-Client, which is very handy, if you need graphical access.
VBextpack_update.sh
#!/bin/bash version=$(vboxmanage -v) echo $version var1=$(echo $version | cut -d 'r' -f 1) echo $var1 var2=$(echo $version | cut -d 'r' -f 2) echo $var2 file="Oracle_VM_VirtualBox_Extension_Pack-$var1-$var2.vbox-extpack" echo $file wget http://download.virtualbox.org/virtualbox/$var1/$file -O /tmp/$file VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack" VBoxManage extpack install /tmp/$file --replace
Automatic Start/Stop of virtual machines systemd-style¶
this is taken from http://www.ericerfanian.com/automatically-starting-virtualbox-vms-on-archlinux-using-systemd/
Add a file called vboxvmservice
.service@ in /etc/systemd/system/.
[Unit] Description=VBox Virtual Machine %i Service Requires=systemd-modules-load.service After=systemd-modules-load.service [Service] User=user Group=vboxusers ExecStart=/usr/bin/VBoxHeadless -s %i ExecStop=/usr/bin/VBoxManage controlvm %i savestate [Install] WantedBy=multi-user.target
Replace the user after user= with the username you want to run the VMs. Make sure that the user is in the vboxusers group. If you need to delay the start of the VMs until after your network is started or a network share is mounted, locate the service you want to wait for using ‘systemctl’ and then substitute the service, mount, or network behind ‘After=’.
You can also replace ‘savestate’ in ‘ExecStop=’ with ‘poweroff’ or ‘acpipowerbutton’ to hard-stop the VM, or ask for a clean shut-down, respectively.
To enable one or more VMs at boot, enter:
systemctl enable vboxvmservice@vm_name.service
h2. 5 Automatic Start/Stop of virtual machines SystemV-style
As an alternative to the following solution, someone might find https://sourceforge.net/projects/vboxtool/ interesting to investigate.
To automatically run the guest machines in headless mode on host machine startup, do the following((A new feature of VirtualBox 4.2 is a supplied init-script to automatically start/stop virtual-machines. This I've not tested yet. The old 4.1 way is still working fine. So this section remains as 4.1 until something better is tested.
)):
add the list of names of the virtual machines that should be started / stopped automatically in following files:/etc/virtualbox/machines_enabled_start
and /etc/virtualbox/machines_enabled_stop
Each virtual machine name has to in a separate line. You can create and fill the files by the use of vim
or any other text-editor.
cd /etc
mkdir virtualbox
vim /etc/virtualbox/machines_enabled_start
vim /etc/virtualbox/machines_enabled_stop
Afterwards you can check the file-content by
cat /etc/virtualbox/machines_enabled_start
the content should look like:
firewall-pfsense
clusterOne
clusterTwo
postgresql-solo
windows7-janus
As the machines are started and stopped in the same order as in the files being listed you maybe want to stop the machines in reverse order.
cat /etc/virtualbox/machines_enabled_stop
the content could look like:
windows7-janus
postgresql-solo
clusterTwo
clusterOne
firewall-pfsense
Also create a file /etc/init.d/vboxcontrol
with following content:
Don't forget to set the correct user VM_USER
#! /bin/sh # vboxcontrol Startup script for VirtualBox Virtual Machines # # chkconfig: 345 98 02 # description: Manages VirtualBox VMs # processname: vboxcontrol # # pidfile: /var/run/vboxcontrol/vboxcontrol.pid # ### BEGIN INIT INFO # ### END INIT INFO # # Version 20110509 by Jeremias Keihsler based on: # Version 20090301 by Kevin Swanson <kswan.info> based on: # Version 2008051100 by Jochem Kossen <jochem.kossen@gmail.com> # http://farfewertoes.com # # Released in the public domain # # This file came with a README file containing the instructions on how # to use this script. # # Source function library. if [ -f /etc/init.d/functions ] ; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions else exit 1 fi ################################################################################ # INITIAL CONFIGURATION VBOXDIR="/etc/virtualbox" VM_USER="OMB" USE_NAT="no" export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin" if [ -f $VBOXDIR/config ]; then . $VBOXDIR/config fi SU="su $VM_USER -c" VBOXMANAGE="VBoxManage -nologo" ################################################################################ # FUNCTIONS # Determine if USE_NAT is set to "yes" use_nat() { if [ "$USE_NAT" = "yes" ]; then return `true` else return `false` fi } log_failure_msg() { echo $1 } log_action_msg() { echo $1 } # Check for running machines every few seconds; return when all machines are # down wait_for_closing_machines() { RUNNING_MACHINES=`$SU "$VBOXMANAGE list runningvms" | wc -l` if [ $RUNNING_MACHINES != 0 ]; then sleep 2 wait_for_closing_machines fi } ################################################################################ # RUN case "$1" in start) if [ -f /etc/virtualbox/machines_enabled_start ]; then cat /etc/virtualbox/machines_enabled_start | while read VM; do log_action_msg "Starting VM: $VM ..." $SU "$VBOXMANAGE startvm "$VM" --type headless" sleep 20 RETVAL=$? done touch /var/lock/subsys/vboxcontrol fi ;; stop) # NOTE: this stops all running VM's. Not just the ones listed in the # config cat /etc/virtualbox/machines_enabled_stop | while read VM; do log_action_msg "Shutting down VM: $VM ..." $SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton" sleep 10 done rm -f /var/lock/subsys/vboxcontrol wait_for_closing_machines ;; export) # NOTE: this stops and exports the listed VMs cat /etc/virtualbox/machines_enabled_export | while read VM; do log_action_msg "Shutting down VM: $VM ..." $SU "$VBOXMANAGE controlvm "$VM" acpipowerbutton" /bin/echo -en "\a" > /dev/console sleep 10 done wait_for_closing_machines JKE_DATE=$(date +%F) cat /etc/virtualbox/machines_enabled_export | while read VM; do log_action_msg "Exporting VM: $VM ..." $SU "$VBOXMANAGE export "$VM" -o "$VM"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE" done rm -f /var/lock/subsys/vboxcontrol ;; start-vm) log_action_msg "Starting VM: $2 ..." $SU "$VBOXMANAGE startvm "$2" --type headless" ;; stop-vm) log_action_msg "Stopping VM: $2 ..." $SU "$VBOXMANAGE controlvm "$2" acpipowerbutton" ;; poweroff-vm) log_action_msg "Powering off VM: $2 ..." $SU "$VBOXMANAGE controlvm "$2" poweroff" ;; export-vm) # NOTE: this exports the given VM log_action_msg "Exporting VM: $2 ..." JKE_DATE=$(date +%F) $SU "$VBOXMANAGE export "$2" -o "$2"_"$JKE_DATE"."ova" --manifest --vsys 0 --version $JKE_DATE" ;; status) echo "The following virtual machines are currently running:" $SU "$VBOXMANAGE list runningvms" | while read VM; do echo -n "$VM (" echo -n `$SU "VBoxManage showvminfo ${VM%% *}|grep Name:|sed -e 's/^Name:s*//g'"` echo ')' done ;; *) echo "Usage: $0 {start|stop|status|export|start-vm <VM name>|stop-vm <VM name>|poweroff-vm <VM name>}|export-vm <VMname>" exit 3 esac exit 0
To make the file executeable do
chmod +x /etc/init.d/vboxcontrol
Add vboxcontrol as service:
cd /etc/init.d
chkconfig --add vboxcontrol
Manually start the service
service vboxcontrol start
you can check the runlevels by
chkconfig --list vboxcontrol
you should get an output like:
vboxcontrol 0:off 1:off 2:off 3:on 4:on 5:on 6:off
With this setup, guest machines are also automatically shutdown cleanly in a host shutdown
process. The shell-script vboxcontrol
processes the file machines_enabled_stop
. The first machines is sent a ACPI-Poweroff-Signal, after 10 seconds the second machine and so on. After the last machine have got the ACPI-Poweroff-Signal the script waits until all machines have reached power-off-status. By doing so a crashed or hanging virtual machine will prevent a shutdown of the host-system.
At boot-time each virtual machine being listed in the file machines_enabled_start
is being started according to the order within the file. The time gap between each machine is 20 seconds.
Problem¶
KVM and Virtualbox side by side¶
VirtualBox might not work while KVM extensions are active
http://www.dedoimedo.com/computers/kvm-virtualbox.html may help
Von Jeremias Keihsler vor 3 Monaten aktualisiert · 1 Revisionen