First I'll create a 500M image file:
$ cd /tmp
$ fallocate -l $((1024*1024*500)) ./disk
Now I'll give it a GPT:
$ gdisk ./disk
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
o for create new GPT.
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y
n for create new partition. I just press enter to select all defaults after that.
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-1023966, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-1023966, default = 1023966) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
w writes changes to disk.
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to ./disk.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
Now I'll set it up as a partitioned block device and format the first partition with a filesystem:
$ sync; lp=$(sudo losetup --show -fP ./disk)
$ sudo mkfs.vfat -n SOMEDISK "${lp}p1"
Results:
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"
NAME FSTYPE LABEL PARTUUID
loop0
└─loop0p1 vfat SOMEDISK f509e1d4-32bc-4a7d-9d47-b8ed0f280b36
Now, to change that.
First, destroy the block dev:
$ sudo losetup -d "$lp"
Now, edit the GPT:
$ gdisk ./disk
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
i gives extended info about a single partition. Had I more than one partition, I would next be prompted to enter its partition number. The same goes for the c command later.
Command (? for help): i
Using 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: F509E1D4-32BC-4A7D-9D47-B8ED0F280B36
First sector: 2048 (at 1024.0 KiB)
Last sector: 1023966 (at 500.0 MiB)
Partition size: 1021919 sectors (499.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'
x is the xperts menu.
Command (? for help): x
c for change PARTUUID.
Expert command (? for help): c
Using 1
Enter the partition's new unique GUID ('R' to randomize): F509E1D4-32BC-4A7D-9D47-B00B135D15C5
New GUID is F509E1D4-32BC-4A7D-9D47-B00B135D15C5
w writes out the changes to disk (or, in this case, to my image file).
Expert command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to ./disk.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
$ sync; lp=$(sudo losetup --show -fP ./disk)
The results:
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"
NAME FSTYPE LABEL PARTUUID
loop0
└─loop0p1 vfat SOMEDISK f509e1d4-32bc-4a7d-9d47-b00b135d15c5