Tuesday, February 28, 2012

Disk Management in Linux

Disk Management in Linux

Descriptions:

Secondary storage forms the fundamental part of any computing infrastructure. System administrators are expected to utilize hard drives effectively to help users in optimizing  their productivity. Using command line tools to manage hard disks in linux.

Introduction:

Linux offers utilities to manage hard disks. Users may add, delete change partition types. Furthermore they can also implement software RIAD, LVM etc using command line utility.

Here are a few caveats regarding hard disks.
  • A disk drive requires a partition table.
  • The partition is the logical sequence of cylinders in the disk.
  • A cylinder represents all the sectors that can be read by all heads with on movement of the arm that contains all these heads.
  • Linux supports up to 16 partitions on any individual IDE or SCSI drive.
  • Primary partitions: 3 , Extended partition: 1, Logical partition:12


Hard Disk Overview:

Firstly we start off by inspecting the hard disk for its current set-up. Our aim now is to find the partitions and their types those are currently existing. All commands need to be executed as the 'root' user. Hard disks are detected in the location /dev/hda'n' ( for IDE drvies) or /dev/sda'n' ( for SATA/SCSI drives). The 'n' denotes the partition number in that hard drive. Primary partitions are numbered from 1-3 and extended partition is given the number 4. All logical partitions are given numbers 5 onwards. However, the conventions differ as per the distribution of linux that you are using.

The 'a' in the hda (or sda) is the location of the hard disk controller where the hard drive is connected. So for IDE drives, 'a' is the primary master channel, 'b' is the primary slave channel, 'c' is the secondary master channel, 'd' is the secondary slave channel. Accordingly the location where the hard disk gets read would change to either /dev/had, /dev/hdb , /dev/hdc, or /dev/hdd.

In my system that has 2 hard disks, a 500 GB primary master and a 1 TB primary slave, I execute the following commands. I have just added the 1 TB partition. So lets perform all our operation in this hard drive only.

#fdisk -l


Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000080


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      194560   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              25       38914   312373249    5  Extended
/dev/sda5              25         523     3998720   82  Linux swap / Solaris
/dev/sda6             523       38914   308373504   83  Linux

When I gave this command without specifying the device, I get a list of all hard drives and I get an informatory messages that the hard disk /dev/hdb has no valid partition table. Also the hard drives are recognized as IDE hard drives in slots 'a' and 'b'. To get details regarding only one hard drive, pass the location of the hard disk to the same command.

#fdisk -l /dev/hda

Lets analyses the output:

  • The command request the details of the hard disk attached to /dev/hda.
  • The output first gives the human-readable ( MB, GB etc.) size of the hard disk.
  • Next it gives the actual size of the hard disk in bytes.
  • Next are a few details on the number of heads, sectors and the total number of cylinders in the hard disk.
  • Then the details of the partitions are given. Each column is as follows.


Title
Explanation
Device
The absolute path to the partition
Boot
Specifies which partition is bootable. An asterisk in marked to designated this partition
Start
The starting cylinder of the partition
End
The last cylinder of the partition
Blocks
The number of blocks in that partition
Id
The file system id, a hexadecimal number to denore the file system in the partition
System
The type of the partition. A human-understandable format
 
Creation and Deletion of partitions :

As we have a 4 GB hard disk that does not have a partition table. We will create 2 partition in it.
  • We use the fdisk to create partition in the second hard drive.
#fdisk /dev/hdb

  • Pressing 'm' will display the help for you.

  • We create a new primary partitions occupying 6000 cylinders for the first one and the remaining for the second partition which will be an extended partition. Note: You can create a partition of a specific size that  you want. Just rad the option carefully. Pressing ENTER at any question will take the default value for that question, if there is any.
Command ( m for help): n

  • We look at the partition table by pressing 'p'

  • The changes we made so far only temporary and will be finalized to the disk only when you explicitly  order 'fdisk' to do so. Confirm changes using the 'w' option. The 'q' option will quit without saving changes.
Command (m for help): w

  • This creates the partition in the hard disk. But the changes are not yet read by the Operation System. The next step is no make the kernel re-read the partition in the hdb device.
# partprobe /dev/hdb

  • We next make the filesystem that linux can read in the partition hdb1.
#mkfs.ext3 /dev/hdb1 ( partition name )

  • Similarly we add a filesystem to the hdb2 partition as well
#mkfs.ext3 /dev/hdb2

  • The deletion of a partition can be accomplished by typing 'd' and corresponding number of the  partition which you want to delete when prompted for one.


 


No comments: