Listing all disks linux

How to list disks, partitions and filesystems in Linux? [duplicate]

In Windows, if you type LIST DISK using DiskPart in a command prompt it lists all physical storage devices, plus their size, format, etc. What is the equivalent of this in Linux?

3 Answers 3

There are many tools for that, for example fdisk -l or parted -l , but probably the most handy is lsblk (aka list block devices):

Example

$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 200M 0 part /boot/efi ├─sda2 8:2 0 500M 0 part /boot └─sda3 8:3 0 237.8G 0 part ├─fedora-root 253:0 0 50G 0 lvm / ├─fedora-swap 253:1 0 2G 0 lvm [SWAP] └─fedora-home 253:2 0 185.9G 0 lvm 

It has many additional options, for example to show filesystems, labels, etc. As always man lsblk is your friend.

@Dor it is worth explaining what additional options do, if you are recommending their use. -f or —fs shows the information about filesystems, such as format, crypto, raid member, etc. It is somewhat slower than the default though.

You’ll like this : you can do sudo lsblk —scsi and this shows the disk types including name(sda,sdb. ), scsi addr, type,vendor, model, rev, .. it’s easy to find which is which when you want to physically locate the disk.

Another way to quickly see the filesystems is the command df. On my machine (Finnish localization) it shows like this:

ptakala@athlon:/mnt$ df Tiedostojärjestelmä 1K-lohkot Käyt Vapaana Käy% Liitospiste /dev/root 38317204 19601752 16762352 54% / devtmpfs 4063816 0 4063816 0% /dev tmpfs 4097592 81988 4015604 3% /dev/shm tmpfs 4097592 10120 4087472 1% /run tmpfs 5120 8 5112 1% /run/lock tmpfs 4097592 0 4097592 0% /sys/fs/cgroup /dev/sda9 535267140 287403688 220666804 57% /work /dev/sda7 288239836 201635356 71956016 74% /home tmpfs 819520 4 819516 1% /run/user/113 tmpfs 819520 8 819512 1% /run/user/1000 /dev/sda1 39070048 37083304 1986744 95% /mnt/sda1 /dev/sda10 22662140 14032580 8629560 62% /mnt/sda10 /dev/sda5 29280176 20578032 8702144 71% /mnt/sda5 

It won’t show the file system type, but usually that is non-essential, and you see by one eyedrop everything needed.

ptakala@athlon:/mnt$ df -h Tiedostojärjestelmä Koko Käyt Vapaa Käy% Liitospiste /dev/root 37G 19G 16G 54% / devtmpfs 3,9G 0 3,9G 0% /dev tmpfs 4,0G 89M 3,9G 3% /dev/shm tmpfs 4,0G 9,9M 3,9G 1% /run tmpfs 5,0M 8,0K 5,0M 1% /run/lock tmpfs 4,0G 0 4,0G 0% /sys/fs/cgroup /dev/sda9 511G 275G 211G 57% /work /dev/sda7 275G 193G 69G 74% /home tmpfs 801M 4,0K 801M 1% /run/user/113 tmpfs 801M 8,0K 801M 1% /run/user/1000 /dev/sda1 38G 36G 1,9G 95% /mnt/sda1 /dev/sda10 22G 14G 8,3G 62% /mnt/sda10 /dev/sda5 28G 20G 8,3G 71% /mnt/sda5 

Источник

This post and this website contains affiliate links. See my disclosure about affiliate links.

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.

Читайте также:  Ssd for linux swap

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.

df

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.

Output of df command in Linux

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.

output of lsblk command in linux

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.

lshw

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.

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

Читайте также:  Linux yandex disk log

bash$ lshw -class disk -class storage -short

Output of lshw command

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.

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 отображает подключённые жёсткие диски иначе, чем Windows. В операционной системе от Microsoft мы привыкли к тому, что у нас есть диск C, D, E, и нам не нужно задумываться о реальных именах разделов и жёстких дисков. Все диски размещены в проводнике и очень просто доступны.

В Linux такой возможности нет, как и нет такой абстракции. Диски и разделы именуются как есть, и вы будете иметь дело именно с этими именами. В этой статье мы разберём, как посмотреть список дисков Linux.

Читайте также:  Hash all files linux

Как посмотреть список дисков в Linux

В Linux все отображается в файловом виде, в том числе и устройства. Все подключённые к операционной системе Linux устройства размещаются в каталоге /dev/ здесь вы найдете микрофоны, камеры, жёсткие диски, флешки, одним словом, все внешние и внутренние устройства.

Жёсткие диски имеют особенные названия. В зависимости от интерфейса, через который подключён жёсткий диск, название может начинаться на:

  • sd — устройство, подключённое по SCSI;
  • hd — устройство ATA;
  • vd — виртуальное устройство;
  • mmcblk — обозначаются флешки, подключённые через картридер;

В наше время большинство блочных устройств Linux подключаются через интерфейс SCSI. Сюда входят жёсткие диски, USB-флешки, даже ATA-диски теперь тоже подключаются к SCSI через специальный переходник. Поэтому в большинстве случаев вы будете иметь дело именно с дисками sd.

Третья буква в имени диска означает его порядковый номер в системе. Используется алфавитная система. Например sda — первый диск, sdb — второй диск, sdc — третий и так далее. Дальше следует цифра — это номер раздела на диске — sda1, sda2.

Самый простой способ увидеть все подключённые диски — это посмотреть содержимое каталога /dev/ и отфильтровать устройства sd:

Как видите, в моей системе сейчас есть только один диск и два раздела. Дальше мы можем посмотреть, куда примонтирован каждый из разделов:

Здесь, кроме дисков, будут отображаться различные специальные файловые системы: procfs, sysfs, tmpfs, cgroup и так далее. Однако все эти команды не помогут нам получить доступ к информации о дисках. Поэтому нам понадобится кое-что другое. Посмотреть подключённые диски с выводом информации о размере и свободном пространстве можно с помощью утилиты df:

Здесь отображается уже подробная информация. Но вы можете узнать ещё больше с помощью команды lsblk:

В этом случае список примонтированных дисков Linux включает ещё и информацию о точке монтирования, типе раздела (диск, раздел, привод) и его мажорном и минорном номере, по которым можно понять, что это за устройство. Если вам нужна информация о размере, то лучше использовать fdisk:

Это все утилиты, которыми вы можете воспользоваться, чтобы просмотреть список дисков Linux. Но есть ещё и графические утилиты.

Посмотреть список дисков в GUI

Во-первых, если к компьютеру подключено несколько дисков, то вы сможете их увидеть на левой панели файлового менеджера Nautilus или Dolphin. Там будет отображаться список подключенных устройств Linux, их метки и размер:

В Gnome есть программа Disks, которая позволяет настраивать поведение дисков, она же может отображать список подключенных устройств к системе. Вы можете найти её в главном меню:

Утилита отображает всю доступную информацию о дисках и разделах на них, вы можете даже посмотреть информацию о состоянии smart. Список дисков находится на панели слева, а справа разделы на этом диске:

Ещё одна утилита, которую вы можете использовать, чтобы посмотреть список жёстких дисков Linux — это Gparted. Это редактор разделов для Linux, но вы можете посмотреть подключнёные диски и структуру каждого из них. Раскрывающийся список вы найдёте в верхнем правом углу:

А в основной части окна программы отображается список разделов.

Выводы

В этой статье мы разобрали несколько способов посмотреть список примонтированных дисков Linux. Каждый из них может понадобиться в различных ситуациях. Если у вас остались вопросы, спрашивайте в комментариях!

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

Оцените статью
Adblock
detector