Henning Rohde posted this technique to synthesize a partition table onto a filesystem using device mapper:
# dd if=/dev/zero of=/tmp/zero count=63 # losetup -fv /tmp/zero # sda1size=$( blockdev --getsz /dev/sda1 ) # echo -e "unit: sectors\n\n/dev/sda1 : start=63, size=$sda1size, Id=7" | sfdisk --force /dev/loop0 # echo -e "0 63 linear /dev/loop0 0\n63 $sda1size linear /dev/sda1 0" | dmsetup -v create virtdisk # fdisk -lu /dev/mapper/virtdisk
- The dd command creates a file of all zeroes which is 63 sectors long (default blocksize for dd is 512 which happens to be the same as the traditional size of a sector).
- losetup and sfdisk are used to create a partition table on it. The partition table is configured to have a single partition which starts at sector 63 and has the same size as the (real) /dev/sda1. Of course this just creates the partition table on our empty file. If it existed, the partition would follow the end of the file, but the partition is not really being created by these commands.
- Use dmsetup to create a device mapper disk which consists of two linear maps: The first is the fake partition table file. The second is the real /dev/sda1. Effectively what we have created is a device mapper disk called /dev/mapper/virtdisk where you can read sectors 0..62 from the fake p.t. file, followed by sectors 63 onwards from the real /dev/sda1. /dev/mapper/virtdisk is, therefore, a lot like a virtual block device containing a partition table and a partition.
This is all risky, requires root, could seriously corrupt your data, and AFAIK no one has tried to boot a VM yet, so as Henning said, YMMV.