Skip to main content

dev_root_is_on_device

Function dev_root_is_on_device 

Source
fn dev_root_is_on_device(device_name: &str, primary: &str) -> bool
Expand description

Return true if /dev/root (a root-partition alias used by Ubuntu/AWS and similar cloud images) belongs to device_name.

Two strategies, tried in order:

  1. Symlink (read_link): common on Debian and some Ubuntu builds. The symlink target (e.g. nvme0n1p1) is resolved and matched against the device prefix.

  2. /proc/self/mountinfo + sysfs: when /dev/root is a device node (not a symlink), we read the major:minor string from mountinfo field 3 for the / mount whose source is /dev/root, then scan /sys/block/<device>/<partition>/dev for a matching string. Both sources use the same "major:minor" text format, so no encoding or makedev(3) arithmetic is needed.