Asign unallocated free space on external volume to (new) partition OSX
-
29-04-2021 - |
Frage
I formated a external USB drive to mount with 10 different volumes. (Actually I forgot how i made this work)
The drive will not show as being partitioned in drive utility in OSX but show all volumes(MBR) on this drive as kind of individual ones which are not related like partitions are.
With diskutil in terminal I was able to delete the unnecessary volumes. But now I have a 2TB drive with only two volumes left, which share 400GB together. So the unallocated space is missing and I do not know how to reallocate it either asigning it to one of the volumes or by creating a new volume which takes all unalloacted space. Does anybody know what to do?
I would realy want to avoid erasing the whole disk, as the two volumes keep backups of different machines.
Disk
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *2.0 TB disk2
1: Apple_HFS Name1 200.2 GB disk2s1
2: Apple_HFS Name2 200.2 GB disk2s5
sudo gpt -r show disk2
start size index contents
0 1 MBR
1 390965066
390965067 390965064 1 MBR part 175
781930131 2345790390 2 MBR part 5
3127720521 779308647
Is there any way to keep the two left volumes and allocate the free space?
Best, hirschferkel
Disk: /dev/disk2 geometry: 243201/255/63 [3907029168 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: AF 1023 254 63 - 1023 254 63 [ 390965067 - 390965064] HFS+
2: 05 1023 254 63 - 1023 254 63 [ 781930131 - 2345790390] Extended DOS
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: AF 1023 254 63 - 1023 254 63 [2736755457 - 390965064] HFS+
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
Lösung
The procedure posted in this answer relies on the use of the command gdisk
. The command is not included with macOS. Included is the procedure for installing this command.
Note: Disk identifiers (
disk2
for example) and partition identifiers (disk2s1
for example) can be set arbitrarily by macOS. I tried to post the correct identifiers. Before executing a command, you may want to review the output fromdiskutil list
to insure the correct identifier is being used.
Install gdisk
- Download gdisk from the internet. I assume this will be downloaded to your
Downloads
folder. Execute the command given below to remove the quarantine.
xattr -d com.apple.quarantine ~/Downloads/gdisk-1.0.4.pkg
Use the Finder application to install
gdisk
.
Convert a MBR Partition Table to a GUID Partition Table (GPT).
Note: Not all drives using a MBR Partition Table can be converted to use a GUID Partition Table (GPT). The drive posted in the OP's question happens a drive that can be easily converted.
Use command given below to determine the identifier for the drive. I will assume this is
disk2
, as shown in your question.diskutil list
Execute the following commands to perform the conversion.
diskutil unmountdisk disk2 gdisk /dev/disk2 w y
Below is an example.
$ diskutil unmountdisk disk2 Unmount of all volumes on disk2 was successful $ gdisk /dev/disk2 GPT fdisk (gdisk) version 1.0.4 Warning: Devices opened with shared lock will not have their partition table automatically reloaded! Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! *************************************************************** 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/disk2. 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.
Eject the drive by executing the command given below.
diskutil eject disk2
Unplug the drive and plug back in. Execute the command below to see if the drive identifier has changed.
diskutil list
Add an EFI Partition
Note: The defaults shown in the examples may not match what you will see.
Create the partition. Selecting a partition type of Linux prevents the partition from mounting before being formatted.
diskutil unmountdisk disk2 gdisk /dev/disk2 s n 3 40 409639 8300 s w y
Below is an example.
$ diskutil unmountdisk disk2 Unmount of all volumes on disk2 was successful $ gdisk /dev/disk2 GPT fdisk (gdisk) version 1.0.4 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): s You may need to edit /etc/fstab and/or your boot loader configuration! Command (? for help): n Partition number (2-128, default 2): 3 First sector (34-3906250006, default = 40) or {+-}size{KMGTP}: 40 Last sector (40-409639, default = 409639) or {+-}size{KMGTP}: 409639 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): s You may need to edit /etc/fstab and/or your boot loader configuration! 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/disk2. 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.
Eject the drive by executing the command given below.
diskutil eject disk2
Unplug the drive and plug back in. Execute the command below to see if the drive identifier has changed.
diskutil list
FAT32 format the partition.
newfs_msdos -F 32 -v EFI /dev/rdisk2s1
Below is an example.
$ newfs_msdos -F 32 -v EFI /dev/rdisk2s1 512 bytes per physical sector /dev/rdisk2s1: 403266 sectors in 403266 FAT32 clusters (512 bytes/cluster) bps=512 spc=1 res=32 nft=2 mid=0xf8 spt=32 hds=32 hid=40 drv=0x80 bsec=409600 bspf=3151 rdcl=2 infs=1 bkbs=6
Change the partition type to EFI.
diskutil unmountdisk disk2 gdisk /dev/disk2 t 1 EF00 w y
Below is an example.
$ diskutil unmountdisk disk2 Unmount of all volumes on disk2 was successful $ gdisk /dev/disk2 GPT fdisk (gdisk) version 1.0.4 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): t Partition number (1-2): 1 Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = AF00): EF00 Changed type of partition to 'EFI System' 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/disk2. 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.
Add a New Mac OS Extended (Journaled) Volume
The free space before the original two volumes can not be added to either of these volumes. To reclaim this space, one or more new volumes need to be created. The procedure below creates one new volume.
Create the partition. Selecting a partition type of Linux prevents the partition from mounting before being formatted.
diskutil unmountdisk disk2 gdisk /dev/disk2 n 4 409640 69999999 8300 s w y
Below is an example.
$ diskutil unmountdisk disk2 Unmount of all volumes on disk2 was successful $ gdisk /dev/disk2 GPT fdisk (gdisk) version 1.0.4 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): n Partition number (2-128, default 2): 4 First sector (34-3906250006, default = 409640) or {+-}size{KMGTP}: 409640 Last sector (409640-3906250006, default = 3906250006) or {+-}size{KMGTP}: 69999999 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): s You may need to edit /etc/fstab and/or your boot loader configuration! 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/disk2. 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.
Eject the drive by executing the command given below.
diskutil eject disk2
Unplug the drive and plug back in. Execute the command below to see if the drive identifier has changed.
diskutil list
Format the partition Mac OS Extended (Journaled). This will also change the partition type to the correct value.
diskutil erasevolume jhfs+ Name3 disk2s2
Below is an example.
$ diskutil erasevolume jhfs+ Name3 disk2s2 Started erase on disk2s2 My2TB Unmounting disk Erasing Initialized /dev/rdisk2s2 as a 33 GB case-insensitive HFS Plus volume with a 8192k journal Mounting disk Finished erase on disk2s2 Name3
Reclaim the Remaining Free Space
Add the remaining free space to the existing Volumes. Any free space that is remaining after entering these commands should be fairly small and is required to be reserved for use by macOS.
diskutil resizevolume disk2s2 R
diskutil resizevolume disk2s3 R
diskutil resizevolume disk2s4 R
Below is an example.
$ diskutil resizevolume disk2s2 R
Unable to find disk for disk2s2
$ diskutil resizevolume disk2s2 R
Resizing to full size (fit to fill)
Started partitioning on disk2s2 Name3
Verifying the disk
Verifying file system
Volume was successfully unmounted
Performing fsck_hfs -fn -x /dev/rdisk2s2
Checking Journaled HFS Plus volume
Checking extents overflow file
Checking catalog file
Checking multi-linked files
Checking catalog hierarchy
Checking extended attributes file
Checking volume bitmap
Checking volume information
The volume Name3 appears to be OK
File system check exit code is 0
Restoring the original state found as mounted
Resizing
Modifying partition map
Growing file system
Finished partitioning on disk2s2 Name3
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *2.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS Name3 199.8 GB disk2s2
3: Apple_HFS Name1 200.2 GB disk2s3
4: Apple_HFS Name2 200.2 GB disk2s4
$ diskutil resizevolume disk2s3 R
Resizing to full size (fit to fill)
Started partitioning on disk2s3 Name1
Verifying the disk
Verifying file system
Volume was successfully unmounted
Performing fsck_hfs -fn -x /dev/rdisk2s3
Checking Journaled HFS Plus volume
Checking extents overflow file
Checking catalog file
Checking multi-linked files
Checking catalog hierarchy
Checking extended attributes file
Checking volume bitmap
Checking volume information
The volume Name1 appears to be OK
File system check exit code is 0
Restoring the original state found as mounted
Resizing
Modifying partition map
Growing file system
Finished partitioning on disk2s3 Name1
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *2.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS Name3 199.8 GB disk2s2
3: Apple_HFS Name1 1.2 TB disk2s3
4: Apple_HFS Name2 200.2 GB disk2s4
$ diskutil resizevolume disk2s4 R
Resizing to full size (fit to fill)
Started partitioning on disk2s4 Name2
Verifying the disk
Verifying file system
Volume was successfully unmounted
Performing fsck_hfs -fn -x /dev/rdisk2s4
Checking Journaled HFS Plus volume
Checking extents overflow file
Checking catalog file
Checking multi-linked files
Checking catalog hierarchy
Checking extended attributes file
Checking volume bitmap
Checking volume information
The volume Name2 appears to be OK
File system check exit code is 0
Restoring the original state found as mounted
Resizing
Modifying partition map
Growing file system
Finished partitioning on disk2s4 Name2
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *2.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS Name3 199.8 GB disk2s2
3: Apple_HFS Name1 1.2 TB disk2s3
4: Apple_HFS Name2 598.6 GB disk2s4
Appendix
Descriptions for the gdisk
commands is given below.
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu