Closed goigle closed 2 years ago
Since you are using clobber() on the device, it is destroying the disk label. newDisk() can't work without a disk label. If you want to create a new Disk object with a specific lable, you need to use freshDisk:
dev.clobber()
disk = parted.freshDisk(dev, TYPE)
Where TYPE is a value from the parted.diskType dict. Such as parted.diskType["gpt"]:
disk = parted.freshDisk(dev, parted.diskType["gpt"])
Which will create a new Disk object for dev that has a GPT disk label.
Note that you will need to use disk.commitToDevice() to write the label to the disk, otherwise it's just all in memory.
I am trying to create a partition on /dev/sda, but for some reason pyparted is having issues. At first I was directly creating the device based on the path, but that gave the 'unrecognized disk label' error so I tried enumerating the disks and checking the path but I had the same results. The disk is a 120GB SATA SSD on /dev/sda. It works fine and GParted isn't having issues.
libparted-dev is on version 3.3-4ubuntu0.20.04.1. I'm on Ubuntu 20.04.3 LTS with Python 3.8.10.
Offending code (args.device is '/dev/sda'):
Console Output: