Monday, July 16, 2012

Partitions

Before getting into partitioning, it is better to have some idea about hard disks. There are mainly four types of hard disks available in market.

SATA - Serial Advanced Technology Attachment
SAS - Serial Attached SCSI

Based on hard disk types the Linux OS will identify them separately.
SATA as /dev/sda
IDE as /dev/hda

(The above is just sample. Need not be in same all the time)

Partitioning

The method of dividing hard disk into logical units called partitions.
Types of partitions
Primary Partition – Place to store system files. These partitions cannot be sub divided further.
Extended – These types of partitions can be further sub divided into smaller logical drives.

For every type of Hard disk allow to create up to four primary partitions and any number of logical partitions.

Linux provides the following utilities to work with partitions
-fdisk

Let’s work with partitions using fdisk which is most widely used.

# To display all hard disks and partitions available on them use the following command.
fdisk –l


Step to create partitions.

Select hard disk that needs to be partitioned.

fdisk /dev/sda

Provide following letters mentioned and follow the instructions. That’s it.
n - create new partition
w – save changes and quit
q – quit without changes
p – Print partition
d – delete partition

New partitions will be created in serial order Say /dev/sda1, /dev/sda2 etc…
Once partitions are created they need to be formatted with file system in order to make the OS to operate on them.

#Command to write file system is mkfs.
mkfs –t <file system type> <partition>

#Example
mkfs –t ext4 /dev/sda1

mkfs creates a special block called super block with hold the information about other blocks in that partition.
superblock, which contains information such as:
-File system type
-Size
-Status
-Information about other metadata structures

Linux maintains multiple redundant copies of the superblock in every file system. Backup copies can be used to restore damaged primary super block.

#Command to display primary and backup superblock location on /dev/sda1:
dumpe2fs /dev/hda1 | grep -i superblock

Once filesystem is applied, the partition needs to be mounted under some directory, so that OS can use the space to write/read data.

#Command to mount temporarly.
Mount <device partition> <mount dir>

Example
mount /dev/sda1 /mnt

This mounting is temporary and will be lost once system is reboot. In order to make the mount permanent details about the partition need to be updated in /etc/fstab file.


fstab Format

Device_Name Mount_Point File_Type   Options     Dump_Value  Fsck_Priority

#Sample
/dev/sda1   /mnt        ext4        default     0           0

Options - rw,sync,root_squash, wdelay, rdelay, noroot_sqaush, ro, async
Dump_Value - To check backup is set. It just provides information to the users.
Fsck_Priority - Order to check the file system for corruption. Can be 0, 1, 2, 3, etc... “0” means no check.


Enhanced by Zemanta

No comments:

Post a Comment