1

Before using dd to write a bootable ISO to a USB drive, I would like to be certain that I have the correct device. My plan was to list all devices, using fdisk -l, before and after inserting the USB device. Then I simply use diff to find the additional device entry and I know where I am.

But these days, fdisk -l generates tons of output (with single records spread across multiple lines) for snap software. This, of course, messes with my plan.

Can I get fdisk -l to elide loopback devices? I searched for "loop", and also "snap" in the manpage, but found nothing.

Any other suggestions?

TIA

2 Answers2

3

You can specify the device name in the command. This example will give you (only) all of the /dev/sdX devices:

sudo fdisk -l /dev/sd?
ajgringo619
  • 1,243
0

You're not guaranteed to have /dev/sdX devices (for example my connected devices are /dev/zd... and /dev/nvme... and you can't wildcard nvme

$ fdisk -l /dev/nvme?
fdisk: cannot open /dev/nvme0: Illegal seek
fdisk: cannot open /dev/nvme1: Illegal seek
$ fdisk -l /dev/nvme0?
zsh: no matches found: /dev/nvme0?

A better solution is to filter out the loop entries and display everything else with

sudo fdisk -l | sed -e '/Disk \/dev\/loop/,+5d'

You also get a lot more information with way

$ sudo fdisk -l | sed -e '/Disk \/dev\/loop/,+5d'

Disk /dev/nvme1n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Samsung SSD 980 PRO 1TB Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 3BA5EFE1-2851-4223-94CC-993F936B1AE8

Device Start End Sectors Size Type /dev/nvme1n1p1 2048 1050623 1048576 512M EFI System /dev/nvme1n1p2 1050624 1953523711 1952473088 931G Linux filesystem

Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Samsung SSD 980 PRO 1TB Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 56AD8CC1-5804-4F63-A0F8-E0D546E044D0

Device Start End Sectors Size Type /dev/nvme0n1p1 2048 2203647 2201600 1G EFI System /dev/nvme0n1p2 2203648 6397951 4194304 2G Linux filesystem /dev/nvme0n1p3 6397952 23175167 16777216 8G Linux filesystem /dev/nvme0n1p4 23175168 1953521663 1930346496 920.5G Linux filesystem

Disk /dev/zd0: 20 MiB, 20971520 bytes, 40960 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 16384 bytes I/O size (minimum/optimal): 16384 bytes / 16384 bytes

Disk /dev/mapper/keystore-rpool: 4 MiB, 4194304 bytes, 8192 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 16384 bytes I/O size (minimum/optimal): 16384 bytes / 16384 bytes

Disk /dev/mapper/dm_crypt-0: 8 GiB, 8589934592 bytes, 16777216 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes

Credit: https://askubuntu.com/a/1195398/18029


Another useful way of listing connected devices and filtering out snaps with lsblk, which provides a concise summary if you're not looking for all the information provided by fdisk

lsblk --exclude 7

Device type 7 are virtual consoles (vcs), which is the type of device snaps lists as, get filtered out.

$ lsblk -e 7 -o name,size,type,fstype,mountpoint

NAME SIZE TYPE FSTYPE MOUNTPOINT zd0 20M disk crypto_LUKS └─keystore-rpool 4M crypt ext4 /run/keystore/rpool nvme1n1 931.5G disk ├─nvme1n1p1 512M part vfat └─nvme1n1p2 931G part ext4 nvme0n1 931.5G disk ├─nvme0n1p1 1G part vfat /boot/efi ├─nvme0n1p2 2G part zfs_member ├─nvme0n1p3 8G part │ └─dm_crypt-0 8G crypt swap [SWAP] └─nvme0n1p4 920.5G part zfs_member