Sunday, January 25, 2015

How to Create a CentOS 7 Minimal VM on VMware Player

By popular request, here is an updated (for CentOS 7) version of an older tutorial for CentOS 6. This post provides step-by-step instructions how to:
  • create a VMware virtual machine from a CentOS-7.0-1406-x86_64-Minimal.iso using VMware Player 6.0.4 on Windows 7;
  • bring the virtual machine to a minimally usable state, i.e. to be able to connect to CentOS mirrors in order to update your new system and install additional software packages;
  • install VMware Tools 9.6.2 or open-vm-tools 9.4.0;
  • open ports with firewall-cmd.

Let's Get Started

First, download the CentOS-7.0-1406-x86_64-Minimal.iso image from one of the CentOS mirrors. Save it anywhere on your local disk.

Pre-Configure Your Future Virtual Machine

Start VMware Player (download and install if you have not done so; remember that it is free only for non-commercial use). At the moment of this writing, the most recent version of VMware Player is 6.0.4 (VMs are compatible with VMware Workstation 10).

Click "Create a New Virtual Machine".

On the next dialog box, select the "I will install the operating system later..." option (automatic installation doesn't work correctly because VMware Player assumes that you need a desktop system with GUI). Click "Next".

On the next dialog box, under "Guest operating system" select "Linux" and under "Version" - "Other Linux 3.x kernel 64-bit" (there are no "CentOS 7" or "RHEL 7" options in VMware Player 6.0.4). Click "Next".
    UPDATE: VMware Player 6.0.5 (with VMware Tools 9.6.4) has just been released. Now there is an option "Red Hat Enterprise Linux 7 64-bit". Most likely, this is what you should pick.

On the next dialog box, give your virtual machine a more descriptive and recognizable name (if you have many virtual machines, you'll be glad you did) and, optionally, edit the location (on Windows it defaults to "C:\Users\YourUserName\Documents\Virtual Machines\VirtualMachineName"). Click "Next".

In most cases, you will hardly need 20 GB (default) of disk space for it. So, on the next dialog box, you can give it less or keep the default (don't worry - it doesn't pre-allocate disk space). There is hardly any reason to split even a 20 GB virtual disk into multiple files, so select "Store virtual disk as a single file". Click "Next".

On the next dialog box, click the "Customize Hardware..." button. You may (although don't have to) want to change the default configuration of the virtual network adapter. The default configuration is "NAT: Used to share the host's IP address", but if you would rather have your virtual machine behave more like a real computer on your network (here I assume that that's what you want), change it to "Bridged: Connect directly to the physical network". Make sure that the "Connect at power on" check box under "Status" is checked. Again, assuming that you are building a virtual server, you can probably safely remove the "USB Controller", "Sound Card" and "Printer". Keep the CD/DVD drive (otherwise you won't be able to install the operating system and VMware Tools). You can reduce the memory to as little as 512 MB (according to the documentation, it is the minimum requirement). When finished, click the "Close" button.

Click "Finish".

Prepare to Install CentOS 7

Click "Edit virtual machine settings" (make sure the correct virtual machine is selected!).

Under "Hardware", select "CD/DVD". Under "Device status", make sure that the "Connect at power on" box is checked. Under "Connection", select the "Use ISO image file:" option, and then "Browse..." to where you saved the downloaded CentOS-7.0-1406-x86_64-Minimal.iso image. Click the "OK" button.

Install CentOS 7

Click "Play virtual machine" (again, make sure the correct virtual machine is selected).

Your new virtual machine will boot from the virtual CD/DVD drive. When the boot options screen comes up, hit "Enter" to select "Install CentOS 7" (default) or just wait for 60 seconds for the installation process to start. On the next screen, you will be prompted to hit "Enter" again, but the installation will continue after a brief delay even if you don't. Then the install wizard loads. Note that, unlike with CentOS 6, graphical install wizard (aka "anaconda") loads even with just 512 MB of memory. The install wizard itself is mostly self-explanatory with some minor quirks explained below.

On the second screen of the GUI install wizard, you must click "INSTALLATION DESTINATION" and then click the default virtual disk under "Local Standard Disk". Under "Other Storage Options" further down, leave the default "Automatically configure partitioning" option as is (unless you want to do it manually). FYI: with automatic partitioning, two partitions are created: swap, the size of which is automatically set to double the size of memory allocated for the VM, and root that takes the rest of the virtual disk space. When finished, click the "Done" button in the upper left corner, which will take you back to the previous screen. Occasionally, the wizard may still complain that no disk has been selected. If so, try again (make sure that the virtual disk is highlighted and there is a checkmark on the disk icon when you click the "Done" button).

While on the same install wizard screen, click "NETWORK & HOSTNAME". Your virtual network card should be listed on the left, and its status should be "Disconnected". Click the "ON/OFF" toggle switch on the right to enable networking. Optionally, at the bottom of the screen type in your hostname (default is "localhost.localdomain"; if not sure, leave it as is). Click the "Done" button in the upper left corner, which will take you back to the previous screen.

Proceed with the installation by clicking the "Begin Installation" button.

On the next screen, create root password (should be self-explanatory). Don't forget it!!!

The installer then will proceed to install 297 packages, which may take a couple of minutes.

When finished, the installer will prompt you to reboot the virtual machine. Reboot.

Update the System and Install Some Optional Packages

Login as root with the password created during installation.

Update your new system by running
yum update

Optionally, you can also do the following:

Not to torture yourself with the vi editor, you may install nano by running
yum install nano

While you're at it, you might as well install wget
yum install wget

It also might be a good idea to add the EPEL (Extra Packages for Enterprise Linux) repository:
rpm -Uvh epel-release-7-5.noarch.rpm
You don't really have to download the rpm. You can just run
rpm -Uvh

Now you can install htop
yum install htop

If you can't connect to any repositories, you may have forgotten to enable networking during installation. See below how to fix that.

Enable Networking

If you forgot to enable networking during installation (see above), below are the instructions how to fix that.

First, verify that networking is indeed disabled by running
ip a
You will see that the IP address of your virtual network adapter is

Navigate to /etc/sysconfig/network-scripts/
cd /etc/sysconfig/network-scripts/
and list the files in that directory

One of the files should be ifcfg-eno*, where "*" is a number, which is generated during installation (I think). For example, on one of my Cent OS 7 VMs it is ifcfg-eno16777736.

Now, you need to edit /etc/sysconfig/network-scripts/ifcfg-eno*. To do that, run
vi /etc/sysconfig/network-scripts/ifcfg-eno*

In ifcfg-eno*, change "ONBOOT=no" to "ONBOOT=yes". In order to save and exit the editor, hit "Esc", then - type :wq, then hit "Enter".

Now, in order for your changes to take effect, run
service network restart
or, using the "new style",
systemctl restart network.service

ip a
to verify that your virtual network adapter has a usable IP address now.

Now you should be able to connect to CentOS repositories, update your system, and install optional software as described in the section above.

Install VMware Tools OR open-vm-tools

Boot up your new VM and login as root.

In order to be able to install and configure VMware Tools, you need to install some extra packages. With the current version of CentOS (7.0) and VMware Tools (9.6.2), the only missing packages appear to be Perl (VMware Tools installer and configurator are Perl scripts) and net-tools (it contains ifconfig required by the VMware Tools installer). To install them run:
yum install perl net-tools

In the /mnt directory create cdrom subdirectory by running
mkdir /mnt/cdrom/

From the VMware Player menu select "Manage" > "Install VMware Tools". It should prompt you to mount the virtual CD drive in the guest. So, inside the VM, run
mount /dev/cdrom/ /mnt/cdrom/
You will get a message something like block device /dev/sr0 is write-protected, mounting read-only, which is fine.

Now, in the /opt directory create a subdirectory, e.g. vmwaretools, by running
mkdir /opt/vmwaretools/
and copy everything from the virtual CD drive into that directory:
cp /mnt/cdrom/* /opt/vmwaretools/
To make sure that everything was copied, you can run
ls /mnt/cdrom/
ls /opt/vmwaretools/
and compare the results (just in case).

You can unmount the virtual CD drive now:
umount /dev/cdrom/ /mnt/cdrom/

Go to the /opt/vmwaretools/ directory
cd /opt/vmwaretools/
and unpack the archive with VMware Tools
tar -xzvf VMwareTools*.tar.gz (the exact file name will depend on the version of VMware Player you are using).
This should create a subdirectory vmware-tools-distrib inside /opt/vmwaretools/ with a whole bunch of subdirectories and files in it.

Go to that directory:
cd /opt/vmwaretools/vmware-tools-distrib/
and run

Accept all the defaults during the installation until you get to the prompt whether you want to run /usr/bin/ Make a note of the name of the script and its location because, in case it fails now due to missing packages it depends on, you will have to install those missing packages and run it again. Now, you can let the install script run the configuration script for you.

There is hardly any reason to enable the folder sharing feature, so, when you get to that prompt, you can answer "no" (the default is "yes"). The same goes for the dragging and copying feature (the default is "yes"). If you want to, you may enable automatic kernel modules (the default is "no", and I would rather keep it that way).

If the configuration script complains about some missing packages (the most likely suspects are: gcc, make, kernel-devel), install them and re-run
cd /usr/bin/
By the way, you will have to re-run this script every time the kernel is updated.

Should you need to uninstall VMware Tools, run
cd /usr/bin/

CentOS 7 comes bundled with open-vm-tools, an open source implementation of VMware Tools. So, if the above seems like too much work, you may install open-vm-tools instead:
yum install open-vm-tools
However, VMware Player throws an error on power-on (but, oddly enough, not on warm reboot) "The VMware Tools power-on script did not run successfully in this virtual machine...", but vmtoolsd appears to be running. Whether it loads correctly or not is an open question.


It is more than likely that you will want to run a web server (Apache or some other) on your virtual machine. By default, all ports are blocked by firewalld, so don't get frustrated because the web server is "not working". Open port 80 (and 443 if you are going to use https; do the same for other ports that you need open):
firewall-cmd --zone=public --add-port=80/tcp
Test the web server and, if everything works as expected, save the new settings:
firewall-cmd --zone=public --add-port=80/tcp --permanent
Reload the firewall:
firewall-cmd --reload
See the RHEL 7 firewalld documentation for more info.

That's it. Continue building your lean and mean virtual machine, but before you begin experimenting, "clone" your VM in this state: should something go wrong, you won't have to start from scratch again.


Dmitry R said...

Thank you! Very useful

Ira Portman said...

You are welcome, Dmitry.

Yogendra Mehta said...

very well explained procedure
but I failed to see the cenots desktop !
is it because new user we did not add
just the root login ?

Ira Portman said...

I am not sure I understand your question correctly, but, when you install CentOS _minimal_, there is not supposed to be any "desktop" (GUI).