Skip to content

Instantly share code, notes, and snippets.

@TobidieTopfpflanze
Created December 14, 2021 10:42
Show Gist options
  • Save TobidieTopfpflanze/218e57792ba183538d0acd9853ccfa8b to your computer and use it in GitHub Desktop.
Save TobidieTopfpflanze/218e57792ba183538d0acd9853ccfa8b to your computer and use it in GitHub Desktop.
USB investigation (ubuntu 18.04)

Important commands:

# Get related infos for flashing (sector size, start and end addresses)
sudo fdisk -l /dev/sdc

# Alternative for better regex actions:
sudo sfdisk -d /dev/sdc

# Copy image to storage
sudo dd if=/dev/sdb of=/media/auvidea/500GB-HD-USB3.0/image.bin conv=noerror,sync status=progress

# write raw image
sudo dd if=/media/auvidea/500GB-HD-USB3.0/image.bin of=/dev/sdb conv=noerror,sync status=progress

# get device info, "/dev/sdX" is your device here
lsblk -l -o name,size,maj:min "/dev/sdb" --json

# connected sdx
readlink -f /dev/disk/by-path/pci-*-usb-*-scsi-0:0:0:0

# Get additionally information
udevadm info /dev/sda

# Results for Bus 4, Port 4 -> 2 -> 1
E: ID_PATH=pci-0000:08:00.0-usb-0:3.4.2:1.0-scsi-0:0:0:0

# RegEx: /\/([0-9])-([0-9.]*):1\.0\//s
devices/pci0000:00/0000:00:1c.7/0000:08:00.0/usb4/4-3/4-3.4/4-3.4.2/4-3.4.2:1.0/host9/target9:0:0/9:0:0:0/block

# 8 Major / 16 Minor
ls -l /sys/dev/block/8\:16/

Output:

linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sdc" --json
{
   "blockdevices": [
      {"name": "sdc", "size": "1,9T", "maj:min": "8:32"},
      {"name": "sdc1", "size": "29,3G", "maj:min": "8:33"},
      {"name": "sdc2", "size": "64M", "maj:min": "8:34"},
      {"name": "sdc3", "size": "64M", "maj:min": "8:35"},
      {"name": "sdc4", "size": "448K", "maj:min": "8:36"},
      {"name": "sdc5", "size": "448K", "maj:min": "8:37"},
      {"name": "sdc6", "size": "63M", "maj:min": "8:38"},
      {"name": "sdc7", "size": "512K", "maj:min": "8:39"},
      {"name": "sdc8", "size": "256K", "maj:min": "8:40"},
      {"name": "sdc9", "size": "256K", "maj:min": "8:41"},
      {"name": "sdc10", "size": "300M", "maj:min": "8:42"},
      {"name": "sdc11", "size": "18K", "maj:min": "8:43"}
   ]
}
linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sdb" --json
{
   "blockdevices": [
      {"name": "sdb", "size": "465,7G", "maj:min": "8:16"},
      {"name": "sdb1", "size": "465,7G", "maj:min": "8:17"}
   ]
}
linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sda" --json
{
   "blockdevices": [
      {"name": "sda", "size": "465,8G", "maj:min": "8:0"},
      {"name": "sda1", "size": "465,8G", "maj:min": "8:1"}
   ]
}

Output after reboot:

linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sdc" --json
{
   "blockdevices": [
      {"name": "sdc", "size": "465,7G", "maj:min": "8:32"},
      {"name": "sdc1", "size": "465,7G", "maj:min": "8:33"}
   ]
}
linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sdc" --jsob
lsblk: unrecognized option '--jsob'
Try 'lsblk --help' for more information.
linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sdb" --json
{
   "blockdevices": [
      {"name": "sdb", "size": "465,8G", "maj:min": "8:16"},
      {"name": "sdb1", "size": "465,8G", "maj:min": "8:17"}
   ]
}
linux@linux:~$ lsblk -l -o name,size,maj:min "/dev/sda" --json
{
   "blockdevices": [
      {"name": "sda", "size": "1,9T", "maj:min": "8:0"},
      {"name": "sda1", "size": "29,3G", "maj:min": "8:1"},
      {"name": "sda2", "size": "64M", "maj:min": "8:2"},
      {"name": "sda3", "size": "64M", "maj:min": "8:3"},
      {"name": "sda4", "size": "448K", "maj:min": "8:4"},
      {"name": "sda5", "size": "448K", "maj:min": "8:5"},
      {"name": "sda6", "size": "63M", "maj:min": "8:6"},
      {"name": "sda7", "size": "512K", "maj:min": "8:7"},
      {"name": "sda8", "size": "256K", "maj:min": "8:8"},
      {"name": "sda9", "size": "256K", "maj:min": "8:9"},
      {"name": "sda10", "size": "300M", "maj:min": "8:10"},
      {"name": "sda11", "size": "18K", "maj:min": "8:11"}
   ]
}
linux@linux:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment