macOS-Simple-KVM icon indicating copy to clipboard operation
macOS-Simple-KVM copied to clipboard

Extend disks

Open dvelaren opened this issue 4 years ago • 11 comments

Hello,

I would like to first thank you for this incredible self-automated script, that helped me to run MacOS Catalina. I would like to ask you what is the procedure to extend hard drive space since I have tried out many things but I could not achieve to grow the disk space. Here are the steps I tried: General information: I have latest qemu installed (QEMU 5.0) in my Linux computer

Using qemu-img resize and Disk Util GUI

  1. I turned off the Mac and run the following command in my linux host:
qemu-img resize MyDisk.qcow2 +50G

The output of the command showed Image resized. 2. Then I launched the virtual macos machine with the usual command ``sudo ./basic.sh` and went into Disk Utility app. From here I first tried finding the Container disk, and clicked on Partition. Here are the images that I seen: Screen Shot 2020-05-06 at 9 00 51 AM Screen Shot 2020-05-06 at 9 03 03 AM Screen Shot 2020-05-06 at 9 02 01 AM Screen Shot 2020-05-06 at 9 01 39 AM

Using mac terminal (after qemu-img resize)

After errors in Disk Util, I tried to directly use a bash terminal from MacOS recovery menu (in order to have all disks available). I have done the following steps:

  1. Get the list of all disks:
diskutil apfs list

Which showed the all the disks and I found the target APFS Physical Store Disk (see highlighted - disk1s2): Screen Shot 2020-05-06 at 6 24 10 PM

  1. Resized the disk to the maximum capacity (0 at the end for maximum grow):
diskutil apfs resizeContainer disk1s2 0

Which showed me the following error:

Started APFS operation
Error: -69519: The target disk is too small for this operation, or a gap is required in your partition map which is missing or too small, which is often caused by an attempt to grow a partition beyond the beginning of another partition or beyond the end of partition map usable space

Any ideas what I could be doing wrong?

dvelaren avatar May 06 '20 16:05 dvelaren

I tried to extend the disk too with the same procedure as you. It didn't work but I know why : recovery partition is hided by MacOS but exists at the end of your initlial partition. Therefore, you cannot extend the main APFS parition because it must be contiguous and recovery is blocking the expansion. After many tries to move / delete the recovery partition, I ended to reinstall all the system because nothing works and I think it's currently impossible.

Froogy444 avatar May 13 '20 13:05 Froogy444

I tried to extend the disk too with the same procedure as you. It didn't work but I know why : recovery partition is hided by MacOS but exists at the end of your initlial partition. Therefore, you cannot extend the main APFS parition because it must be contiguous and recovery is blocking the expansion. After many tries to move / delete the recovery partition, I ended to reinstall all the system because nothing works and I think it's currently impossible.

That makes sense... Thanks for your findings! I will reinstall all the system again.

dvelaren avatar May 14 '20 07:05 dvelaren

i was able to extend the disk size from recovery mode.

first you need create new qcow2 partition with your new size in host and mount it to the vm then enter the recovery mode from clover and format the new added disk, next unmount the your old macos disk then restore it to new added disk.

laxamore avatar Oct 29 '20 06:10 laxamore

@laxamore: could you be more explicit please ! "mount it to the vm" : from a terminal ? add the disk in vm.xml ? "unmount the old": idem ? "restore to the new": commands ?

jphconstantin avatar Mar 08 '21 13:03 jphconstantin

@laxamore: could you be more explicit please ! "mount it to the vm" : from a terminal ? add the disk in vm.xml ?

Create new qcow2 with qemu-img create -f qcow2 MyDisk2.qcow2 124G (With the space you want) and add it to the end of basic.sh:

    -drive id=SystemDisk2,if=none,file=MyDisk2.qcow2 \
    -device ide-hd,bus=sata.5,drive=SystemDisk2 \

"unmount the old": idem ? "restore to the new": commands ?

Start the vm with ./basic.sh in the recovery mode from clover (Button with plus), open Disk Utility, format the new added disk to APFS, then unmount the old macos disk (Right click in partition > Unmount), In the new disk use restore button (Above Disk Utility) to restore the old disk Data in the new, this takes a while. Next close the vm and remove the old mount command from basic.sh, surely something like this:

    -drive id=SystemDisk,if=none,file=MyDisk.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \

And start the virtual machine as normal with ./basic.sh.

ollm avatar May 02 '21 10:05 ollm

Thanks @ollm , it's working great. This issue should be closed IMO.

gustavklopp avatar Jun 19 '21 11:06 gustavklopp

Thanks to @laxamore for bringing up the idea and @ollm for the detailed and working solution. This could finally make the big sur upgrade possible. It also seems this will save me from a much dreaded "Account Limit Reached" when reinstalling macOS with a bigger system-partition.

JackLeEmmerdeur avatar Jul 09 '21 22:07 JackLeEmmerdeur

I wanted to resize from 80GiB to 250GiB

This is after running sudo qemu-img resize MyDisk.qcow2 +170G on host machine

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *268.4 GB   disk0
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk0s1
   2:                 Apple_APFS ⁨Container disk2⁩         85.7 GB    disk0s2
                    (free space)                         182.5 GB   -

/dev/disk1 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *107.4 GB   disk1
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk1s1
   2:       Microsoft Basic Data ⁨Shared⁩                  107.2 GB   disk1s2

/dev/disk2 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +85.7 GB    disk2
                                 Physical Store disk0s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     28.1 GB    disk2s1
   2:                APFS Volume ⁨Preboot⁩                 267.9 MB   disk2s2
   3:                APFS Volume ⁨Recovery⁩                1.1 GB     disk2s3
   4:                APFS Volume ⁨VM⁩                      1.1 MB     disk2s4
   5:                APFS Volume ⁨Macintosh HD⁩            15.8 GB    disk2s5
   6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.8 GB    disk2s5s1

In OSX i had to run

diskutil repairdisk disk0
diskutil apfs resizeContainer disk0s2 0

After that everything work as expected

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *268.4 GB   disk0
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk0s1
   2:                 Apple_APFS ⁨Container disk2⁩         268.2 GB   disk0s2

/dev/disk1 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *107.4 GB   disk1
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk1s1
   2:       Microsoft Basic Data ⁨Shared⁩                  107.2 GB   disk1s2

/dev/disk2 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +268.2 GB   disk2
                                 Physical Store disk0s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     28.1 GB    disk2s1
   2:                APFS Volume ⁨Preboot⁩                 267.9 MB   disk2s2
   3:                APFS Volume ⁨Recovery⁩                1.1 GB     disk2s3
   4:                APFS Volume ⁨VM⁩                      1.1 MB     disk2s4
   5:                APFS Volume ⁨Macintosh HD⁩            15.8 GB    disk2s5
   6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.8 GB    disk2s5s1

This works for APFS disks For HFS disk type use diskutil resizeVolume / R

Sources:

matus-sabo avatar Feb 28 '22 12:02 matus-sabo

@lamanabie could you leave a PR here to incorporate instructions about this into the docs?

notAperson535 avatar Mar 01 '22 20:03 notAperson535

@lamanabie Thank you!!

slococo avatar Mar 18 '22 12:03 slococo

Thanks, @ollm This worked like a charm. I was able to upgrade my OSX to Ventura, though.

yaovicoder avatar Aug 22 '23 13:08 yaovicoder