VirtualBox
Installing
Download and install from the VirtualBox website.
Creating a Debian VM
Download a network install image from Debian.
In the
Storage
tab of the VM's settings, selectEmpty
underController: IDE
in the list ofStorage Devices
.Select
IDE Secondary Master
for theOptical Drive
in the list ofAttributes
on the right hand side of the dialog.Click the CD/DVD icon to the right of the
Optical Drive
and selectChoose Virtual Optical Disk File...
Browse to the location of the ISO image downloaded earlier and select it.
In the
System
tab, change the boot order so that theOptical
disk is booted after theHard Disk
.Click
OK
Start the VM
-- Frank Dean - 7 Apr 2018
Guest Additions
On a Debian system, installing the virtualbox-guest-utils
and
virtualbox-guest-x11
packages provides the VirtualBox Guest Additions.
However, these packages are no longer available in Debian 10 (Buster), nor
are they available in backports. See https://wiki.debian.org/VirtualBox.
See the VirtualBox user manual for full installation details (In the
VirtualBox Manager GUI, Help -> Contents...
).
Install the appropriate linux headers package in order to be able to build a linux kernel, e.g.
$ dpkg -l 'linux-image*' | egrep '^ii' ii linux-image-4.19.0-8-amd64 4.19.98-1+deb10u1 amd64 Linux 4.19 for 64-bit PCs (signed) ii linux-image-amd64 4.19+105+deb10u3 amd64 Linux for 64-bit PCs (meta-package) $ sudo apt-get install build-essential linux-headers-amd64
Mount the
VBoxGuestAdditions.iso
file that comes with the VirtualBox distribution. The easiest way is probably to choose theDevices -> Insert Guest Additions CD image...
option from the menu bar of the running Virtual Machine GUI. That should automatically configure the virtual machine's CD drive to use the distribution image. You may need to mount the CD as follows:$ grep media /etc/fstab /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 $ mount /media/cdrom0
Build the Guest Additions and kernel modules.
$ cd /media/cdrom0 $ sudo /bin/sh ./VBoxLinuxAdditions.run
Restart the VM, then you can do handy things like find the allocated IP address of the VM after it has started:
$ VBoxManage startvm 'Debian 10 (Buster)' --type headless
$ VBoxManage list runningvms
$ VBoxManage guestcontrol 'Debian 10 (Buster)' \
run --exe /sbin/ifconfig --username $USER --password $MY_PASSWORD
Alternatively, use the --passwordfile <file>
option to avoid the password
being exposed in both the shell command history and the host's running process
list.
-- Frank Dean - 29 May 2020
Passing arguments:
$ VBoxManage guestcontrol 'Debian 11 (Bullseye)' run --exe /sbin/ip \
--username $USER --passwordfile secret.txt -- -- addr
Note the examples in the user manual suggest --
is required once, but in
practice, I found it necessary to supply a second --
before the actual
target program parameters.
-- Frank Dean - 06 Apr 2022
Time Synchronisation
See Tuning the Guest Additions Time Synchronization Parameters under 'Advanced Topics' of the VirtualBox User Guide.
$ VBoxManage guestproperty set "${VM-NAME}" "/VirtualBox/GuestAdd/VBoxService/${PROPERTY}" value
where ${PROPERTY}
is one of:
--timesync-interval
--timesync-min-adjust
--timesync-set-threshold
e.g.
$ VBoxManage guestproperty set "${VM-NAME}" \
"/VirtualBox/GuestAdd/VBoxService/--timesync-interval" 10000
$ VBoxManage guestproperty set "${VM-NAME}" \
"/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust" 100
$ VBoxManage guestproperty set "${VM-NAME}" \
"/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 1200000
-- Frank Dean - 19 May 2023
Disabling Time Synchronisation
$ VBoxManage setextradata "${VM-NAME}" \
"VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
Shared Folders
Installing the VirtualBox Guest Additions provides the facility to share
folders. If this is inconvenient or doesn't work, another option to copy
files to and from the guest is to setup SSH and use tools
like rsync
and scp
. Install the ssh
package on the Debian 10 guest. In
the Network
section of the VM settings, select Bridged Adapter
in the
Attached to
drop-down and under Name
select an appropriate network
interface on from the host machine. Restart the guest.
It may also be useful to install VNC which might provide cut-and-paste between the client and the host and vice versa. See VncTips.
-- Frank Dean - 10-Feb-2020
Note: If /sbin/mount.vboxsf
is not present in the VM, it is most likely
because the Guest Additions have not been installed. Install the VirtualBox
Guest Additions as described above, shared folders can then be created as
follows.
Create a shared folder in the VirtualBox Manager under Settings -> Shared Folders.
Manually mount for read-write as root:
$ sudo mkdir /media/${MOUNT_POINT}
$ sudo mount -t vboxsf ${FOLDER_NAME} ${MOUNT_POINT}
For the current user:
$ sudo mount -t vboxsf -o uid=$UID,gid=`id -g $UID` ${FOLDER_NAME} ${MOUNT_POINT}
To allow a user to write to the shared folder you can add the user to the
vboxsf
group which should have write access to the shared folder.
$ sudo adduser ${USERNAME} vboxsf
Unmount by unmounting all VirtualBox shared folders:
$ sudo umount -a -t vboxsf
Run sudo /sbin/mount.vboxsf
to list the available options.
An entry in /etc/fstab
might be:
Shared /media/shared vboxsf rw,auto,uid=1000,gid=1000
Where Shared
is the folder name configured in VirtualBox settings. The
mount point is a folder you have previously created ready to use as a mount
point.
Shared Clipboard
After installing the VirtualBox Guest Additions as decribed above, enable the shared clipboard in VirtualBox Manager settings | General | Advanced | Shared Clipboard
-- Frank Dean - 18 Dec 2019
Clone via Command Line
$ VBoxManage clonevm 'Debian 10 (Buster)' --name='Debian 10 (Buster) Clone' --register
Shutdown via Command Line
$ VBoxManage controlvm 'Debian 10 (Buster)' acpipowerbutton
or
$ VBoxManage controlvm 'Debian 10 (Buster)' poweroff
Run Headless by Default
$ VBoxManage modifyvm $VM_NAME --defaultfrontend headless|gui|separate
Snapshots Panel Missing
Reset the split window with:
$ VBoxManage setextradata global GUI/SplitterSizes 236,516
https://forums.virtualbox.org/viewtopic.php?f=8&t=56537
Frank Dean - 30 Mar 2020
-- Frank Dean - 22 Apr 2017
Related Topics: LinuxHintsAndTips, DockerTips, VncTips