Install Centos On Virtualbox Mac

  1. Virtualbox Centos 8
  2. Centos For Virtualbox

If you don't have VirtualBox already go to download page and install it. To get an image of CentOS go here and choose the version you want (I went for 6.5) by clicking on x8664 then pick one of the mirror servers for downloading the desired image (my choice was CentOS-6.5-x8664-minimal.iso). Instalation steps.

  • Installing VirtualBox 6.1 in RHEL/CentOS and Fedora. To install the latest stable version of VirtualBox, you need to first download the virtualbox.repo configuration file using the following wget command and then import the public key using rpm command.
  • A new VM should be created. Now, select the VM and click on Settings. Now, go to the Storage section. Then, click on Empty in Controller: IDE, then click on the CD icon and click on Choose Virtual Optical Disk File. Now, select the CentOS 8 ISO installation image and click on Open. Now, click on OK.

For an upcoming project and blog article, I'm going to need a Linux setup on my main machine. The project requires me to use a minimal install of CentOS 7 (Linux) as the operating system. In order to run another operating system on my hardware I will use VirtualBox so that I can run CentOS alongside OS X.

VirtualBox is a free and open source virtualization app that allows users to run multiple operating systems on their machine from within their main operating system. In other words, you can run a linux box (or whatever your favorite flavor of OS is) as if it were any other application inside your Windows OS, Mac OS X, or even on another Linux box. This is also known as running a Virtual Machine (VM).

What is a Virtualization Application?

Different operating systems have different processes for interacting with hardware. VirtualBox, and other virtualization apps, simulate hardware in a way that the virtualized operating system (the VM) thinks that it's running on real hardware. What VirtualBox is really doing underneath the hood is translating the VMs systems calls to calls that the main operating system can understand. VirtualBox sits between the two operating systems translating calls and responses between the two.

Install Centos On Virtualbox Mac

Why would we want to run a Virtual Machine?

One of the main reasons to run a VM is to gain access to technology and functionality that does not exist in the current operating system running on our hardware.

For example, my operating system of choice is OS X, but if I want to do any serious Windows development I need to use Visual Studio. Microsoft hasn't released an OS X version of Visual Studio as of yet so to use the IDE I have to run Windows in a VM.

Another example would be the need to run an ssh server like openssh-server, or a source control server like Gitolite. Yes, you can do both on OS X, but Linux or FreeBSD generally provides a better environment for server like functions.

Virtual Machines give us the freedom of choice no matter what operating system sits on top of our hardware. There is also the added bonus of separating responsibilities. We can have different VMs running different types of servers with totally different setups. You could have a Rails app running in Apache on one VM, and another Rails app running in Nginx on another VM.

Is there a disadvantage to virtualization?

Virtual Machines can help us solve a lot of problems, but there are some fallbacks.

One of the main fallbacks is the virtualization itself. Virtualbox has to spend extra time converting calls from one operating system to another, so there is inherently a loss in performance.

Most machines, now days, have powerful, multi-core cpus and large amounts of RAM so this isn't really a big deal.

Where can I get VirtualBox?

At the time of writing this article the current version of VirtualBox was 5.0.4.

VirtualBox can be downloaded by following this link: virtualbox.org

Downloading CentOS 7

I will be using the CentOS 7 Minimal ISO which is a 636MB download versus a 4GB download for the DVD ISO. The minimal install is exactly what it sounds like, minimal. It doesn't come with a windows manager or any development tools. It's a bare bones install that allows us to customize the environment to fit our exact needs.

CentOS 7 can be found here: centos.org

The Install

I'm not going to walk you through the VirtualBox install because it's simple and straight forward. I will however, go through the steps of installing CentOS in VirtualBox.

Virtualbox

Once you have VirtualBox installed, open it up and click on the New icon on the top left of the toolbar.

Name your VM anything you want, but make sure you choose Linux as the type and Red Hat (64-bit) as the version.

Next, choose the amount of memory you'd like to reserve for this VM. I usually just go with the suggested amount, which in this case is 768MB.

Install virtualbox centos 7 server

The next prompt will ask you to add a virtual hard disk. Go ahead and select Create a virtual hard disk now which should be the default.

Next, you can select whichever type of VM hard disk type you'd like. I usually just select VDI.

The next prompt will ask you if you'd like dynamic storage or fixed storage. Select dynamic. Dynamic storage means that VirtualBox will only use the amount of space, on your real hard drive, that the VM actually needs until it reaches the maximum we allot. This will also allow us to add more to the VM later if we need it.

The next step is to actually allot the amount of hard disk space for the VM. 8.00GB will be more than plenty to start off. Go ahead and press the Create button to finish up this part of the process.

Now that we've setup the setup, it's time to install the VM. Your VirtualBox window should now contain a VM that is powered off.

Find your newly created VM space and double click on it to start it up. You'll be prompted to point the manager to the iso we downloaded earlier. Locate the file and click start.

After you click start, VirtualBox will start the iso and you will be prompted to select an install mode. I usually just select Install CentOS 7, but it defaults to Test this media & install CentOS 7.

The install process will begin by asking you to select your language of preference. Once you've done that the next prompt will be to select the install destination.

Click on the Install Destination label and then immediately click Done at the top of the next window. Everything in this part of the install wizard has been set for us because of earlier selections we made when setting up the VM space.

You'll now notice that the Install Destination section no longer contains the warning that was previously there. Now you can click on Begin Install.

The install will begin, but there are still two more steps we need to take. The next window will give us the opportunity to set the root password and to add an additional account. Lets do both now.

Select Root Password and create a new password for the root account.

Add another account so that you can log in to the VM without directly logging into root. Go ahead and make the user an administrator.

Click on Finish configuration.

The installer will complete a few more things and then you'll see a message at the bottom that says Complete and will find a button to reboot the VM. Go ahead and click Reboot to startup the VM for the first time.

Once the VM reboots you'll be able to log in.

Setting up ssh access on the VM

There is a small oddity when installing CentOS when it comes to accessing the internet. When you first install the OS you may or may not be able to connect to the outside world, but after the first reboot you most certainly will not have a connection. This is due to the ONBOOT property in the ifcfg config file being set to no by default.

If you type ip addr at the command-line you'll notice a lack of any other ip address other than 127.0.0.1.

Change the working directory to /etc/sysconfig/network-scripts/ and edit the ifcfg-enp0s3 config file and set ONBOOT to yes. You may need to run vi as sudo if you aren't logged in as root (which is never recommended).

After you reboot (via the reboot command) and the system comes back up type ip addr once again to view your VMs ip address.

CentOS minimal comes with an ssh server so the last step needed to be able to ssh in from our local machine is to setup port forwarding on our VM.

The status bar, on the bottom of the running vm, should have a bunch of icons. The one of interest to us is the network (double monitor) icon.

The dialog that opens shows the current configuration of the network adapter.

Next press the Port Forwarding button to bring up the settings that will allow us to ssh into the VM.

In the Port Forwarding dialog click on the green plus icon to add a new Rule. In this new rule enter information for Host IP, Host Port, Guest IP, and Guest Port.

Install centos on virtualbox macbook pro

I use the following settings:

  • Host IP: 127.0.0.1 - this is the IP address (localhost) of the host operating system (not the VM). If you want to access the VM from anywhere on the internet you'll need to use your computers real IP.
  • Host Port: 2222 - use a port that is open on your machine.
  • Guest IP - this is the IP address shown when ip addr is typed in the VM command-line. In my case it has been 10.0.2.15 every time I have only one VM running.
  • Guest Port - 22 is the default ssh port and that's what we want to use here.

Click the OK button to finalize the port forwarding settings.

Now you should be able to ssh in from a local terminal.

Wrapping up

We should now have a running, minimal version of CentOS 7 in VirtualBox. VirtualBox makes it extremely easy to run many different operating systems on existing hardware without having a separate machine for each different operating system we want to run.

Install Centos On Virtualbox Mac

Virtualbox Centos 8

Having this setup will save some time for the next article where we'll go through installing Erlang and Elixir on our CentOS 7 VM.

If you want to learn how to administer a Linux server or have a need to test your application on a specific Linux distribution, a good point of start is to virtualize it locally using VirtualBox.This post explains how get CentOS up and running on OS X. Our goal here is to install minimal Linux server and access it for administration via ssh from your Host operating system. We will also enable the Guest system to act like a web server.

If you don't have VirtualBox already go to download page and install it.

To get an image of CentOS go here and choose the version you want (I went for 6.5) by clicking on x86_64 then pick one of the mirror servers for downloading the desired image (my choice was CentOS-6.5-x86_64-minimal.iso).

Instalation steps.

Run VirtualBox

  • Clik New.
  • Choose the Name of you choice, Linux for Type, Red Hat 64 bit for Version.
  • Give at least 1024 MB of memory.
  • Check Create a virtual hard drive now
  • Hard drive filetype: VDI.
  • Storage on physical hard drive: Dynamically allocated.
  • File location and size: leave 8 GB for the size.

Go to Settings

  • System -> Processor: set 2 cores.
  • Mount the operating system disk image of Cent OS minimal that you have downloaded earlier: select storage tab, select Empty in Storage Tree frame. In Attributes section browse to your iso by clicking the cd icon.
  • Click start (the green arrow) - this will start the installation process in graphical mode.
  • Choose the first option.
  • Skip the media test.
  • Choose the language.
  • Check the basic storage devices button.
  • The next screen will ask you to discard data - click yes.
  • Provide a server name and a root password.
  • Choose replace existing linux in one of the following screens.
  • Reboot after installation.

After rebooting log in in the terminal with the root user and the password you created during installation.

Connection to the Internet

If you run ifconfig in the Guest console, the only network interface listed is lo (loopback device). The first action to take in this case will be setting up another two interfaces: one for accessing the Internet, second for connecting the Guest Linux from your Host OS via ssh.

To enable eth0 (access to the network) edit /etc/sysconfig/network-scripts/ifcfg-eth0 and change ONBOOT to yes. Restart the network service by running: service network restart. You can check your internet connection with ping centos.org (all must be done as root, not via sudo).

Host to Guest ssh connection

Shut down your Guest VM.

Go to VirtualBox -> Preferences, pick the Network and Host-only Network tab. Click plus on the right hand (Add host-only network) to create vboxnet0.Then go to your Guest VM settings, tab Network -> Adapter 2. Click Enable Network Adapter and choose Host-only Adapter.Now boot up your Guest VM, navigate to /etc/sysconfig/network-scripts/ and create a new file ifcfg-eth1 with the following content:

Run ifup eth1.

The last thing will be opening port 22. Go to the Guest VM settings - Network - Adapter 1 - port forwarding - add and set Host and Guest ports to 22.

Now you should be able to connect to your Guest VM from your Host OS terminal: ssh [email protected] with the root password.

From now on you can administrate the CentOS server without switching to the VirtualBox instance console.

Enable the Guest VM to act like a web server.

First you have to open port 80 on your Guest machine. To to this edit the file /etc/sysconfig/iptables and add the following line: -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT.Restart the network service: service network restart.To test the server you can use python's SimpleHTTPServer: create a new folder for storing your http content, for example /var/www and place there a new index.html file with a content of your choice.Now run python -m SimpleHTTPServer 80. This command will start a http server listening on port 80.If you navigate a browser to http://192.168.56.101 you should be able to see the content of your index.html file.

To take the burden of remembering the IP number off your memory, let's create an easy to remember host name, both for ssh and http access.Edit the /etc/hosts file (on your Host) and attribute the IP an easy to remember name, for example: 192.168.56.101 centos.local.

Centos For Virtualbox

Now you can access your Guest VM by ssh [email protected] and check the web server using the http://centos.local url.

If you've come so far, it means that you have succesfully installed your Linux distribution.Now you are ready to dig for more information about how to install the technology stack of your choice.