how to list all hard disks in linux from command line
Hard Disk, Hard Drive, Disk Drive or Hard Disk Drive are all names for a data storage device (hardware device) for storing and retrieving digital information usually in a computer. A computer can have multiple hard disks attached to it, both internal and external.
Now these hard disks can be further divided to multiple logical containers in order to host different file systems or to keep file systems/files separate. These are called partitions and they can then mounted independently with out affecting the other disks and partitions. At a high level abstraction, you can view partition as separate disks as well.
Hard disks on a system are detected and/or identified by various device drivers in the kernel and then assigned an unique device id at boot time, enabling it to be mounted and read later (yeah, this is an over simplification of how it all works but it should suffice for this post). We will see later in the post how you can list disks that have been identified by the system.
The hard disks can be differentiated based on the interface used to interact with them. Some of the commonly used types of disk are SCSI (Small Computer System Interface), ATA or IDE (Advanced Technology Attachment), SATA (Serial ATA), SAS (Serial Attached SCSI) among others. As I mentioned, the physical hard disk is assigned an unique id at startup. This can configured (using udev among others) so that you can assign it pretty much id, but usually most systems follow some universally accepted conventions when naming devices.
By convention, the IDE disks use the device id prefixed with hd and the SCSI (and SATA) disks prefix their device id with sd. So, an IDE disk would be located at /dev/hd(*). eg: /dev/hda, /dev/hdb etc. Similarly, the SCSI disks would be /dev/sda, /dev/sdb etc or in general of the format /dev/sd(*).
There are several different commands that you can use in a Linux environment to list disks that have been mounted on the system.
The df command is primarily intended to report file system disk space usage. It is still a good utility to print out the disks that are available to the system, although it prints filesystems rather than disks per se.
You can use the -h or –human-readable option with df to print out the disk usage in a human readable format. Look for file systems that identify as /dev/sda, /dev/sdb or /dev/hda to identify the disks.
lsblk
The lsblk command is to list block devices. It reads the data from udev database along with sysfs file system to print a report on all available or specified block devices. Block devices abstracts the actual hardware characteristics of any physical device and allows you to interact with it using a buffered interface.
The lsblk command with out any argument will print out the block devices in a tree format. Again look for names, such as sda, sdb etc. The top level denotes the disk and the first level children represent the partitions with in the block.
The are several useful command line options that can be used with lsblk command. The -d or –nodeps will print out the device and not the partitions. The -S or –scsi will output only the SCSI devices.
Another commonly used utility is lshw, which can print out detailed information about your hardware. Again it might not be default in some distros even though it is a system application.
bash$ lshw -class disk
The above command will list all disks on the system. You can also specify the storage class if you want to print out the storage controllers as well. You can further reduce the verbosity of the output by using the -short option
bash$ lshw -class disk -class storage -short
blkid
The previously mentioned lsblk command is a better and recommended option that the blkid command. I include it here just for the sake of completeness.
blkid will print out several different attributes about the block devices. You can usually make out the disks and partitions from the output just as with lsblk.
fdisk
fdisk is a popular command mostly used to manipulate the partition table. You can use it to list all partitions from the partition table and find the devices that are available. The –list or -l command line option will print out all the known partitions from all devices.
You are probably looking for something like this in the output.
Disk /dev/sda: 149.1 GiB, 160041885696 bytes, 312581808 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
Disklabel type: dos
Disk identifier: 0xa461a461
Disk /dev/sdb: 111.8 GiB, 120034123776 bytes, 234441648 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
Disklabel type: dos
Disk identifier: 0x00000000
There are couple of other partition table manipulation tools built on top of fdisk, with more options and features. sfdisk and cfdisk are two such examples. They might not however be installed in most distros.
parted
Along the lines of fdisk, parted is another partition table manipulation utility. Again you can use the –list or -l command line option to print out the devices or disks and all its info. I like the default output of parted better than fdisk, but then that is subjective.
Model: ATA ST3160815AS (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
/proc/ file
Another rudimentary way is to print out the contents of the /proc/partitions/ folder. This will print out all known devices and partitions in the system. By this time you should be able to differentiate between the disk and partitions, i assume.
bash$ cat /proc/partitions
Look for minor ‘0’ or name that conforms to the /dev/sda format.
lsscsi
If you know that you have only SCSI devices or only need the information about SCSI disks, then you can use the lsscsi command. This utility might not be installed on some distros by default.
As the command name suggests, it prints out all information about the SCSI devices on the system.
No matter what distribution you are on, you should be able to list disks on your system using at least one of the commands listed above.
Источник
Как посмотреть диски в Linux
Системные администраторы ОС Linux обычно просматривают диски, чтобы проверить все дисковое пространство и его использование. Список дисков также помогает увидеть подключенные диски к системе, разделы и файловую систему, используемую дисками.
В системе Linux существует несколько способов посмотреть все жесткие диски. Из этой статьи вы узнаете, как посмотреть диски в Linux с помощью командной строки.
1. lsblk
lsblk (list block devices) используется для просмотра информации обо всех доступных блочных устройствах, таких как жесткий диск и флэш-накопители.
Просто набрав команду lsblk, вы получите список всех блочных устройств в виде древовидного формата. Это удобный и простой способ посмотреть диски.
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 529M 0 part
├─sda2 8:2 0 100M 0 part /boot/efi
├─sda3 8:3 0 16M 0 part
├─sda4 8:4 0 165.8G 0 part
├─sda5 8:5 0 70G 0 part /
└─sda6 8:6 0 2G 0 part [SWAP]
zram0 252:0 0 8G 0 disk [SWAP]
2. df -h
Команда df используется для просмотра объема доступного дискового пространства. Так же команда df отобразит имя устройства, общее количество блоков, используемое дисковое пространство, доступное дисковое пространство, процент используемого пространства, точку монтирования файловой системы, а также покажет удаленно смонтированные файловые системы, такие как NFS.
Команда df -h покажет доступное пространство всех дисков в удобочитаемом виде.
Ответ в терминале:
Filesystem Size Used Avail Use% Mounted on
devtmpfs 5.8G 0 5.8G 0% /dev
tmpfs 5.8G 90M 5.7G 2% /dev/shm
tmpfs 2.4G 11M 2.4G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/sda5 69G 62G 3.1G 96% /
tmpfs 5.8G 4.7M 5.8G 1% /tmp
/dev/sda2 96M 41M 56M 43% /boot/efi
tmpfs 1.2G 200K 1.2G 1% /run/user/1000
3. fdisk -l
Команда fdisk — это текстовая утилита, используемая для управления разделами диска. С помощью fdisk вы можете отобразить разделы диска, создать новый раздел, удалить существующий раздел жесткого диска и просмотреть размер раздела.
Для этого используется команда fdisk -l отобразит все доступные разделы диска
Ответ в терминале:
Disk /dev/sda: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model: SK hynix SC300B
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4
Device Start End Sectors Size Type
/dev/sda1 2048 1085439 1083392 529M Windows recovery environment
/dev/sda2 1085440 1290239 204800 100M EFI System
/dev/sda3 1290240 1323007 32768 16M Microsoft reserved
/dev/sda4 1323008 349122559 347799552 165.8G Microsoft basic data
/dev/sda5 349122560 495923199 146800640 70G Linux filesystem
/dev/sda6 495923200 500117503 4194304 2G Linux swap
Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/loop0: 207.15 MiB, 217214976 bytes, 424248 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 /dev/loop1: 99.18 MiB, 103993344 bytes, 203112 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
4. parted -l
Parted — это полезный и мощный инструмент используемый для управления разделами жесткого диска из терминала (командной строки). Обладает способностями такими как список, создание, сжатие, удаление, поиск и восстановление разделов диска. С помощью команды parted вы можете легко управлять всеми разделами жесткого диска.
команда parted-l покажет расположение разделов дисков.
Ответ в терминале:
Model: ATA SK hynix SC300B (scsi)
Disk /dev/sda: 256GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 556MB 555MB ntfs Basic data partition hidden, diag
2 556MB 661MB 105MB fat32 EFI System Partition boot, esp
3 661MB 677MB 16.8MB Microsoft reserved partition msftres
4 677MB 179GB 178GB ntfs Basic data partition msftdata
5 179GB 254GB 75.2GB ext4
6 254GB 256GB 2147MB linux-swap(v1) swap
Model: Unknown (unknown)
Disk /dev/zram0: 8590MB
Sector size (logical/physical): 4096B/4096B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 8590MB 8590MB linux-swap(v1)
5. cfdisk
Cfdisk немного отличается от вышеприведенных команд, эта команда обеспечивает графическое представление в терминальном интерфейсе. С помощью cfdisk вы можете просматривать, создавать, удалять и изменять разделы.
Disk: /dev/sda Size: 238.47 GiB, 256060514304 bytes, 500118192 sectors Label: gpt, identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4 Device Start End Sectors Size Type
/dev/sda1 2048 1085439 1083392 529M Windows recovery environment
/dev/sda2 1085440 1290239 204800 100M EFI System
/dev/sda3 1290240 1323007 32768 16M Microsoft reserved
/dev/sda4 1323008 349122559 347799552 165.8G Microsoft basic data
/dev/sda5 349122560 495923199 146800640 70G Linux filesystem
/dev/sda6 495923200 500117503 4194304 2G Linux swap
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Partition name: Basic data partition │
│ Partition UUID: E73F9719-F144-42A8-87BC-862FB470828B │
│ Partition type: Windows recovery environment (DE94BBA4-06D1-4D40-A16A-BFD50179D6AC) │
│ Attributes: RequiredPartition │
│ Filesystem UUID: 8C0A62C30A62A9C2 │
│Filesystem LABEL: Recovery │
│ Filesystem: ntfs │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
[ Delete ] [ Resize ] [ Quit ] [ Type ] [ Help ] [ Write ] [ Dump ]
Команда для просмотра дисков в Linux cfdisk
6. sfdisk -l
sfdisk — это редактор таблиц разделов. Он может показать разделы, показать размер раздела, проверить разделы на устройстве и подготовить устройство.
Команда sfdisk -l покажет разделы каждого диска.
Ответ в терминале:
Disk /dev/sda: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model: SK hynix SC300B
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4
Device Start End Sectors Size Type
/dev/sda1 2048 1085439 1083392 529M Windows recovery environment
/dev/sda2 1085440 1290239 204800 100M EFI System
/dev/sda3 1290240 1323007 32768 16M Microsoft reserved
/dev/sda4 1323008 349122559 347799552 165.8G Microsoft basic data
/dev/sda5 349122560 495923199 146800640 70G Linux filesystem
/dev/sda6 495923200 500117503 4194304 2G Linux swap
Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/loop0: 207.15 MiB, 217214976 bytes, 424248 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 /dev/loop1: 99.18 MiB, 103993344 bytes, 203112 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
7. ls -l /dev/disk/by-id
команда ls — это очень простая, но мощная команда, используемая для отображения файлов и каталогов. Мы можем посмотреть диски, посмотреть каталог /dev/disk/by-id.
$ ls -l /dev/disk/by-id
Ответ в терминале:
total 0
lrwxrwxrwx 1 root root 9 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9 -> ../../sda
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part6 -> ../../sda6
lrwxrwxrwx 1 root root 9 Jun 20 23:26 wwn-0x5ace42e0900dd482 -> ../../sda
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part6 -> ../../sda6
Вы также можете посмотреть:
8. lshw -class disk
lshw — это инструмент Linux, который используется для получения подробной информации об аппаратной конфигурации системы.
Используйте -class disk для просмотра информации о диске.
Ответ в терминале:
*-disk
description: ATA Disk
product: SK hynix SC300B
physical id: 0.0.0
bus info: scsi@1:0.0.0
logical name: /dev/sda
version: 0P00
serial: FI68N023911308NC9
size: 238GiB (256GB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: ansiversion=5 guid=ff57c955-d98a-49c4-b1ed-835a44f2a0a4 logicalsectorsize=512 sectorsize=4096
Кроме того, можно вывести class disk as-json или -html или-xml.
Ответ в терминале:
<
«id» : «disk»,
«class» : «disk»,
«claimed» : true,
«handle» : «GUID:ff57c955-d98a-49c4-b1ed-835a44f2a0a4»,
«description» : «ATA Disk»,
«product» : «SK hynix SC300B»,
«physid» : «0.0.0»,
«businfo» : «scsi@1:0.0.0»,
«logicalname» : «/dev/sda»,
«dev» : «8:0»,
«version» : «0P00»,
«serial» : «FI68N023911308NC9»,
«units» : «bytes»,
«size» : 256060514304,
«configuration» : <
«ansiversion» : «5»,
«guid» : «ff57c955-d98a-49c4-b1ed-835a44f2a0a4»,
«logicalsectorsize» : «512»,
«sectorsize» : «4096»
>,
«capabilities» : <
«gpt-1.00» : «GUID Partition Table version 1.00»,
«partitioned» : «Partitioned disk»,
«partitioned:gpt» : «GUID partition table»
>,
«children» : [
]
>
Заключение
Для всех команд, кроме lsblk и ls-l dev/disk, требуется root — доступ или разрешения суперпользователя для его запуска.
В этой статье мы узнали, как посмотреть диски в Linux с помощью командной строки.
Источник