Linux list hdd devices

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

6 Different Ways to List Hard Drives in Linux

There are several ways to list all the hard drives present in a system through Linux command lines.

Keep in mind a hard drive could be physically connected, virtually connected or even emulated (for example: when you use storage devices such as EMC, Sun or IBM).

Here are some different commands which can list the hard drives, keep in mind there are others but these are probably the most commonly used and easy to get the job done.

Listing Hard Drives in Linux

Please note that some of these commands are actually disk partitioning tools and listing disk partition is one of their features.

Let’s see what commands you can use to show disk info in Linux.

The df command in Linux is probably one of the most commonly used. It lists the actual “disk space usage” and it can give you information about what hard disks (or current disk space) is being used in the entire system.

The most common way to use it is with the -h argument which means “human readable” (because we are not machines, right?):

As you can see, the first column is the current logic name (or the name you can find it within your system), the second column is how big is each of them, the third column is how much is currently used (in bytes), the fourth column is how much is currently available in each for usage (in bytes), the fifth column is how much is used (in %) and the sixth and last column is where is it physically mounted in your Linux system.

2. fdisk

fdisk is another common option among sysops. It currently lists the different partitions (which is related to hard drives as a hard drive can be divided into several partitions) in your system.

This will return the entire amount of space (in GB or MB), the entire amount of bytes and the entire amount of sectors per each partition and as a summary, it also gives you the start and end sectors, the amount of disk space (in Bytes) and the type of partition.

Tip: Usually a SATA disk is labelled with sd.

3. lsblk

This one is a little more sophisticated but gets the job done as it lists all block devices. It will give you a very simple list of all devices:

It is probably more visual than the others as it even shows the partitions per each disk in a visual way (like the sda in the example above). It also gives information about the total size per each partition and disk and the physical location for each. This is very commonly used when you need to mount things to be used (like a USB stick or similar) so you can know where is it in order to proceed to mount it.

4. cfdisk

cfdisk is probably the most advanced one in GUI (Graphical User Interface), as it is absolutely visual and interactive. It allows at first to list all disks/partitions in your system but it also allows you to manage them by selecting them and then applying actions such as “Delete”, “Resize”, “Type” (to change partition Type) and “Write” changes done to partitions.

cfdisk example

It also gives you very friendly information about each partition and disk as it gives you where does each partition cylinders start and ends, amount of sectors used by each one and the full size of each one with its type. It won’t give you for example how much is used or free to use.

5. parted

This one is similar to previous ones mentioned, it lists all partitions and allows to manage them. Its main difference is that it also informs you the brand and model of your hard disks and even the type of connectivity used in it (scsi, sata, etc) and total disk size.

6. sfdisk

This is very similar to fdisk, however sfdisk allows you to see both physical and logical volumes and also gives you a “summary” of the actual physical volumes’ partitions with the cylinders (start and end), sectors, size and type.

Probably the “s” is for “super”, as it is a fdisk with super powers:

These commands should allow you to at least see what logical volumes, partitions and hard drives you have in your system and make use of this information for whatever reason you need it, being this just to know more or manipulate any of these.

Most of these commands also give you managing capabilities to modify and manipulate partitions at your will, so make sure to use them with responsibility.

If you like checking system information, do read the article about getting processor information in Linux command line.

If you have any questions or suggestions, do let me know in the comment section.

Источник

How To – Linux List Disk Partitions Command

WARNING ! These examples may crash your computer if NOT executed with proper care. BE EXTREMELY CAREFUL WITH THE FOLLOWING COMMANDS. ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST.

lsblk Command to list block device on Linux

Listing disks and partitions on Linux using lsblk

Understanding lsblk option that displays block devices and partitions

  • -m : Show info about Linux permissions
  • -f : List info about Linux filesystems
  • -l : Force list format output option
  • -d : Avoid printing holders. In other words just see block device/disk names
  • -o NAME,FSTYPE,SIZE,MOUNTPOINT : Only display selected columns as per Table 1.
Table 1
Column Descripton
NAME device name
KNAME internal kernel device name
PATH path to the device node
MAJ:MIN major:minor device number
FSAVAIL filesystem size available
FSSIZE filesystem size
FSTYPE filesystem type
FSUSED filesystem size used
FSUSE% filesystem use percentage
MOUNTPOINT where the device is mounted
LABEL filesystem LABEL
UUID filesystem UUID
PTUUID partition table identifier (usually UUID)
PTTYPE partition table type
PARTTYPE partition type UUID
PARTLABEL partition LABEL
PARTUUID partition UUID
PARTFLAGS partition flags
RA read-ahead of the device
RO read-only device
RM removable device
HOTPLUG removable or hotplug device (usb, pcmcia, …)
MODEL device identifier
SERIAL disk serial number
SIZE size of the device
STATE state of the device
OWNER user name
GROUP group name
MODE device node permissions
ALIGNMENT alignment offset
MIN-IO minimum I/O size
OPT-IO optimal I/O size
PHY-SEC physical sector size
LOG-SEC logical sector size
ROTA rotational device
SCHED I/O scheduler name
RQ-SIZE request queue size
TYPE device type
DISC-ALN discard alignment offset
DISC-GRAN discard granularity
DISC-MAX discard max bytes
DISC-ZERO discard zeroes data
WSAME write same max bytes
WWN unique storage identifier
RAND adds randomness
PKNAME internal parent kernel device name
HCTL Host:Channel:Target:Lun for SCSI
TRAN device transport type
SUBSYSTEMS de-duplicated chain of subsystems
REV device revision
VENDOR device vendor
ZONED zone model

How to locate/print block device attributes using blkid

Apart from physical block storage and logical partitions, your Linux box may have software RAID and encrypted hard disks too. We can determine the type of filesystem that a block device holds and also the attributes:
# blkid
The ugly output provided as follows; hence it is recommended to use lsblk:

List partitions ynder Linux using the fdisk command

Open a terminal window (select Applications > Accessories > Terminal). Switch to the root user by typing the su — and entering the root password, when prompted by the su command. Or use the sudo command:
$ su —
# fdisk -l
OR
$ sudo fdisk -l
Here is what I see from my Linux desktop:

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):
# fdisk -l

Display disk partitions using sfdisk command in Linux

The sfdisk command act as a partition table manipulator for Linux. You can use this tool to list partitions too:
# sfdisk -l /dev/sda
# sfdisk -lu /dev/sda
# sfdisk -ls /dev/sda
Linux partitions info:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

  1. -l : List the partitions of a device.
  2. -s : List the size of a partition.
  3. -u or -uS or -uB or -uC or -uM : Accept or report in units of sectors (blocks, cylinders, megabytes, respecpively). The default is cylinders, at least when the geometry is known.

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 the Extensible 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
GNU/Linux parted prompt:

Set unit type to TB or GB by typing ‘unit TB‘ or ‘unit GB‘ at the (parted) prompt:
(parted) unit TB
OR
(parted) unit GB
To list partitions type print command at the (parted) prompt:
(parted) print
Detailed information:

To exit from parted session type ‘quit’ at the (parted) prompt:
(parted) quit

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
Sample outputs:

Fig.01: Show Linux Disk Partitions With GNU parted Command

lssci command to list SCSI devices (or hosts) and their attributes

Use the lsscsi command to show SCSI devices (or hosts) and their attributes:
# lsscsi
Sample outputs:

Here is another outputs:

A note about GUI tools

Linux desktop comes with “Disks & storage” utility to show disk information and perform everyday tasks. Open Disks from the Activities overview under Gnome.

A dialog will open where we can see disks. For instance, I have two 1 TB Samsung NVMe SSD installed in my system. Make sure you choose the disk to see partition information. See the gnome help section for other options.

Using hardware detction tools to print disk paritions on Linux

You can install and use the following tools. I don’t use and promote third party tools on Linux servers as inbuilt tools provide all information. But, I added them here as they might be useful to someone. We can use the hwinfo command to probe for hardware as follows:
hwinfo | more
hwinfo —block | more
hwinfo —block —short
inxi -P
inxi -p | more

See the following pages:

Conclusion

You just learned how to list disk partitions using various Linux commands. For for info see “ls* Commands Are Even More Useful Than You May Have Thought” blog post and man pages by typing the following man command:
man fdisk
man lsblk
man sfdisk
man parted

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Disk /dev/sda: 145.4 GB, 145492017152 bytes
255 heads, 63 sectors/track, 17688 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 5 40131 de Dell Utility
/dev/sda2 6 1458 11671222+ 83 Linux
/dev/sda3 * 1459 1471 104422+ 83 Linux
/dev/sda4 1472 17688 130263052+ 5 Extended
/dev/sda5 1472 17688 130263021 8e Linux LVM

Model: ST380215A (ide)
Disk /dev/hda: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 16.8GB 16.8GB primary ext3 boot
2 16.8GB 32.5GB 15.7GB primary ext3
3 32.5GB 48.2GB 15.7GB primary ext3
4 48.2GB 80.0GB 31.8GB extended
5 48.2GB 60.8GB 12.6GB logical ext3
6 60.8GB 66.1GB 5239MB logical ext3
7 66.1GB 71.3GB 5239MB logical linux-swap

# fdisk -l
cannot open /proc/partitions

You’re probably missing sudo at the beginning of line 😉

it helps me a lot, thank you . . .

Very informative and nicely written, thanks.

I tried parted -l in debian operating system and it is not working as it is not available in the help command option. Please advise. is there any other command that shows all the partitions and the type of the partition on the operating system.

I am unsure but when I did the sfdisk I got this

sfdisk -lu /dev/sda
unrecognized format – using sectors

Disk /dev/sda: 121601 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System
/dev/sda1 * 4096 81922047 81917952 83 Linux
/dev/sda2 81922247 1715951615 1634029369 83 Linux
start: (c,h,s) expected (1023,254,63) found (1003,108,9)
end: (c,h,s) expected (1023,254,63) found (317,12,15)
/dev/sda3 1715951616 1748717551 32765936 82 Linux swap / Solaris
/dev/sda4 1748717568 1953515519 204797952 83 Linux

Can anyone tell me how to fix the /dev/sda2 ?

How many years have linux installations been plagued by the infamous “No Root File System is Defined” message, whenever a pc user attempts to install Linux or Ubuntu on a hard-drive alongside their Windows installation?!

This has been going on way too long, for the makers of Linux and Ubuntu to not find a simpler way to facilitate this issue. We all know what the problem is yet, for those of us whom wish to use Linux on the same drive as their Windows OS, literally seem to have no choice but to format the entire drive in order to install Linux, because of some stupid glitch that prevents it recognizing the appropriate partition parameters.

Of all my experiences with Linux, none of them have ever been with a hard-drive installation but instead only using the LiveCD versions—because I will not remove Windows, just so that I can install Linux on the one Hard drive I have—which is why I want to install Linux alongside Windows.

The nagging but persistent problem is always the same, “No Root File System is Defined.”

Even after I extended the system partition and changed the partition id of said system partition (which had over 100GB of unused space), to [ “Linux Native” ] from the drop-down menu of the partition program I was using, it still displayed the same error message above. I tried it with the [ Primary ] option in the Linux installation module, as well as an attempt with the [ Logical ] option——-both of these made no difference and yes, before any nit-picking techies get on my case about it——-I tried the above scenarios with following options:

[ Use As: (Ext 4) and Mount Point: ( / ) ]

[ Use As: (EFI Boot Partition) ]

This is what I got after I listed the partition info from the terminal:

WARNING: GPT (GUID Partition Table) detected on ‘/dev/sda’! The util fdisk doesn’t support GPT. Use GNU Parted.

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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: 0x02ebc2e4

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 206847 102400 7 HPFS/NTFS/exFAT
/dev/sda2 206848 505081855 252437504 7 HPFS/NTFS/exFAT
/dev/sda3 505083904 625139711 60027904 83 Linux

When I visited the Ubuntu and Linux support pages which depict a working installation, what displays is a screen-shot of the Linux installation module, at the screen that actually gives the user a choice if they would like to install it with Windows. I was never given that option when I attempted to install Linux Mint 17 or Ubuntu 14.04.1. Both ISO’s provided me with the exact same setup scenario upon installation——-Either I could erase my only hard-drive (which includes my Win7 I want to keep) or (I could attempt to install manually using the partition options). That’s it!

No option to install with Windows like it showed on the website.

This is so disconcerting to me that after hours of attempting to install a Linux or Ubuntu platform, neither installation module will recognize the appropriate partition configurations to make a dual-boot (without removing Windows) work.

Microsoft may definitely be number one at the top of my list of the most frustrating companies in the world, but after enduring this rigmarole to simply install the OS, Linux is definitely not far behind Microsoft when it comes to such improprieties.

Heck, even Microsoft’s installation of Windows is far simpler than this.

Linux may have intrigued me time and again, but the more I’ve delved into it’s world, all the more frustrated I became. Really——-how different from Microsoft is Linux, when it’s developers couldn’t even fully automate something as simple as a detect and auto-configuration feature to as to facilitate any type of installation a user might want?!

After all these years——-and Linux still can’t fix this problem with partition allocation and configuration, except to again dump all this nonsense on the user to try to sort out?!

It doesn’t matter if it’s free. It’s still marketed as and geared toward users whom want an alternative and even better experience than Windows (even if they still want to keep their Windows installation). Yet the current options available easily put average users in an enormous debacle just to get started with this so-called great Software.

If its that great——–then why make it extremely difficult to setup?! Us average users in the Windows community already have enough Microsoft headaches to deal with all on their own. You promote a cleaner experience on a faster OS that’s easy to use but fall short of making it a complete package by putting together a very sloppy, at best, installation module, which undoubtedly leaves much to be desired——-to say the least.

Please fix this problem with the boot-loader/partition/allocation/Root File System Definitions issue. This is an unnecessary road-block which is probably turning away a lot of users whom might otherwise benefit from using this software and whom might actually like it and want to contribute——-but heck!——-if it’s this much trouble just to try to get it installed onto the same drive as my primary OS——-then maybe that’s just one of the reasons why Windows will likely always be my “Primary” choice!

Why not just run your Linux distribution of choice in a VM so that you can tinker around in Linux and still be able to use your windows machine at the same time? I found this to be much easier for me as I get more familiar with linux

I have never had this issue you describe. I have successfuly installed Ubuntu easily for years alongside Windows, and also Mac OSX.
But I have also installed operating systems before. I have installed DOS, Windows, and (of course) various Linux distros so it may be easier for me to do.

Installing Ubuntu is much easier and quicker than installing Windows (if you have ever done it) and can detect other OS, unlike Windows, though Mac OSX can detect Windows (usually).

Installing an OS in a virtual machine would probably suit you better. It is easy to do and will not screw anything up if you make a mistake. If you have a decent processor with vt handling it will run very well. You can also install Ubuntu onto a USB disk, and boot it from your BIOS (if your computer is able to do this).
If you have you Windows install disks, you can also try installing both in a VM, so you can learn how to do it confidently.

Is there any issues to install Redhat Linux 6 in IDE based hard drive machine… When I try to install it on my laptop, its not booting.. Pls help to solve this issue

I have doubt in partition. First, I install the os that time itself i partition the hard disk then why we using fdisk command

sir, there is four partition in my linux os
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
2 1049kB 109GB 109GB ext4 partition 2
5 109GB 539GB 430GB ntfs Basic data partition msftdata
6 539GB 749GB 210GB ext4 Basic data partition msftdata
1 749GB 1000GB 252GB ext4 partition 1
but in in the file system i am able to see the
1 749GB 1000GB 252GB ext4 partition 1
5 109GB 539GB 430GB ntfs Basic data partition msftdata
and sda 6 and sda2 is unable to see
how to mount it in file system

Источник

Читайте также:  Не могу обновить windows код 80072efe
Оцените статью