dcantrell/pyparted

[RFE] Set GPT Partition Name

Closed this issue · 3 comments

Can pyparted be extended to allow setting the GPT Partitition Name (https://www.gnu.org/software/parted/manual/html_node/name.html - offset 56 (0x38))?

The Partition object supports this with the 'name' property:

For example, if I have /dev/sda with this GPT label:

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 430A09E7-A228-437B-BC53-B7A554041A63

Device Start End Sectors Size Type
/dev/sda1 2048 411647 409600 200M EFI System
/dev/sda2 411648 2508799 2097152 1G Linux filesystem
/dev/sda3 2508800 107366399 104857600 50G Linux filesystem
/dev/sda4 107366400 212223999 104857600 50G Linux filesystem
/dev/sda5 212224000 1953523711 1741299712 830.3G Linux filesystem

I can do this to set the name of /dev/sda5:

import parted
dev = parted.getDevice("/dev/sda")
disk = parted.Disk(dev)
part = disk.partitions[4]
part.name = '/home'

this seems to break, at least in python 3.7. I get AttributeError: can't set attribute:

Python 3.7.4 (default, Jul 16 2019, 07:12:58) 
[GCC 9.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import parted
>>> dev = parted.getDevice('/dev/vdb')
>>> disk = parted.Disk(dev)
>>> part = disk.partitions[0]
>>> part.name = 'foo'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
[root@test ~]# fdisk -l /dev/vdb
Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 5FCC195B-9A79-4636-B66A-83DC9B44CE99

Device     Start      End  Sectors Size Type
/dev/vdb1   2048 41940991 41938944  20G Linux filesystem

any ideas what might be causing that?

actually, i'll open a new issue since this one's a bit old.