Adding a New Virtual or non Virtual Hard Drive to a Linux
Sometimes you find it that you run out space and you need to add a new hard drive. This is simple task for Windows with the plug and play feature and easy formatting GUI. Well in Linux it’s not the same in my mind. Trying to remember all the steps need to get it up and running as well as getting it mounted on startup is another thing. Therefore I’m creating this doc to help intranet folks with the “simple” task of adding a hard drive in Linux.
This process is more common for me to do with a Virtual Machine therefore I will cover all the steps need when adding a new hard drive to a virtual machine. If you’re just adding a new physical drive to a Linux host then install it, boot it up and step the initial virtual machines steps.
Before I created this doc I always used this site http://www.matttopper.com/?p=25 which gives you the step by step process but using the old GSX server version.
Step 1: Create the disk on ESX Server who will be hosting the Virtual Machine
Terminal Access the ESX Server and go to the directory where the virtual machine is located. You will want to create a hard drive like any or other hard drive. Therefore i.e. run this command to create the disk:
/usr/sbin/vmkfstools -a lsilogic -c 10g -d thin linux-hdb.vmdk
In this case I’m using the vmkfstool command where the ?a option is for the SCSI adapter; either buslogic or lsilogic. The ?c option is for create and in this case 10 GB file size dive. The ?d and thin option will not allocate all the space right away and only take up space as it goes. And last but not least the final thing is the name of drive with the .vmdk extension.
Step 2: Adding the new hard to the virtual machine
Using the VMware Client, shutdown the machine and edit the settings. Next use the add option to add a hard drive.
Since we created the disk by hand on the machine to save disk space and not allocate all the space at once you will use the option to select an existing hard drive.
Browse to the location on the machine where the newly created disk is created and select the vmdk file.
Since we created it as a lsilogic drive you will need to use the SCSI node with the next available drive for the system.
And finally click finish to complete the process. After this is complete you can go ahead and start the machine again.
Formatting, Mounting, and everything else to configure the drive in Linux
Once the Linux is up and running you will need a terminal window to configure everything. I like to start xserver with gnome and configure everything from a desktop terminal. Also helps with the print screening for documenting.
First you will need to run fdisk to format the new drive. Since it?s a SCSI drive, the first drive is already setup as sda therefore the next drive will be called sdb. In a terminal window run:
This will open the fdisk utility to format the new drive as sdb. Next you type n for a new partition and hit p for a primary partition. The partition number will be 1 and the last cylinder will be the last number by default because we will want to format the whole disk. Finally you will use the w command to write these changes to the partition table. After that it will take some time to format the disk depending on the size.
Next you will have to make the file system by using the mkfs command. I prefer to run the following:
mkfs -t ext3 /dev/sdb
That command will make the file system on the sdb drive with extend 3 as the file system type.
Next you will need to create a mounting root to mount the newly created file system and drive too. In this case below I create a new folder call software on the / partition. Next I used mount -t ext3 /dev/sdb /software. This will mount the new file system on the newly created directory.
The last thing to do is add the drive the fstab file so I will on boot up in the event the machine is restarted. You will need to edit the /etc/fstab file and add the line:
/dev/sdb /software ext3 defaults 1 1
This will mount the directory software to the second hard drive device with an extend 3 file system.
After everything is complete I try a system reboot to make sure everything is configured properly.