Ubuntu Karmic Desktop on EC2

| 14 Comments | 0 TrackBacks | Bookmark and Share

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.

No TrackBacks

TrackBack URL: http://alestic.com/mt/mt-tb.cgi/59

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

Stay Updated

Subscribe with email address:
 Subscribe with a reader
Join the EC2 Ubuntu Google Group
Follow Eric Hammond on Twitter

More Entries

Alestic.com Sponsorship
A quick but heartfelt note of thanks to Ben Cherian at ServiceCloud, a long term supporter and faithful sponsor of…
Move a Running EBS Boot Instance to New Hardware on Amazon EC2
Amazon EC2 has been experiencing some power issues in a portion of one of their many data centers. Even though…
One Weekend to Prototype CrowdPhoto.net using AWS Technologies
On Friday evening (2 days ago) I and a number of other high octane LA individuals came to LA StartupWeekend…
Ubuntu AMIs available for Amazon EC2 in Asia Pacific (Singapore)
Amazon EC2 just launched the Asia Pacific region with data centers in Singapore. The standard Ubuntu and Debian AMIs (Amazon…
Ubuntu 10.04 Lucid Released for Amazon EC2
Ubuntu 10.04 Lucid was released on Amazon EC2 right on schedule today along with the rest of the normal Ubuntu…
Upgrading Servers to Ubuntu 10.04 Lucid on Amazon EC2
Ubuntu 10.04 Lucid is expected to be released this Thursday (April 29, 2010). This is the first LTS (long term…
Identifying When a New EBS Volume Has Completed Initialization From an EBS Snapshot
On Amazon EC2, you can create a new EBS volume from an EBS snapshot using a command like ec2-create-volume --availability-zone…
New releases of Ubuntu and Debian Images for Amazon EC2 (20100319)
Note: I do not recommend that new users start with these AMIs. These AMIs run with older versions of Amazon’s…
SCALE 8x Talk Notes: EC2 Beginners Workshop
At SCALE 8x (Southern California Linux Expo, Feb 2010) I did a walkthrough demonstrating how to use the AWS console…
The BitSource Interview of Eric Hammond (SCALE, EC2)
Matthew Sacks, of The BitSource, made the mistake of asking me some questions about Amazon EC2, so I rambled on…
Resizing the Root Disk on a Running EBS Boot EC2 Instance
In a previous article I described how to run an EBS boot AMI with a larger root disk size than…
New Ubuntu 8.04.3 Hardy AMIs for Amazon EC2
Scott Moser (Canonical) built and released new Ubuntu 8.04.3 LTS Hardy images and AMIs for Amazon EC2. I also published…
Southern California Linux Expo - Februrary 19-21, 2010 at the Westin LAX
The 8th Southern California Linux Expo (aka SCaLE 8x) is a community organized, non-profit event. Those words and the…
Public EBS Boot AMIs for Ubuntu on Amazon EC2
If you’ve been following along, you probably know that I have been recommending that folks using EC2 switch to the…
How to Report Bugs with Ubuntu on Amazon EC2: ubuntu-bug
The official Ubuntu AMIs published by Canonical for EC2 starting in October have proven to be solid and production worthy.…
Three Ways to Protect EC2 Instances from Accidental Termination and Loss of Data
Here are a few little-publicized benefits that were launched with Amazon EC2’s new EBS boot instances: You can lock them…
Building EBS Boot AMIs Using Canonical's Downloadable EC2 Images
In the last article, I described how to use the vmbuilder software to build an EBS boot AMI from scratch…
Building EBS Boot and S3 Based AMIs for EC2 with Ubuntu vmbuilder
Here’s my current recipe for how to build an Ubuntu 9.10 Karmic AMI, either the new EBS boot or the…
Call for testers (building EBS boot AMIs with Ubuntu vmbuilder)
I’m polishing up an article about how to build images from scratch with Ubuntu vmbuilder, both for S3 based AMIs…
ec2-consistent-snapshot release 0.1-9
Thanks to everybody who submitted bug reports and feature requests for ec2-consistent-snapshot, software which can be used to create consistent…