From a78d6b7a5e4524f67e9cfea93e3aee153e80f540 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 29 Aug 2013 11:24:00 +0100 Subject: [PATCH] format: Set MBR partition type byte appropriately (RHBZ#1000428). Windows won't see a filesystem unless the MBR partition type byte is set correctly. $ ./run ./format/virt-format -a /tmp/test.img $ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h Name Type VFS Label MBR Size Parent /dev/sda1 filesystem unknown - - 1.0G - /dev/sda1 partition - - 83 1.0G /dev/sda /dev/sda device - - - 1.0G - $ ./run ./format/virt-format -a /tmp/test.img --filesystem=ntfs $ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ntfs - - 1.0G - /dev/sda1 partition - - 07 1.0G /dev/sda /dev/sda device - - - 1.0G - $ ./run ./format/virt-format -a /tmp/test.img --filesystem=vfat $ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h Name Type VFS Label MBR Size Parent /dev/sda1 filesystem vfat - - 1.0G - /dev/sda1 partition - - 0b 1.0G /dev/sda /dev/sda device - - - 1.0G - $ ./run ./format/virt-format -a /tmp/test.img --lvm --filesystem=vfat $ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h Name Type VFS Label MBR Size Parent /dev/VG/LV filesystem vfat - - 1020M - /dev/VG/LV lv - - - 1020M /dev/VG /dev/VG vg - - - 1020M /dev/sda1 /dev/sda1 pv - - - 1020M - /dev/sda1 partition - - 8e 1.0G /dev/sda /dev/sda device - - - 1.0G - Thanks: Gerd Hoffmann (kraxel) (cherry picked from commit d432ab2b5a965110bab542bfd397785eee9753dd) --- format/format.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/format/format.c b/format/format.c index 3418d2c..718fb2b 100644 --- a/format/format.c +++ b/format/format.c @@ -364,6 +364,31 @@ do_format (void) exit (EXIT_FAILURE); } free_dev = 1; + + /* Set the partition type byte appropriately, otherwise Windows + * won't see the filesystem (RHBZ#1000428). + */ + if (STREQ (ptype, "mbr") || STREQ (ptype, "msdos")) { + int mbr_id = 0; + + if (vg && lv) + mbr_id = 0x8e; + else if (filesystem) { + if (STREQ (filesystem, "msdos")) + mbr_id = 0x01; + else if (STREQ (filesystem, "fat") || STREQ (filesystem, "vfat")) + mbr_id = 0x0b; + else if (STREQ (filesystem, "ntfs")) + mbr_id = 0x07; + else if (STRPREFIX (filesystem, "ext")) + mbr_id = 0x83; + else if (STREQ (filesystem, "minix")) + mbr_id = 0x81; + } + + if (mbr_id > 0) + guestfs_part_set_mbr_id (g, devices[i], 1, mbr_id); + } } if (vg && lv) { -- 1.8.3.1