Lsblk linux maj min

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.

Читайте также:  Где хранятся ssh key linux ubuntu

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.

Источник

lsblk command in Linux to List Block Devices tutorial for beginners 2021

use-lsblk-command-in-linux-to-list-block-device-image

The lsblk command in Linux is a useful command for administrators, which is used to list information about all available block devices.

It does not list information about RAM disks.

lsblk command gets the information from the /sys virtual file system to obtain the information and display on the screen.

By default, you will get the information about all block devices in tree-like formate excluding except RAM disks.

lsblk is pre-installed in most of Linux destributions as part of the util-Linux package.

The “util-Linux” package contains a large variety of low-level system utilities that are necessary for a Linux system to function.

Basic syntax of lsblk command in linux

Open the terminal and run lsblk command without option, You will get information all attached devices including hard disk, DVD Device, Pen Drive etc.

You can see in the following example:

[[email protected] ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 32G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 31G 0 part ├─cl-root 253:0 0 28.9G 0 lvm / └─cl-swap 253:1 0 2.1G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sdc 8:32 0 16G 0 disk sr0 11:0 1 56.9M 0 rom /run/media/vijay/VBox_GAs_6.1.4 [[email protected] ~]$ 

There are seven columns namely:

NAME : First column has the device name .

Читайте также:  Usb hid device linux

MAJ:MIN : This column shows the major and minor device number.

RM: RM is a short form of removal, yes you can get the information about device is removable or not. If the RM value is 1, then the device is removable and 0 value for the non-removable disk.

SIZE: This column works as its name, It consists of information on the size of the device. For example, 298.1G indicates the device is 298.1GB and 1K indicate the device size is 1KB.

RO : RO stands for Read-Only, yes this indicates whether a device is read-only. In this case all devices have a RO=0, indicating they are not read-only.

TYPE :This column shows information whether the block device is a disk or a partition(part) within a disk.

MOUNTPOINT : This column indicates mount point on which the device is mounted.

View block devices in List Format

If you want to print device information in list format, then use lsblk command followed by -l option.

It only happened you don’t want to print output in a tree-like format, Use command as follows:

[[email protected] ~]$ lsblk -l NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 32G 0 disk sda1 8:1 0 1G 0 part /boot sda2 8:2 0 31G 0 part sdb 8:16 0 8G 0 disk sdc 8:32 0 16G 0 disk sr0 11:0 1 56.9M 0 rom /run/media/vijay/VBox_GAs_6.1.4 cl-root 253:0 0 28.9G 0 lvm / cl-swap 253:1 0 2.1G 0 lvm [SWAP] [[email protected] ~]$ 

List All devices

For your kind information, By default, lsblk command doesn’t print list of empty devices.

If you want to view all devices information including empty files then use command followed by -a option. So the command can be used as follows:

[[email protected] ~]$ lsblk -a NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 32G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 31G 0 part ├─cl-root 253:0 0 28.9G 0 lvm / └─cl-swap 253:1 0 2.1G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sdc 8:32 0 16G 0 disk sr0 11:0 1 56.9M 0 rom /run/media/vijay/VBox_GAs_6.1.4 [[email protected] ~]$ 

View Permissions and Owner of Device

-m option can be used with lsblk command to list the ownership of a particular device as well as the group the mode.

The syntax will be as follows:

[[email protected] ~]$ lsblk -m NAME SIZE OWNER GROUP MODE sda 32G root disk brw-rw---- ├─sda1 1G root disk brw-rw---- └─sda2 31G root disk brw-rw---- ├─cl-root 28.9G root disk brw-rw---- └─cl-swap 2.1G root disk brw-rw---- sdb 8G root disk brw-rw---- sdc 16G root disk brw-rw---- sr0 56.9M root cdrom brw-rw---- [[email protected] ~]$ 

List Information of Specific Devices

It is possible to get information about a specific device only. You can use print information of spcific device.

You can use lsblk command followed by the device name. For example, you would be interested to know your hard drive size in bytes.

Читайте также:  Linux update alternatives remove

You can use command syntax as follows:

[[email protected] ~]$ lsblk -b /dev/sda1 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda1 8:1 0 1073741824 0 part /boot [[email protected] ~]$
[[email protected] ~]$ lsblk -b /dev/sda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 34359738368 0 disk ├─sda1 8:1 0 1073741824 0 part /boot └─sda2 8:2 0 33284947968 0 part ├─cl-root 253:0 0 31058821120 0 lvm / └─cl-swap 253:1 0 2222981120 0 lvm [SWAP] [[email protected] ~]$ 

You can use the -o flag to filter out only specific fields For example, Name, SIZE etc.

In the following example, I am going to filter fields with the NAME, SIZE and MOUNPOINT attributes for the block devices.

lsblk -o NAME,SIZE,MOUNTPOINT

[[email protected] ~]$ lsblk -o NAME,SIZE,MOUNTPOINT NAME SIZE MOUNTPOINT sda 32G ├─sda1 1G /boot └─sda2 31G ├─cl-root 28.9G / └─cl-swap 2.1G [SWAP] sdb 8G sdc 16G sr0 56.9M /run/media/vijay/VBox_GAs_6.1.4 [[email protected] ~]$ 

List Devices Without Header in List Form

You can also combine two or more options to get the desired output.

For example, If you want to print the list of the devices in a list format instead of the default tree format, I have told you already about -l option.

But if you don’t want to display a header with the name of the different columns, then you can use -n or –noheadings options with lsblk command.

I am going to combine both options -n and -l, So the command syntax and output as follows:

[[email protected] ~]$ lsblk -nl sda 8:0 0 32G 0 disk sda1 8:1 0 1G 0 part /boot sda2 8:2 0 31G 0 part sdb 8:16 0 8G 0 disk sdc 8:32 0 16G 0 disk sr0 11:0 1 56.9M 0 rom /run/media/vijay/VBox_GAs_6.1.4 cl-root 253:0 0 28.9G 0 lvm / cl-swap 253:1 0 2.1G 0 lvm [SWAP] [[email protected] ~]$ 

or still you can use the option which will give the same output.

List SCSI Devices by lsblk Command

If you are looming to get a list of SCSI devices only, Then you can use command followed by the option -S.

This option is capital S and it should not be confused with the option -s which prints dependencies in inverse order.

Conclusion:

I’ve tried my best to cover most of the basic uses of lsblk command in Linux, but still, lsblk contains a variety of other expert commands you can use them.

For more detailed information, you can check the manual page. To display the manual page use man command from the terminal.

If I’ve missed any important command, please do share it with me via the comment section.

Special Offer on Ethical hacking Course in Hindi

If you like our content, please consider buying us a coffee.
Thank you for your support!

Источник

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