Created
June 1, 2018 20:15
-
-
Save brodygov/7f3e528672f5b8e758e63fd434175b6d to your computer and use it in GitHub Desktop.
Create a linux ramdisk and mount it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
run() { | |
echo >&2 "+ $*" | |
"$@" | |
} | |
usage() { | |
cat >&2 <<EOM | |
usage: $(basename "$0") MOUNTPOINT [DEVICE] | |
MOUNTPOINT: where to mount the ramdisk | |
DEVICE: defaults to /dev/ram0 | |
For example: | |
$(basename "$0") /mnt/ramdisk | |
EOM | |
} | |
if [ $# -lt 1 ]; then | |
usage | |
exit 1 | |
fi | |
mountpoint="$1" | |
device="${2-/dev/ram0}" | |
if [ $UID -ne 0 ]; then | |
echo >&2 "error: this script must be run as root" | |
exit 2 | |
fi | |
if ! [ -d "$mountpoint" ]; then | |
run mkdir -v "$mountpoint" | |
fi | |
run mkfs.ext4 -O '^has_journal' -L ramdisk "$device" | |
run mount "$device" "$mountpoint" | |
mkdir -v "$mountpoint/private" | |
chmod 700 "$mountpoint/private" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment