Skip to main content
27 votes
Accepted

Can I shorten this filter, that finds disk sizes over 100G?

You can specify the form of output you want from lsblk: % lsblk -nblo NAME,SIZE mmcblk0 15931539456 mmcblk0p1 268435456 mmcblk0p2 15662038528 Options used: -b, --bytes Print the SIZE ...
muru's user avatar
  • 77.9k
20 votes
Accepted

Why does writing random data using dd result in disk partitions?

Several possibilities: Linux supports a lot of different partition table types, some of which use very few magic bytes, and then it's easy to mis-identify random data (*) [so it's possible to randomly ...
frostschutz's user avatar
  • 52.1k
19 votes
Accepted

How do I tell which partition I booted from?

Since your system apparently boots in UEFI style, the answer to the titular question is: Run efibootmgr -v as root, see the four-digit ID on the BootCurrent: line (usually the first line of output), ...
telcoM's user avatar
  • 114k
18 votes

Why does writing random data using dd result in disk partitions?

As seen here, the MBR (Master Boot Record) is relatively simple; https://en.wikipedia.org/wiki/Master_boot_record. When you use /dev/urandom you can always create something that looks like a ...
Adam Waldenberg's user avatar
18 votes

Can I shorten this filter, that finds disk sizes over 100G?

You can also tell lsblk to output in JSON format and do the filtering with jq: $ lsblk -Jb | jq -r '..|select(.size? >= 1e11).name' sda sda2 Or: $ lsblk -Jb | jq -r '..|select(.type? == "disk" ...
Stéphane Chazelas's user avatar
16 votes
Accepted

Make lsblk list devices by-id

The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list: lsblk -o name,model,serial The output of this command will look something like ...
Rovanion's user avatar
  • 1,121
13 votes
Accepted

lsblk + capture only the disks

If you want only disks identified as SCSI by the device major number 8, without device partitions, you could search on device major rather than the string "disk": lsblk -d | awk '/ 8:/' where the -d (...
user4556274's user avatar
  • 9,405
13 votes

Why does writing random data using dd result in disk partitions?

The thing that defines a collection of 512 bytes as being a Master Boot Record is the presence of the values 0x55 0xAA at the end. There's a 1-in-65,536 chance of /dev/urandom producing such a value: ...
Mark's user avatar
  • 4,705
10 votes

Make lsblk list devices by-id

As found here, the device ids can be seen by ls -l /dev/disk/by-id. So, Your task could be accomplished e.g. by something like: lsblk |awk 'NR==1{print $0" DEVICE-ID(S)"}NR>1{dev=$1;gsub("[^[:...
Gerald Schade's user avatar
10 votes

Iterate lines of string variable in bash

This is a good situation to use readarray/mapfile: readarray -t usbs < <(lsblk -o NAME,TRAN,VENDOR,MODEL | grep usb) This will create an array with your output where each line is separated into ...
jesse_b's user avatar
  • 41.5k
10 votes
Accepted

Does Linux update the size of a block device?

No. A device with internal wear leveling like eMMC and some flash drives will not advertise their full capacity in the first place. So, a device may have 1536 blocks but shows only 1024 to the system. ...
Ned64's user avatar
  • 9,276
9 votes
Accepted

Where is the udev database stored and what sets the permission?

The UDev database is stored in /run/udev/data. It used to be stored in /dev/.udev* before /run was introduced and the location was configurable in udev.conf but it's no longer possible.
Vojtech Trefny's user avatar
8 votes
Accepted

lsblk + file system type not appears from lsblk

lsblk uses UDev database to get information about filesystems so if it doesn't show the filesystem type, something is probably wrong with UDev. To check what UDev knows about the device, use udevadm ...
Vojtech Trefny's user avatar
8 votes
Accepted

bash + how to compare arg to one of the disks in linux machine

You don't seem to be using most of the components of that command. All you need is: lsblk -lnb | awk '$NF=="disk"{print $1}' Then, to avoid the error message when no argument has been given,...
terdon's user avatar
  • 252k
7 votes
Accepted

lsblk + how to capture the disks that are without filesystem

If your lsblk supports the --json output format, and if you have jq installed, you could parse that for block devices that (a) have no children (i.e. are unpartitioned) and (b) have no defined ...
steeldriver's user avatar
  • 83.8k
7 votes
Accepted

Meaning of the output from lsblk command

You have two disks, sda and sdb. Your second disk, sdb doesn't have a partition table and is formatted directly to ext4. Your first disk has 3 partitions, sda1 (from its size, I assume it's a BIOS ...
Vojtech Trefny's user avatar
6 votes
Accepted

Why is usb-drive not visible with `lsblk` after having been ejected from Thunar?

Mounting just means "set up the operating system to actively use the some (part of) a block device". Often there is some "busy" or "dirty" on the superblock that gets changed when a file system is ...
dirkt's user avatar
  • 33.4k
6 votes

Can I shorten this filter, that finds disk sizes over 100G?

try lsblk| awk '$4 ~ /G$/ && $4+0 > 100 {print $1}' this will grep and filter at same time. $4 ~ /G$/ get filed with size in G $4+0 > 100 get size over 100G {print $1} print NAME as a ...
Archemar's user avatar
  • 32.3k
6 votes
Accepted

How to update/refresh changed partlabels as reported by lsblk?

I found an answer: sudo udevadm trigger Source: http://ptspts.blogspot.com/2009/09/how-to-refresh-devdisk-on-linux.html Update #1: It appears the sudo may be unnecessary. So: udevadm trigger Update #...
mpb's user avatar
  • 1,861
6 votes

bash + how to compare arg to one of the disks in linux machine

Since lsblk allows for JSON output, it seems natural to use jq with it to figure out whether the given argument is a disk or not: #!/bin/sh if lsblk -J | jq -e --arg name "$1" '....
Kusalananda's user avatar
  • 356k
5 votes
Accepted

How to capture all disks that don’t have a file system

lsblk -o NAME,FSTYPE -dsn This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second ...
jdwolf's user avatar
  • 5,257
5 votes
Accepted

How to set a disk's (not partition) LABEL?

That depends on the contents of the device. More specifically, it depends on whether or not there is a known superblock that provides a label. This can be a filesystem superblock (like ext4, xfs, fat,...
frostschutz's user avatar
  • 52.1k
5 votes

bash + how to compare arg to one of the disks in linux machine

One possibility is to have two if-checks. At first, check if you can use $1 (the first argument) (it is not zero and is not --help) and then compare it to your lsblk-Output. For example: #!/bin/env ...
rathier's user avatar
  • 416
4 votes
Accepted

Do all disks devices in my HW machines start with - sd?

Most disk drivers use the sd prefix, but not all. Historically sd stood for “SCSI disk”, but most disks use a protocol which is close to SCSI, and most of Linux's disk drivers use the generic sd layer ...
Gilles 'SO- stop being evil''s user avatar
4 votes

Can i list unmounted drives without fdisk or lsblk?

When the kernel looks for possible devices it looks at cat /proc/partitions Sample output: major minor #blocks name 8 0 488386584 sda 8 1 472382464 sda1 8 2 ...
hschou's user avatar
  • 2,976
4 votes

lsblk + capture only the disks

I wanted to get only the device names of all disks without any other output. Ended up using this: lsblk -nd --output NAME Which yields something like sda sdb -d only outputs disks, -n removes the ...
thrau's user avatar
  • 141
4 votes

Displaying physical block devices

Assuming you actually want to see physical devices, and not just all block devices: My recommendation will then be: lsblk -a -d -e 230 Why? Let us review what these command line options do, from ...
Michael Hampton's user avatar
4 votes
Accepted

lsblk - what are the possible values for the column "state"

Looking at the source code for lsblk, for the STATE column, the only states defined are running or suspended
fpmurphy's user avatar
  • 4,756
4 votes

Iterate lines of string variable in bash

This is mostly a dupe of new lines and bash variable although that doesn't cover arrays. From there, to use a variable containing multiple lines, you need to make parameter expansion split at newline ...
dave_thompson_085's user avatar
4 votes
Accepted

Disk doesn't appear in blkid but does appear in lsblk

About blkid: When device is specified [… (irrelevant)]. If none is given, all partitions or unpartitioned devices which appear in /proc/partitions are shown, if they are recognized. While lsblk ...
Kamil Maciorowski's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible