Persistent Workspace Setup
Configure your GPU instance to persist your home directory, packages, and configurations across restarts.
Overview
By default, GPU instances use ephemeral storage - any files, packages, or configurations in your home directory are lost when the instance restarts. This guide shows you how to set up a persistent workspace so your environment survives restarts.
Prerequisites
- A running GPU instance with persistent storage attached
- SSH or terminal access to your instance
Quick Setup
Run this one-time setup script to configure workspace persistence:
#!/bin/bash
# Persistent Workspace Setup Script
# Set your persistent storage mount (adjust to your volume name)
STORAGE_PATH="/mnt/your-volume"
# Create workspace directories on persistent storage
mkdir -p $STORAGE_PATH/workspace/{home,pip,conda,cache}
# Create a setup script that runs on login
cat > $STORAGE_PATH/workspace/init.sh << 'EOF'
#!/bin/bash
# Link home directories to persistent storage
STORAGE_PATH="/mnt/your-volume"
# Create symlinks for common directories
ln -sfn $STORAGE_PATH/workspace/pip ~/.local
ln -sfn $STORAGE_PATH/workspace/cache ~/.cache
# Set environment variables
export PIP_CACHE_DIR="$STORAGE_PATH/workspace/pip"
export HF_HOME="$STORAGE_PATH/workspace/cache/huggingface"
export TRANSFORMERS_CACHE="$HF_HOME"
# Source any custom bashrc
if [ -f "$STORAGE_PATH/workspace/home/.bashrc_custom" ]; then
source $STORAGE_PATH/workspace/home/.bashrc_custom
fi
echo "Workspace loaded from persistent storage"
EOF
chmod +x $STORAGE_PATH/workspace/init.sh
# Add to bashrc for automatic loading
echo 'source /mnt/your-volume/workspace/init.sh' >> ~/.bashrc
echo "Setup complete! Your workspace will now persist across restarts."What Gets Persisted
| Directory | Purpose | Persisted |
|---|---|---|
~/.local | pip packages, local binaries | Yes (symlinked) |
~/.cache | pip cache, HuggingFace models | Yes (symlinked) |
$STORAGE_PATH/workspace | Your projects, scripts, data | Yes (on NFS) |
/home/ubuntu | Home directory (system files) | No (ephemeral) |
Recommended Workflow
Store Projects on Persistent Storage
# Clone repos directly to persistent storage
cd /mnt/your-volume/workspace
git clone https://github.com/your/project.git
# Create a symlink in home for convenience
ln -s /mnt/your-volume/workspace/project ~/projectInstall Packages with Persistence
# Install packages (will use persisted pip cache)
pip install torch transformers
# Or use a requirements file from persistent storage
pip install -r /mnt/your-volume/workspace/project/requirements.txtStore Environment Variables
# Add custom environment variables
cat >> /mnt/your-volume/workspace/home/.bashrc_custom << 'EOF'
export MY_API_KEY="your-key-here"
export PROJECT_ROOT="/mnt/your-volume/workspace/project"
alias project="cd $PROJECT_ROOT"
EOFAfter Restart
When your instance restarts:
- Persistent storage is automatically remounted at
/mnt/your-volume - Your
.bashrcsources the init script (you need to re-run the setup once on fresh instances) - Symlinks restore access to your pip packages and caches
- Your projects and data are immediately available
Important Note
If you terminate your instance (not just restart), you'll need to re-run the setup script on your new instance. The data on persistent storage remains, but the symlinks and bashrc entries need to be recreated.
Pro Tips
Use a Setup Script Repository
# Store your setup script on GitHub
# Then on any new instance:
curl -sSL https://raw.githubusercontent.com/you/dotfiles/main/setup.sh | bashDocker/Container Workflows
If you're using Docker:
# Mount persistent storage into containers
docker run -v /mnt/your-volume:/data -it your-imageConda Environments
# Store conda environments on persistent storage
mkdir -p /mnt/your-volume/workspace/conda/envs
conda config --prepend envs_dirs /mnt/your-volume/workspace/conda/envs
# Create environment (persisted automatically)
conda create -n myenv python=3.10Troubleshooting
Packages not found after restart
Ensure your init script is being sourced:
# Check if init script exists
cat /mnt/your-volume/workspace/init.sh
# Manually source it
source /mnt/your-volume/workspace/init.sh
# Verify symlinks
ls -la ~/.localPermission errors
# Fix ownership
sudo chown -R $USER:$USER /mnt/your-volume/workspaceNeed Help?
Contact us at support@packet.ai
