Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting up a gpu (nvidia) ec2 instance with ubuntu and electron for headless webgl rendering
#!/bin/bash -xe
# Unload nouveau
sudo rmmod nouveau
# Load nvidia
sudo modprobe nvidia
# Configure X
sudo nvidia-xconfig --use-display-device=None --virtual=1280x1024 --output-xconfig=/etc/X11/xorg.conf --busid=PCI:0:3:0 --enable-all-gpus
#!/bin/bash -xe
# Update
apt-get update -y
# Install necessary packages
export DEBIAN_FRONTEND=noninteractive
apt-get install -y git build-essential libssl-dev awscli python-setuptools libgtk2.0 libgconf-2-4 libnss3 libasound2 dbus-x11 xorg linux-image-extra-virtual linux-source linux-headers-generic
# Disable nouveau driver
# Ref: http://tleyden.github.io/blog/2014/10/25/cuda-6-dot-5-on-aws-gpu-instance-running-ubuntu-14-dot-04/
cat << EOF | tee /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
EOF
echo options nouveau modeset=0 | tee -a /etc/modprobe.d/nouveau-kms.conf
NEW_KERNEL_NAME=$(dpkg --list | command grep linux-image-3 | awk '{ print $2 }' | sort -r | head -n 1 | sed -e 's/linux-image-//')
# Download, compile, and install NVIDIA drivers
pushd /home/ubuntu
wget -nd -q http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run
chmod +x cuda_6.5.14_linux_64.run
mkdir nvidia_installers
./cuda_6.5.14_linux_64.run -extract=$(pwd)/nvidia_installers
pushd nvidia_installers
./NVIDIA-Linux-x86_64-340.29.run --ui=none --no-questions --accept-license --no-backup --no-nouveau-check --kernel-name=${NEW_KERNEL_NAME}
popd
rm cuda_6.5.14_linux_64.run
popd
export AWS_DEFAULT_REGION=$(curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document | command grep region | command awk -F\" '{print $4}')
INSTANCE_ID=$(curl --silent http://169.254.169.254/latest/meta-data/instance-id)
PUBLIC_HOSTNAME=$(curl --silent http://169.254.169.254/latest/meta-data/public-hostname)
# Notify that step 1 is complete
# aws sns publish \
# --topic-arn <your_arn> \
# --message "Headless Graphics EC2 instance ready for setup step 2. Instance id: ${INSTANCE_ID} Hostname: ${PUBLIC_HOSTNAME}" \
# --subject "EC2 instance ready"
# reboot
reboot
@danmactough

This comment has been minimized.

Copy link
Owner Author

commented Oct 18, 2015

appears the --enable-all-gpus option breaks now
sudo nvidia-xconfig --use-display-device=None --virtual=1280x1024 --output-xconfig=/etc/X11/xorg.conf --busid=PCI:0:3:0 --enable-all-gpus

to
sudo nvidia-xconfig --use-display-device=None --virtual=1280x1024 --output-xconfig=/etc/X11/xorg.conf --busid=PCI:0:3:0

false -- that only happens if the nouveau driver is still loaded 👿

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.