Jumat, 15 Maret 2013

Xathrya Sabertooth

Xathrya Sabertooth


Managing VirtualBox VM on Slackware64

Posted: 15 Mar 2013 01:11 AM PDT

In earlier article we have discussed about how to install VirtualBox on Slackware64.

VirtualBox has a graphical front end which gives us easy access to manage and utilize our virtual machines. In some condition, we are restricted to use GUI while we want to manage virtual machine(s). This such condition might occur when we deal with service like cloud, or even managing our virtual machine on remote machine. Well, VirtualBox is not always about GUI. In fact, we can too manage everything using terminal / command line.

In this article, we will discuss about how we can manage VirtualBox’ Virtual Machine on Slackware. The term manage in this arcitle including: creating a VM, list supported OS, add device (disk, dvd, etc), and of course start/stop VM. In this article I use:

  1. Slackware64 14.0
  2. VirtualBox 4.6.2

Although it is said that we focus on Slackware64, but the method we use here is a generic one. It means, we can do it into other linux distribution as well.

For simplicity, I have divided this article into some stage.

Creating a Disk

VirtualBox can use VDI, VMware’s VMDK, etc. Originally, VirtualBox use VDI. There are two disk type: static size disk, or dynamic size disk. A static size means the file size is static and when created it will consume the specified size. A dynamic size means the size can be dynamically change up to the maximum size specified. At initial, the disk won’t consume all the disk size, but everytime it is filled with data it will grow bigger until the maximum size it is allowed. The disk can’t grow any larger after reach disk maximum size.

As stated, a disk need a maximum capacity. VirtualBox use Mega Bytes as capacity unit. Therefore, to create a 10GB disk we specify the size as 10*1024=10240MB.

To create a static size (for example ArchSlack.vdi):

  VBoxManage createhd --filename ArchSlack.vdi --size 10240 --variant Fixed  

To create a dynamic size (for example ArchSlack.vdi):

  VBoxManage createhd --filename ArchSlack.vdi --size 10240  

See Recognized OS

VirtualBox support some Operating System. We can see what OS supported by:

  VBoxManage list ostypes  

If we want to install an OS on VM, search whether your OS is recognized. Once you find it, note what ID it use. For example Ubuntu 64 bit is having ID Ubuntu_64. If you don’t find one, see what family type for your OS and choose generic type for those family. For example: Slackware64 is not listed there, but we know that Slackware64 is a 64-bit Linux. Thus we use close / similar system we can find, I choose ArchLinux_64.

See VMs

Querying Info

We can know some information for a particular Virtual Machine. The information is specific to the VM. For example we want to query information about ArchSlack, we can invoke:

  VBoxManage showvminfo ArchSlack  

Existing VMs

We can too list what VM on our system. Technically, it list any registered VM which usually located inside “$HOME/VirtualBox VMs/”.

  VBoxManage list vms  

If we want to query detail information for all vms (similar to VBoxManage showvminfo to all vms), we can use:

  VBoxManage list vms --long  

Running VMs

apart from existing VMs, we can also see what VM running on our system.

  VBoxManage list runningvms  

Create (Register) a VM

In this section, we will create a Virtual Machine. The VM will recognized as ArchSlack. Remember that Slackware will use ArchLinux_64 configuration. Here we write ArchSlack after –name and ArchLinux_64 after –ostype.

  VBoxManage createvm --name ArchSlack --ostype ArchLinux_64 --register  

If you open your VirtualBox GUI, you will find new entry, ArchSlack. If so, we have sucessfully create our Virtual machine.

Add Device and Controller

Generally, devices can be divided into SATA or IDE. A new created VM doesn’t have both so if we have a fresh VM, we should add it first.

SATA

We will add a SATA Controller and register it to our ArchSlack as “SATA Controller”. After Controller is registered, we can add various devices, such as hard disk. Here is the example:

  VBoxManage storagectl ArchSlack --name "SATA Controller" --add sata --controller IntelAHCI  VBoxManage storageattach ArchSlack --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ArchSlack.vdi  

IDE

Other than SATA, there is IDE. Like SATA, we can create IDE Controller and use it to hold some device. In this snippet, we will attach DVD drive to “IDE Controller”. Later we will insert an ISO to this “DVD drive”. Here is the snipper:

  VBoxManage storagectl ArchSlack --name "IDE Controller" --add ide  VBoxManage storageattach ArchSlack --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium Slackware64.iso  

To eject the DVD, we can simply use this:

  VBoxManage storageattach ArchSlack --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none  

Misc System Setting

These should be self explaining.

  VBoxManage modifyvm ArchSlack --ioapic on  VBoxManage modifyvm ArchSlack --boot1 dvd --boot2 disk --boot3 none --boot4 none  VBoxManage modifyVM ArchSlack --memory 1024 --vram 128  VBoxManage modifyvm ArchSlack --nic1 bridged --bridgeadapter1 e1000g0  

Start VM

To start a VM, we must use the name we register on VirtualBox. In this case we use ArchSlack:

  VBoxManage startvm ArchSlack  

Controlling Running VM

Once a VM running, we still can control the running VM on terminal. Well, there is no command such as stopvm to stop the VM, but we can manipulate a VM into three state: pause, running, poweroff.

Pause

In this state, VM is still running but in pause state. Pause state means the VM is not responding any input and not giving any output to its environment. To pause ArchSlack, we can use:

  VBoxManage controlvm ArchSlack pause  

Resume

When a VM in pause state, we can make it back to running state. This is called as resume. To resume ArchSlack we can use:

  VBoxManage controlvm ArchSlack resume  

Poweroff

A running VM can be forced to shutdown. We can power off ArchSlack by invoking:

  VBoxManage controlvm ArchSlack poweroff  

Snapshots

Snapshot can be imagined as a portion or “snapshot” of condition when VM is running. VirtualBox will save state or condition happen currently on specified machine. The saved snapshot then can later be recovered.

Take a snapshot of ArchSlack and save it as ArchSlack001:

  VBoxManage snapshot ArchSlack take ArchSlack001  

Restore snapshot ArchSlack001 to ArchSlack:

  VBoxManage snapshot ArchSlack restore ArchSlack001  

Remove (Unregister) VM

A registered VM can be unregistered / removed from VirtualBox. When we do this, VirtualBox will delete corresponding configuration file (in this case ArchSlack.vbox).

  VBoxManage unregistervm ArchSlack  

Tidak ada komentar:

Posting Komentar