Monday, 24 September 2012

Adding an external HDD in Ubuntu 12.04


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

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

The steps are pretty straight forward, and can be replicated on most of the Ubuntu Releases.

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

NOTE: I have added a single 20 GB Disks here

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

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

Create a New Partition (n)
Make that new Partition a Primary Partition (p)
Accept the default values for the first and last sectors

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. Finally, Write (w) the changes to the Partition Table

Once the partition table is ready, simply create the file system on that particular hard disk using mkfs.<filesystemtype> command as shown:

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/

NOTE: If you have multiple new HDDs, then don't mount the second Hard Disk on the same mount point. Create a new one for each Hard Disk.

 You can view the different HDDs and their mount Points using the df -h command

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

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

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 20 GB HDD was mounted successfully or not.

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.