wic: Fixed support of GPT partition table
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
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
@@ -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
PATCH 2/7 wic: check if part_type is set only for msdos partition table
In reply to Ed BartoshSpecifying 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
@@ -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
PATCH 3/7 wic: Add gpt to the list of supported partition table formats
In reply to Ed BartoshOnly msdos partition table format was supported by wic source plugins.
scripts/lib/wic/plugins/source/bootimg-efi.py +2 -2
@@ -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
@@ -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
@@ -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
PATCH 4/7 wic: Use gptmbr.bin MBR for gpt partitions
In reply to Ed BartoshUsed proper syslinux MBR gptmbr.bin for GPT partitons. Added check for unsupported partition formats.
scripts/lib/wic/plugins/source/bootimg-pcbios.py +4 -0
@@ -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
@@ -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
PATCH 5/7 wic: Make _ptable_format public
In reply to Ed BartoshNames 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 6/7 wic: create directdisk-gpt.wks
In reply to Ed Bartoshdirectdisk-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
@@ -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
PATCH 7/7 wic: Test creation of directdisk image with GPT table
In reply to Ed BartoshAdded new wic testcase to the sute - creation of directdisk-gpt image.
meta/lib/oeqa/selftest/wic.py +6 -0
@@ -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