Устанавливаем CentOS в VirtualBox

Installation of CentOS in VirtualBox

Устанавливаем CentOS в VirtualBox

  • Course Home Page
  • Course Outline
  • All Weeks
  • Plain Text

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.

Download the free VirtualBox software

  1. After installing VirtualBox, start it. You will see a window similar to this on your computer:

Virtual Box Opening Screen

  1. 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.

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 14F, then use the name CST1234-14F-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.

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.

  2. Click Next

  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.

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.

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

  1. Where it says “Extended Features: Enable PAE/NX”, make sure this feature is enabled. Turn it on.

  2. Click OK.

  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.

  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

  1. Make sure that Enable Network Adapter is checked.

  2. Make sure that Attached to: is set to just NAT (not NAT Network, just simple NAT).

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 a green “plus” sign. Select it.

Create a Port Forwarding Rule for SSH

  1. Change the Name of the new rule rule from Rule 1 to SSH.

  2. Leave the Protocol as TCP.

  3. Leave the Host IP field blank (empty).

  4. Set the Host Port to some unused port on your Host O/S, e.g. try 2222 as a ly 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.

  5. Leave the Guest IP field blank (empty).

  6. Set the Guest Port to 22. (The SSH service on your Guest VM uses port 22.)

  7. Select OK to close this window and return to the Network window.

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.)

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.

  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

  1. 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.

  2. Make sure only the CD/DVD and Hard Disk are enabled.

  3. Click OK.

  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.

  1. 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

  1. 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.

  2. 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.

  3. 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.

  4. Click OK.

  1. Now, power on (boot) your virtual machine. You should see the CentOS installation screen:

Welcome to CentOS Boot Window

  1. Click in the window and use the arrow keys to stop the Automatic boot.

  2. 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. Here are some changes you will need to make to those instructions:
    1. 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.
    2. 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.
  3. 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.

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.

  1. Install the gcc compiler package: yum install gcc
    • Many other dependency packages will also be installed with gcc.
  2. Find out the version (release) of the kernel that you are running: uname -r

  3. 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 )
  1. 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 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: https://blogs.oracle.com/fatbloke/entry/networking_in_Virtualbox1

  3. VirtualBox has a FAQ section that may be of use to you: https://www.Virtualbox.org/manual/ch12.html

  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.

| (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

          Author Ian! D. Allen

Источник: http://teaching.idallen.com/cst8207/14f/notes/000_centos_virtualbox_install.html

Поделиться:
Нет комментариев

    Добавить комментарий

    Ваш e-mail не будет опубликован. Все поля обязательны для заполнения.