Building a virtual machine with VirtualBox
From Mandriva Community Wiki
If you want to contribute, simply click on the edit tab. View the other pages to improve and maintain.
Contents |
Installation
Install VirtualBox and the VirtualBox kernel module provided with Mandriva. Reboot with the kernel having this module if you choosed the specific kernel with the module but not if you choosed to use dkms.
Ensure the module is started (lsmod | grep vboxdrv should return a non empty line).
Creating a virtual machine with a virtual harddrive
- Start VirtualBox. Its window appears.
- Click on new, then next, then give a name to your VM. Then choose the wanted OS and its version, then click next.
Choose the RAM size you want, then click next.
- Then choose to use a bootable hard disk, and choose to create a new one, then click next twice and choose a dynamic sized drive, click next and choose the max size of the hard drive. Click next, the finish.
You now have a virtual machine with a virtual hard drive ready to host an OS.
Install an OS on this virtual harddrive
Installation using your CD/DVD drive
On the main window, simple-click on the virtual machine you have created, then click on the preferencies button, then click on the CD (optical disk) and choose insert an optical disk. Click on the OK button. Your virtual machine will then be able to access your CD/DVD drive at boot stage.
Installation using an ISO image
On the main window, simple-click on the virtual machine you have created, then click on the preferencies button, then click on the CD (optical disk) and choose insert an optical disk. Then choose to use an ISO image file. Click on the OK button. Your virtual machine will then be able to access your ISO image.
Installation using a chroot (non bootable) directory
This will create a minimal installation on the selected virtual disk and make it bootable.
- First create a new virtual disk with enough space.
- Format it (you can start an installation on this disk and stop the process when formating is done).
- Then add the virtual disk to an already working virtual machine.
- Boot on this virtual machine, then mount the newly virtual disk :
- Create first needed files:
- Install grub:
- Modify /boot/grub/menu.lst for matching your system
- Mount virtual filesystems:
Doing so does not signify your chrooted system will be fully okay especially if your chrooted system needs modules or so that your host system does not use. A good example of this is making such an installation within VirtualBox and running it on VMware. This won't work, the boot process claiming it can't find the root partition.
As far as I know a solution to this would be to use an initramfs instead of an initrd.- Now run the following command :
- Unmount /proc, /sys/ and /dev from the chrooted directory
- Unmount /mnt/mount_point
- Halt the system
The virtual disk should be able to be booted on.
Installation using the network card
You simply need to put your network card in the bridged mode and boot on it.
Networking
Networking won't work if you change the MAC address of the network device(s). So it is really important to keep the same MAC address, even on cloned virtual drives. However as long as a network device hasn't been configured (never been upped), you can put whatever MAC address to a new network device. For example if you have configured a single network card for doing NAT, you can add new card(s) later for any other network types (other than NAT), and network will work for those newly installed cards. Nevertheless, after those new card(s) have been installed, you must keep their MAC address(es).
NAT Networking
NAT (Network Address Translation) will allow the guest to access Internet through a NATed network. There's no specific options to give to VirtualBox and networking in the guest should work if the guest has configured its network to use DHCP. This is the easiest way to have networking threw a guest. However NAT networking won't allow a connection starting from the host to the guest. If the host has a public IP address, then the guest should be able to connect to the host.
Private host networking
Private host networking is the best mean to achieve a connection between the host and the guest in either ways. For this to work you'll need to set the matching options in VirtualBox and to start the VirtualBox DHCP server. You'll also need to wake up eth1 or eth2 (it seems eth1 is not used) if you setup a new card to do private host networking along with a first card doing NAT.
In a theoretical way you can set a static IP to the guest. However the configuration is outside of VirtualBox scope and is quiete hard.
You can use the following command to setup the DHCP server and to launch it:
Use modify instead of add if the dhcpserver name was already created.
Notes on networking
If you need both access to Internet and your host system from within the guest, you'll need to setup 2 network cards, one in NAT, and one in host-only.
Using Shared Folders in VirtualBox
Mandriva already has the Virtualbox Guest Additions package pre-installed, which is required for sharing folders. Users may or may not want to update this package in order for the Shared Folders feature to work.
Adding a Shared Folder
- On the Virtualbox Manager, select the Mandriva Virtual Machine .
- On the Virtualbox Toolbar, click Settings or right-click on the Mandriva Virtual Machine and click Settings.
- Click Shared Folders and Add Shared Folders.
- On the Folder Path, type the folder path or select a specific folder in the host operating system by clicking the arrow.
- Example: Virtualbox is installed on Windows 7 and the user wants to be able access the Downloads folder from the Virtual Machine Mandriva.
- Type a "'sharename"' on the Folder Name box. This does not need to be the exact name of the Shared Folder. Select the Auto-mount check box.
- Click Ok.
Accessing the Shared Folder within the Mandriva 2010.x Virtual Machine
Users need to create a folder in order for Mandriva to open the designated Shared Folder. After booting into the Mandriva desktop, create a folder by launching a Terminal.
- To create a folder for the Shared Folder within Mandriva type the command below:
Tip !
The command "'mkdir"' command creates a folder within the ""mnt"" folder in Mandriva. To avoid confusion, use a different name from the sharename typed in the Virtualbox Add Share dialog box. This new folder in mnt is the mount folder where the Shared Folder will be loaded into. Example: mkdir /mnt/win7folder - To gain access to the shared folder from within the Mandriva guest, type the command below:
- Example based on the screenshot above: mount -t vboxsf Desktop 7 /mnt/win7folder
- To access the folder's file, launch Mandriva's file manager Nautilus (Press ALT+F2 and type Nautilus or double-click any folder on the Mandriva desktop). Press CTRL+L and type /mnt/folder name on the Location Bar.
Creating a Shared Folder with VBoxManage
Shared Folders can also be created within the Mandriva guest by typing the following command in Terminal:
Users can then mount the shared folder on the guest using the following command:
Adding another virtual drive to an existing virtual machine
- Click on the Virtual Machine you want to add a disk to
- Click on 'Preference'
- Click on 'Hard Disk'
- Click on the icone showing plates with a green plus ('add attachment') on the right
- A pop-up window will appear, asking you to chose a virtual drive. If there is not unused virtual drive, it would propose you to create one.
Making copies of a virtual harddisk (.vdi)
In order to copy a vdi you must clone it with using VBoxManage. The command is simple:
The trick is that it will look the input file from the default VirtualBox harddisk directory (~/.VirtualBox/Harddisks). If you want to clone an harddisk from a different location you must give it the full path.
Please note!
The system on the cloned vdi would fully work only if the configuration is exactly the same as for the virtual machine that runs the first vdi. You can have the same configuration with simply using the same virtual machine xml file. This is really important for networking to run as the network devices must have the same MAC address as the original.
Common issues
Shared directories
- If, when trying to mount a shared directory, it complains about an error other than unknown file system, you'll have to change the share name and try again (you'll have to halt the guest before).
- If the error complains about unknow file system, then it appears there's need to install the VBox additions (see VirtualBox documentation for taht point). You might also need to insert the vboxvfs module.
- Sometimes the shared directory can freeze for copies when doing them inside the guest. You just need to CTRL-C and to do the command again. It generally works well.
- Some other times, the shared directory can completely freeze. This will generally prevent the virtual machine to shutdown. You'll then have to kill the virtual box process from within the host.
Networking
- When making a private host network between the host and the guest (threw VirtualBox and/or VBoxManage) and when setting the VirtualBox dhcp server's options, IP addresses might not match your wishes. This can be very frustrating. The only workaround I've found is to use the settings VirtualBox defaults to (so the settings it put regardless the choices you have made).
Mouse Integration (Gnome)
- The feature Mouse Integration allows the mouse to work on the host OS and move into Mandriva seamlessly. Although VirtualBox will indicate that the guest system Mandriva supports mouse integration, the left-click on the mouse may not work for Mandriva 2010.2 even with VirtualBox Guest Additions installed.
- The mouse will move back and forth between Windows and Mandriva desktops but the users' left mouse button will not be able to click on anything within Mandriva. Users can use the keyboard within Mandriva fine but left-click will not work properly and right-click is limited to the right-click properties of the desktop only (ie. will not work with Computer and Trash Bin). Switching mice such as a A4tech wired optical mouse to a Microsoft wireless mouse will not resolve the issue.
- The workaround is to switch off Mouse Integration. To do this, click Machine>Disable Mouse Integration or use the shortcut HOSTt+I (ie. The Host Key by default is the right CTRL key on the keyboard). Turning off Mouse Integration will allow the mouse to work independently in Mandriva and have a working right-click button.
- To work within Mandriva, just click on the right CTRL key to “capture” Mandriva’s mouse. To go work back in Windows, press the same key a second time.
Other virtualization applications







