% Installation of CentOS in VirtualBox % Ian! D. Allen - - [www.idallen.com] % Winter 2015 - January to Apil 2015 - Updated Thu Mar 26 12:16:02 EDT 2015 Overview for VirtualBox Installation ==================================== > This document was originally written by CST student Joshua Caseley. This document outlines how to install CentOS into the free **VirtualBox** virtualization software. Students should normally be installing CentOS into **VMware** using the [CentOS Install and Configure] document. > This VirtualBox document is only for students who are having problems using > VMware. Your instructors are not familiar with VirtualBox; use VMware if at > all possible. Download the free VirtualBox software ===================================== 1. Go to and download VirtualBox based on what OS you are using. i.e. `Linux/OS X/Windows` and `x32/x64` Create and Configure a Virtual Machine ====================================== 1. After installing **VirtualBox**, start it. You will see a window similar to this on your computer: ![Virtual Box Opening Screen] 2. Click on the **New** icon in the toolbar, or go to the Menu bar, Machine, New, or press Ctrl+N to create a new virtual machine. Name and operating system ------------------------- ![Set the Name, Type, and Version of your new VM] 1. **Name**: Choose a name for your new Virtual Machine: If your course and term is `CST1234` and `15W`, then use the name `CST1234-15W-CentOS-6` (no spaces). You can invent your own virtual machine name, if you prefer. 2. **Type:** `Linux` 3. **Version:** Choose either `Red Hat (32-bit)` or `Other Linux (32-bit)` **Do not choose 64 bit!** 4. Double check your settings and click Next. Memory Size (RAM) ----------------- ![Set Memory Size to 1024 MB (1 GB)] 1. The installation software requires more memory than the running CentOS server. If you are installing or re-installing your system, set your VM Memory to at least 1024MB (1 GB) before you continue. You can reduce the memory later. 2. Click Next Hard Drive ---------- 1. Select **create a virtual hard drive now** and then **Create**. Another window will open. Hard drive file type -------------------- 1. Select **VDI (VirtualBox Disk Image)** and then **Next**. Storage on physical hard drive ------------------------------ 1. Select **Dynamically allocated** and then **Next**. File Location and Size ---------------------- ![Create a 2GB Hard Drive] 1. Leave the default file name in the name box. 2. For the size of the virtual hard drive enter `2GB` (actually type the number `2` and the letters `GB` into the box) and then **Create**. PAE Settings ------------ **The PAE/NX feature must be enabled or VirtualBox will not install CentOS.** 1. Click on the Settings icon in the toolbar or go to the menu, Machine, Settings 2. In the left hand navigation pane, go to System 3. Go to the tab that says Processor ![Enable PAE/NX Extended Features] 4. Where it says “Extended Features: Enable PAE/NX”, make sure this feature is enabled. Turn it **on**. 5. Click **OK**. Disable Unnecessary Hardware ---------------------------- 1. Open the **Settings** window. 2. In the left hand navigation pane, go to Audio. 3. Un-check **Enable Audio**. Turn this **off**. 4. In the left hand navigation pane, go to USB. 5. Un-check **Enable USB Controller**. Turn this **off**. 6. Click **OK**. If either of these things re-enables itself, don’t fight it. Just move on. Networking ---------- 1. Open the **Settings** window. 2. In the left hand navigation pane, go to Network. 3. Select the tab for **Adapter 1**. ![Enable Network Adapter 1 and attach to NAT] 4. Make sure that **Enable Network Adapter** is checked. 5. Make sure that **Attached to:** is set to just **NAT** (not **NAT Network**, just simple **NAT**). ### Enable Port Forwarding for SSH > When using NAT with VirtualBox, by default the IP address will always be > `10.0.2.15` for every new virtual machine. (This is not how VMware does > their NAT virtual machines.) To use SSH to connect from your host O/S to > the VirtualBox VM behind NAT, you must setup and use **Port Forwarding** on > each virtual machine. 1. In the Network settings, click the drop-down arrow next to Advanced to show the advanced settings that includes the Port Forwarding button. 2. Toward the bottom of network Adapter 1, select the link button called **Port Forwarding**. A new window will open named **Port Forwarding Rules**. 3. In the **Port Forwarding Rules** window, locate the tiny **add new rule** icon at the far right of the dialog box. It is the top icon of the two and looks like a green “plus” sign. Select it. ![Create a Port Forwarding Rule for SSH] 4. Change the **Name** of the new rule rule from **Rule 1** to **SSH**. 5. Leave the **Protocol** as TCP. 6. Leave the **Host IP** field blank (empty). 7. Set the **Host Port** to some unused port on your Host O/S, e.g. try `2222` as a likely free port. Make sure you choose a port that will be unique for this virtual machine. If you have multiple Virtual Box virtual machines, each will need a different **Host Port** number. 8. Leave the **Guest IP** field blank (empty). 9. Set the **Guest Port** to 22. (The SSH service on your Guest VM uses port 22.) 10. Select **OK** to close this window and return to the Network window. ### Using SSH to connect to your VirtualBox VM > Refer back to this section once you have installed CentOS and enabled > networking. You cannot connect from your Host O/S to the Virtual Box private address `10.0.2.15` of a virtual machine using NAT networking. You must use Port Forwarding with NAT networking under Virtual Box. When using Putty or any other client SSH program on your Host O/S to connect to this Virtual Box virtual machine, set up Port Forwarding in your VM and then use the following settings in your SSH client program to connect to the VM: - `Host: 127.0.0.1` - `Port: 2222` *(or whatever port forwarding port number you chose, above)* ![Set Host Name and Port Number in your Client] For this client connection to work: 1. You must have created a Network Port Forwarding rule in your CentOS virtual machine that forwards the `2222` port on your local Host O/S machine to port `22` at the private IP address of the running Virtual Box VM. 2. You must have enabled Networking in your CentOS virtual machine. 3. The `sshd` service must be available in your CentOS virtual machine. If you have multiple Virtual Box virtual machines using NAT networking, you must give each one a different local Host Port number. (Choose host port numbers above 1024 if running Virtual Box unprivileged under Linux or MacOSX.) Booting CentOS from the CD/DVD drive ==================================== To install CentOS, we need to download and connect the CentOS ISO image file to the virtual CD/DVD drive of the VirtualBox Virtual Machine and make sure that the system chooses that CD/DVD drive at boot time. Configuring the Boot Order -------------------------- 1. Open the **Settings** window. 2. In the left hand navigation pane, go to System 3. Go to the tab that says Motherboard ![Change Boot Order to put CD/DVD before Hard Drive] 4. In the box labelled **Boot Order**: Uncheck the **Floppy** and use the right hand arrow buttons to move **Floppy** to the third spot, under **Hard Disk**. Make the **CD/DVD** (checked) first, the **Hard Disk** (checked) second, the **Floppy** (not checked) third, and the **Network** (not checked) last. 5. Make sure only the **CD/DVD** and **Hard Disk** are enabled. 6. Click **OK**. Connect the CentOS ISO file to the virtual CD/DVD drive ------------------------------------------------------- 1. Open the **Settings** window. 2. In the left hand navigation pane, go to Storage Under Storage, you will see Storage Tree with a Controller:IDE, and inside the Controller is your VM name and under that is a poorly shown visual CD drive icon with **Empty** beside it. 3. Click on the CD line, where it says **Empty**. A new Attributes and Information section opens on the right in the same window. ![Settings for Empty CD/DVD Drive] 4. In the right hand pane, under Attributes, beside CD/DVD Drive, you will see a box containing IDE Secondary Master. There is a tiny CD icon on the right of this box. Click on the CD icon to open a menu that lets you set the path to your downloaded CentOS CD ISO image file. 5. Use the menu to navigate to your previously downloaded CentOS ISO image file and select it. The window will close and you will return to the Storage settings window. 6. Verify that in the Storage settings window, on the right under Information, you see **Size: 339.00 MB** (the size of the CentOS Installation CD) and the **Location:** is the location of your CentOS install CD ISO image file. 7. Click **OK**. Install CentOS ============== 1. Now, power on (boot) your virtual machine. You should see the CentOS installation screen: ![Welcome to CentOS Boot Window] 2. Click in the window and use the arrow keys to stop the Automatic boot. 3. Continue to install CentOS from the installation CD using most of the directions starting at “Installing the CentOS 6 Operating System” in [CentOS Install and Configure][1]. Here are some changes you will need to make to those instructions: a. During the installation, you will need come back to VirtualBox to re-attach the ISO image to the virtual CD/DVD drive after verifying the media contents. b. You cannot use the VMware instructions for using an SSH client to connect from your Host O/S to the private IP of your VM, since VirtualBox completely hides the NAT private IP address from the Host O/S. To use an SSH client to connect to a VirtualBox VM, follow the [Using SSH to connect] instructions in the Networking section of this document. 4. After you have finished installing CentOS, you should shut down your CentOS machine safely and return to VirtualBox Settings, System, Motherboard, and change the Base Memory back down to to 256MB. This will make snapshots you take much smaller in size. Install VirtualBox Guest Additions ================================== > VirtualBox **Guest Additions** are equivalent to *VMware Tools* You must > have a working CentOS virtual machine to install them. Once you have CentOS running, you can install the VirtualBox **Guest Additions** that improve virtual machine performance. Here’s how: 1. You may need to download and install the `VBoxGuestAdditions.iso` file separately from VirtualBox. Do this, if necessary. 2. Start (boot) your CentOS VM. 3. Use the Menu bar on your CentOS VM console to go to Devices and select **Insert Guest Additions CD Image** at the bottom of the menu. This action should connect the Guest Additions CD ISO file to your virtual CD/DVD drive. 4. Open the **Settings** window, select Storage, and in the Storage Tree box verify that instead of **Empty** it says `VBoxGuestAdditions.iso` beside the CD/DVD icon. 5. In the CentOS console window, log in as `root` and run the command `file -s /dev/sr0` and make sure the output starts with: `/dev/sr0: ISO 9660 CD-ROM filesystem data 'VBOXADDITIONS_`… 6. Create a mount point for the CD/DVD: `mkdir –p /mnt/cdrom` 7. Mount the CD/DVD on the mount point: `mount /dev/sr0 /mnt/cdrom` - You will see a warning about mounting read-only. This is good. To install the Guest Additions, some software must be compiled and installed in the current Linux kernel. We need to install some packages to make this possible. 8. Install the `gcc` compiler package: `yum install gcc` - Many other dependency packages will also be installed with `gcc`. 9. Find out the version (release) of the kernel that you are running: `uname -r` 10. Install the kernel headers package for your running kernel, using the above version number in place of **XXX** in this command line: `yum install kernel-devel-XXX` - You can also use: `yum install kernel-devel-$( uname -r )` 11. Execute the installer program `/mnt/cdrom/VBoxLinuxAdditions.run` that should install the VirtualBox Guest Additions. - If you see error messages that suggest packages to download, do what they say and try the installer again. - The successful install will look like this: ![Building Virtual Box Guest Additions] You can ignore the warning about not finding the Window System, since your CentOS machine does not run a window system. Notes on using VirtualBox ========================= 1. Snapshots can be made by going to the Menu, Machine, Take snapshot, or use the **Snapshots** button near the top right of the main VirtualBox Manager window. 2. VirtualBox uses private IP address `10.0.2.15` as the IP for every VM using NAT networking, and that private IP address is not visible to the Host O/S, which is not the way VMware does it. You can read about why here: 3. VirtualBox has a FAQ section that may be of use to you: 4. You may have network problems (no Internet) if you try to start a VirtualBox VM at home with NAT networking while your Host computer is connected to the Algonquin VPN. - If you see private `10.` addresses in `/etc/resolv.conf`, instead of only one single `172.` address, you may have problems. - Turn off the VPN, then start up the VM (or restart networking), then turn the VPN back on after the VM is running. - Let Ian! know if you can make this work. Document License ================ > © 2014, Joshua Caseley. Licensed under the Creative Commons Attribution 3.0 > license, Rewritten by Ian!, using Joshua’s base document. Thanks, Joshua! -- | (From an original document by Joshua Caseley.) | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/ [Plain Text] - plain text version of this page in [Pandoc Markdown] format [www.idallen.com]: http://www.idallen.com/ [CentOS Install and Configure]: 000_centos_install.html [Virtual Box Opening Screen]: data/virtualbox_image1.png [Set the Name, Type, and Version of your new VM]: data/virtualbox_image2.png [Set Memory Size to 1024 MB (1 GB)]: data/virtualbox_image3.png [Create a 2GB Hard Drive]: data/virtualbox_image4.png [Enable PAE/NX Extended Features]: data/virtualbox_image5.png [Enable Network Adapter 1 and attach to NAT]: data/virtualbox_image8.png [Create a Port Forwarding Rule for SSH]: data/virtualbox_image9.png [Set Host Name and Port Number in your Client]: data/virtualbox_image10.png [Change Boot Order to put CD/DVD before Hard Drive]: data/virtualbox_image6.png [Settings for Empty CD/DVD Drive]: data/virtualbox_image7.png [Welcome to CentOS Boot Window]: data/virtualbox_image11.png [1]: 000_centos_install.html#install-the-centos-6-operating-system [Using SSH to connect]: #using-ssh-to-connect-to-your-virtualbox-vm [Building Virtual Box Guest Additions]: data/virtualbox_image12.png [Plain Text]: 000_centos_virtualbox_install.txt [Pandoc Markdown]: http://johnmacfarlane.net/pandoc/