Thursday, 20 September 2012

Best Practices- Installing CentOS VM on Vmware Workstation- Part 3 ADDING EXTERNAL HDD and FORMATTING IT

Best Practices- Installing CentOS VM on

VMware Workstation

- Part 3


In PART 1 of this series, we successfully installed CentOS 6.3 on a VMware Workstation environment.. and in PART 2, I showed you how to install VMware Tools in CentOS manually..

In this continuation series (PART 3), I am going to show you how to add a additional virtual Hard Drive to the CentOS VM, that too without rebooting it..

There are two ways to configure a new disk drive into a CentOS system:

  • One very simple method is to create one or more Linux partitions on the new drive, create Linux file systems on those partitions and then mount them at specific mount points so that they can be accessed. This is the approach that will be covered in this tutorial.

  • Another approach is to add the new space to an existing volume group or create a new volume group.

When CentOS is installed using the default disk configuration layout, a volume group is created and called VolGroup00. Within this volume group are two logical volumes named LogVol00 and LogVol01 that are used to store the / file system and swap partition respectively. By configuring the new disk as part of a volume group we are able to increase the disk space available to the existing logical volumes. Using this approach we are able, therefore, to increase the size of the / file system by allocating some or all of the space on the new disk to LogVol00.

First, we will add the Hard Disk to the VM...
Virtual Machine Settings

Select your virtual machine, as you can see from the above PIC selected the virtual machine. Next press the "Settings' to open the Virtual Machine Settings dialog.

From the "
Virtual Machine Settings" dialog select the "Add..." button at the bottom of the screen. From this dialog you can also modify how much memory you dedicate to the machine when it boots.

Virtual Machine Settings Dialog

Next we will walk through the "Add Hardware Wizard" the process makes it very simple to add additional hardware to a predefined virtual machine. From this screen we can see the many types of hardware we can add to a virtual machine. You can emulate just about any piece of hardware that one can expect in a modern operating system. It definitely makes testing with different configurations and devices much easier. 

For our example we want to select "Hard Disk" and then select the "Next >" button.

Adding new Hard Disk Wizard

In the next screen we see the three options for adding a new disk. We can "Create a new virtual disk", this will create a brand new disk on the guest operating system.

The second option, "
Use an existing virtual disk", allows you to mount a disk from another virtual machine.

The last option is to "
Use a physical disk", this allows you to mount a local physical disk to the operating system. This option is akin to NFS mounting a drive to a virtual machine. To add a new disk we select the "Create a new virtual disk" option and select the "Next >" button.

Create New Hard Disk

Next we want to select the type of disk. So in this step we want to select "SCSI (Recommended)" and the "Next >" button.

Hard Disk type

Now we want to set the size of the disk we are creating.

One of the nice features of VMware is that you don't have to allocate all of the disk when you create it. So if you create a 40 GB disk it doesn't have to take it all right away, the disk will grow as your virtual machine needs it. I will say this is a big performance hit you take when the disk has to extend, but for most applications its OK.

Also, I will warn that if the virtual disk grows and there is no physical disk left on the host operating system you will see a catastrophic failure and in most cases both the host and guest operating systems lock up and become unusable. (Don't say I didn't warn you !)

Lastly, you can
split the files into 2GB sizes, while this isn't necessary, it just makes all the disks much easier to manage and move around. For this step we want to set our disk size (12 GB in this case), I chose to allocate the disk space right now.. 20 GB in size and Split disk into 2 GB files.

Hard Disk size

This is actually pretty simple in that you decide what you want to physically call the disk and where to put it. .vmdk is the extension for VMware virtual disks. After we name the disk we can select the "Finish" button which adds the disk to the virtual machine.

Hard Disk name

So now we can see that the new disk has been added to the "Virtual Machine Settings" within the selected virtual machine. From here the disk acts just like it would if you added a new disk to a standalone server. So we select the "OK" button to continue.

NOTE: I have added two 20 GB Disks here

Virtual Machine Settings Dialog

After we've logged in and accessed a terminal window as root (or another user with root/sudo priveledges) we first want to run fdisk -l to display list of partitions.

In Linux the first SCSI drive is
sda, the second sdb, the third sdc, etc. since this was the second SCSI drive we added to the system, the device is known as /dev/sdb and /dev/sdc

Executing fdisk -l command
As shown above, the new hard drive has been assigned to the device file/dev/sdb. At this point the drive has no partitions shown (because we have yet to create any).

The next step is to create one or more Linux partitions on the new disk drive. This is achieved using the
fdisk utility which takes as a command-line argument the device to be partitioned:

The basic fdisk commands you need are:

  • m - print help
  • p - print the partition table
  • n - create a new partition
  • d - delete a partition
  • q - quit without saving changes
  • w - write the new partition table and exit

In order to view the current partitions on the disk enter the p command:

In this example we only plan to create one partition which will be partition 1.

Next we need to specify where the partition will begin and end. Since this is the first partition we need it to start at cylinder 1 and since we want to use the entire disk we specify the last cylinder as the end.

that if you wish to create multiple partitions you can specify the size of each partition by cylinders, bytes, kilobytes or megabytes.

Once you have specified the partition we need to write it to the disk using the w command
Creating new Partition Table for /dev/sdb

The next step is to create a file system on our new partition.

We now have a new disk installed, it is visible to CentOS and we have configured a Linux partition on the disk.

The next step is to
create a Linux Filesystem system on the partition so that the operating system can use it to store files and data. The easiest way to create a file system on a partition is to use the mkfs.ext4 utility which takes as arguments the label and the partition device:

Creating a new File System for /dev/sdb1

Your /dev/sdb Hard Disk is now ready for use. Use the same procedure on the second Hard Disk (/dev/sdc) as well.

Creating a new Partition Table for /dev/sdc

The option is t is used to replace the type of the current partition.

You can
list the different types of Partitions by pressing L as shown below.. this will list down all the available partition types..

for our example,
we need a Linux Partition, i.e. number 83.. similarly, if you want to create a SWAP out of this new HDD, then the number would be 82 (Linux/ Swap). Type 83 and press Enter key to continue

Viewing the different Partition Options

Once the partition table is ready, simply create the file system on that particular hard disk as done in previous steps

Creating File system for /dev/sdc1

If you do a fdisk -l again, you will see the newly created Disk with the Partition table allocated as shown below.

Executing fdisk -l command to view disks

In order to do this we need to create a mount point. A mount point is simply a directory or folder into which the file system will be mounted. For the purposes of this example we will create a /extra in root (/) directory to match our file system label (although it is not necessary that these values match): mkdir -p /export/primary

The file system may then be manually mounted using the mount command: mount /dev/sdb1 /export/primary/

Creating a new Folder and mounting HDD to it

Do the same for mounting the second hard disk (/dev/sdc1) as well. 

NOTE: Don't mount the second Hard Disk on the same mount point. Create a new one for each Hard Disk.

Creating a new Folder and mounting a HDD to it

In order to set up the system so that the new file system is automatically mounted at boot time an entry needs to be added to the /etc/fstab file.

The following example shows an
fstab file configured to automount our /export/primary and /export/secondary partitions:

IMP NOTE: Do not provide <spaces> between each text in the fstab file. Use the TAB key instead.

Editing the fstab
With the appropriate configuration line added to the fstab file, the file system will automatically mount on the next system restart.

Once you reboot your VM, run the command df -h to see whether the two 20 GB HDDs were mounted successfully or not.

Executing df -h command

 That's it for this tutorial.. Stay tuned for much more !!

No comments :

Post a Comment

Note: only a member of this blog may post a comment.