Get all drives linux

Cross platform way to list disk drives on Linux, Windows and Mac using Python?

I am using Python2.6. I am trying to list the disk drives that a system may have.

On Windows, it may be something like C:/ , D:/ , E:/ , etc. On Linux, it may be something like /boot , /media/SDCard , etc. And I don’t know what it’s like on a Mac. Maybe something under /Volumes.

Does anyone know of a cross platform way (that is, one which works on Linux, Windows and Mac) in Python?

4 Answers 4

The psutil package (https://pypi.python.org/pypi/psutil) has a disk_partitions function.

There isn’t really a unified naming scheme for Linux devices that guarantees you a formatable block device. There are conventions, but they can vary widely and I can call my thumb-drive /Thomas/O if I want and there is no cross-platform way in Python to know:

  1. That /Thomas/O corresponds to /dev/sdf1
  2. That /dev/sdf1 can have a FAT32 filesystem made on it
  3. That /dev/sdf is not preferred to /dev/sdf1

I’m pretty sure that neither is there a cross-platform Python module which will allow you to determine that H:/ is formattable on a Windows system but that Z:/ is not.

Each system will require its own specific checks and validations which you could best learn from studying open-source disk manipulation software.

Источник

How To Find Hard Disk Drive Details In Linux

This guide lists various methods to find Hard disk drive details in Linux operating systems. Using the below methods, you can able to find the hard disk make, hard disk type, size, firmware version, partition tables and other hardware parameters. First, we will see how to display hard disk details with hdparm command line utility.

1. Hdparm

Hdparm is a command line program to get or set hardware parameters for PATA, SATA, SAS and SSD devices.

It accepts any device as mass storage that is connected to IDE, SATA, SAS interfaces, so we can even retrieve information about CD/DVD drives as well.

Using hdparm utility, we can tune the hard disk or DVD drive, test the HDD or SSD speed, reduce noise level by activating acoustic mode, turn energy-saving mode on or off, enable or disable sleep mode, enable/disable drive cache and even erase drives securely.

Hdparm is written by Mark Lord, the lead developer and maintainer of the (E)IDE driver for Linux, and current contributor to the «libata» subsystem.

A word of caution

Even though hdparm offers significant advantages to increase disk performance, it is also EXTREMELY DANGEROUS . It will very likely lead to massive data loss when some parameters are misused. The hdparm documentation suggests that YOU SHOULD NOT USE SOME COMMANDS AT ANY CIRCUMSTANCES . So I’ve excluded such dangerous commands in this guide. More importantly, It is always recommended to backup your hard drive before testing hdparm on your Linux system.

1.1. Install hdparm on Linux

Hdparm comes pre-installed in most Linux distributions. If it is not included for any reason, install hdparm on your Linux system using the default package manager.

Читайте также:  Сборка ядра linux pdf

On Arch Linux, Manjaro Linux:

On Debian, Ubuntu, Linux Mint:

On Fedora, CentOS, RHEL:

1.2. Find Hard Disk Drive details in Linux using Hdparm

To display detailed information of the hard disk, simply run hdparm with sudo or root privileges as shown below:

Here, sda is my hard disk. Replace it with your own device. Here I have used «less» command for interactive reading. Press ENTER key or hit UP/DOWN arrows to go through the rest of the output. Press q to exit when done.

Sample output from my Ubuntu system:

As you can see, the hdparm displays the hard disk’s model number, serial number, firmware revision followed by hard disk configuration (no of cylinders, heads, sectors), DMA settings, list of enabled features, security parameters etc. All functions found under «Commands/features» section and marked with an asterisk are currently active.

Similarly, you can check information of other devices.

When running hdparm with no options, -acdgkmur is assumed. Refer man pages to know what each option is for.

For more details, refer man pages.

2. lshw

Lshw (Hardware Lister) is a simple, yet full-featured utility that provides detailed information on the hardware configuration of a Linux system. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, Hard disk drive details, cache configuration, bus speed and a lot more.

2.1. Install lshw in Linux

lshw comes pre-installed with some Linux distributions like Ubuntu by default. If it is not installed by any chance, install lshw in your Linux box using the default package manager like below.

On Arch Linux and its variants like Manjaro Linux, run:

On Debian, Ubuntu, Linux Mint:

On Fedora, CentOS, RHEL:

2.2. Find Hard Disk Drive Details In Linux Using lshw

After installing lshw, simply run the following command to get the details of your hard disk drive in Linux:

Sample output:

To display only the name of the disks, run:

Sample output:

For more details, check man pages.

3. inxi

Inxi is yet another full-featured command line system information tool. It shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information. Be it a hard disk or CPU, mother board or the complete detail of the entire system, inxi will get them for you more accurately in seconds.

3.1. Install inxi in Linux

Inxi is also available in the default repositories of most Linux distributions.

For Arch Linux, it is available in AUR. You can install it using any AUR helper programs, for example Yay.

On Debian, Uubntu:

On CentOS and RHEL:

Enable [EPEL] repository using the following command:

3.2. Find Hard Disk Drive Details In Linux Using Inxi

To get the details of the installed hard disk drives in your Linux system, run:

Sample output:

You can also display more disk details like disk controller speed, serial no and temperature using the following command:

Sample output:

Unlike Hdparm and lshw programs, it will only display the hard disk drive details. The hdparm and lshw utilities will display all drive details including CD/DVD ROM.

For more details, refer man pages.

Suggested read:

4. Smartctl

Smartclt is a command line, control and monitor utility for SMART disks. It controls the Self-Monitoring, Analysis and Reporting Technology (shortly SMART) system built into most ATA/SATA and SCSI/SAS hard drives and solid-state drives. Smartclt command is part of the smartmontools package, which comes pre-installed in most Linux versions.

4.1. Find Hard Disk Drive Details In Linux Using Smartctl

To fetch the complete details about the hard disk drive in your Linux box, run:

Sample output:

For more details, refer man pages.

5. Find Hard Disk Drive Details In Linux Using Lsblk

Lsblk is a command line utility to display all available or the specified block devices in Unix-like operating systems. It reads the «sysfs» filesystem and «udev db» to gather information. The lsblk command is part of the «util-linux» package, which comes pre-installed in most Linux distributions.

Читайте также:  Windows start up needed

To display all block devices using lsblk command, run:

Sample output:

You can even display more details including filesystem type, UUID, Mountpoint etc., like below:

Sample output:

If you want to display only the physical devices, use «-d» flag.

6. Find Hard Disk Drive Details In Linux Using Fdisk and Sfdisk Commands

Fdisk and Sfdisk commands are used to create and manipulate partition tables. fdisk is a dialog-driven program for creating and manipulating partition tables whereas sfdisk is a script-oriented tool for partitioning any block device. Both are part of util-linux package which comes pre-installed in all Linux distros.

To get the HDD details, run fdisk as root or sudo user with «-l» flag:

Sample output:

The usage of Sfdisk is same as fdisk. To list HDD details using Sfdisk, run it with -l flag with root or sudo privileges:

To exclude the details of dm (device mapper) devices from the output, run:

Sample output:

7. Find Hard Disk Drive Details In Linux Using /proc

The /proc is a special virtual filesystem in Unix-like distributions. It is also known as process information pseudo-file system. It doesn’t contain any ‘real’ files but runtime system information such as processes, system memory, mounted devices and hardware configuration etc. Each device details are stored in a separate directory under /proc directory. The storage devices’ details will be available in «/proc/scsi/scsi» file.

Sample output:

8. Hwinfo

Hwinfo is a free, open source and command line utility to find Linux system hardware information. It probes for the hardware present in a Linux system and displays the extensive details of each hardware device. It uses libhd.so library to gather details of almost all hardware such as BIOS, CPU, Architecture, Memory, Hard Disk(s), Partitions, Camera, Bluetooth, CD/DVD drives, Keyboard/Mouse, Graphics card, Monitor, Modem, Scanner, Printer, PCI, IDE, SCSI, Sound card, Network interface card, USB and a lot more.

8.1. Install Hwinfo In Linux

Refer the following link to install Hwinfo in your Linux system.

8.2. Find Hard Disk Drive Details In Linux Using Hwinfo

To find Hard disk drive details using Hwinfo, run:

Sample output:

Or you can display the short summary of the disk details:

Sample output:

9. GNOME Disks

Disks or Gnome-disk-utility is a graphical user interface program to view, modify and configure available storage devices and media in a Linux system. If you are not comfortable with command line way, you can use use GNOME Disks to create and restore disk images, partition and format drives, inspect drive speed, benchmark drives and check health status etc. It comes pre-installed in all Linux distributions that has GNOME desktop environment.

9.1. Find Hard Disk Drive Details In Linux Using GNOME Disks

Launch Disks either from Menu or Dash. It lists all available disks and media in your Linux system.

Источник

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.

Читайте также:  Panasonic kx mb1500 драйвер windows 10 x64

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.

Источник

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