Ubuntu Karmic Desktop on EC2

| 14 Comments

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:

  1. 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
    EOM
    
  2. Start 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-1515f67c
    
  3. Connect 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 ubuntu user using copy/paste from the pwgen output. 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 ubuntu
    

    If anybody knows how to use ssh keys with NX, I’d love to do this instead of using passwords.

  4. 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.

14 Comments

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:

sudo vi /etc/ssh/sshd_config

Add the following line & save the file:

AuthorizedKeysFile /usr/NX/home/nx/.ssh/authorized_keys2

Restart sshd by typing:

sudo /etc/init.d/ssh restart

Restart nxserver by typing:

sudo /etc/init.d/nxserver restart

Verify nxserver is configured properly by typing:

sudo /usr/NX/bin/nxserver --status

This should return:


NX> 900 Connecting to server ..
NX> 110 NX Server is running.
NX> 999 Bye.

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

yes "" | aptitude safe-upgrade -y

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

Leave a comment

Ubuntu AMIs

Ubuntu AMIs for EC2:


More Entries

Ubuntu Developer Summit, May 2012 (Oakland)
I will be attending the Ubuntu Developer Summit (UDS) next week in Oakland, CA.  This event brings people from around…
Uploading Known ssh Host Key in EC2 user-data Script
The ssh protocol uses two different keys to keep you secure: The user ssh key is the one we normally…
Seeding Torrents with Amazon S3 and s3cmd on Ubuntu
Amazon Web Services is such a huge, complex service with so many products and features that sometimes very simple but…
CloudCamp
There are a number of CloudCamp events coming up in cities around the world. These are free events, organized around…
Use the Same Architecture (64-bit) on All EC2 Instance Types
A few hours ago, Amazon AWS announced that all EC2 instance types can now run 64-bit AMIs. Though t1.micro, m1.small,…
ec2-consistent-snapshot on GitHub and v0.43 Released
The source for ec2-conssitent-snapshot has historically been available here: ec2-consistent-snapshot on Launchpad.net using Bazaar For your convenience, it is now…
You Should Use EBS Boot Instances on Amazon EC2
EBS boot vs. instance-store If you are just getting started with Amazon EC2, then use EBS boot instances and stop…
Retrieve Public ssh Key From EC2
A serverfault poster had a problem that I thought was a cool challenge. I had so much fun coming up…
Running EC2 Instances on a Recurring Schedule with Auto Scaling
Do you want to run short jobs on Amazon EC2 on a recurring schedule, but don’t want to pay for…
AWS Virtual MFA and the Google Authenticator for Android
Amazon just announced that the AWS MFA (multi-factor authentication) now supports virtual or software MFA devices in addition to the…
Updated EBS boot AMIs for Ubuntu 8.04 Hardy on Amazon EC2 (2011-10-06)
Canonical has released updated instance-store AMIs for Ubuntu 8.04 LTS Hardy on Amazon EC2. Read Ben Howard’s announcement on the…
New Release of Alestic Git Server
New AMIs have been released for the Alestic Git Server. Major upgrade points include: Base operating system upgraded to Ubuntu…
Using ServerFault.com for Amazon EC2 Q&A
The Amazon EC2 Forum has been around since the beginning of EC2 and has always been a place where you…
Rebooting vs. Stop/Start of Amazon EC2 Instance
When you reboot a physical computer at your desk it is very similar to shutting down the system, and booting…
Upper Limits on Number of Amazon EC2 Instances by Region
[Update: As predicted, these numbers are already out of date and Amazon has added more public IP address ranges for…
Unavailable Availability Zones on Amazon EC2
I’m taking a class about using Chef with EC2 by Florian Drescher today and Florian mentioned that he noticed one…
Desktop AMI login security with NX
Update 2011-08-04: Amazon Security did more research and investigated the desktop AMIs. They have confirmed that their software incorrectly flagged…
Updated EBS boot AMIs for Ubuntu 8.04 Hardy on Amazon EC2
For folks still using the old, reliable Ubuntu 8.04 LTS Hardy from 2008, Canonical has released updated AMIs for use…
Creating Public AMIs Securely for EC2
Amazon published a tutorial about best practices in creating public AMIs for use on EC2 last week: How To Share…
Canonical Releases Ubuntu 11.04 Natty for Amazon EC2
As steady as clockwork, Ubuntu 11.04 Natty is released on the day scheduled at least eleven months ago; and thanks…