Skip to Content
Operating Systems

Scan Attached Disks with cnspec

Scan the operating system on a disk or snapshot volume attached to a Linux or Windows machine with cnspec, without booting it.

Scan the operating system on a disk without booting it. Attach the disk, or a volume you created from a disk snapshot, to a Linux or Windows machine that runs cnspec, and scan it with the device connection. cnspec mounts the disk's partitions, finds the one that holds the operating system, and scans it like any other host. This lets you assess disks from machines that are stopped or that you can't connect to.

New to cnspec? Start with the Quickstart, or read the Operating systems overview to see every platform cnspec can secure.

Prerequisites

To scan an attached disk with cnspec, you must have:

  • A Linux or Windows machine with cnspec installed. The device connection doesn't run on macOS.
  • The disk attached to that machine as a block device
  • Root privileges on Linux, where cnspec mounts the disk's partitions, or an administrator PowerShell session on Windows, where cnspec may change the disk's online and read-only state

Identify the disk

The device connection doesn't take a target argument. Instead, use one of these flags to tell cnspec which disk to scan:

FlagPlatformDescription
--lunLinux, WindowsThe SCSI logical unit number (LUN) of the disk
--device-namesLinuxOne or more device paths, such as /dev/sdb. Separate multiple devices with commas.
--serial-numberWindowsThe serial number of the disk

You must pass one of the flags your platform supports, and you can't combine them. On Linux, use --lun or --device-names. On Windows, use --lun or --serial-number.

Scan an attached disk on Linux

Run cnspec as root and identify the disk by its device path:

sudo cnspec scan device --device-names /dev/sdb

Or identify the disk by its LUN:

sudo cnspec scan device --lun 2

cnspec looks up LUNs in /sys/block, or with lsscsi --brief if that fails.

By default, cnspec mounts each partition on the disk that has a file system, including LVM logical volumes. It skips boot partitions and partitions that are already mounted on the scanning machine. If the disk has an /etc/fstab file, cnspec uses it to mount the partitions the way the operating system does. cnspec then looks for the partition that holds the operating system and scans it. If it can't detect an operating system on any partition, the connection fails with a no platform detected error. When the scan finishes, cnspec unmounts the partitions.

Scan an attached disk on Windows

Open PowerShell as an administrator and identify the disk by its serial number:

cnspec scan device --serial-number SERIAL_NUMBER

Or identify the disk by its LUN:

cnspec scan device --lun 2

cnspec looks up the disk with Get-WmiObject Win32_DiskDrive, which reports each disk's SerialNumber and SCSILogicalUnit. If Windows reports a serial number with an underscore suffix, such as the namespace ID that NVMe volumes on AWS Nitro instances add (vol0123456789abcdef0_00000001), you can pass the part before the underscore.

If the disk is offline or read-only, cnspec brings it online and clears the read-only attribute for the scan, and restores both settings when the scan finishes. cnspec scans the first partition of type Basic, Windows, or IFS that has a drive letter, so make sure the partition that holds Windows has a drive letter assigned.

Explore the disk interactively

Open a cnspec shell on the disk to run MQL queries against the operating system it holds:

sudo cnspec shell device --device-names /dev/sdb

Options

FlagDescription
--mount-all-partitions(Linux) Also mount boot partitions.
--include-mounted(Linux) Include partitions that are already mounted on the scanning machine.
--skip-attempt-expand-partitions(Linux) Don't look for an /etc/fstab file on the disk. cnspec mounts each partition on its own.
--keep-mountedLeave the partitions mounted after the scan. On Windows, cnspec doesn't restore the disk's online and read-only settings.
--platform-idsAdd platform IDs to the scanned asset, such as the IDs of the VM the disk belongs to. Separate multiple IDs with commas.

Learn more

Last updated on

On this page