Skip to main content

GPT Image

Create GUID Partition Table disk images on local disks. Written in pure Python gpt-image allows GPT disk images to be built on a local filesystem and exported to a destination device.

This is useful for creating a disk image on SD Cards or embedded devices.

Quick Start

Installation

pip install gpt-image

Create a GPT disk image

from gpt_image.disk import Disk
from gpt_image.partition import Partition, PartitionType

# create a new, 16 MB disk, size is in bytes
disk = Disk("disk-image.raw")
disk.create(16 * 1024 * 1024)

# create a 2MB Linux partition named "boot"
boot_part = Partition(
        "boot", 
        2 * 1024 * 1024, 
        PartitionType.EFI_SYSTEM_PARTITION.value
    )
disk.table.partitions.add(boot_part)

# create an 8MB Linux partition named "data"
data_part = Partition(
        "data", 
        8 * 1024 * 1024, 
        PartitionType.LINUX_FILE_SYSTEM.value
    )
disk.table.partitions.add(data_part)

# commit the change to disk
disk.commit()

# dump the current GPT information:

print(disk)

The final print(disk) command outputs a JSON document of the current GPT configuration:

{
  "path": "disk-image.raw",
  "image_size": 16777216,
  "sector_size": 512,
  "primary_header": {
    "backup": false,
    "signature": "EFI PART",
    "revision": "\u0000\u0000\u0001\u0000",
    "header_size": 92,
    "header_crc32": 3533962731,
    "reserved": 0,
    "my_lba": 1,
    "alternate_lba": 32767,
    "first_usable_lba": 34,
    "last_usable_lba": 32734,
    "disk_guid": "3f09c9fe-66ea-4c67-b0fb-fd35906b393a",
    "partition_entry_lba": 2,
    "number_of_partition_entries": 128,
    "size_of_partition_entries": 128,
    "partition_entry_array_crc32": 673632436
  },
  "backup_header": {
    "backup": true,
    "signature": "EFI PART",
    "revision": "\u0000\u0000\u0001\u0000",
    "header_size": 92,
    "header_crc32": 727034965,
    "reserved": 0,
    "my_lba": 32767,
    "alternate_lba": 1,
    "first_usable_lba": 34,
    "last_usable_lba": 32734,
    "disk_guid": "3f09c9fe-66ea-4c67-b0fb-fd35906b393a",
    "partition_entry_lba": 32735,
    "number_of_partition_entries": 128,
    "size_of_partition_entries": 128,
    "partition_entry_array_crc32": 673632436
  },
  "partitions": [
    {
      "type_guid": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
      "partition_name": "boot",
      "partition_guid": "67ed0675-9d44-46a6-bc29-99a2778e7563",
      "first_lba": 40,
      "last_lba": 4135,
      "alignment": 8,
      "size": 2097152,
      "attribute_flags": []
    },
    {
      "type_guid": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
      "partition_name": "data",
      "partition_guid": "1a44bc84-bb53-4f9f-b699-1d1268bfdbfa",
      "first_lba": 4136,
      "last_lba": 20519,
      "alignment": 8,
      "size": 8388608,
      "attribute_flags": []
    }
  ]
}

MIT License

Copyright (c) 2021 Scott Wysocki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt-image-0.7.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpt_image-0.7.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file gpt-image-0.7.0.tar.gz.

File metadata

  • Download URL: gpt-image-0.7.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.1 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.12.0 keyring/23.9.1 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.14

File hashes

Hashes for gpt-image-0.7.0.tar.gz
Algorithm Hash digest
SHA256 72877fc117e5aab1f419be11ff3db4bc74d3789e2ff5ee40c5e47802b924a095
MD5 f67b1697a1e913ec873981ff7d33d454
BLAKE2b-256 78da7a01d7c3b9d60636b17068e7750dc1ed258d654f3c2f9277cfbc34ab8bb3

See more details on using hashes here.

File details

Details for the file gpt_image-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: gpt_image-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.1 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.12.0 keyring/23.9.1 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.14

File hashes

Hashes for gpt_image-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4975df32154adf03a73422596a1b92d0662dea89d49d6179a9a36b76cfc84ad5
MD5 cae53e7616a8d867896cbcc7d5071e36
BLAKE2b-256 1c230341ccc10e467ee727049c554a8dd88abdba95d7c02fe146c630d83d10e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page