As Thilo Maier pointed out in comments on my request for UDS input, I have been publishing both server and desktop AMIs for running Ubuntu on EC2 up through Jaunty, but the official Karmic AMIs on EC2 only support server installations by default.
Ubuntu makes it pretty easy to install the desktop software on a server, and NX from NoMachine makes it pretty easy to access that desktop remotely, with near real-time interactivity even over slowish connections.
Here’s a quick guide to setting this up, starting with an Ubuntu 9.10 Karmic AMI on Amazon EC2:
Create a user-data script which installs runurl (not on Karmic AMIs by default) and then runs a simple desktop and NX server installation script. Examine the desktop script to see what it’s doing to install the software.
cat <<EOM >install-desktop #!/bin/bash -ex wget -qO/usr/bin/runurl run.alestic.com/runurl chmod 755 /usr/bin/runurl runurl run.alestic.com/install/desktop EOMStart an instance on EC2 telling it to run the above user-data script on first boot. The following example uses the current 32-bit Karmic server AMI. Make sure you’re using the latest AMI id.
ec2-run-instances --key YOURKEY --user-data-file install-desktop ami-1515f67cConnect to the new instance and wait for it to complete the desktop software installation (when sshd is restarted). This takes about 30 minutes on an m1.small instance and 10 minutes on a c1.medium instance. Then generate and set a secure password for the
ubuntuuser using copy/paste from thepwgenoutput. Save the secure password so you can enter it into the NX client later.ssh -i YOURKEY.pem ubuntu@THEHOST tail -f /var/log/syslog | egrep --line-buffer user-data: pwgen -s 16 1 sudo passwd ubuntuIf anybody knows how to use ssh keys with NX, I’d love to do this instead of using passwords.
Back on your local system, install and run the NX client. For computers not running Ubuntu, download the appropriate software from NoMachine.
wget http://64.34.161.181/download/3.4.0/Linux/nxclient_3.4.0-5_i386.deb sudo dpkg -i nxclient_3.4.0-5_i386.deb /usr/NX/bin/nxclient --wizard &Point the NX Client to the external hostname of your EC2 instance. Enter the Login “ubuntu” and the Password from above. Choose the “Gnome” desktop.
If all goes well, you should have a complete and fresh Ubuntu desktop filling most of your screen, available for you to mess around with and then throw away.
ec2-terminate-instances INSTANCEID
If you want to have a persistent desktop with protection from crashes, you’ll need to learn how to do things like placing critical directories on EBS volumes.
If you’d like to run KDE on EC2, replace the package “ubuntu-desktop” with “kubuntu-desktop” in the installation script.



it would be great if you could mention how much it costs to set up and use this configuration. i am thinking about using a vserver or doing something like you describe... so whats the price?
You can see pricing for Amazon EC2 at:
http://ec2pricing.notlong.com/
The above test will run you about a dime.
I had to do a few extra things to get NX running:
(mostly borrowed from here: http://ubuntuforums.org/showthread.php?t=204976)
open sshd_config for editing:
Add the following line & save the file:
Restart sshd by typing:
Restart nxserver by typing:
Verify nxserver is configured properly by typing:
This should return:
Hi, cool post. Using it now.
I think it might be worth pointing out *before* the command to run stuff :-P that this installs *everything*, the entire desktop, and takes a while to run :-P
Also, I might tweak your script to take advantage of the information in http://ubuntuforums.org/showthread.php?t=1155961 to get just the graphical desktop installed, plus nx, and nothing else.
I am trying the variation of this desktop install with just the minimal amount of packages for remote server with Eclipse environment. I am getting the following 2 prompts after 'sudo apt-get -yq upgrade':
Configuring grub-pc
The following Linux command line was extracted from /etc/default/grub or the `kopt' parameter in GRUB Legacy's menu.lst. Please verify that it is correct, and modify it if necessary. Linux command line:
Configuring grub-pc
The following string will be used as Linux parameters for the default menu entry but not for the recovery mode.
Linux default command line: nosplash
I both cases I just hit enter and all is coming out fine but I am trying to achieve unattended install and those prompts ruin it.
I tried latest official Ubuntu 9.10 Karmic AMI on both Small and High CPU medium instances.
Any help would be much appreciated.
gene: Yeah, that is annoying and I don't know how to avoid the interactive prompt.
gene: I had the same problem, but I worked around it by piping yes to aptitude, as in
zfcd21: Your workaround does not seem to work when running a fresh instance of ami-1515f67c. The following commands still do the interactive prompting:
sudo apt-get update
yes "" | sudo aptitude safe-upgrade -y
I've submitted a bug requesting updated Ubuntu AMIs which would solve this problem.
https://bugs.launchpad.net/ubuntu/+bug/503649
Note: If I run with the following --user-data-file then the upgrade seems to perform cleanly even though there is nobody around to accept defaults:
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt-get update &&
apt-get upgrade -y
Argh. I *do* know how to avoid the interactive prompt but I occasionally forget to put it in. The key is the '-E' in the following commands. This allows the sudo command to pass the DEBIAN_FRONTEND environment variable to the apt-get command.
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo -E apt-get upgrade -y
Run the above on a Karmic AMI and you won't get any prompts from the grub-pc package upgrade.
Fellow ThursdayLunch.com member Vaibhav Puranik describes how to install the open source FreeNX server in his blog article:
http://aws-musings.com/4-easy-steps-to-enable-remote-desktop-on-your-ubuntu-ec2-instance/
it works great. thanks for the instructions.
I installed desktop and nx server with the scripts.
wget -qO/usr/bin/runurl run.alestic.com/runurl
chmod 755 /usr/bin/runurl
runurl run.alestic.com/install/desktop
and i could connect to the ec2 instance with nx client.
but when I restarted the ec2 instance, nx server was not running.
it doesn't start automatically.
how can I make it auto-start?
youngmin: I rarely use NX, but I assume that you should be able to add a server startup command to something like /etc/rc.local or go all the way and create a config in the new upstart system.
After following these instructions I had the same question as youngmin (about getting nx server to start on boot). A quick and dirty way is to add this to add this to the root crontab:
@reboot /etc/init.d/nxserver start
Thanks, Jay.