pyparted icon indicating copy to clipboard operation
pyparted copied to clipboard

How can I label a disk?

Open tdunning opened this issue 10 months ago • 2 comments

I want to do the equivalent of parted /dev/sdb mklabel gpt using pyparted but I can't figure this out from the (slim) documentation or by inspecting the pyparted source code and examples.

Any hints?

tdunning avatar Feb 15 '25 16:02 tdunning

there is a very similar (but unmaintained) package called python-parted that has the necessary functionality.

https://github.com/dkmstr/python-parted

In this other package, the syntax is:

dsk = dev.new_table(disk.DiskType.WNT.GPT)

tdunning avatar Feb 18 '25 03:02 tdunning

Answering my own question:

disk = parted.freshDisk(dev, "gpt")
disk.commit()

is the non-intuitive equivalent of mklabel gpt.

I would be happy to write this up. It might be good as part of the README to have a section that describes the equivalence between common parted idioms like this and the python code that can be used to implement them.

Thoughts?

tdunning avatar Feb 18 '25 04:02 tdunning