Create 2 GB of free space. Here, I will assume your current hard disk is configured as shown below. This output is from the command diskutil list
.
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *80.5 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 40.0 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
4: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 2.0 GB disk0s4
5: 21686148-6449-6E6F-744E-656564454649 1.0 MB disk0s5
6: Linux Swap 4.3 GB disk0s6
7: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 33.4 GB disk0s7
During this step, the 2nd partition will be shrunk by 2 GB to create free space after the 3rd partition. Since the 2nd partition is 40 GB in size, the command below will shrink the 2nd partition to 38 GB and relocate the 3rd partition, so the free space occurs after the 3rd partition.
diskutil resizevolume disk0s2 38g
The results can be summarized by the output from the diskutil list
command, as shown below.
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *80.5 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 38.0 GB disk0s2
3: Apple_Boot 650.0 MB disk0s8
4: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 2.0 GB disk0s4
5: 21686148-6449-6E6F-744E-656564454649 1.0 MB disk0s5
6: Linux Swap 4.3 GB disk0s6
7: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 33.4 GB disk0s7
Below is the output of the sudo gpt -r show disk0
command. This output shows 2 GB (3906256 sectors) of free space has been created between the 3rd and 4th partitions.
gpt show: disk0: Suspicious MBR at sector 0
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 6
40 409600 1 GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
409640 74218744 2 GPT part - 48465300-0000-11AA-AA11-00306543ECAC
74628384 1269536 3 GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
75897920 3906256
79804176 3891200 4 GPT part - 0FC63DAF-8483-4772-8E79-3D69D8477DE4
83695376 240
83695616 2048 5 GPT part - 21686148-6449-6E6F-744E-656564454649
83697664 8388608 6 GPT part - 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
92086272 65198080 7 GPT part - 0FC63DAF-8483-4772-8E79-3D69D8477DE4
157284352 2015
157286367 32 Sec GPT table
157286399 1 Sec GPT header
Use the gdisk
command to add the free space to the 4th and 5th partitions and update the hybrid partitioning.
Note: To help insure GRUB is not compromised, the new (after) BIOS boot partition needs to contain all the sectors from the old (before) BIOS boot partition.
Determine a new starting sector for the 5th partition so the BIOS boot space will be 8 MiB in size. Basically, subtract 14336 (7 MiB) from the current starting sector, as shown in the table below.
Table of Changes in the 5th Partition (BIOS boot)
|
Start Sector |
End Sector |
Size |
Before |
83695616 |
83697663 |
2048 sectors = 1 MiB |
Change |
-14336 |
0 |
14336 sectors = 7 MiB |
After |
83681280 |
83697663 |
16384 sectors = 8 MiB |
The rest of the free space will be added to the 4th partition. Enter the command below to edit the partition tables.
gdisk /dev/sda
Below are the entries made to gdisk
. Make the appropriate substitution when necessary.
Table of Entries to the gdisk
Command
Entry |
Default |
Type |
Comment |
p |
|
command |
Print the GPT. |
d |
|
command |
Delete a GPT partition. |
4 |
|
data |
Partition to delete. |
d |
|
command |
Delete a GPT partition. |
5 |
|
data |
Partition to delete. |
n |
|
command |
Add a new GPT partition. |
5 |
|
data |
Partition to add. |
83681280 |
|
data |
First sector of 5th GPT partition. (Your value may be different.) |
+8m |
|
data |
5th GPT partition size of 8 MiB. |
ef02 |
|
data |
5th GPT partition type "BIOS boot". |
p |
|
command |
Print the GPT. |
n |
|
command |
Add a new GPT partition. |
4 |
X |
data |
Partition to add. |
75897920 |
X |
data |
First sector of 4th GPT partition. (Your value may be different.) |
83681279 |
X |
data |
Last sector of 4th GPT partition. (Your value may be different.) |
8300 |
|
data |
4th GPT partition type "Linux filesystem". |
p |
|
command |
Print the GPT. |
r |
|
command |
Goto recovery and transformation menu. |
h |
|
command |
Make hybrid MBR. |
2 3 4 |
|
data |
2nd, 3rd and 4th GPT partitions. |
y |
|
data |
Make 1st MBR partition type EE . |
af |
X |
data |
2nd MBR partition type "Apple HFS/HFS+". |
n |
|
data |
No boot flag for 2nd MBR partition. |
ab |
X |
data |
3rd MBR partition type "Apple Recovery". |
n |
|
data |
No boot flag 3nd MBR partition. |
83 |
X |
data |
4th MBR partition type "Linux filesystem". |
y |
|
data |
Set boot flag for 4th MBR partition. |
o |
|
command |
Print the MBR partition table. |
w |
|
command |
Write tables to drive and exit. |
y |
|
data |
Confirm write and exit. |
Example output from using the gdisk /dev/sda
command to edit the MBR partition table and the GPT is given below.
GPT fdisk (gdisk) version 1.0.3
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/disk0: 157286400 sectors, 75.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): A00FDE86-5A09-431E-89BA-45CC6D3ACF58
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 157286366
Partitions will be aligned on 8-sector boundaries
Total free space is 3908517 sectors (1.9 GiB)
Number Start (sector) End (sector) Size Code Name
1 40 409639 200.0 MiB EF00 EFI System Partition
2 409640 74628383 35.4 GiB AF00 Apple HFS/HFS+
3 74628384 75897919 619.9 MiB AB00 Recovery HD
4 79804176 83695375 1.9 GiB 8300 Linux filesystem
5 83695616 83697663 1024.0 KiB EF02
6 83697664 92086271 4.0 GiB 8200
7 92086272 157284351 31.1 GiB 8300
Command (? for help): d
Partition number (1-7): 4
Command (? for help): d
Partition number (1-7): 5
Command (? for help): n
Partition number (4-128, default 4): 5
First sector (34-157286366, default = 75897920) or {+-}size{KMGTP}: 83681280
Last sector (83681280-83697663, default = 83697663) or {+-}size{KMGTP}: +8m
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): ef02
Changed type of partition to 'BIOS boot partition'
Command (? for help): p
Disk /dev/disk0: 157286400 sectors, 75.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): A00FDE86-5A09-431E-89BA-45CC6D3ACF58
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 157286366
Partitions will be aligned on 8-sector boundaries
Total free space is 7785381 sectors (3.7 GiB)
Number Start (sector) End (sector) Size Code Name
1 40 409639 200.0 MiB EF00 EFI System Partition
2 409640 74628383 35.4 GiB AF00 Apple HFS/HFS+
3 74628384 75897919 619.9 MiB AB00 Recovery HD
5 83681280 83697663 8.0 MiB EF02 BIOS boot partition
6 83697664 92086271 4.0 GiB 8200
7 92086272 157284351 31.1 GiB 8300
Command (? for help): n
Partition number (4-128, default 4):
First sector (34-157286366, default = 75897920) or {+-}size{KMGTP}:
Last sector (75897920-83681279, default = 83681279) or {+-}size{KMGTP}:
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): 8300
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/disk0: 157286400 sectors, 75.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): A00FDE86-5A09-431E-89BA-45CC6D3ACF58
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 157286366
Partitions will be aligned on 8-sector boundaries
Total free space is 2021 sectors (1010.5 KiB)
Number Start (sector) End (sector) Size Code Name
1 40 409639 200.0 MiB EF00 EFI System Partition
2 409640 74628383 35.4 GiB AF00 Apple HFS/HFS+
3 74628384 75897919 619.9 MiB AB00 Recovery HD
4 75897920 83681279 3.7 GiB 8300 Linux filesystem
5 83681280 83697663 8.0 MiB EF02 BIOS boot partition
6 83697664 92086271 4.0 GiB 8200
7 92086272 157284351 31.1 GiB 8300
Command (? for help): r
Recovery/transformation command (? for help): h
WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,
just hit the Enter key at the below prompt and your MBR partition table will
be untouched.
Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 2 3 4
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): y
Creating entry for GPT partition #2 (MBR partition #2)
Enter an MBR hex code (default AF):
Set the bootable flag? (Y/N): n
Creating entry for GPT partition #3 (MBR partition #3)
Enter an MBR hex code (default AB):
Set the bootable flag? (Y/N): n
Creating entry for GPT partition #4 (MBR partition #4)
Enter an MBR hex code (default 83):
Set the bootable flag? (Y/N): y
Recovery/transformation command (? for help): o
Disk size is 157286400 sectors (75.0 GiB)
MBR disk identifier: 0x00000000
MBR partitions:
Number Boot Start Sector End Sector Status Code
1 1 409639 primary 0xEE
2 409640 74628383 primary 0xAF
3 74628384 75897919 primary 0xAB
4 * 75897920 83681279 primary 0x83
Recovery/transformation 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 /dev/disk0.
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.
The results can be summarized by the output from the diskutil list
command, as shown below.
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *80.5 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 38.0 GB disk0s2
3: Apple_Boot 650.0 MB disk0s8
4: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 4.0 GB disk0s9
5: 21686148-6449-6E6F-744E-656564454649 8.4 MB disk0s10
6: Linux Swap 4.3 GB disk0s6
7: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 33.4 GB disk0s7
Below is the output of the sudo gpt -r show disk0
command. This output shows there is no longer any free space between the 3rd and 4th partitions.
gpt show: disk0: Suspicious MBR at sector 0
start size index contents
0 1 MBR
1 1 Pri GPT header
2 32 Pri GPT table
34 6
40 409600 1 GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
409640 74218744 2 GPT part - 48465300-0000-11AA-AA11-00306543ECAC
74628384 1269536 3 GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
75897920 7783360 4 GPT part - 0FC63DAF-8483-4772-8E79-3D69D8477DE4
83681280 16384 5 GPT part - 21686148-6449-6E6F-744E-656564454649
83697664 8388608 6 GPT part - 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
92086272 65198080 7 GPT part - 0FC63DAF-8483-4772-8E79-3D69D8477DE4
157284352 2015
157286367 32 Sec GPT table
157286399 1 Sec GPT header
The 4th partition is now large enough to hold the Lubuntu installation file and the 5th partition has been increased to 8 MiB.