Linux and Open Source articles, topics and discussion with your questions answered by dmourati, a Linux expert with over eight years production experience.

Monday, December 10, 2007

Fun with Fdisk

When managing disks under Linux, one of the most powerful and lowest level tools you will need to use is called fdisk. Fdisk has been around for a long time and even has use in the Microsoft world. Today, however, we will deal with linux fdisk. The Linux fdisk is a used to manipulate the partition table of disks.


Partition Table


Hard disks can be divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the disk. Fdsik manpage.

Example Partition Table

This is the partition table for a production Linux database server. The server has two disks. First, let us examine the first disk, referred to in Linux parlance as /dev/sda.

To do so, run the fdisk command and pass the argument /dev/sda to tell fdisk to look at the first disk. At the prompt, hit "p" to print the table. Pressing "m" will show you all the options.

[root@lncproddb2 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 8844.
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): p

Disk /dev/sda: 72.7 GB, 72746008576 bytes
255 heads, 63 sectors/track, 8844 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 8844 70935007+ 8e Linux LVM


Above we see the partition table for /dev/sda on production host lncproddb2. The /dev/sda device or disk contains two partitions /dev/sda1, and /dev/sda2. The first partition, /dev/sda1 starts at the beginning of the disk, or cylinder 1 and goes to cylinder 13. It is of type 83, or Linux.

The second partition on /dev/sda is /dev/sda2. It begins on the following cylinder, number 14, and goes to the end of the disk. The /dev/sda2 partition is of type 8e known as Linux LVM which stands for Logical Volume Manager. The disk has a total of 8844 cylinders. We can also see above the this is a 72.7 GB SCSI disk.

Scanning the Bus

Some Linux machines will have more than one disk. In this case, it is helpful to scan the bus to see how many disks are there and what they are called. You can scan the bus with the fdisk -l command.

[root@lncproddb2 ~]# fdisk -l

Disk /dev/sda: 72.7 GB, 72746008576 bytes
255 heads, 63 sectors/track, 8844 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 8844 70935007+ 8e Linux LVM

Disk /dev/sdb: 218.9 GB, 218909114368 bytes
255 heads, 63 sectors/track, 26614 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System


Here we see the /dev/sda again as described above. There is a second hard disk, /dev/sdb that is available on this system as well.

No comments: