arch-anywhere-in-virtualbox

A Portable Working environment inside virtualbox

This post records the setup procedure of my working environment in a virtual machine.

Install Guest System

Launch VirtualBox, create a new machine and install the system of your choice, which depends largely on your personal preferences. For me, I have been using Arch Linux for a while and is happy about it. Instead of manually setting up everything, I used Arch-Anywhere to install Arch Linux with Openbox.

There are other Archer installers out there, like AUI, Revenge, etc. All of them should do the job well, I chose Arch-Anywhere mainly due to its simplicity.

Guest Machine Setup

After guest system installation, we have a fresh installed Arch Linux machine. Now it’s time to do some basic setup.

VirutalBox Guest Utils

Before start, it is advised that virtualbox-guest-utils be installed to have more support of virtualbox features. After that, enable vboxservice.service to load the modules and synchronize the guest’s system time with the host. Also, add VBoxClient-all to autostart script on login to support (see this entry on Arch Wiki):

  • shared clipboard and drag and drop between the host and the guest;
  • seamless window mode;
  • the guest display is automatically resized according to the size of the guest window;
  • checking the VirtualBox host version.
sudo pacman -S virtualbox-guest-utils
sudo systemctl enable vboxservice.service

Other Configurations

Also, I would like to bring some configurations over from a physical machine I have been using to this virtual machine.

Installed Packages

It is easy using pacman to export the list of all packages (explicitly) installed on the old machine and install them on the new one.

# On the old machine
sudo pacman -Qe | awk '{print $1}' > packages.txt

# Copy packages.txt to the new virtual machine and do
for x in $(cat package_list.txt); do pacman -S $x; done

# Or
sudo pacman -S `cat package_list.txt`
#This will also work, but Pacman will exit if you have a package
#installed that is not in the repositories.

Dot Files

I am managing many of my configuration files in this Github repo. Using it is as simple as cloning it somewhere and run ./install.sh.

git clone git@github.com:xywei/dot-files.git
cd dot-files
./install.sh

SSH Server

Since I would like to connect to the guest machine via ssh, sshd.service should be enabled. Also remember to double check on /etc/ssh/sshd_config.

sudo pacman -S openssh
sudo systemctl enable sshd.service

Host Machine Setup

Some setup is also needed on the host side to make things perform smoothly.

Shared Folder

Shared folders can be easily setup using VirtualBox GUI. Check the auto-mount option and you don’t have to worry about mounting them on the guest side. Just to make sure that the user of the guest machine is under vboxsf group to have the right access to those shared folders.

By default, the shared folders are mounted under /media/sf_FolderName.

SSH Access

To access the guest machine using ssh, you need to:

  • Create the vboxnet0 interface. Using VirtualBox GUI, go to VirtualBox > File > Preferences > Network > Host-only Networks > Add.
  • Shutdown the virtual machine and enable I/O APIC. VM’s Settings > System > check “Enable I/O APIC.”
  • Add adapter for vboxnet0. VM’s Settings > Network > Adapter 2 > host-only vboxnet0.
  • Configuring port forwarding with NAT. VM’s Settings > Network > Adapter 1 (Attached to NAT) > Advanced > Port Forwarding. Add a new rule with each column “GuestSSH,tcp, ,2222, ,22”.

Now, you should be able to start the virtual machine and connect to it via ssh

ssh -l -p 2222 localhost

Basic Management

Now that the virtual machine is ready for use, here is my preferred way of using it.

Start Headless

I prefer to use the virtual machine via ssh. Using VirtualBox CLI, we can start the machine using the following command:

VBoxManage startvm MachineName --type=headless

Shutdown

To shutdown the machine, use

VBoxManage controlvm MachineName poweroff soft

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax