A Lightweight CentOS VM for VirtualBox

I recently changed jobs, and my new employer is ALL IN on Windows. I’ve given it a try for 3 months … but it’s time.

Today I spent a solid hour getting a basic CentOS install going in a VirtualBox VM. Here are the steps I took, explained at a “Newbie” level of detail. Good luck and Godspeed.

Install Oracle VM VirtualBox.

I grabbed the latest from here: http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

You need your BIOS-level virtualization bit flipped, if it isn’t already. Then just follow the prompts. You may need Admin access to allow Oracle to install a few drivers as well.

Download the Minimal CentOS ISO.

This is the installation CD for CentOS. I picked a mirror from here: http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso

Create a machine in VirtualBox.

Start VirtualBox. Click on “New”. Pick a name (this is a name used only by VirtualBox). You can also specify the Type (Linux) and the Version (I went for “Other Linux, 64-bit). Click Next.

Choose how much RAM you want to dedicate to this VM when it’s running. I went with half of my RAM, as I will actually be doing development in this machine. Obviously you’ll want enough RAM for the Operating System to work … probably no less than 2GB these days, even for a “lightweight install.” Next.

I went with the default of “Create a virtual hard disk now”. For hard disk file type, I went with the default of VDI. VDI is VirtualBox’s own format for virtual disks — if curious about the other options, check out this link: https://www.virtualbox.org/manual/ch05.html#vdidetails. Next.

I went with the default of “dynamically allocated” for the virtual disk allocation. Next.

I went with a 100 GB max size for my virtual disk, then clicked Create.

Finally our machine is ready, but now it needs an Operating System (OS).

Insert the CentOS disk.

With VirtualBox, this can be unnecessarily difficult. I now have a new virtual machine listed on the left of the VirtualBox Manager window. I single-click to select the new machine, and click on the orange “Settings” icon to go “insert” the downloaded ISO disk image for installation.

In the Settings window, I click “Storage” on the left column, then select the “Empty” entry in the “Storage Tree”.

In the far right column, a dropdown box has “IDE Secondary Master” selected. I click the small CD icon to the right of the dropdown, then “Choose Virtual Optical Disk File”, then finally browse to the CentOS Minimal Installation I downloaded earlier.

I click OK and it’s back to the VirtualBox Manager Window for something more exciting.

Install CentOS.

I double-click on the new machine to start it. I click into the new Window and hit Enter to start the installation process.

VirtualBox gave me a couple of info bubbles about mouse integration. I X off of these to preserve what little screen real estate I currently have.

I select “English” and “English (United States)” and click Continue.

I set my Time Zone, and click Done.

I scroll down under “System” and click “Network and Hostname”. I flip the switch (currently OFF in the top right) for the Ethernet connection. Mine has a funny name, “enp0s3”. I set my hostname to my favorite machine name. I click Done.

Finally, I click on “Installation Destination” to deal with a warning about automatic partitioning. I accept those defaults (without changing anything!) and click Done.

Back at the “Installation Summary” page, the “Begin Installation” button is finally enabled in blue, in the bottom right. Let’s roll.

A new “Configuration” page pops up, with a couple of options. I click on “Root Password” to set the admin password, and click Done. I do the same for “User Creation”, creating a user for myself. I check to “Make this user administrator,” set a password, and click Done there.

The skinny blue progress bar near the bottom of the screen will march on, and eventually a blue Reboot button is available. I mash it. #YOLO

Install GNOME and some basic tools.

I log in with my username and password from the setup (note: not the admin or “root” password, but the one for the administrator user I set up). I make it to a bash prompt. Ah.

The next few commands are all going to be run as root, so I use “sudo su -” to enter a root shell.

First things first: Let’s update packages to secure the system. [“yum” is the package manager for Red Hat Linux, and for its open-source cousin CentOS that we are installing here.]

yum install -y && yum upgrade -y

Next, I like to add a graphical environment. I found a minimal set of installs for GNOME in the following thread: https://www.centos.org/forums/viewtopic.php?t=47088

yum groupinstall -y “X Window System”
yum install -y gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts

From that same link, these two commands tell our system to boot into the new environment by setting up some OS-level links:

unlink /etc/systemd/system/default.target
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Finally, reboot to pick up these changes:


Install the VirtualBox Guest Additions.

I’m almost there, but there are some issues with the current VM (like the tiny screen) that can be addressed by installing the “Guest Additions” from VirtualBox. Unfortunately, there is an optional (but recommended) dependency for CentOS Guest Additions that should be installed first, according to what appears to be a well-maintained wiki page from CentOS: https://wiki.centos.org/HowTos/Virtualization/VirtualBox/CentOSguest.

I now boot into a graphical environment, and log in. I click on Applications in the top left, then Terminal (which is one of the only applications installed right now).

As soon as I try to install dkms with “sudo yum install dkms”, it fails :( It turns out that the CentOS repositories for packages do not include this package. I found through some Googling that a reasonably updated version of this package is available in the EPEL repo. We now need to add the EPEL repo, so that we can obtain and install DKMS.

This page details one way to enable EPEL:

I applied those steps successfully:

yum install -y wget
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
sudo rpm -ivh epel-release-7–8.noarch.rpm
sudo yum -y install dkms

It turns out there is one more dependency needed for the Guest Additions to install correctly:

sudo yum install -y bzip2

Now I can finally install the Guest Additions, which are actually provided by VirtualBox itself. The “Insert Guest Additions CD Image” option is available under the “Devices” menu along the top of our VM’s window. I click that option, and CentOS picks up the inserted disk, prompting me to open and view files. In the window listing the files, there is an “autorun.sh”. We need to run this file as root in order install the Guest Additions.

I right-click on the autorun.sh file, go to Properties, and then Copy the “Location” from here with Ctrl+C. Back in my Terminal, I switch to that directory, and run the script:

cd /run/media/bryan/VBOXADDITIONS_5.1.6_110634
sudo ./autorun.sh

Finally. I can reboot and get my full screen real estate!

sudo reboot

What now?

For me, I’ll move on to installing a few more things:

Docker: https://docs.docker.com/engine/installation/linux/centos/
Atom: https://github.com/atom/atom/releases/tag/v1.11.2 (Use wget to download the RPM in your terminal, and yum to install)
Chrome: http://www.tecmint.com/install-google-chrome-on-redhat-centos-fedora-linux/

Choose your own adventure!