How to make Linux read partition table in a partition?
I have a (GPT-partitioned) disk, for example
/dev/sda8 is a partition on that disk. I used the
cfdisk utility to create a GPT table with few partitions in
/dev/sda8. I expected these partitions to become available via something like
/dev/sda8p1. But Linux did not automatically recognize them.
How do I make Linux recognize partitions in a partition, and automatize that if possible?
There is no automated recognition for such a nested partition structure, because such nesting is not part of any partition table specification I know about.
kpartx can be used to create device-mapper-based device nodes for such partitions-within-partition, using a syntax essentially identical to
partx. The resulting partition devices would be something like
A nested partition structure like this can arise from e.g. mapping a partition as a virtual disk for a virtual machine. Accessing the partitions of such a virtual disk from the host via
kpartx can be an useful troubleshooting tool if the VM has an issue that prevents it from booting.
You must be aware of its limitations though: trying to access the VM’s partitions from the host system while the VM is running would cause filesystem corruption, as the filesystem-level caches in the host and in the VM are not communicating with each other, and so cannot possibly be aware of one’s write operation invalidating some data that the other has cached.
I know of nothing that that will automatically scan a partition as if it were a disk, and indeed it can’t even be scanned manually:
partx --add - /dev/sda8 partx: /dev/sda8: error adding partitions 1-2
However, you can use a loop device to map the partition back to a device – and this device can be scanned as if it were a disk. Example for a device
/dev/sda8 containing two partitions:
losetup --show --find --partscan /dev/sda8 /dev/loop0 ls -1 /dev/loop0* # Arg is #1, not lowercase "L" /dev/loop0 /dev/loop0p1 /dev/loop0p2
Remember to delete the loop device when you’ve finished
losetup -d /dev/loop0