sysconfig/mac-create-vdisk.sh
2026-01-26 19:03:26 +08:00

19 lines
862 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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.