Best Practices- Installing CentOS VM on
- Part 3
ADDING EXTERNAL HDD AND FORMATTING IT
In PART 1 of this series, we successfully installed CentOS 5.8 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. This topic will be discussed in detail in Adding a New Disk to a CentOS Volume Group and Logical Volume.
First, we will add the Hard Disk to the VM...
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.
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.
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.
Next we want to select the type of disk. So in this step we want to select "SCSI (Recommended)" and the "Next >" button.
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.. 10 GB in size and Split disk into 2 GB files.
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.
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.
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
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:
As we can see from the above fdisk output the disk currently has no partitions because it is a previously unused disk.
The next step is to create a new partition on the disk, a task which is performed by entering n (for new partition) and p (for primary partition):
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.
Note that if you wish to create multiple partitions you can specify the size of each partition by cylinders, bytes, kilobytes or megabytes.
The next option is t. 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
Now that we have specified the partition we need to write it to the disk using the w command:
If you do a fdisk -l again, you will see the newly created Disk with the Partition table allocated as shown below.
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.ext3 utility which takes as arguments the label and the partition device:
Now that we have createda new file system on the Linux partition of our new disk drive we need to mount it so that it is accessible to the CentOS system and its users.
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 /extra
The file system may then be manually mounted using the mount command: mount /dev/sdb1 /extra
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 /extra partition:
With the appropriate configuration line added to the fstab file, the file system will automatically mount on the next system restart.