viewing disk partitions
The fdisk utility is a common partition table manipulator for Linux. Use fdisk –l to list the partition table. Output varies depending on the number of attached disks and partitions. To display the partition for a specific device, include the device name as an argument. For example:
# fdisk -l /dev/sda Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000dddc2 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM
Without specifying a device as an argument, partitions in /proc/partitions are listed. The first five lines of output from the fdisk –l /dev/sda command are summary information about the device itself, /dev/sda. The example output shows a 21.5 GB virtual disk (sda) with 41943040 sectors.
The partition table is displayed after the summary information. Seven columns of information are listed in the partition table. The Device column shows two partitions: /dev/sda1 and /dev/sda2.
Boot : The Boot column shows that the first partition, /dev/sda1, has an asterisk (*) indicating that this partition contains the files required by the boot loader to boot the system.
Start and End : The start and end columns list the starting and ending sectors of each partition.
Blocks : The blocks column lists the number of blocks allocated to the partition.
Id and System : These columns identify the partition type.
Partition Naming
The Linux partition naming scheme is in the /dev/xxyN form. Elements of this naming scheme are described as follows:
/dev/ : This is the directory in which all device files reside.
xx (or xxx) : The first two of three letters indicate the type of device on which the partition resides. These letters are usually hd (for IDE disks), sd (for SCSI disks), or xvd (for virtual disks).
y : This letter indicates which device the partition is on—for example, /dev/sda (the first SCSI hard disk) or /dev/xvdb (the second virtual disk).
N : This number indicates the partition. For example, /dev/sda1 is the first partition on the first SCSI device and /dev/xvda3 is the third partition on the first virtual disk.
Partition Types
The partition types can be displayed and changed by using the fdisk utility. A partial list (most commonly used) of partition types are:
83: Linux
82: Linux swap
5: Extended
8e: Linux LVM
To view a list of all available partitions use the fdisk subcommand l.
Using the fdisk Utility
The fdisk utility also provides an interactive interface for manipulating the partition table of a disk device.
# fdisk [device_name] Command (m for help):
Basic fdisk commands include:
– d: Delete a partition.
– l: List the known partition types.
– m: Print the available commands.
– n: Add a new partition.
– p: Print the partition table.
– w: Write the table to disk and exit fdisk.
To view, all the available fdisk commands use the m subcommand:
Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table 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)
partprobe Command
This command informs the kernel of partition table changes. Run this command with the device name as an argument to require the operating system to re-read the partition table:
# partprobe /dev/xvdb