APFS Image Slimming Critical Task #146

Open
opened 2025-12-29 05:23:12 +01:00 by adam · 6 comments
Owner

Originally created by @sickcodes on GitHub (Mar 18, 2021).

Big Sur is using APFS only...

Failed (read only)
image

APFS mountable in Linux but READ ONLY

Therefore it must be done inside OSX.

Secondly, Big Sur must be used to mount Big Sur

How to mount Big Sur writable:

Boot into recovery mode with two disks https://github.com/sickcodes/Docker-OSX#mount-a-disk-inside-osx-from-the-host

Disable SIP

# inside Recovery Disk shell
csrutil authenticated-root disable
csrutil disable
reboot

Log into Big Sur good one

Unmount the only other disk that you can unmount in disk utility.

Sometimes it's disk3 disk4 or disk5

Remount as writable, as shown below thanks to https://mobile.twitter.com/ebadtweet/status/1275454103900971012

The partition to remount is always s2

sudo mount -o nobrowse -t apfs /dev/diskNsM /path/to/mntpoint

cd your mountpoint

ncdu is handy for finding large files today delete

After finishing, create a snapshot and reboot
sudo bless --folder /path/to/mntpoint/System/Library/CoreServices --bootefi --create-snapshot

image

However this image will not shrink when using https://github.com/sickcodes/Docker-OSX#how-to-reduce-the-size-of-the-image

This is crucial for development as we need much smaller images, 40GB is unwieldy for security research and takes even a few minutes on a good SSD to copy it.

Originally created by @sickcodes on GitHub (Mar 18, 2021). Big Sur is using APFS only... Failed (read only) ![image](https://user-images.githubusercontent.com/65906298/111672981-67f79600-8812-11eb-92ca-df4f2ed2274e.png) APFS mountable in Linux but READ ONLY Therefore it must be done inside OSX. Secondly, Big Sur must be used to mount Big Sur ### How to mount Big Sur writable: Boot into recovery mode with two disks https://github.com/sickcodes/Docker-OSX#mount-a-disk-inside-osx-from-the-host Disable SIP ```bash # inside Recovery Disk shell csrutil authenticated-root disable csrutil disable reboot ``` Log into Big Sur good one Unmount the only other disk that you can unmount in disk utility. Sometimes it's disk3 disk4 or disk5 Remount as writable, as shown below thanks to https://mobile.twitter.com/ebadtweet/status/1275454103900971012 The partition to remount is always s2 `sudo mount -o nobrowse -t apfs /dev/diskNsM /path/to/mntpoint` cd your mountpoint `ncdu` is handy for finding large files today delete After finishing, create a snapshot and reboot `sudo bless --folder /path/to/mntpoint/System/Library/CoreServices --bootefi --create-snapshot` ![image](https://user-images.githubusercontent.com/65906298/111674265-bbb6af00-8813-11eb-910b-ead21600a615.png) However this image will not shrink when using https://github.com/sickcodes/Docker-OSX#how-to-reduce-the-size-of-the-image This is crucial for development as we need much smaller images, 40GB is unwieldy for security research and takes even a few minutes on a good SSD to copy it.
adam added the enhancement label 2025-12-29 05:23:12 +01:00
Author
Owner

@sickcodes commented on GitHub (Mar 18, 2021):

image

Ultimate

rm -rf mnt/usr/share/man/*
rm -rf mnt/System/Library/Desktop\ Pictures/*

Okay

rm -rf mnt/System/Applications/Music.app/*
rm -rf mnt/System/Applications/Books.app/*
rm -rf mnt/System/Applications/TV.app/*
rm -rf mnt/System/Applications/Maps.app/*
rm -rf mnt/System/Applications/Podcasts.app/*
rm -rf mnt/System/Applications/Music.app/*

Fail


rm -rf mnt/usr/share/tokenizer/*
rm -rf mnt/System/iOSSupport/System/Library/PrivateFrameworks/*
rm -rf mnt/System/iOSSupport/System/Library/Frameworks/*
rm -rf mnt/System/iOSSupport/System/Library/AccessibilityBundles/*
rm -rf mnt/System/Library/Templates/*

Not sure


rm -rf mnt/System/Library/SpeechBase/*
rm -rf mnt/System/Library/Audio/*
rm -rf mnt/System/Library/Frameworks/Vision.Framework/Versions/A/Resources/*

@sickcodes commented on GitHub (Mar 18, 2021): ![image](https://user-images.githubusercontent.com/65906298/111675216-c9b8ff80-8814-11eb-8d80-dc5772fef46f.png) Ultimate ``` rm -rf mnt/usr/share/man/* rm -rf mnt/System/Library/Desktop\ Pictures/* ``` Okay ``` rm -rf mnt/System/Applications/Music.app/* rm -rf mnt/System/Applications/Books.app/* rm -rf mnt/System/Applications/TV.app/* rm -rf mnt/System/Applications/Maps.app/* rm -rf mnt/System/Applications/Podcasts.app/* rm -rf mnt/System/Applications/Music.app/* ``` Fail ``` rm -rf mnt/usr/share/tokenizer/* rm -rf mnt/System/iOSSupport/System/Library/PrivateFrameworks/* rm -rf mnt/System/iOSSupport/System/Library/Frameworks/* rm -rf mnt/System/iOSSupport/System/Library/AccessibilityBundles/* rm -rf mnt/System/Library/Templates/* ``` Not sure ``` rm -rf mnt/System/Library/SpeechBase/* rm -rf mnt/System/Library/Audio/* rm -rf mnt/System/Library/Frameworks/Vision.Framework/Versions/A/Resources/* ```
Author
Owner

@Diassico commented on GitHub (Mar 18, 2021):

Big Sur is using

Failed (read only)
image

APFS mountable in Linux but READ ONLY

Therefore it must be done inside OSX.

Secondly, Big Sur must be used to mount Big Sur

How to mount Big Sur writable:

Boot into recovery mode with two disks https://github.com/sickcodes/Docker-OSX#mount-a-disk-inside-osx-from-the-host

Disable SIP

# inside Recovery Disk shell
csrutil authenticated-root disable
csrutil disable
reboot

Log into Big Sur good one

Unmount the only other disk that you can unmount in disk utility.

Sometimes it's disk3 disk4 or disk5

Remount as writable, as shown below thanks to https://mobile.twitter.com/ebadtweet/status/1275454103900971012

The partition to remount is always s2

sudo mount -o nobrowse -t apfs /dev/diskNsM /path/to/mntpoint

cd your mountpoint

ncdu is handy for finding large files today delete

After finishing, create a snapshot and reboot
sudo bless --folder /path/to/mntpoint/System/Library/CoreServices --bootefi --create-snapshot

image

However this image will not shrink when using https://github.com/sickcodes/Docker-OSX#how-to-reduce-the-size-of-the-image

This is crucial for development as we need much smaller images, 40GB is unwieldy for security research and takes even a few minutes on a good SSD to copy it.

@Diassico commented on GitHub (Mar 18, 2021): > Big Sur is using > > Failed (read only) > ![image](https://user-images.githubusercontent.com/65906298/111672981-67f79600-8812-11eb-92ca-df4f2ed2274e.png) > > APFS mountable in Linux but READ ONLY > > Therefore it must be done inside OSX. > > Secondly, Big Sur must be used to mount Big Sur > > ### How to mount Big Sur writable: > > Boot into recovery mode with two disks https://github.com/sickcodes/Docker-OSX#mount-a-disk-inside-osx-from-the-host > > Disable SIP > > ```bash > # inside Recovery Disk shell > csrutil authenticated-root disable > csrutil disable > reboot > ``` > > Log into Big Sur good one > > Unmount the only other disk that you can unmount in disk utility. > > Sometimes it's disk3 disk4 or disk5 > > Remount as writable, as shown below thanks to https://mobile.twitter.com/ebadtweet/status/1275454103900971012 > > The partition to remount is always s2 > > `sudo mount -o nobrowse -t apfs /dev/diskNsM /path/to/mntpoint` > > cd your mountpoint > > `ncdu` is handy for finding large files today delete > > After finishing, create a snapshot and reboot > `sudo bless --folder /path/to/mntpoint/System/Library/CoreServices --bootefi --create-snapshot` > > ![image](https://user-images.githubusercontent.com/65906298/111674265-bbb6af00-8813-11eb-910b-ead21600a615.png) > > However this image will not shrink when using https://github.com/sickcodes/Docker-OSX#how-to-reduce-the-size-of-the-image > > This is crucial for development as we need much smaller images, 40GB is unwieldy for security research and takes even a few minutes on a good SSD to copy it.
Author
Owner

@sickcodes commented on GitHub (Mar 19, 2021):

Reasonable explanation for 40GB image lol!

40gb

@sickcodes commented on GitHub (Mar 19, 2021): Reasonable explanation for 40GB image lol! ![40gb](https://user-images.githubusercontent.com/65906298/111845805-7cfd2380-88fd-11eb-8d0d-310c745a6c2c.png)
Author
Owner

@sickcodes commented on GitHub (Mar 19, 2021):

Testing non-qcow images currently!

EDIT: useless code below do not use!

FAIL READ ONLY

touch "${APFS_NAME}"
fallocate --zero-range --length 50G "${APFS_NAME}" 
mkfs.apfs "${APFS_NAME}"

mkdir -p ./mnt
sudo losetup -f 
sudo losetup /dev/loop0 "${APFS_NAME}"
sudo apfs-fuse -o uid=0,gid=0,allow_other -p 1 /dev/loop0 ./mnt
# mount the disk
ls ./mnt
# private-dir  root
sudo umount ./mnt
sleep 1
sudo losetup -d /dev/loop0

Boot two disks

IMAGE_NAME=${PWD}/mac_hdd_ng_big_sur.img"
DISK_TWO="${PWD}/mac_hdd_ng_nonqcow.img"
docker run -it \
    --device /dev/kvm \
    -e "DISPLAY=${DISPLAY:-:0.0}" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e RAM=10 \
    -p 50922:10022 \
    -e GENERATE_SPECIFIC=true \
    -e DEVICE_MODEL="${DEVICE_MODEL}" \
    -e SERIAL="${SERIAL}" \
    -e BOARD_SERIAL="${BOARD_SERIAL}" \
    -e UUID="${UUID}" \
    -e MAC_ADDRESS="${MAC_ADDRESS}" \
    -e NETWORKING=vmxnet3 \
    -v "${IMAGE_NAME}":/image \
    -e WIDTH=1600 \
    -e HEIGHT=900 \
    -v "${DISK_TWO}:/disktwo" \
    -e EXTRA='-device ide-hd,bus=sata.5,drive=DISKTWO -drive id=DISKTWO,if=none,file=/disktwo,format=raw' \
    -e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \
    sickcodes/docker-osx:naked

Installing now...

@sickcodes commented on GitHub (Mar 19, 2021): Testing non-qcow images currently! EDIT: useless code below do not use! FAIL READ ONLY ~~~APFS_NAME=mac_hdd_ng_nonqcow.img touch "${APFS_NAME}" fallocate --zero-range --length 50G "${APFS_NAME}" mkfs.apfs "${APFS_NAME}" mkdir -p ./mnt sudo losetup -f sudo losetup /dev/loop0 "${APFS_NAME}" sudo apfs-fuse -o uid=0,gid=0,allow_other -p 1 /dev/loop0 ./mnt ~~~ ```bash # mount the disk ls ./mnt # private-dir root sudo umount ./mnt sleep 1 sudo losetup -d /dev/loop0 ``` Boot two disks ```bash IMAGE_NAME=${PWD}/mac_hdd_ng_big_sur.img" DISK_TWO="${PWD}/mac_hdd_ng_nonqcow.img" docker run -it \ --device /dev/kvm \ -e "DISPLAY=${DISPLAY:-:0.0}" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -e RAM=10 \ -p 50922:10022 \ -e GENERATE_SPECIFIC=true \ -e DEVICE_MODEL="${DEVICE_MODEL}" \ -e SERIAL="${SERIAL}" \ -e BOARD_SERIAL="${BOARD_SERIAL}" \ -e UUID="${UUID}" \ -e MAC_ADDRESS="${MAC_ADDRESS}" \ -e NETWORKING=vmxnet3 \ -v "${IMAGE_NAME}":/image \ -e WIDTH=1600 \ -e HEIGHT=900 \ -v "${DISK_TWO}:/disktwo" \ -e EXTRA='-device ide-hd,bus=sata.5,drive=DISKTWO -drive id=DISKTWO,if=none,file=/disktwo,format=raw' \ -e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \ sickcodes/docker-osx:naked ``` Installing now...
Author
Owner

@sickcodes commented on GitHub (Mar 20, 2021):

Image can be shrunk later, using a second disk's Big Sur image.

Must be done on another Big Sur.

And must be done on a separate disk as above code because you can't resize while you're booted off recovery EFI disk.

Screenshot_2021-03-19_23-05-52

@sickcodes commented on GitHub (Mar 20, 2021): Image can be shrunk later, using a second disk's Big Sur image. Must be done on another Big Sur. And must be done on a separate disk as above code because you can't resize while you're booted off recovery EFI disk. ![Screenshot_2021-03-19_23-05-52](https://user-images.githubusercontent.com/65906298/111850346-f26df180-8907-11eb-97e6-9428c2f214b0.png)
Author
Owner

@sickcodes commented on GitHub (Mar 20, 2021):

Got it down to 17GB, will be adding :big-sur-auto or :auto-big-sur shortly, or just name it both lol

@sickcodes commented on GitHub (Mar 20, 2021): Got it down to 17GB, will be adding `:big-sur-auto` or `:auto-big-sur` shortly, or just name it both lol
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX-sickcodes#146