Run Google Chrome and Chromium complete from RAM so that it doesn't leave any trace of cache or any browing related data on the Hard Disk. For this you need at least 4GB of free RAM.
sudo mkdir /media/ramdisk
sudo nano /etc/fstab
(add the following lines at the end of the file
# RAM Disk for browsers
tmpfs /media/ramdisk tmpfs size=15G,uid=1000,gid=1000,defaults,nodev,nosuid,noatime,mode=0755 0 0
(save the file and exit)
mkdir ~/bin/
nano ~/bin/chrome-ram
(paste the below code in this file)
#!/usr/bin/env bash
set -Eeuo pipefail
###############################################################################
# chrome-ram
#
# RAM-backed browser launcher for:
# - Google Chrome Stable
# - Google Chrome Dev
# - Chromium (including snap)
#
# Version 1.0.3 – multi‑instance, cache size fix
###############################################################################
VERSION="1.0.3"
###############################################################################
# USER CONFIGURATION
###############################################################################
RAMDISK="/media/ramdisk"
DEFAULT_BROWSER="stable" # stable | dev | chromium | auto
DEFAULT_DOWNLOAD_MODE="ask" # ask | ram | disk
RAM_CACHE_SIZE="1G"
RAM_MEDIA_CACHE_SIZE="512M"
VERIFY_TMPFS="yes"
AUTO_CLEANUP="yes"
KEEP_LOGS="no"
ALLOW_MULTIPLE_INSTANCES="yes" # changed to yes to allow multiple instances
COLOR_OUTPUT="yes"
DEBUG="no"
KEEP_SESSION="no" # yes = keep RAM session after Chrome exits
CHECK_WRITES="yes" # runtime file verification
REAL_CHROME_BINARIES="yes" # resolve symlinks to real binary
###############################################################################
# COLORS
###############################################################################
if [[ "$COLOR_OUTPUT" == "yes" ]] && [[ -t 1 ]]; then
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
CYAN="\033[0;36m"
NC="\033[0m"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
CYAN=""
NC=""
fi
###############################################################################
# LOGGING
###############################################################################
log()
{
echo -e "${BLUE}[*]${NC} $*"
return 0
}
success()
{
echo -e "${GREEN}[✓]${NC} $*"
return 0
}
warning()
{
echo -e "${YELLOW}[!]${NC} $*"
return 0
}
error()
{
echo -e "${RED}[✗]${NC} $*" >&2
}
die()
{
error "$*"
exit 1
}
debug()
{
if [[ "$DEBUG" == "yes" ]]; then
echo "[DEBUG] $*"
fi
return 0
}
###############################################################################
# GLOBAL VARIABLES
###############################################################################
SESSION=""
BROWSER_BIN=""
BROWSER_NAME=""
LOCKFILE=""
###############################################################################
# SAFETY CHECKS
###############################################################################
check_root()
{
if [[ "$EUID" -eq 0 ]]; then
die "Do not run this script as root."
fi
}
check_dependencies()
{
local deps=(
mktemp
mountpoint
findmnt
grep
awk
sed
realpath
bc
)
for d in "${deps[@]}"; do
command -v "$d" >/dev/null 2>&1 || \
die "Required command missing: $d"
done
}
###############################################################################
# RAMDISK CHECKS
###############################################################################
check_ramdisk()
{
[[ -d "$RAMDISK" ]] || \
die "$RAMDISK does not exist"
[[ -w "$RAMDISK" ]] || \
die "$RAMDISK is not writable"
if [[ "$VERIFY_TMPFS" == "yes" ]]; then
if ! mountpoint -q "$RAMDISK"; then
die "$RAMDISK is not mounted"
fi
# Use findmnt (robust) instead of parsing `mount` output
if ! findmnt -n -t tmpfs "$RAMDISK" >/dev/null 2>&1; then
die "$RAMDISK is not a tmpfs mount"
fi
fi
success "RAM disk verified: $RAMDISK"
}
###############################################################################
# FREE SPACE CHECK
###############################################################################
check_free_space()
{
# Convert human-readable sizes to bytes for estimation
local cache_bytes=$(to_bytes "$RAM_CACHE_SIZE")
local media_bytes=$(to_bytes "$RAM_MEDIA_CACHE_SIZE")
local needed=$((cache_bytes + media_bytes + 500*1024*1024))
local avail=$(df -P "$RAMDISK" | awk 'NR==2 {print $4}')
avail=$((avail * 1024))
if [[ $avail -lt $needed ]]; then
warning "RAM disk may have insufficient space (needed ~$((needed/1024/1024))MB, available $((avail/1024/1024))MB)"
else
debug "Sufficient free space on RAM disk"
fi
}
###############################################################################
# UNIT CONVERSION
###############################################################################
to_bytes()
{
local val="$1"
local num=$(echo "$val" | sed 's/[^0-9.]*//g')
local unit=$(echo "$val" | sed 's/[0-9.]*//g' | tr '[:lower:]' '[:upper:]')
case "$unit" in
K) echo "$num * 1024" | bc ;;
M) echo "$num * 1024 * 1024" | bc ;;
G) echo "$num * 1024 * 1024 * 1024" | bc ;;
T) echo "$num * 1024 * 1024 * 1024 * 1024" | bc ;;
*) echo "$num" ;; # assume bytes
esac
}
###############################################################################
# SNAP HELPER
###############################################################################
find_snap_binary()
{
local snap_name="$1"
local snap_dir="/snap/$snap_name/current"
local candidates=(
"$snap_dir/usr/lib/chromium-browser/chrome"
"$snap_dir/usr/lib/chromium-browser/chromium"
"$snap_dir/usr/bin/chromium"
"$snap_dir/usr/bin/chromium-browser"
"$snap_dir/usr/lib/chromium/chrome"
)
for candidate in "${candidates[@]}"; do
if [[ -x "$candidate" ]]; then
echo "$candidate"
return 0
fi
done
return 1
}
###############################################################################
# BROWSER DETECTION
###############################################################################
resolve_binary()
{
local bin="$1"
if [[ "$REAL_CHROME_BINARIES" == "yes" ]]; then
bin="$(readlink -f "$bin" 2>/dev/null || echo "$bin")"
fi
echo "$bin"
}
find_browser()
{
local requested="${1:-$DEFAULT_BROWSER}"
case "$requested" in
stable)
if [[ -x /usr/bin/google-chrome-stable ]]; then
BROWSER_BIN="/usr/bin/google-chrome-stable"
BROWSER_NAME="Google Chrome Stable"
elif command -v google-chrome >/dev/null; then
BROWSER_BIN="$(command -v google-chrome)"
BROWSER_NAME="Google Chrome Stable"
fi
;;
dev)
if [[ -x /usr/bin/google-chrome-unstable ]]; then
BROWSER_BIN="/usr/bin/google-chrome-unstable"
BROWSER_NAME="Google Chrome Dev"
elif command -v google-chrome-unstable >/dev/null; then
BROWSER_BIN="$(command -v google-chrome-unstable)"
BROWSER_NAME="Google Chrome Dev"
fi
;;
chromium)
if [[ -x /usr/bin/chromium ]]; then
BROWSER_BIN="/usr/bin/chromium"
BROWSER_NAME="Chromium"
elif [[ -x /usr/bin/chromium-browser ]]; then
BROWSER_BIN="/usr/bin/chromium-browser"
BROWSER_NAME="Chromium"
elif command -v chromium >/dev/null; then
local cmd_path="$(command -v chromium)"
if [[ -L "$cmd_path" ]] && readlink -f "$cmd_path" | grep -q "/snap/"; then
if SNAP_BIN="$(find_snap_binary chromium)"; then
BROWSER_BIN="$SNAP_BIN"
BROWSER_NAME="Chromium (snap)"
success "Using snap binary: $BROWSER_BIN"
else
die "Unable to find real Chromium binary in snap"
fi
else
BROWSER_BIN="$cmd_path"
BROWSER_NAME="Chromium"
fi
elif command -v chromium-browser >/dev/null; then
BROWSER_BIN="$(command -v chromium-browser)"
BROWSER_NAME="Chromium"
else
die "Chromium not found"
fi
;;
auto)
if [[ -x /usr/bin/google-chrome-stable ]]; then
BROWSER_BIN="/usr/bin/google-chrome-stable"
BROWSER_NAME="Google Chrome Stable"
elif [[ -x /usr/bin/google-chrome-unstable ]]; then
BROWSER_BIN="/usr/bin/google-chrome-unstable"
BROWSER_NAME="Google Chrome Dev"
elif command -v chromium >/dev/null; then
local cmd_path="$(command -v chromium)"
if [[ -L "$cmd_path" ]] && readlink -f "$cmd_path" | grep -q "/snap/"; then
if SNAP_BIN="$(find_snap_binary chromium)"; then
BROWSER_BIN="$SNAP_BIN"
BROWSER_NAME="Chromium (snap)"
else
die "Unable to find real Chromium binary in snap"
fi
else
BROWSER_BIN="$cmd_path"
BROWSER_NAME="Chromium"
fi
elif command -v chromium-browser >/dev/null; then
BROWSER_BIN="$(command -v chromium-browser)"
BROWSER_NAME="Chromium"
fi
;;
*)
die "Unknown browser: $requested"
;;
esac
[[ -n "$BROWSER_BIN" ]] || \
die "Browser not installed"
BROWSER_BIN="$(resolve_binary "$BROWSER_BIN")"
success "Browser detected: $BROWSER_NAME"
debug "Executable: $BROWSER_BIN"
}
###############################################################################
# LOCK MANAGEMENT (now effectively disabled because ALLOW_MULTIPLE_INSTANCES=yes)
###############################################################################
create_lock()
{
if [[ "$ALLOW_MULTIPLE_INSTANCES" != "yes" ]]; then
local lock_name="chrome-ram-${BROWSER_NAME// /_}-${USER}.lock"
LOCKFILE="/tmp/$lock_name"
if [[ -e "$LOCKFILE" ]]; then
local old_pid
old_pid="$(cat "$LOCKFILE" 2>/dev/null || true)"
if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then
die "Another instance of $BROWSER_NAME is running (PID $old_pid)"
else
warning "Removing stale lock file for $BROWSER_NAME"
rm -f "$LOCKFILE"
fi
fi
echo "$$" > "$LOCKFILE"
else
debug "Locking disabled – multiple instances allowed"
fi
}
remove_lock()
{
if [[ -n "$LOCKFILE" ]] && [[ -f "$LOCKFILE" ]]; then
local lock_pid
lock_pid="$(cat "$LOCKFILE" 2>/dev/null || true)"
if [[ "$lock_pid" == "$$" ]]; then
rm -f "$LOCKFILE"
fi
fi
}
###############################################################################
# RAM SESSION CREATION
###############################################################################
create_session()
{
log "Creating RAM browser session"
SESSION="$(mktemp -d "$RAMDISK/chrome-session-XXXXXX")"
mkdir -p \
"$SESSION/home/.config" \
"$SESSION/home/.cache" \
"$SESSION/home/.local/state" \
"$SESSION/home/.local/share" \
"$SESSION/home/.pki" \
"$SESSION/home/Desktop" \
"$SESSION/home/Documents" \
"$SESSION/home/Downloads" \
"$SESSION/home/Pictures" \
"$SESSION/home/Videos" \
"$SESSION/profile" \
"$SESSION/cache" \
"$SESSION/runtime" \
"$SESSION/tmp" \
"$SESSION/logs"
chmod 700 "$SESSION"
success "RAM session created"
debug "Session path: $SESSION"
}
###############################################################################
# ENVIRONMENT ISOLATION
###############################################################################
setup_environment()
{
log "Building isolated browser environment"
export HOME="$SESSION/home"
export XDG_CONFIG_HOME="$SESSION/home/.config"
export XDG_CACHE_HOME="$SESSION/home/.cache"
export XDG_STATE_HOME="$SESSION/home/.local/state"
export XDG_DATA_HOME="$SESSION/home/.local/share"
export TMPDIR="$SESSION/tmp"
export GNUPGHOME="$SESSION/home/.gnupg"
mkdir -p "$GNUPGHOME"
success "HOME redirected to RAM"
}
###############################################################################
# DOWNLOAD LOCATION HANDLING
###############################################################################
configure_downloads()
{
case "$DEFAULT_DOWNLOAD_MODE" in
ask)
log "Download mode: Ask every time (default to RAM)"
;;
ram)
mkdir -p "$SESSION/home/Downloads"
log "Download mode: RAM"
;;
disk)
mkdir -p "$HOME/Downloads"
log "Download mode: Persistent disk"
;;
*)
die "Invalid download mode: $DEFAULT_DOWNLOAD_MODE"
;;
esac
}
###############################################################################
# SESSION VERIFICATION
###############################################################################
verify_session()
{
log "Verifying RAM environment"
[[ "$HOME" == "$SESSION/home" ]] || \
die "HOME isolation failed"
[[ "$TMPDIR" == "$SESSION/tmp" ]] || \
die "TMPDIR isolation failed"
[[ -d "$SESSION/profile" ]] || \
die "Chrome profile directory missing"
[[ -d "$SESSION/cache" ]] || \
die "Chrome cache directory missing"
success "RAM environment verified"
}
###############################################################################
# CLEANUP HANDLING
###############################################################################
cleanup()
{
local exit_code=$?
if [[ "$KEEP_SESSION" == "yes" ]]; then
warning "Keeping RAM session:"
echo "$SESSION"
else
if [[ "$AUTO_CLEANUP" == "yes" ]]; then
if [[ -n "$SESSION" ]] && [[ -d "$SESSION" ]]; then
log "Removing RAM session"
rm -rf "$SESSION"
fi
fi
fi
remove_lock
exit "$exit_code"
}
###############################################################################
# SIGNAL HANDLING
###############################################################################
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
###############################################################################
# CHROME FLAGS
###############################################################################
build_browser_flags()
{
local flags=()
# Convert cache sizes to bytes
local cache_bytes=$(to_bytes "$RAM_CACHE_SIZE")
local media_bytes=$(to_bytes "$RAM_MEDIA_CACHE_SIZE")
flags+=(
"--user-data-dir=$SESSION/profile"
"--disk-cache-dir=$SESSION/cache"
"--disk-cache-size=$cache_bytes"
"--media-cache-size=$media_bytes"
)
case "$DEFAULT_DOWNLOAD_MODE" in
ram|ask)
flags+=(
"--download-default-directory=$SESSION/home/Downloads"
)
;;
disk)
flags+=(
"--download-default-directory=$HOME/Downloads"
)
;;
esac
flags+=(
"--no-first-run"
"--disable-background-networking"
"--disable-background-timer-throttling"
"--disable-client-side-phishing-detection"
"--disable-component-update"
"--disable-default-apps"
"--disable-domain-reliability"
"--disable-features=OptimizationHints"
"--disable-sync"
"--disable-breakpad"
"--disable-crash-reporter"
"--metrics-recording-only"
"--password-store=basic"
"--disable-application-cache"
"--disable-offline-load-stale-cache"
"--disable-gpu-shader-disk-cache"
"--no-default-browser-check"
"--no-service-autorun"
)
printf '%s\n' "${flags[@]}"
}
###############################################################################
# LAUNCH BROWSER
###############################################################################
launch_browser()
{
log "Launching $BROWSER_NAME"
local flags=()
while IFS= read -r line; do
flags+=("$line")
done < <(build_browser_flags)
debug "Browser command:"
debug "$BROWSER_BIN ${flags[*]}"
"$BROWSER_BIN" "${flags[@]}" ${@+"$@"} &
local browser_pid=$!
debug "Browser PID: $browser_pid"
if [[ "$CHECK_WRITES" == "yes" ]]; then
runtime_write_check "$browser_pid" &
fi
wait "$browser_pid"
local result=$?
if [[ $result -ne 0 ]]; then
warning "Browser exited with code $result"
else
success "Browser closed normally"
fi
return $result
}
###############################################################################
# RUNTIME VERIFICATION
###############################################################################
runtime_check()
{
log "Runtime verification"
if [[ "$HOME" == "$SESSION/home" ]]; then
success "HOME is RAM-backed"
else
warning "HOME is not isolated"
fi
if [[ "$XDG_CACHE_HOME" == "$SESSION/home/.cache" ]]; then
success "Cache is RAM-backed"
else
warning "Cache location unexpected"
fi
if [[ -d "$SESSION/profile" ]]; then
success "Chrome profile location verified"
fi
}
runtime_write_check()
{
local pid="$1"
[[ -z "$pid" ]] && return 0
log "Checking browser file locations (PID: $pid)"
if command -v lsof >/dev/null; then
echo
echo "Open browser files outside RAM session:"
lsof -p "$pid" 2>/dev/null \
| grep -v "$SESSION" \
| grep -E 'config|cache|state|profile|Cookies|History' \
|| echo "None detected"
else
warning "lsof not installed – cannot check open files"
fi
}
validate_download_mode()
{
case "$DEFAULT_DOWNLOAD_MODE" in
ask|ram|disk) return 0 ;;
*) die "Invalid download mode: $DEFAULT_DOWNLOAD_MODE (must be ask, ram, or disk)" ;;
esac
}
###############################################################################
# COMMAND LINE HELP
###############################################################################
show_help()
{
cat <<EOF
chrome-ram $VERSION
RAM-backed browser launcher
Usage:
chrome-ram [browser] [options]
Browsers:
stable Launch Google Chrome Stable
dev Launch Google Chrome Dev
chromium Launch Chromium (supports snap)
auto Automatically select browser
Options:
--help Show this help
--version Show version
--self-test Run system checks only
--diagnose Show environment information
--debug Enable debug output
Examples:
chrome-ram stable
chrome-ram dev
chrome-ram chromium
chrome-ram auto --debug
Configuration is controlled at the top of the script.
EOF
}
###############################################################################
# VERSION
###############################################################################
show_version()
{
echo "chrome-ram version $VERSION"
}
###############################################################################
# DIAGNOSTICS
###############################################################################
diagnose()
{
cat <<EOF
chrome-ram diagnostics
Version:
$VERSION
Configured RAM disk:
$RAMDISK
Current shell HOME:
$HOME
Note:
The RAM HOME exists only inside the Chrome process.
Configured browser:
$DEFAULT_BROWSER
Download mode:
$DEFAULT_DOWNLOAD_MODE
tmpfs status:
EOF
mount | grep "$RAMDISK" || echo "Not mounted"
}
###############################################################################
# SELF TEST
###############################################################################
self_test()
{
echo
echo "chrome-ram self test"
echo "===================="
echo
check_root
success "User privileges OK"
check_dependencies
success "Dependencies OK"
check_ramdisk
success "tmpfs check OK"
find_browser auto
success "Browser detection OK"
create_session
setup_environment
verify_session
success "RAM environment OK"
cleanup
echo
success "All tests passed"
}
###############################################################################
# ARGUMENT PARSER
###############################################################################
parse_arguments()
{
BROWSER_REQUEST="$DEFAULT_BROWSER"
PASSTHROUGH_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
stable|dev|chromium|auto)
BROWSER_REQUEST="$1"
;;
--help|-h)
show_help
exit 0
;;
--version)
show_version
exit 0
;;
--self-test)
self_test
exit 0
;;
--diagnose)
diagnose
exit 0
;;
--debug)
DEBUG="yes"
;;
*)
PASSTHROUGH_ARGS+=("$1")
;;
esac
shift
done
}
###############################################################################
# FINAL MAIN
###############################################################################
main()
{
parse_arguments "$@"
check_root
check_dependencies
check_ramdisk
find_browser "$BROWSER_REQUEST"
validate_download_mode
create_lock
check_free_space
create_session
setup_environment
configure_downloads
verify_session
runtime_check
success "Starting $BROWSER_NAME"
launch_browser "${PASSTHROUGH_ARGS[@]:-}"
}
main "$@"
chmod a+x ~/bin/chrome-ram
create keyboard shortcuts to launch Chrome Dev, Chrome Stable and Chromium in incognito mode as follows
~/bin/chrome-ram dev --incognito
~/bin/chrome-ram stable --incognito
~/bin/chrome-ram chromium --incognito