I understand your question is related to the partition table and the partitions and not the data. If this is correct then your answer is already in the man pages for parted
and here.
In essence create a script of the parted
commands necessary to create your gpt scheme and then
parted --script /dev/sdx [script commands]
This can be put into a shell script and executed as you need, perhaps passing the device as an argument to the script.
Edit after comment: According to the man sgdisk
page, to get the sgdisk output for a 'phantom' disk, use the '-P' option which performs the task(s) in memory but does not commit changes to disk.
I just tried this with a usb and it appears to work
sudo sgdisk -p /dev/sdb
Disk /dev/sdb: 31653888 sectors, 15.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2016C547-548B-482E-8810-A5E7A1466CED
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 31653854
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 31651839 15.1 GiB 0700 IDEA #old name
sudo sgdisk -P -c 1:random -p /dev/sdb #change the name
Setting name!
partNum is 0
REALLY setting name!
Disk /dev/sdb: 31653888 sectors, 15.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2016C547-548B-482E-8810-A5E7A1466CED
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 31653854
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 31651839 15.1 GiB 0700 random #name changed
re-executing
sudo sgdisk -p /dev/sdb
Number Start (sector) End (sector) Size Code Name
1 2048 31651839 15.1 GiB 0700 IDEA #change not written
The change is also reflected in the output from
sudo sgdisk -P -c 1:random --backup=phantomDisk /dev/sdb
/dev/sdx
disk, erasing all data? I was looking to output the resulting GPT table rather than writing it to disk. – sudo Nov 27 '17 at 05:21