[[!toc levels=2]]

GPT only, single partition
==========================

$ gdisk /dev/sdb

1. o	create a new empty GUID partition table (GPT)
2. n	add a new partition
3. Partition number (1-128, default 1): 1
4. First sector (34-3891166, default = 34) or {+-}size{KMGTP}: 

Information: Moved requested sector from 34 to 2048 in
order to align on 2048-sector boundaries.
Use 'l' on the experts' menu to adjust alignment

5. Last sector (2048-3891166, default = 3891166) or {+-}size{KMGTP}: 

Current type is 'Linux/Windows data'

6. Hex code or GUID (L to show codes, Enter = 0700): 

Changed type of partition to 'Linux/Windows data'

7. w	write table to disk and exit

partprobe

mkfs.vfat /dev/sdb1

Result: Windows says the disk is not formated.

GPT + Hybrid MBR, single partition
==================================

$ gdisk /dev/sdb

1. o	create a new empty GUID partition table (GPT)
2. x	extra functionality (experts only)
3. l	set the sector alignment value
4. Enter the sector alignment value (1-65536, default = 2048): 63
5. m	return to main menu
6. n	add a new partition
7. Partition number (1-128, default 1): 1
8. First sector (34-3891166, default = 34) or {+-}size{KMGTP}: 63
9. Last sector (2048-3891166, default = 3891166) or {+-}size{KMGTP}: 

Current type is 'Linux/Windows data'

10. Hex code or GUID (L to show codes, Enter = 0700): 

Changed type of partition to 'Linux/Windows data'

11. r	recovery and transformation options (experts only)
12. h	make hybrid MBR
13. Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 1
14. Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N
15. Enter an MBR hex code (default 07): 0c
16. Set the bootable flag? (Y/N): N
17. Unused partition space(s) found. Use one to protect more partitions? (Y/N): N
18. w	write table to disk and exit

	partprobe
	mkfs.vfat /dev/sdb1

Result: in the MBR, the first partition is the FAT32 one, which is
detected and mounted by Windows.

GPT + Hybrid MBR, single bootable partition
===========================================

Same steps as previously, but the bootable flag is set at step 15.
After using liveusb-creator, the stick boots.


GPT + Hybrid MBR, 3 partitions, 2nd one is bootable
===================================================

$ gdisk /dev/sdb

1. o	create a new empty GUID partition table (GPT)
2. x	extra functionality (experts only)
3. l	set the sector alignment value
4. Enter the sector alignment value (1-65536, default = 2048): 63
5. m	return to main menu
6. n	add a new partition
7. Partition number (1-128, default 1): 1
8. First sector (34-3891166, default = 34) or {+-}size{KMGTP}: 63
9. Last sector (2048-3891166, default = 3891166) or {+-}size{KMGTP}: +64M
10. Hex code or GUID (L to show codes, Enter = 0700): 

Changed type of partition to 'Linux/Windows data'

11. x	extra functionality (experts only)
12. l	set the sector alignment value
13. Enter the sector alignment value (1-65536, default = 2048): 2048
14. m	return to main menu
15. n	add a new partition
16. Partition number (2-128, default 2): 2
17. First sector (34-3891166, default = 131135) or {+-}size{KMGTP}: 

Information: Moved requested sector from 131135 to 133120 in
order to align on 2048-sector boundaries.

18. Last sector (133120-3891166, default = 3891166) or {+-}size{KMGTP}: +1500M
19. Hex code or GUID (L to show codes, Enter = 0700): 8301

Changed type of partition to 'Linux reserved'

20. n	add a new partition
21. Partition number (3-128, default 3): 3
22. First sector (34-3891166, default = 3205120) or {+-}size{KMGTP}: 
23. Last sector (3205120-3891166, default = 3891166) or {+-}size{KMGTP}: 
24. Hex code or GUID (L to show codes, Enter = 0700): 8301

Changed type of partition to 'Linux reserved'

25. x	extra functionality (experts only)
26. a	set attributes
27. Partition number (1-3): 2
28. Toggle which attribute field (0-63, 64 or <Enter> to exit): 0
29. Toggle which attribute field (0-63, 64 or <Enter> to exit): 2
30. Toggle which attribute field (0-63, 64 or <Enter> to exit): 60
31. Toggle which attribute field (0-63, 64 or <Enter> to exit): 62
32. Toggle which attribute field (0-63, 64 or <Enter> to exit): 63

Attribute value is D000000000000005. Set fields are:
0 (system partition)
2 (legacy BIOS bootable)
60 (read-only)
62 (hidden)
63 (do not automount)

33. Toggle which attribute field (0-63, 64 or <Enter> to exit):
34. a	set attributes
35. Partition number (1-3): 3
36. Toggle which attribute field (0-63, 64 or <Enter> to exit): 63

Attribute value is 8000000000000000. Set fields are:
63 (do not automount)

37. Toggle which attribute field (0-63, 64 or <Enter> to exit):
38. r	recovery and transformation options (experts only)
39. h	make hybrid MBR
40. Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 1 2
41. Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N

Creating entry for GPT partition #1 (MBR partition #1)

42. Enter an MBR hex code (default 07): 0c
43. Set the bootable flag? (Y/N): N

Creating entry for GPT partition #2 (MBR partition #2)

44. Enter an MBR hex code (default 83): 1c
45. Set the bootable flag? (Y/N): Y
46. Unused partition space(s) found. Use one to protect more partitions? (Y/N): Y
47. Enter an MBR hex code (EE is EFI GPT, but may confuse MacOS): 0a
48. w	write table to disk and exit

	partprobe
	mkfs.vfat /dev/sdb1
	mkfs.vfat /dev/sdb2

Use of liveusb-creator to install an ISO on `/dev/sdb2`.

GPT + protective MBR, two partitions
====================================

	$ /sbin/sgdisk                      \
	--clear                     \   # create a new partition table
	--new=1:0:+1500M            \   # new partition 1, starts at begining, 1500 MiB size
	--typecode=1:8301           \   # part 1, set type 8301 (Linux reserved)
	--attributes=1:set:0        \   # part 1, set flag: system partition
	--attributes=1:set:2        \   # part 1, set flag: legacy BIOS bootable
        --attributes=1:set:60       \   # part 1, set flag: read-only
        --attributes=1:set:62       \   # part 1, set flag: hidden
        --attributes=1:set:63       \   # part 1, set flag: do not automount
        --change-name=1:Linux       \   # part 1, change label to 'Linux'
	--largest-new=2             \   # new partition, starts at begining, max size
	--typecode=2:8301           \   # part 2, set type 8301 (Linux reserved)
	--attributes=1:set:62       \   # part 2, set flag: hidden
	--attributes=1:set:63       \   # part 2, set flag: do not automount
	--change-name=2:persistent  \   # part 2, change label to 'persistent'
	/dev/sdb

Make the partition accessible to Windows, for the time of the installation:

	<<EOF sed -e 's/^\([^#]*\) \+# .*$/\1/' | /sbin/gdisk /dev/sdb
	r    # recovery and transformation options
	h    # make hybrid MBR
	1    # add first partition
	N    # no EFI GPT (0xEE) partition
	0c   # partition type (Win95 FAT32 LBA)
	N    # don't set the bootable flag
	N    # no protective partition
	w    # write table to disk and exit
	Y    # proceed, possibly destroying data
	EOF


Once the install has been done, lock things up:

	<<EOF sed -e 's/^\([^#]*\) \+# .*$/\1/' | /sbin/gdisk /dev/sdb
	x    # extra functionality
	n    # create a new protective MBR
	w    # write table to disk and exit
	Y    # proceed, possibly destroying data
	EOF
