This commit is contained in:
Luk
2026-01-26 19:03:26 +08:00
parent 25632ab024
commit cbe9d7ef85
5 changed files with 50 additions and 12 deletions

18
mac-create-vdisk.sh Normal file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
DISKNAME=vdisk
DISKSIZE=33554432 # 磁盘扇区数,每个扇区大小是 512 字节n*1024*1024*1024/512 = n Gigabytes. Do NOT set the formula to DISKSIZE.
# 虚拟磁盘并不是一创建就把内存空间划走,而是等到真正写入了虚拟磁盘的时候,才会使用对应的内存空间,所以给虚拟磁盘分配大一点的空间是没有问题的
if [ -d /Volumes/$DISKNAME ]; then
echo 'Found /Volumes/$DISKNAME!'
else
DISKID=$(hdid -nomount ram://$DISKSIZE)
diskutil apfs create ${DISKID} $DISKNAME
fi
# copy this script to some public folder, e.g. `sudo cp this-script.sh /etc/`, because in my test, it doesn't work in /Users/...
# copy the corresponding plist file to /Library/LaunchDaemons/,
# optionally run `sudo launchctl load /Library/LaunchDaemons/my-launch-file.plist` immediately for test.