程式扎記: [Linux 文章收集] HowTo: Linux List Disk Partitions Command

標籤

2015年9月3日 星期四

[Linux 文章收集] HowTo: Linux List Disk Partitions Command

Source From Here
Question
How do I list all hard disk partitions under Linux operating systems? Usually, your hard disk drive divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the hard disk.

The device is usually /dev/sda/dev/sdb or so. A device name refers to the entire disk and the device name will be as follows:
- /dev/hd* - IDE disks. /dev/hda will be first IDE hard disk, /dev/hdb will be second IDE hard disk, and so on.
- /dev/sd* - SCSI or SATA disks. /dev/sda will be first SATA/SCSI hard disk, /dev/sdb will be second SATA/SCSI hard disk, and so on.

How-To

lsblk Command
To list all block devices, run:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 18G 0 part /
├─sda2 8:2 0 1K 0 part
├─sda3 8:3 0 20G 0 part /media/john/MyData
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 1024M 0 rom

List Partitions Under Linux
Switch to the root user by typing su - and entering the root password, when prompted. Or use sudo command:
# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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 identifier: 0x0007c003

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 37750783 18874368 83 Linux
/dev/sda2 37752830 41940991 2094081 5 Extended
...

The -l options shows the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used. You can specify device name as follows (in this example list partitions for /dev/sda).

sfdisk Command
The sfdisk command act as a partition table manipulator for Linux. You can use this tool to list partitions too:
// -s, --show-size: List the size of a partition.
// -l, --list: List the partitions of a device.
// -u, --unit letter: Interpret the input and show the output in the units specified by letter. This letter can be one of S, C, B or M, meaning
// Sectors, Cylinders, Blocks and Megabytes, respectively.

# sfdisk -l /dev/sda
Disk /dev/sda: 5221 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 2349- 2350- 18874368 83 Linux
/dev/sda2 2350+ 2610- 261- 2094081 5 Extended
...

Listing Linux a Partition Size Larger Than 2TB
The fdisk or sfdisk command will not list any partition size larger than 2TB. To solve this problem you need to use GNU parted command with GPT partitions. It supports Intel EFI/GPT partition tables. Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk. It is a part of theExtensible Firmware Interface (EFI) standard proposed by Intel as a replacement for the outdated PC BIOS, one of the few remaining relics of the original IBM PC. EFI uses GPT where BIOS uses a Master Boot Record (MBR). In this example list partitions on /dev/sdb using the parted command:
# parted /dev/sdb

Set unit type to TB or GB by typing 'unit TB' or 'unit GB' at the (parted) prompt:
(parted) unit GB // Or 'unit TB'
(parted) print
Model: ATA ST33000651AS (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 0.00GB 3001GB 3001GB ext4 primary

(parted) quit // To exit from parted session type 'quit' at the (parted) prompt

How Do I List All Partitions Layout On All Block Devices?
Pass the -l OR --list option to the parted command to lists partition layout on all block devices:
# parted -l

lssci command
Use the lsscsi command to show SCSI devices (or hosts) and their attributes:
# lsscsi
[0:0:0:0] disk ATA TOSHIBA MK5061GS MF00 /dev/sda
[1:0:0:0] cd/dvd MATSHITA BD-RE UJ232A 1.10 /dev/sr0
[2:0:0:0] disk ATA ST9500420ASG 0004 /dev/sdb
...


沒有留言:

張貼留言

網誌存檔