Preface
This blog mainly describes how to install Vbox on Ubuntu Server, and whether you have created or imported an existing virtual machine.
This blog is not original. It mainly comes from three websites: VBox Forum, VBox Docs, and an unknown website.
If possible, read the official documents as much as possible.
Although this blog is about installing VBox without a GUI, we always need to test it before we actually do it. If it is installed directly on the Server, an error occurs in the middle, why don't I die? So for testing, we will select Ubuntu with UI interface when we work normally, but we will use the command line to complete the import and creation.
Reprinted, please indicate the source for preparation
1. to install the VBox Installation File, first download a Vbox and put it on the server, right?
2. Download The VBox extension. Go to the download URL, find and install the corresponding version number folder, download a Oracle_VM_VirtualBox_Extension_Pack-4.3.6-91406.vbox-extpack file such as this name, note and you use the VBox version needs to be consistent.
Start Installation
Take Ubuntu as an example (# comment later)
Sudo apt-get install dkms build-essential # install the compilation tool sudo dpkg-I virtualbox-4.3.6-91406 ~ Ubuntu ~ Maverick_i386.deb # Install software
In this step, an error may be reported. (If no error is reported, you can skip the following steps.) errors similar to dependency package missing. If you can install these dependencies independently, you can resolve them by yourself. Otherwise, you can try the following method to install it automatically.
sudo apt-get -f install
When the installation is complete, the last vbox installation process will be repeated. If vbox is not installed, run it once.
sudo dpkg -i virtualbox-4.3.6-91406~Ubuntu~maverick_i386.deb
Wait until the installation is complete and proceed to the next step
Install Extension
The command for installing the extension is very simple: (Note that the location of vbox-extpack should not be wrong)
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.6-91406.vbox-extpack
Now we can test it.
VBoxManage list extpacks
If similar information appears, the installation is successful.
Extension Packs: 1Pack no. 0: Oracle VM VirtualBox Extension PackVersion: 4.2.12Revision: 84980Edition: Description: USB 2.0 Host Controller, VirtualBox RDP, PXE ROM with E1000 support.VRDE Module: VBoxVRDPUsable: true Why unusable:
Import an existing VM (. ova file)
It should be said that it was created first. Personal reasons. Import the file first.
Assume that an exported ova file ub-server.ova exists now
The import command is:
VBoxManage import ub-server.ova
This command can be added with the-dry-run or-n parameter (selected when-n is the OVF file), indicating that after the import is complete, the system immediately tries to start [failed when I tried], for example:
VBoxManage import ub-server.ova --dry-run
After the import is complete, you can view the imported virtual machine information.
VBoxManage showvminfo "ub-server". If you do not remember the name, you can use VBoxManage list vms to view the list of existing virtual machines.
Next we can start it.
VBoxManage startvm ub-server
Startup is complete. The command line is over.
The result is dumbfounded .. Why? Because we are testing and playing with ubuntu with a UI, it starts. We can see it intuitively and then log on to it. At that time, if it was on the server, we generally performed ssh link operations, and we simply couldn't see the interface! You cannot log on to the virtual machine to view its ip address. Because we don't know how to ssh it without an ip address.
Okay, let's look down.
First, shut down the started virtual machine.
Then run the following
VBoxHeadless --startvm "ub-server" &
What is the role of this? In fact, VBox has enabled a remote desktop for this virtual machine.
This port is 3389 by default.
If you do not like it, you can use the following command to modify its default value:
VBoxHeadless --startvm "ub-server" -e "TCP/Ports=8899" &
The above is modified to port 8899.
At this time, you can use the remote desktop to view it.
Ubuntu comes with a remote desktop that is the Remmina tool. You can use it to connect. If you have not installed the tool, you can install it.
sudo apt-get install rdesktop
Centos and other operating systems can use the following installation commands.
sudo yum install rdesktop
This software is also very simple to use:
rdesktop -a 16 <IP_address_host_machine:port_number>
The command is like this because I tested it locally.
Rdesktop-a 16 127.0.0.1: 3389 # use the default port here
Then you can see the startup interface. How to configure Nic information is not the content of this blog. But I still have love in LZ. Let's talk about it... ^ _ ^
First, if you export data from the local machine and then import the data to the local machine, the problem will not occur. (I did not try)
If you export data from A and then import data in B or C, the imported virtual machine cannot connect to the network due to different pc configurations. Or the network card cannot be found. Now I will talk about several solutions.
1. if you copy data from one pc A to another pc B, and they all use A wired Nic. The solution is relatively simple.
Solution A: (this is also mentioned below. Please note .) (For Ubuntu) Find/etc/udev/rules. d/70-persistent-net.rules and comment out all the contents. Restart the VM. Sudu reboot here the centos file exists a little bit different. It should also be in the/etc/udev directory, but the specific location must be searched. The file name is also different, but it is basically a xx-persistent-net.rules file.
If you still cannot configure the NIC, you should reset the NIC type of the VM.
First, turn off the enabled virtual machine. View the configurations of this virtual machine.
VBoxManage showvminfo ub-server -- machinereadable # Here, ub-server is the name of my virtual machine. You need to change it to your own name, which will not be marked below.
There will be a lot of information here. Some useful
...bridgeadapter1="eth0"macaddress1="080027C8DD05"cableconnected1="on"nic1="bridged"nictype1="82540EM"nicspeed1="0"nic2="none"...
This part is about the NIC configuration.
Nictype1 is displayed, and its value is 82540EM. This value indicates a network card type. In VBox, there are several network card types:
AMD PCNet PCI II (Am79C970A);AMD PCNet FAST III (Am79C973, the default);Intel PRO/1000 MT Desktop (82540EM);Intel PRO/1000 T Server (82543GC);Intel PRO/1000 MT Server (82545EM);Paravirtualized network adapter (virtio-net).
Here I am corresponding to the Intel PRO/1000 MT Desktop Nic type.
For details about the differences between these NICs, see the official documentation. Here is only one, so when the imported virtual machine is not Am79C973 Nic type, and according to the solution mentioned above, A still cannot connect to the Internet, please try to change to this Nic type. This type matches the vast majority of NICs.
VBoxManage modifyvm ub-server --nictype1 Am79C973
After that, you can repeat solution A mentioned above.
If you export a virtual machine from a pc with a wired Nic to a pc with a wireless Nic, and vice versa. You may need to add a new virtual network card. That is to say, when your VM is used in different network modes (including wireless and wired), you may need to switch the NIC (if the NIC does not exist, you also need to add it)
You can run the following command to view the current available NIC:
VBoxManage list bridgedifs
The following information is displayed:
Name: wlan0GUID: 6e616c77-0030-4000-8000-6036dd82d336DHCP: DisabledIPAddress: 192.168.1.103NetworkMask: 255.255.255.0IPV6Address: fe80:0000:0000:0000:6236:ddff:fe82:d336IPV6NetworkMaskPrefixLength: 64HardwareAddress: xx:36:xx:82:d3:xxMediumType: EthernetStatus: UpVBoxNetworkName: HostInterfaceNetworking-wlan0Name: eth0GUID: 30687465-0000-4000-8000-b888e3e8bab3DHCP: DisabledIPAddress: 0.0.0.0NetworkMask: 0.0.0.0IPV6Address: IPV6NetworkMaskPrefixLength: 0HardwareAddress: b8:xx:e3:xx:ba:xxMediumType: EthernetStatus: UpVBoxNetworkName: HostInterfaceNetworking-eth0
The IP address is not 0.0.0.0, that is, wlan0, that is, the currently available Nic is wlan0,
In the preceding section, we use VBoxManage showvminfo ub-server -- machinereadable to view and select the NIC information of the ub-server. It is found that its bridgeadapter1 = "eth0", that is, before the export, this virtual machine uses the eth0 Nic type. At present, wlan0 is available on our machine. (Of course, if eth0 is available on the machine in your current experiment, you do not need to modify the configuration steps below .) If you do not modify the NIC configuration, the network cannot be connected. This is intolerable.
Note: In general, the wired network card is eth0, and the wireless network card is wlan0. that is to say, eth0 is used on the average desktop, and eth0 and wlan0 are used on the notebook. The method mentioned above shows whether the current network usage mode is wifi or network connection. Select based on the actual situation. It seems a bit cool.
Modify the NIC configuration now (modify the Virtual Machine ub-server to the wlan0 connection ):
VBoxManage modifyvm ub-server --bridgeadapter1 wlan0
Now, start the VM. As mentioned above
VBoxHeadless --startvm "ub-server" &
A new terminal monitors the Remote Desktop of vbox. (Fully simulate server operations)
Rdesktop-a 16 127.0.0.1: 3389 # use the default port here and 127.0.0.1 should be changed to the server ip address if it is a server. If the server has a firewall, it should be disabled.
After logging on to the VM, find the NIC configuration file (as mentioned above, ubuntu is used as an example here. Of course, if you check whether the NIC is normal after startup, you do not need to perform the following operations if it is normal. Use ifconfig to view the current network configuration)
cd /etc/udev/rules.d/sudo vim 70-persistent-net.rules
Edit the content after entering the page (if you do not know how to use vim, I have no choice), comment out or delete all content, save and exit.
Okay, so you won't use vim. Sudo vim 70-persistent-net.rules do not press any button after running this command. Press the primary key d until all the content is deleted completely. At the same time, press the Shift key and the key, that is, output A:, and press wq next to it. A wq similar to this will appear at the bottom of the window and press Enter.
Restart the VM.
sudo reboot
After logging on to the VM
Welcome to Ubuntu 12.04.3 LTS (GNU/Linux 3.8.0-29-generic i686) * Documentation: https://help.ubuntu.com/ System information as of Thu Jan 16 21:01:13 CST 2014 System load: 0.21 Processes: 73 Usage of /: 13.2% of 7.26GB Users logged in: 1 Memory usage: 6% IP address for eth0: 192.168.1.109 Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/Last login: Thu Jan 16 21:00:18 2014
Get it done, close the job!
Wait... Leo... You can only import the virtual machine. I haven't said how to create it yet... T
I wrote this article for two days.
No way. Don't waste your time. Let's proceed.
Note !!!! The following content is irrelevant to what needs to be described in this blog after the virtual machine is created. Only backup memory for personal commands. Do not use it on your own in the Virtual Machine. As a result, the network cannot be connected. I am not responsible for this. Of course, since I am not responsible, you can try it if you want to play... Haha ..
Add the NIC VBoxManage natnetwork add-t wlan-test-n "192.168.15.0/24"-enat-int-network is a name of 192.168.9.0/24, which can be arbitrary. 192.168.9.0/24 add a DHCP serverVBoxManage natnetwork modify-t wlan-test-h on to the network adapter after the network adapter is added according to the actual situation. Change the network connection to bridge vboxmanage modifyvm winxp -- nic1 bridged -- bridgeadapter1 wlan-test
Create a virtual machine
Creation seems easier than importing...
Open a terminal on your machine. (Simulate ssh to the server), run the CREATE command:
VBoxManage createvm --name "lzGoodboy" --register
The above command registers and creates a virtual machine called lzGoodBoy. Note that no memory or video card is configured. We pass
VBoxManage modifyvm command to add and modify.
After adding the file, check whether the file is successfully added.
VBoxManage list vms
Obtain the following information:
"xp" {f379678e-bee9-4d07-ad47-da4c05b69525}"centos" {e73df52a-f9ef-4f05-8a3f-04013845ade4}"ub-server" {24182f56-6e7c-497c-aa96-70422996afa3}"lzGoodboy" {2af26cc3-ad30-44d5-bb99-107455c977f7}
The lzGoodboy virtual machine is displayed here.
Configure hard disk CPU or something now
VBoxManage modifyvm "lzGoodboy" --memory 512 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 wlan0 --ostype Linux
In fact, you should know what the configuration is based on the meaning of the word. A little bit:
Memory is obvious
Acpi is the motherboard controller? Or what? I don't know about LZ. Okay, Baidu. Advanced Configuration and Power interface. The English word is:
Advanced Configuration and Power Management Interface
Boot1 should be set to boot sequence, and-boot1 dvd should be guided first by dvd. After all, we need to install the image...
Nic1 is familiar with nic again .. Yes, this is the NIC configuration. I have mentioned this many times. -- Nic1 bridged uses the Bridge Mode (here we will only discuss the bridge mode. Because it is based on the virtual machine on the server, it must have an intranet ip address and be able to connect the host to the network)
Bridgeadapter1 eth0: the adapter that bridges the NIC. You don't need to talk about how to choose here. The above is clear. According to the actual situation.
Ostype Linux operating system type ID Linux can also be specific to others. Here we will not list them one by one. You can run the VBoxManage list ostypes command to view supported operating systems and corresponding IDs. Therefore, the parameter followed by ostype is the ID field in the information displayed by the preceding command. If your ID is incorrect, an error is returned. For example, you can use the Ubuntu Virtual Machine -- ostype Ubuntu, because when I write this blog, there is no ubuntu system on the computer and there is only one centos on it. In addition, because the supported operating system does not directly specify the centos ID, you can only use ID Linux to represent a universal linux system, such as centos.
Then we create a virtual hard disk.
VBoxManage createvdi --filename ~/VirtualBox\ VMs/lzGoodboy/lzGoodboy.vdi --size 9000
The above command means ~ VirtualBox VMs in the default configuration folder under VBox (one of the commands is \ because there is a space in the middle, which needs to be escaped) create a virtual hard disk that belongs to the Virtual Machine lzGoodboy (of course, this virtual hard disk can be located at will, not necessarily in the VirtualBox VMs directory like me, just remember where it is, ). The size parameter is followed by the hard disk size, in MB.
Add an IDE Controller
VBoxManage storagectl "lzGoodboy" --name "IDE Controller" --add ide
Then, attach the created hard disk.
VBoxManage storageattach "lzGoodboy" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/lzGoodboy/lzGoodboy.vdi
The hard disk is mounted, and a DVD drive is mounted. Load the ISO image. (The File Location of the ISO image is based on the actual situation. I put it in the download folder in the main directory .)
VBoxManage storageattach "lzGoodboy" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/ec/download/CentOS-6.5-i386-LiveCD.iso
In this way, the basic hardware has been configured. In the above content, I didn't talk about setting the graphics card memory and the number of CPU cores. You can find these in the official documentation. If you do not configure these settings, Vbox will also produce some default configurations. For example, the CPU core is 1 by default. The default memory size is 12 Mb.
For example, set the cpu core to VBoxManage modifyvm "lzGoodboy" -- cpus 2 # Allow virtual machines to use two cores
The solution is to start the virtual machine. Similar to importing a virtual machine. Install the SDK through remote desktop. After all, some options must be directly selected during system installation.
VBoxHeadless --startvm "lzGoodboy"
Remote
rdesktop -a 16 127.0.0.1:3389
Then you can see the remote Vbox interface. The following system installation section is not covered in this blog.
Finally, add some control commands for the started Virtual Machine: (for details, see the official documentation)
VBoxManage controlvm resume pause # control virtual machine resume pause VBoxManage controlvm lzGoodboy resume # restart VBoxManage controlvm restart reset # restart VBoxManage controlvm restart poweroff # restart and shut down VBoxManage controlvm lzGoodboy savestate # Save...
Officially completed.
Indicate the source for reprinting. -Ended at a.m. on February 16