Jump to content

Cool Disk Command


V.T. Eric Layton

Recommended Posts

V.T. Eric Layton

I learned a new disk command today. Very interesting. What rock have I been under?

 

vtel57@ericsbane07~:$ lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
fd0                                                      
sda                                                      
|-sda1 ext4         6fef022f-2894-4d50-9bb9-7b79ed1018e3 /
|-sda2 ext4         75e5b42f-9c48-49de-afec-7b732cadde8f /home
|-sda3 ext4         113fd1e9-5401-44a6-81cc-deede5d00efd /home/vtel57/vtel57_storage
`-sda4 swap         ba80d646-bf62-4085-8056-08fa95f750b4 [SWAP]
sdb                                                      
|-sdb1 ext4         91d27734-7f70-41e5-aa07-be5e74aa8471 
|-sdb2 ext4         1627143c-42aa-492c-808c-6481bd210db4 
|-sdb3 ext4         cd7a174b-0248-4162-95bc-4023e2696f8a 
`-sdb4 swap         04d779a7-09eb-456d-b2ec-cdffe5b525cb [SWAP]
sdc                                                      
|-sdc1 ntfs         ECB0640BB063DB1A                     
`-sdc2 vfat         15B3-8531                            /home/vtel57/vtel57_common
sdd                                                      
|-sdd1 ntfs         ECB0640BB063DB1A                     
`-sdd2 vfat         15B3-8531                            
sr0                                                      
sr1                     

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

V.T. Eric Layton
7 minutes ago, amenditman said:

I bet you knew it once and forgot. Re-learn daily. That's my procedure.

 

Heh! Good possibility. It's also the same reason old stale jokes I've heard a thousand times are still funny... cuz, I don't remember the punchlines. ;)

Link to comment
Share on other sites

V.T. Eric Layton

Oh, and for those interested...

 

$man lsblk

 

Quote


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.

The default output as well as default output from options like --topology and --fs is subject to change, so whenever possible you should avoid using default outputs in your scripts. Always explicitly define expected columns by --output columns in environment where a stable output is required.
Options

-a, --all
    lsblk does not list empty devices by default. This option disables this restriction.
-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. The filter is applied to the top-level devices only.
-I, --include list
    Include devices specified by a comma-separated list of major device numbers only. The filter is applied to the top-level devices.
-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. All potentially unsafe characters are hex-escaped (\x<code>).
-r, --raw
    Use the raw output format. All potentially unsafe characters are hex-escaped (\x<code>) in NAME, KNAME, LABEL, PARTLABEL and MOUNTPOINT columns.
-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".
-V, --version
    Output version information and exit.

Notes
For partitions, some information (e.g. queue attributes) is inherited from the parent device.

The lsblk needs to be able to lookup sysfs path by major:minor, which is done done by using /sys/dev/block. The block sysfs appeared in kernel 2.6.27 (October 2008). In case of problem with new enough kernel check that CONFIG_SYSFS was enabled at the time of kernel build.
Authors

Milan Broz <mbroz@redhat.com>
Karel Zak <kzak@redhat.com>

 

  • Like 1
Link to comment
Share on other sites

Nice, I'll be using that in future. In siduction it also shows disk usage:

roger@siduction-brain2:~$ lsblk -f
NAME   FSTYPE LABEL     UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda
├─sda1 ntfs   WIN7      677EE28C54F5FC0F
├─sda2 ext4             45a5cc41-596c-4783-b066-8609f04c28a6    2.6G    82% /
├─sda3 swap             ee8c3db0-ccee-40ef-93b1-1a244e7ecb19                [SWAP]
├─sda4
├─sda5 ext4             eaa79911-410b-4d2d-86e9-c271bab29f5f
└─sda6 ext4             73db6bc2-7ceb-4a53-9103-e7eb6c3f8f88
sdb
├─sdb1 ntfs   win-stash 4E25F0444084DA77
├─sdb2 ntfs   win-progs 69B1A5EF6A01E52F
└─sdb3 ext4   stash     11c68f17-0fc7-4413-92e5-99a5021197bf  169.9G    53% /mnt/stash
sdc
└─sdc1 ext3   music     7605433f-5c96-4d6c-bb11-a1818eda16d4  126.5G    81% /mnt/music
sr0

 

  • Like 1
Link to comment
Share on other sites

securitybreach

Wait.. how did you not know about lsblk -f? I have been using that for well over a decade. 

 

I use it on every arch install so that I know where to install to.

  • Confused 1
Link to comment
Share on other sites

securitybreach
40 minutes ago, amenditman said:

I bet you knew it once and forgot. Re-learn daily. That's my procedure.

 

That has to be it. I refuse to believe that he didn't know lsblk.

  • Like 1
Link to comment
Share on other sites

I always used it with no options.

I just experimented with options to get it to show SIZE as well. lsblk -mf works well but has several columns I didn't want. Tried with -o and a list of columns but didn't get there with that.

This little exercise did remind me I have about 100GB of redundant data in sdb.

  • Like 2
Link to comment
Share on other sites

I'm surprised that I've been using lsblk all this time and never knew about lsblk -f. I'm not sure that I ever looked at man lsblk before today.

 

One switch (for a different command) that I'm sure I knew before but had forgotten about until I saw it today: the -r switch for repo info with inxi. For example, inxi -Fr, or inxi -br.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...