Monday, October 8, 2012

Partitioning Disk



Determine Drive Information

We assume that the hard drive is physically installed and detected by the BIOS.
To determine the path that your system has assigned to the new hard drive, open a terminal and run:



sudo lshw -C disk

Command Line Partitioning


You'll be using "fdisk" to accomplish this. Refer back to the logical name you noted from earlier. For illustration, I'll use /dev/sdb, and assume that you want a single partition on the disk, occupying all the free space.
If the number of cylinders in the disk is larger than 1024 (and large hard drives always have more), it could, in certain setups, cause problems with:
  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Otherwise, this will not negatively affect you. 
1) Initiate fdisk with the following command:
  •   sudo fdisk /dev/sdb 
2) Fdisk will display the following menu:
  •   Command (m for help): m <enter>
      Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
      Command (m for help):
3) We want to add a new partition. Type "n" and press enter.
  Command action
   e   extended
   p   primary partition (1-4)

4) We want a primary partition. Enter "p" and enter.
  Partition number (1-4):

5) Since this will be the only partition on the drive, number 1. Enter "1" and enter. 
  Command (m for help):

If it asks about the first cylinder, just type "1" and enter. (We are making 1 partition to use the whole disk, so it should start at the beginning.)
6) Now that the partition is entered, choose option "w" to write the partition table to the disk. Type "w" and enter.
  The partition table has been altered!

7) If all went well, you now have a properly partitioned hard drive that's ready to be formatted. Since this is the first partition, Linux will recognize it as /dev/sdb1, while the disk that the partition is on is still /dev/sdb.

Command Line Formatting


To format the new partition as ext3 file system (best for use under Ubuntu):
  •   sudo mkfs -t ext3 /dev/sdb1
To format the new partition as fat32 file system (best for use under Ubuntu & Windows):
  •   sudo mkfs -t fat32 /dev/sdb1
As always, substitute "/dev/sdb1" with your own partition's path.

Modify Reserved Space (Optional)


When formatting the drive as ext2/ext3, 5% of the drive's total space is reserved for the super-user (root) so that the operating system can still write to the disk even if it is full. However, for disks that only contain data, this is not necessary.
NOTE: You may run this command on a fat32 file system, but it will do nothing; therefore, I highly recommend not running it.
You can adjust the percentage of reserved space with the "tune2fs" command, like this:
 sudo tune2fs -m 1 /dev/sdb1

This example reserves 1% of space - change this number if you wish.
  • (i) Using this command does not change any existing data on the drive. You can use it on a drive which already contains data.

Create A Mount Point


Now that the drive is partitioned and formatted, you need to choose a mount point. This will be the location from which you will access the drive in the future. I would recommend using a mount point with "/media", as it is the default used by Ubuntu. For this example, we'll use the path "/media/mynewdrive"
  •   sudo mkdir /media/mynewdrive
Now we are ready to mount the drive to the mount point.

Mount The Drive


You can choose to have the drive mounted automatically each time you boot the computer, or manually only when you need to use it.