Skip to contentSkip to conversation

wic: Fixed support of GPT partition table

PATCH New Ed Bartosh 1 participant 8 messages Jun 2, 2015

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

cover wic: Fixed support of GPT partition table

Hi,

This is a set of fixes for GPT partition table support in wic. Added new canned .wks and correspondent testcase were added to the codebase.

Result direct-gpt core-minimal image was successfully booted on NUC.

Ed Bartosh (7):
wic: set legacy_boot flag for gpt partitions
wic: check if part_type is set only for msdos partition table
wic: Add gpt to the list of supported partition table formats
wic: Use gptmbr.bin MBR for gpt partitions
wic: Make _ptable_format public
wic: create directdisk-gpt.wks
wic: Test creation of directdisk image with GPT table

 meta/lib/oeqa/selftest/wic.py                       |  6 ++++++
 scripts/lib/image/canned-wks/directdisk-gpt.wks     | 10 ++++++++++
 scripts/lib/wic/imager/direct.py                    |  6 +++---
 scripts/lib/wic/plugins/source/bootimg-efi.py       |  4 ++--
 scripts/lib/wic/plugins/source/bootimg-pcbios.py    |  8 ++++++--
 scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py | 12 ++++++++++--
 scripts/lib/wic/utils/partitionedfs.py              |  4 ++--
 7 files changed, 39 insertions(+), 11 deletions(-)
 create mode 100644 scripts/lib/image/canned-wks/directdisk-gpt.wks

--
Regards,
Ed

author
#1 lore raw

PATCH 1/7 wic: set legacy_boot flag for gpt partitions

This flag is used to tell special purpose software that the GPT partition may be bootable.

scripts/lib/wic/utils/partitionedfs.py +1 -1
index 1c9e3ea..06d4eac 100644
@@ -312,7 +312,7 @@ class Image:
                                     parted_fs_type, p['start'], p['size'])
 
             if p['boot']:
-                flag_name = "boot"
+                flag_name = "legacy_boot" if d['ptable_format'] == 'gpt' else "boot"
                 msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
                             (flag_name, p['num'], d['disk'].device))
                 self.__run_parted(["-s", d['disk'].device, "set",
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/7 wic: check if part_type is set only for msdos partition table

In reply to Ed Bartosh

Specifying partition type(GUID) makes sense for gpt partition table.

Current code checks if part-type is specified and throws exception if it is. This makes sense to do only for msdos partition table.

scripts/lib/wic/utils/partitionedfs.py +1 -1
index 06d4eac..eacf267 100644
@@ -138,7 +138,7 @@ class Image:
                 raise ImageError("No disk %s for partition %s" \
                                  % (p['disk_name'], p['mountpoint']))
 
-            if p['part_type']:
+            if ptable_format == 'msdos' and p['part_type']:
                 # The --part-type can also be implemented for MBR partitions,
                 # in which case it would map to the 1-byte "partition type"
                 # filed at offset 3 of the partition entry.
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/7 wic: Add gpt to the list of supported partition table formats

In reply to Ed Bartosh

Only msdos partition table format was supported by wic source plugins.

scripts/lib/wic/plugins/source/bootimg-efi.py +2 -2
index 2fc0357..22c7b0a 100644
@@ -61,7 +61,7 @@ class BootimgEFIPlugin(SourcePlugin):
 
         kernel = "/bzImage"
 
-        if cr._ptable_format == 'msdos':
+        if cr._ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
@@ -106,7 +106,7 @@ class BootimgEFIPlugin(SourcePlugin):
 
         kernel = "/bzImage"
 
-        if cr._ptable_format == 'msdos':
+        if cr._ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
scripts/lib/wic/plugins/source/bootimg-pcbios.py +1 -1
index 9c63855..c28b9af 100644
@@ -100,7 +100,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
         kernel = "/vmlinuz"
         syslinux_conf += "KERNEL " + kernel + "\n"
 
-        if cr._ptable_format == 'msdos':
+        if cr._ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +1 -1
index ebf95ae..29c873d 100644
@@ -101,7 +101,7 @@ class RootfsPlugin(SourcePlugin):
         syslinux_conf += "LABEL linux\n"
         syslinux_conf += "  KERNEL /boot/bzImage\n"
 
-        if image_creator._ptable_format == 'msdos':
+        if image_creator._ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH 4/7 wic: Use gptmbr.bin MBR for gpt partitions

In reply to Ed Bartosh

Used proper syslinux MBR gptmbr.bin for GPT partitons. Added check for unsupported partition formats.

scripts/lib/wic/plugins/source/bootimg-pcbios.py +4 -0
index c28b9af..ab62b7a 100644
@@ -46,6 +46,10 @@ class BootimgPcbiosPlugin(SourcePlugin):
         mbrfile = "%s/syslinux/" % bootimg_dir
         if cr._ptable_format == 'msdos':
             mbrfile += "mbr.bin"
+        elif cr._ptable_format == 'gpt':
+            mbrfile += "gptmbr.bin"
+        else:
+            msger.error("Unsupported partition table: %s" % cr._ptable_format)
 
         if not os.path.exists(mbrfile):
             msger.error("Couldn't find %s.  If using the -e option, do you have the right MACHINE set in local.conf?  If not, is the bootimg_dir path correct?" % mbrfile)
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +9 -1
index 29c873d..cdd7c84 100644
@@ -169,7 +169,15 @@ class RootfsPlugin(SourcePlugin):
         Called after all partitions have been prepared and assembled into a
         disk image. In this case, we install the MBR.
         """
-        mbrfile = os.path.join(native_sysroot, "usr/share/syslinux/mbr.bin")
+        mbrfile = os.path.join(native_sysroot, "usr/share/syslinux/")
+        if image_creator._ptable_format == 'msdos':
+            mbrfile += "mbr.bin"
+        elif image_creator._ptable_format == 'gpt':
+            mbrfile += "gptmbr.bin"
+        else:
+            msger.error("Unsupported partition table: %s" % \
+                        image_creator._ptable_format)
+
         if not os.path.exists(mbrfile):
             msger.error("Couldn't find %s. Has syslinux-native been baked?" % mbrfile)
 
Signature · 1 line
2.1.4
author
#5 lore raw

PATCH 5/7 wic: Make _ptable_format public

In reply to Ed Bartosh

Names with one leasding underscore considered protected in Python. _ptable_format is accessed outside of its class.
Made it public by removing underscore.

This pylint warning should be fixed now:
Access to a protected member _ptable_format of a client class

scripts/lib/wic/imager/direct.py +3 -3
index 9a7d0f5..83f9688 100644
@@ -62,7 +62,7 @@ class DirectImageCreator(BaseImageCreator):
         self.__disks = {}
         self.__disk_format = "direct"
         self._disk_names = []
-        self._ptable_format = self.ks.handler.bootloader.ptable
+        self.ptable_format = self.ks.handler.bootloader.ptable
 
         self.oe_builddir = oe_builddir
         if image_output_dir:
@@ -83,7 +83,7 @@ class DirectImageCreator(BaseImageCreator):
             if n == num:
                 if  p.no_table:
                     return 0
-                if self._ptable_format == 'msdos' and realnum > 3:
+                if self.ptable_format == 'msdos' and realnum > 3:
                     # account for logical partition numbering, ex. sda5..
                     return realnum + 1
                 return realnum
@@ -276,7 +276,7 @@ class DirectImageCreator(BaseImageCreator):
 
         self._restore_fstab(fstab)
 
-        self.__image.layout_partitions(self._ptable_format)
+        self.__image.layout_partitions(self.ptable_format)
 
         self.__imgdir = self.workdir
         for disk_name, disk in self.__image.disks.items():
scripts/lib/wic/plugins/source/bootimg-efi.py +2 -2
index 22c7b0a..400e3a2 100644
@@ -61,7 +61,7 @@ class BootimgEFIPlugin(SourcePlugin):
 
         kernel = "/bzImage"
 
-        if cr._ptable_format in ('msdos', 'gpt'):
+        if cr.ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
@@ -106,7 +106,7 @@ class BootimgEFIPlugin(SourcePlugin):
 
         kernel = "/bzImage"
 
-        if cr._ptable_format in ('msdos', 'gpt'):
+        if cr.ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
scripts/lib/wic/plugins/source/bootimg-pcbios.py +4 -4
index ab62b7a..1c3c6e6 100644
@@ -44,12 +44,12 @@ class BootimgPcbiosPlugin(SourcePlugin):
         disk image.  In this case, we install the MBR.
         """
         mbrfile = "%s/syslinux/" % bootimg_dir
-        if cr._ptable_format == 'msdos':
+        if cr.ptable_format == 'msdos':
             mbrfile += "mbr.bin"
-        elif cr._ptable_format == 'gpt':
+        elif cr.ptable_format == 'gpt':
             mbrfile += "gptmbr.bin"
         else:
-            msger.error("Unsupported partition table: %s" % cr._ptable_format)
+            msger.error("Unsupported partition table: %s" % cr.ptable_format)
 
         if not os.path.exists(mbrfile):
             msger.error("Couldn't find %s.  If using the -e option, do you have the right MACHINE set in local.conf?  If not, is the bootimg_dir path correct?" % mbrfile)
@@ -104,7 +104,7 @@ class BootimgPcbiosPlugin(SourcePlugin):
         kernel = "/vmlinuz"
         syslinux_conf += "KERNEL " + kernel + "\n"
 
-        if cr._ptable_format in ('msdos', 'gpt'):
+        if cr.ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
scripts/lib/wic/plugins/source/rootfs_pcbios_ext.py +4 -4
index cdd7c84..50b2213 100644
@@ -101,7 +101,7 @@ class RootfsPlugin(SourcePlugin):
         syslinux_conf += "LABEL linux\n"
         syslinux_conf += "  KERNEL /boot/bzImage\n"
 
-        if image_creator._ptable_format in ('msdos', 'gpt'):
+        if image_creator.ptable_format in ('msdos', 'gpt'):
             rootstr = rootdev
         else:
             raise ImageError("Unsupported partition table format found")
@@ -170,13 +170,13 @@ class RootfsPlugin(SourcePlugin):
         disk image. In this case, we install the MBR.
         """
         mbrfile = os.path.join(native_sysroot, "usr/share/syslinux/")
-        if image_creator._ptable_format == 'msdos':
+        if image_creator.ptable_format == 'msdos':
             mbrfile += "mbr.bin"
-        elif image_creator._ptable_format == 'gpt':
+        elif image_creator.ptable_format == 'gpt':
             mbrfile += "gptmbr.bin"
         else:
             msger.error("Unsupported partition table: %s" % \
-                        image_creator._ptable_format)
+                        image_creator.ptable_format)
 
         if not os.path.exists(mbrfile):
             msger.error("Couldn't find %s. Has syslinux-native been baked?" % mbrfile)
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH 6/7 wic: create directdisk-gpt.wks

In reply to Ed Bartosh

directdisk-gpt is the same as directdisk with only one difference:
it uses GPT partition table.

 create mode 100644 scripts/lib/image/canned-wks/directdisk-gpt.wks
scripts/lib/image/canned-wks/directdisk-gpt.wks new file +10 -0
new file mode 100644
index 0000000..76fda1f
@@ -0,0 +1,10 @@
+# short-description: Create a 'pcbios' direct disk image
+# long-description: Creates a partitioned legacy BIOS disk image that the user
+# can directly dd to boot media.
+
+
+part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
+part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
+
+bootloader  --ptable gpt --timeout=0  --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0"
+
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH 7/7 wic: Test creation of directdisk image with GPT table

In reply to Ed Bartosh

Added new wic testcase to the sute - creation of directdisk-gpt image.

meta/lib/oeqa/selftest/wic.py +6 -0
index a2ce2cb..e97dd1d 100644
@@ -73,3 +73,9 @@ class Wic(oeSelfTest):
                                    "-r tmp/work/qemux86-poky-linux/"
                                    "core-image-minimal/1.0-r0/rootfs").status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
+
+    def test06_gpt_image(self):
+        """Test creation of core-image-minimal with gpt table"""
+        self.assertEqual(0, runCmd("wic create directdisk-gpt "
+                                   "--image-name core-image-minimal").status)
+        self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
Signature · 1 line
2.1.4