Setting up and running a server with Ubuntu Server 14.04 on Raspberry Pi 2

The RaspberryPi is something that I’ve always been interested in but never really got around to actually ordering one… until this week!

In February the RaspberryPi Foundation released the RaspberryPi 2, this models sports a quad core, 900Mhz ARM7 processor with 1GB of RAM, this is a massive improvement on the previous models so I thought, well why not order one now, they’re even more powerful and easily be able to run a web server and various other tasks relatively fast!

So this morning, my bits came and in under an hour I had assembled the Pi2 in it’s fancy case that I bought for it too, my parts list that I ordered and received are as follows:

  • 1x Raspberry Pi 2
  • 1x FLIRC case
  • 1x 5v 2A Micro-USB charger
  • 1x SanDisk Ultra 32GB MicroSD (Class 10) Card (Plus MicroSD to SD adapter)

Originally I really wanted to run FreeBSD 10.1 on it but after doing some research online currently FreeBSD is not yet compatible on the RPi2 which was a little disappointing but I knew I had my trusty Ubuntu Server instead so though, I’d use that instead!

Downloading the Ubuntu Server 14.04.2 LTS Server Image for ARMv7

You can download the Ubunu Server 14.04.2 LTS Server image that is compatible with the Raspberry Pi2 using this link.

The default username and password for this image is “ubuntu” and “ubuntu”!

Installing the image on to your MicroSD card is covered on the Raspberry Pi2 website, so instead of me repeating what they’ve already documented, see these links for copying the image to your MicroSD card:

Once you’ve formatted and copied the image to the MicroSD card (as documented in the links provided above) it’s time to insert the MicroSD card into your Pi2 and start it up…

Logging in for the first time

Once you have booted the Pi up using the Ubuntu Server 14.04 image that we flashed to the MicroSD card we should now be able to login, the default username and password is: ubuntu / ubuntu

It’s now a good idea to change this password, to do that type:

passwd

Then enter your new password!

I’ve personally, set a new ‘root’ password and created a new user account and deleted the old ‘ubuntu’ account as a safety precaution, I recommend you do the same really!

Install NTP Client

The Raspberry Pi/Pi2 does not have a realtime clock therefore unless using NTP and having it updated on boot-up the RaspberryPi2 will start it’s clock from Jan 1st 1970 each time, to avoid this I’ll now install the NTP (Network Time Protocol) client to ensure that each time the Pi boot’s up that it connects to web to set it’s time automatically…

sudo apt-get install ntp

You will also find that by default the Ubuntu Server image that we are using is set to use UTC (Universal Time Coordination), I’m now going to set this to my actual timezone (BST), so to do that run the following command to reconfigure your server’s current timezone:

sudo dkpg-reconfigure tzdata

Now once you’ve set the new timezone, test and ensure that the correct date shows when you run

date

Excellent stuff… lets move on!

Installing OpenSSH server

Ideally, we want to run the Pi without a keyboard, mouse or monitor. There is no need for me to keep a keyboard and mouse attached as all configuration can be done remotely using SSH.

I plan to run the RPi2 completely headless and the only two cables being connected is the Power and Ethernet!

So to do this, we’ll install OpenSSH server like so:

sudo apt-get install openssh-server

Although I don’t recommend it, if you want to enable ‘root’ user logins over SSH then you should edit the SSH server configuration file here: /etc/ssh/sshd_config.

Installing some useful tools

Personally I like using htop, htop provides a nice display of running processes and memory utilisation, you can install it like so:

sudo apt-get install htop

Expanding the available disk space

The image size that we’re using is configured for a 4GB flash card, if you are using a card larger than 4GB like myself, it is a good idea to expand the partition sizes so we can utilise the entire card, luckily this can be easily achieved by following these simple steps:

sudo fdisk /dev/mmcblk0

You’ll then be presented with a ‘Command’ prompt, press the following keystrokes in order to delete the second partition:

  1. d
  2. 2

Now you need to re-create it like so, by recreating it, it will then use all the available space, so now press the following keystrokes a the ‘Command’ prompt

  1. n
  2. p
  3. 2
  4. [enter]
  5. [enter]

Finally to save and write the changes to disk and then exit out of the fdisk tool you must now press the follow key at the ‘Command’ prompt

  1. w

Great stuff, we’re done with fdisk now!

Now quickly reboot the Pi using this command:

sudo shutdown -r now

Once logged back on, we need to complete the resize of the partition by running this command:

sudo resize2fs /dev/mmcblk0p2

Adding SWAP space

The image is not setup with an SWAP space, if you would like to add some you can install a cool tool that will automatically configure a default SWAP space for you (~2GB by default but you can change if you wish).

To install like I did, run the following command:

sudo apt-get install dphys-swapfile

Woohoo, you are now ready to install whatever server software your require, I won’t cover installing a web server here as I’ve already covered this in some of my other blog posts and will be the same regardless of running a Raspberry Pi2!

One reply on “Setting up and running a server with Ubuntu Server 14.04 on Raspberry Pi 2”