« Squeezy-Pi

The Pi-Server

  26/09/12 21:59, by , Categories: Uncategorized , Tags: pi, raspbian, server

Let's start with a prediction: The Cloud won't last.

That might be controversial, but having been running my own home server for a couple of years, I think that the future is going to see everyone owning their own "personal cloud" system: probably in the form of a small box you plug in at home, and that stores and runs everything on every device you own, wherever you are.

That means not only your photos, videos and music stored safely on your home network and streamed to your phone, but also all your applications, settings and desktop too. You arrive at work; your phone is wirelessly connected; and the screen flashes up with the desktop as you just left at home. You're on the train; you open you phone to continue watching the same TV programme you were watching on TV last night.

Anyway, that's not the point of this post, which is actually a refresh of my home server setup. Having been playing with my Raspberry Pi for a couple of months, I think it's going to make an excellent replacement for my old Buffalo Linkstation which currently holds together my home network.

Paired up with a 16GB Class 10 SD Card, and an external USB enclosure containing a 2.5" 500GB drive, I think I have a faster system, on which I can run remote X sessions, and do it using less power. Win, win.

So first things first, let's get it up and running:

  1. Download the latest raspbian image from http://www.raspberrypi.org/downloads. (They like you to use the torrents, so please do so).
    I'm currently using the "Hard float" raspian image, which should make things easier for dealing with encoding/decoding, but it does potentially cause some JVM issues as only soft-float is currently supported. It's also worth checking the hash to make sure it downloaded cleanly:

    $ sha1sum ~/2012-09-18-wheezy-raspbian.zip

  2. Use another PC to unzip and write the image to the card. Remember that the image is for the entire disk (/dev/mmcblk0), not just a partition (/dev/mmcblk0p1).

    $ unzip 2012-09-18-wheezy-raspbian.zip
    $ dd bs=8M if=2012-09-18-wheezy-raspbian.img of=/dev/mmcblk0

  3. Now, let's resize the disk: I have a 16GB card, so using fdisk (or parted), leave the boot partition, delete the rest and replace with a new partition taking up the remaining disk.
    $ sudo fdisk /dev/mmcblk0 Command (m for help): p Disk /dev/mmcblk0: 15.9 GB, 15896412160 bytes 4 heads, 16 sectors/track, 485120 cylinders, total 31047680 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000dbfc6 Device Boot Start End Blocks Id System /dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA) /dev/mmcblk0p2 122880 3788799 1832960 83 Linux Command (m for help): d Partition number (1-4): 2 Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (1-4, default 2): 2 First sector (2048-31047679, default 2048): 122880 Last sector, +sectors or +size{K,M,G} (122880-3788799, default 3788799): Using default value 3788799 Command (m for help): w
  4. A quick note on swap space. Linux aficionados might expect to see a swap partition here somewhere, and indeed some versions do. However as this is a flash drive, it's not always a good idea to encourage lots of writes, so raspbian keeps a very low swapiness, and only offers a small swapfile (at /var/swap on mine). Check out free -h and cat /proc/swap if you want to take a look at yours.
  5. The partition is now filling the whole disk, but the filesystem within it is not, so we simply tell the filesize to fill up all the space it can. (I needed to run a fsck first, before it would allow me to resize)

    $ e2fsk /dev/mmcblk0p2
    $ resize2fs /dev/mmcblk0p2

  6. And that's all there is to getting it up and running. SSH is enabled, so we don't even need a display. I plug in a network cable and do the rest over an SSH session.

    $ ssh pi@192.168.x.x
    pi@192.168.x.x's password: [raspberry]

  7. The latest version comes with a rather nifty initial config tool: raspi-config, which helps set up a few things including changing the default password, disabling a desktop at boot (useless for a headless server).
  8. Then we upgrade everything to make sure it's up to date:

    $ sudo apt-get update && sudo apt-get upgrade

  9. And the rest is down to customisation. I'm not a big fan of the move towards NOPASSWD sudo, partly as I tend to use key-based authentication over SSH around the network. So that means a compromise on one device could open up root access network wide without a password. So, along with adding a sudo log (the output of which I'll use later), I've made the following changes to my sudoersfile.
    sudo visudo
    Defaults        insults
    Defaults        logfile=/var/log/sudolog
    Cmnd_Alias POWER_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt, /sbin/poweroff
  10. As well as adding a 'everyday' user account (adduser, not useradd) and fixing the relevant lines in /etc/group, I have updated /etc/hosts and /etc/hostname to a more sensible system name.
  11. Finally, I added the following programs with apt-get installto get the base system finished:
    • screen - a terminal windows manager, the most useful SSH tool
    • htop - graphical process viewer
    • locate - file searching tool
    • git - for building packages not in the repositories
    • logcheck - watches logfiles and emails changes
    • denyhosts - watches denied attempts at access and puts firewall rules in place
    • vlc - media player (no acceleration)
    • exim4 - mail server for getting emails out of the system/network
    • backintime-gnome - backup frontend to rsync
    • mc - midnight commander, terminal file manager
    • tree - lists files in a tree format

At this point,I run a fullback up and save it as an image for future use if necessary. Getting useful the server running useful is a topic for my next post...

This entry was posted by and is filed under Uncategorized. Tags: pi, raspbian, server

No feedback yet

Form is loading...


©2018 by tommy

Contact | Help | b2evo skins by Asevo | multi-blog | webhosting UK