Sunday, September 4, 2011

Linux Partitioning and Formation

Fdisk

The "fdisk" file system management tool is a text-based interface that lets you divide a hard disk into partitions, which are contiguous regions of disk space on which you can make file systems. The process of dividing a hard disk space is called disk partitioning.

To list out the current available hard disks and their layout, you can use "fdisk -l" as shown below.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1930 15398302+ 8e Linux LVM
/dev/sda3 1931 2088 1269135 82 Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 1044 8385898+ 8e Linux LVM

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 * 1 1044 8385898+ 8e Linux LVM

Disk /dev/sdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdd1 * 1 1044 8385898+ 8e Linux LVM

Disk /dev/sde: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sde1 * 1 1044 8385898+ 8e Linux LVM

The "fdisk -l" command will list out the connected hard disks and their partitions as shown above. The output columns can be explained as below.

• The Device column indicates the Linux partition names.

• The Boot column contains an asterisk that indicates the active partition.

• The Start and End columns give the starting and ending cylinder numbers of the partition.

The Blocks column gives the size of the partition in 1024-byte blocks.

• The Id and System columns specify the type of the partition. The id is the hexa code and the System is its description.

To launch the fdisk tool to manage a hard disk, run the fdisk command and specify as an argument the hard disk you want to partition.

For example, the command "fdisk /dev/sdb" will be executed as shown below.

[root@RHEL01 ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and 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)

Command (m for help):

Once fdisk has started, it presents an interactive prompt as shown above it’s prompt is ready to run fdisk commands.

Following are the important fdisk Commands

Command

Description

a

Toggles the active partition flag.

d

Deletes a partition.

l

Lists known partition types.

n

Adds a new partition.

o

Creates a new empty partition table.

p

Prints (displays) the partition table.

q

Quits without saving changes.

t

Sets the partition type.

u

Toggles display units from cylinders to sectors or the reverse.

v

Verifies the partition table.

w

Writes the partition table to disk and exits.


Mkfs

The Linux mkfs command can be used to format a Linux partition. The Linux "mkfs" command allows you to format a partition to a number of different filesystems. The Linux "mkfs" command also serves as a "front end," depending on the filesystem format. if you're formatting a standard ext3 filesystem, mkfs automatically calls the mkfs.ext3 command. The following commands show how create a partition using "fdisk" command and how to format the new partion using "mkfs" command.

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and 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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

The above set of fdisk commands create /dev/sdb1 partition. After creating the partition, we can overlay a filesystem (format) using mkfs command as shown below.

[root@localhost ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Other Linux tools to create filesystems

• mkfs.ext2 command can be used to format a partition with ext2 filesystem.


• mkfs.ext3 command can be used to format a partition with ext3 filesystem.


• mkfs.msdos (or mkfs.vfat or mkdosfs) formats a partition to the Microsoft-compatible VFAT filesystem (The inode numbers for all three files are the same; that means they are three different names for the same command).


• mkswap command can be used to format a partition with Linux swap filesystem.

Standard Linux Filesystem Formats

Filesystem Type

Description

ext

The first Linux filesystem used on early versions.

ext2

The most featureful of the native Linux filesystems, but with no journaling support.

ext3

The ext3 filesystem has all the features of the ext2 filesystem with journaling has been added.

swap

The Linux swap filesystem is associated with dedicated swap partitions.

reiserfs

A stable journaled filesystem.

Jfs

JFS is a journaled filesystem designed by IBM to to work in high performance environments

vfat

VFAT lets you read Windows 9x/NT/2000/XP/Vista partitions formatted to the FAT16 or FAT32 filesystems.

iso9660

The standard filesystem for CD-ROMs

ntfs

The Microsoft Windows NT/2000/XP/2003/2008 filesystem designed for username/password security.

/proc

A Linux virtual filesystem. Virtual means that it doesn't occupy real disk space. Instead, files are created as needed. Used to provide information on kernel configuration and device status.

/dev/pts

The Linux implementation of the Open Group's Unix98 PTY support.

nfs

The Network File System, the system most commonly used to share files and printers between Linux and Unix computers.

cifs

The Common Internet File System (CIFS) is used to to share files and printers with Microsoft Windows operating systems.


No comments:

Post a Comment