- List block devices linux
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- NOTES
- AUTHORS
- SEE ALSO
- AVAILABILITY
- List block devices linux
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- NOTES
- RETURN CODES
- AUTHORS
- ENVIRONMENT
- SEE ALSO
- How to List all Linux Disk Devices
- How to list disk devices in Linux with lsblk
- Lsblk, The column NAME:
- Lsblk, The column MAJ:MIN:
- Lsblk, The column RM:
- Lsblk, The column SIZE:
- Lsblk, The column RO:
- Lsblk, The column TYPE:
- Lsblk, The column MOUNTPOINT:
- How to show free and used space in Linux disk devices
- About the author
- David Adams
List block devices linux
NAME
lsblk - list block devices
SYNOPSIS
lsblk [options] lsblk [options] device.
DESCRIPTION
lsblk lists information about all or the specified block devices. The lsblk command reads the sysfs filesystem to gather information. The command prints all block devices (except RAM disks) in a tree-like format by default. Use lsblk --help to get a list of all available columns.
OPTIONS
-a, --all List all block devices. -b, --bytes Print the SIZE column in bytes rather than in human-readable format. -d, --nodeps Don't print device holders or slaves. For example "lsblk --nodeps /dev/sda" prints information about the sda device only. -D, --discard Print information about the discard (TRIM, UNMAP) capabilities for each device. -e, --exclude list Exclude the devices specified by a comma-separated list of major device numbers. Note that RAM disks (major=1) are excluded by default. -f, --fs Output info about filesystems. This option is equivalent to "-o NAME,FSTYPE,LABEL,MOUNTPOINT". The authoritative information about filesystems and raids is provided by the blkid(8) command. -h, --help Print a help text and exit. -i, --ascii Use ASCII characters for tree formatting. -m, --perms Output info about device owner, group and mode. This option is equivalent to "-o NAME,SIZE,OWNER,GROUP,MODE". -l, --list Use the list output format. -n, --noheadings Do not print a header line. -o, --output list Specify which output columns to print. Use --help to get a list of all supported columns. -P, --pairs Use key="value" output format. -r, --raw Use the raw output format. -t, --topology Output info about block device topology. This option is equivalent to "-o NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED".
NOTES
For the partitions are some information (e.g. queue attributes) inherited from parental device.
AUTHORS
SEE ALSO
findmnt(8), blkid(8), ls(1)
AVAILABILITY
© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
List block devices linux
NAME
lsblk - list block devices
SYNOPSIS
lsblk [options] [device. ]
DESCRIPTION
lsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather information. The command prints all block devices (except RAM disks) in a tree-like format by default. Use lsblk --help to get a list of all available columns. The default output, as well as the default output from options like --fs and --topology, is subject to change. So whenever possible, you should avoid using default outputs in your scripts. Always explicitly define expected columns by using --output columns-list in environments where a stable output is required. Note that lsblk might be executed in time when udev does not have all information about recently added or modified devices yet. In this case it is recommended to use udevadm settle before lsblk to synchronize with udev.
OPTIONS
-a, --all Also list empty devices. (By default they are skipped.) -b, --bytes Print the SIZE column in bytes rather than in a human-readable format. -D, --discard Print information about the discarding capabilities (TRIM, UNMAP) for each device. -d, --nodeps Do not print holder devices or slaves. For example, lsblk --nodeps /dev/sda prints information about the sda device only. -e, --exclude list Exclude the devices specified by the comma-separated list of major device numbers. Note that RAM disks (major=1) are excluded by default. The filter is applied to the top-level devices only. -f, --fs Output info about filesystems. This option is equivalent to -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT. The authoritative information about filesystems and raids is provided by the blkid(8) command. -h, --help Display help text and exit. -I, --include list Include devices specified by the comma-separated list of major device numbers. The filter is applied to the top-level devices only. -i, --ascii Use ASCII characters for tree formatting. -J, --json Use JSON output format. -l, --list Produce output in the form of a list. -m, --perms Output info about device owner, group and mode. This option is equivalent to -o NAME,SIZE,OWNER,GROUP,MODE. -n, --noheadings Do not print a header line. -o, --output list Specify which output columns to print. Use --help to get a list of all supported columns. The default list of columns may be extended if list is specified in the format +list (e.g. lsblk -o +UUID). -O, --output-all Output all available columns. -P, --pairs Produce output in the form of key="value" pairs. All potentially unsafe characters are hex-escaped (\x). -p, --paths Print full device paths. -r, --raw Produce output in raw format. All potentially unsafe characters are hex-escaped (\x) in the NAME, KNAME, LABEL, PARTLABEL and MOUNTPOINT columns. -S, --scsi Output info about SCSI devices only. All partitions, slaves and holder devices are ignored. -s, --inverse Print dependencies in inverse order. -t, --topology Output info about block-device topology. This option is equivalent to -o NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,RA,WSAME. -V, --version Display version information and exit. -x, --sort column Sort output lines by output column.
NOTES
For partitions, some information (e.g. queue attributes) is inherited from the parent device. The lsblk command needs to be able to look up each block device by major:minor numbers, which is done by using /sys/dev/block. This sysfs block directory appeared in kernel 2.6.27 (October 2008). In case of problems with a new enough kernel, check that CONFIG_SYSFS was enabled at the time of the kernel build.
RETURN CODES
0 success 1 failure 32 not found all specified devices 64 some specified devices found, some not found
AUTHORS
ENVIRONMENT
LIBBLKID_DEBUG=all enables libblkid debug output. LIBMOUNT_DEBUG=all enables libmount debug output. LIBSMARTCOLS_DEBUG=all enables libsmartcols debug output.
SEE ALSO
findmnt(8), blkid(8), ls(1)
How to List all Linux Disk Devices
How to list disk devices in Linux with lsblk
The proper way to list block devices such as hard disks is using the command lsblk.
Note: the -a flag forces lsblk to list also empty devices.
In the first column you can see all the connected devices, in the image above you can see 3 devices: sda, sdc and sdd. Lets see some information on each.
Lsblk, The column NAME:
The NAME column shows the name of each disk device and partition. As you can see in the extract of the column below the disk SDA contains 4 partitions: sda1, sda2, sda3 and sda4. You can ignore the “_crypt_” for now.
The second listed disk device is sdc with only one partition, sdc1.
The second listed disk device is sdd with only one partition, sdd1.
The last listed device is the DVD or CDROM:
Lsblk, The column MAJ:MIN:
Following the column NAME there is the column MAJ:MIN is the internal identificator for each device the kernel uses according to the device type.
Lsblk, The column RM:
The column RM shows if the device is removable (where 1 yes and 0 no), in this case last 2 disk are external and the last device is the DVD.
Lsblk, The column SIZE:
The column SIZE displays the size of each of the disk devices listed.
Lsblk, The column RO:
The column RO means Read Only, being 1 positive and 0 negative, if 0 then devices are not read only, if 1, they are read-only.
Lsblk, The column TYPE:
The column TYPE displays the type of device such as devices, partitions, optical devices, encrypted partitions and more.
Lsblk, The column MOUNTPOINT:
The column MOUNTPOINT shows the mount point of each device or partition, the next image shows the partitions of the device sda.
The screenshot below shows an efi partition belonging to sda1, the encrypted sda2 root partition, the sda3 for boot and an encrypted sda4 SWAP.
The flag -l will show the devices and partition as a list rather than as tree:
The flag -f instructs lsblk to inform the filesystem of each partition:
Additional flags for the command lsblk are available and explained in the man page which you can also access at https://linux.die.net/man/8/lsblk.
Listing disk devices in Linux with alternative methods: fdisk and fstab
While the correct way to list disk devices in Linux is using the command lsblk, other options are available.
The first one to try is fdisk, to list all block devices with fdisk run:
How to show free and used space in Linux disk devices
Additionally to listing your storage devices you may need to show the free and used space, this can be achieved using the command df.
As you see in the screenshot below, the availability of space of all disks formerly listed is now displayed.
The command df allows you to easily check each partition identified both by its device name or its mountpoint, yet, the -h option makes it easier to be readed by humans.
For example the image above shows the partition /dev/sda2_crypt which is the root mount point / has 150 GB available and 64 GB used.
About the author
David Adams
David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.