Skip to content

Instantly share code, notes, and snippets.

@enihsyou
Last active March 18, 2020 15:45
Show Gist options
  • Save enihsyou/d8217414c720398333f4cbe33703220f to your computer and use it in GitHub Desktop.
Save enihsyou/d8217414c720398333f4cbe33703220f to your computer and use it in GitHub Desktop.
Create a RamDisk backup DMG image on macOS, detail in Chinese 中文: https://enihsyou.com/2019/02/04/48
#!/usr/bin/env bash
DISKNAME=${1-RAM}
IMAGE_LOCATION=${2-"/Users/enihsyou/Library/RAM.dmg"}
DISK_LOCATION=/Volumes/${DISKNAME}
sudo hdiutil create -srcfolder $DISK_LOCATION $IMAGE_LOCATION -ov
sudo chown enihsyou $IMAGE_LOCATION
#!/usr/bin/env bash
SIZE=${1-2048}
DISKNAME=${2-RAM}
BASE=/Volumes/$DISKNAME
[[ -e $BASE ]] && exit 0
DEVICE_IDENTIFIER=`diskutil info $DISKNAME | sed -n -E 's/^.*Device Identifier:.*(disk.*[0-9]).*/\1/p'`
if [[ -n $DEVICE_IDENTIFIER ]]; then
hdiutil mountvol $DEVICE_IDENTIFIER
exit 0
fi
DISK_ID=`hdiutil attach -nomount ram://$(( ${SIZE} * 1024 * 1024 / 512 ))` # a sector is 512 bytes
diskutil partitionDisk $DISK_ID GPT APFS "$DISKNAME" 0
# Backup location
IMAGE_LOCATION=${3-"/Users/enihsyou/Library/RAM.dmg"}
if [ -e $IMAGE_LOCATION ]; then
asr restore --source $IMAGE_LOCATION --target $BASE --erase --noverify --noprompt
else
cd $BASE
mkdir -p Cache/{Chrome,Firefox}
mkdir -p Compile/Hypers
mkdir -p Temp/{logs,HDFS/{namenode,datanode}}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment