Setup Centos 7 Virtual Machine inside VirtualBox

In this notebook, we will go over the steps to setup a CentOS7 VM inside VirtualBox on a Windows host. The interface of VirtualBox for this process will be similar for MacOS and Linux. Students with Mac laptops can visit the following resources for more details:

Preparation steps:

Installation of VirtualBox

  • The dowload and install isntructions for VirtualBox can be found at virtualbox.org. At the moment, the instructor is using VirtualBox 5.2.18.
  • All installation options for VirtualBox are kept at the default settings.

CentOS 7

CentOS 7 will be used as the default guest OS for the VM. You will need to dowload this ISO

Setup a virtual machine inside VirtualBox

  • Open VirtualBox
  • Click New to bring up the Virtual Machine creation windows
  • Click Guided Mode to switch to a step-by-step interface

Step 1: Name and operating system

  • Type in the name of your VM
  • Select Linux to be the operating system
  • Select Red Hat (64-bit) to be the version of the operating system
  • Click Next

Step 2: Memory size

  • Use the recommended memory size of 1024MB
  • This number can change depending on how much memory your physical machine has
  • Click Next

Step 3: Hard disk

  • Select Create a virtual hard disk now
  • Click Create

Step 4: Hard disk file type

  • Keep the default setting at VMDK
  • Click Next

Step 5: Storage on physical hard disk

  • Keep the default setting at Dynamically allocated
  • Click Next

Step 6: File location and size

  • Set the file size to be 16.00 GB
  • By default, the virtual machine file will be written to a directory inside your Windows Documents folder. However, if you want to save your VM on an external drive for portability, it is possible to do so.
  • Click Create

Step 7: Set up the VM

  • Select the created VM from the list
  • Click the Settings gear button

Step 8: Settings - General

  • Keep all general settings the same

Step 9: Settings - System

  • Under the Processor tab, increase the number of CPUs to two
  • Depending on your laptop, you could increase this number further
  • Keep all other system settings the same

Step 10: Settings - Storage

  • Select Controller: IDE, then click on the disk icon next to Optical Drive.
  • Navigate to the directory where you downloaded the CentOS7 ISO, and select the ISO file
  • All remaining settings should not be changed
  • Click OK to close the Settings window

Step 11: Launch the VM

  • Select the VM from the list
  • Click the green Start button
  • The WM will be launched, and since the CentOS ISO is loaded in the virtual optical drive, you will be presented with the boot screen of CentOS
  • When clicking on the VM for the first time. You will also be presented with a popup windows asking persmission to capture the mouse/keyboard for the VM and also containing instructions on how to return mouse/keyboard to the main Windows operating system (Right Ctrl button by default)
  • Use the Up arrow to select the first option to Install CentOS 7, and hit Enter to begin the CentOS installation process

Install CentOS 7 on the VM

Step 1: Lanuage selection

  • Select English (United States)
  • Click Continue

Step 2: Installation Summary

  • Click on Installation Destination, but do not change anything, and then click Done. This will resolve the warning sign

Step 3: Installation Summary

  • Click on Network & Host Name
  • Click on the slider for Ethernet to turn the Ethernet interface to ON
  • Click Done
  • Click Begin Installation

Step 4: User Settings

  • As CentOS 7 begins its installation process, you will also need to change two user settings options, Root Password and User Creation

Step 5: User Settings - Root Password

  • Click Root Password
  • Provide a strong password for the root account
  • Click Done to return to the User Settings window

Step 6: User Settings - User Creation

  • Click User Creation
  • Provide information and password for your user account
  • Check the box on Make this user administrator
  • Click Done to return to the User Settings window

Step 7: Finish Configuration

  • As the installation process is completed, click Finish Configuration to move to the next stage
  • Once the final configuration stage is completed, click on Reboot to restart the VM

After the reboot is completed, you will be able to login to the newly created CentOS 7 VM

Install Anaconda

From the terminal of your VM, run the following commands

  • Download wget, bzip2, and curl

    $ sudo yum install -y wget curl bzip2
  • Download Anaconda

$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
  • Run the Anaconda installation script
$ bash Anaconda3-5.2.0-Linux-x86_64.sh
  • To scroll through the User Agreements, keep hitting Space until you are asked to accept the license terms, then type yes
  • Click Enter to accept the default installation directory.
  • Type yes and hit Enter to agree to prepend the path to Anaconda3 installation directory to your .bashrc file
  • Type no and hit Enter to opt out of installing VSCode and to complete the installation process
  • Source bashrc to update the path
$ source ~/.bashrc

Setup port forwarding

This is to allow access to Jupyter Notebook from host machine's browser

  • Open port 8888 (default port for Jupyter)
$ sudo su
$ firewall-cmd --permanent --add-port=8888/tcp
$ firewall-cmd --reload
$ exit
  • Identify guest machine (CentOS Vm) IP address
$ ip addr

  • On the bottom bar of the VirtualBox window, right-click on the Network icon
  • Select Network Settings

  • Click Advanced
  • Click Port Forward

  • Click the plus icon and add the following rules
  • Click OK to to accept the Rules
  • Click OK to close the Network Settings windows

Configure and launch Jupyter

From your VM terminal, run the following commands

  • Generate default configuration file:
$ jupyter notebook --generate-config
  • Change default password:
$ jupyter notebook password
  • Launch jupyter notebook
$ jupyter notebook --ip 10.0.2.15 --no-browser

You can now access a Jupyter Notebook server from your host machine's browser. This will be the default platform for the majority of lectures and labs in this class.

Exercise