Julien Goodwin
Raspberry Pi debian notes 
28th-Apr-2012 12:21 am
southpark cartoon
So one of the guys at our office somehow ended up with two Raspberry Pi's from the first batch, as one was enough for him to play with he offered the other one up, and I turned out to be the only person in the office who wasn't so lazy as to not walk over to the other building where he was to borrow for the weekend.




Here's a bunch of useful things that you probably want to do with the default Debian installation to make it more usable.

First, please don't give the foundation guys flack for any of these issues, a decent distro is hard, and I've paid hundreds of times more then this and gotten a horrific hack-job of (usually) debian (often with a kernel already years out of date, istead of one from this year). This really isn't too bad for a first go.

Security


If you're using the pi on a network, or in a public place there are a few things to consider, it's actually pretty good compared to most embedded images I've seen.

Regenerate SSH keys


The pi already has SSH keys on the image, this is a security issue as it makes you a very easy target for MITM attacks.
As root run:
rm /etc/ssh/ssh_host_*key
dpkg-reconfigure openssh-server

Note this enables SSH server on boot, so disable it if you want, see the note below about NFS, just use "ssh" as the service. If you've used SSH before this you'll need to delete your existing entry on your client before SSH will let you connect due to the new keys.

Consider disabling NFS client (the sole open services by default)


Other then the ports being open this has no security implication, but it does save a lot of boot time.
update-rc.d portmap disable
update-rc.d nfs-common disable

Delete the pi user


Or at least change its password. If you create another admin user consider removing pi from sudoers.

Minor bits


"root" has an invalid password (same as Mac OS, Ubuntu, etc.). The users "tli" and "pnd" exist in /etc/shadow with passwords (but not /etc/passwd). The user "suse" also has full root by sudo, but doesn't exist.

Keyboard layout


Most of us don't use UK keyboards, you can switch to your local layout by running "dpkg-reconfigure keyboard-configuration". you may want at least a qwerty (if not UK English) layout keyboard for this step, will be hard without one.

Time zone


I think the concept of a "British Summer" is an oxymoron so I want to change the timezone to something more relevant to me.

You can do that by running "dpkg-reconfigure tzset" (again, sudo for root if needed)

Console Blanking


If you're using a pi as a server you might want to disable console blanking so if you connect a monitor you don't need to hit a key to wake it up (which you might not be able to do if you've somehow crashed it).

To do this edit /etc/kbd/config and change BLANK_TIME to 0>.

Debian Mirror


You may wish to change to a local debian mirror by editing /etc/apt/sources.list and changing "uk" to the appropriate two letter code (debian mirror list), then as with all apt based systems, "apt-get update" to find new packages, apt-get dist-upgrade to upgrade to them (you should be careful what you install unless you've expanded the filesystem as there's not much free space).

I'd actually suggest the following as a good base debian apt set, these include security updates:
# Main, the core of debian
deb http://ftp.us.debian.org/debian/ squeeze main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ squeeze main contrib non-free

# Security updates
deb http://security.debian.org/ squeeze/updates main contrib non-free
#deb-src http://security.debian.org/ squeeze/updates main contrib non-free

# Other important updates before point releases
deb http://ftp.us.debian.org/debian/ squeeze-updates main contrib non-free
#deb-src http://ftp.us.debian.org/debian/ squeeze-updates main contrib non-free


The commented out lines are for source packages, unless you plan to do debian package development on the board itself they're not worth it

Swap


You can (but probably shouldn't unless you like killing SD cards) enable swap by uncommenting the swap line in /etc/fstab and rebooting or running "swapon -a"

Expanding the filesystem to use all (or just more) of your SD card


*WARNING* This is only applicable to the 19/April/2012 Debian build, it's very easy to destroy data by doing this wrong.



I installed on an 8GB card (as it was all I had lying about) and wanted to use all the space available. If you're going to expand the filesystem I'd suggest doing it straight away so you won't feel bad if you stuff up and destroy the OS on the card.

All of this procedure needs to be run as root.

First, change the partition size:
fdisk /dev/mmcblk0

Inside fdisk use these commands:
  • Type "p" and press enter, note the "Start" number of p2 (in this image, 1233)
  • Delete the swap partition with "d" then "3"
  • Delete the root partition with "d" then "2"
  • Recreate the root partition with "n" then "2", then start cylinder (1233 for mine), then either press enter for all the card, or follow the instructions for otherwise (using anything less then the old End cylinder of p2 will break your system)</li>
  • Verify things look ok by printing the table again ("p")
  • If they're all good use "w" to finish.


Now reboot

Once the system is back to finish expansion run:
resize2fs /dev/root

(This took several minutes on my 8GB card)

You can verify the result with "df -h"
Comments 
28th-Apr-2012 12:03 am (UTC)
Noted. -- But I won't be getting one for a while.
5th-May-2012 01:11 pm (UTC)
Anonymous
Thanks for the regenerating SSH keys tip
30th-May-2012 12:37 pm (UTC)
Anonymous
Awesome post, thanks!

However, using fdisk surely is extremely old skool these days? Why does nobody suggest using cfdisk which is much simpler for beginners, or even gparted which makes the process very simple.
30th-May-2012 12:53 pm (UTC)
cfdisk is in fact my preferred version, but due to the exact layout I was unable to do a safe expansion using it.

As for gparted it's not installed by default, and I was limiting myself to inbuilt tools as far as possible.
4th-Jun-2012 04:43 am (UTC)
Anonymous
dpkg-reconfigure keyboard-configuration defintely works, but it delays the boot time by a few order of magnitude. During boot, the kernel wastes about a minute each at showing these messages:

-delay here-
"Setting preliminary keymap"

-delay here too-
"Setting up console font and keymap"

This is not a isolate case. Google it.
4th-Jun-2012 05:17 am (UTC)
I didn't have this issue, was this was a native USB keyboard plugged in?
25th-Jun-2012 10:36 pm (UTC)
Anonymous
Thanks for a nice set of hints, Julien!

I've spotted a minor typo: dpkg-reconfigure tzdata should be used instead of dpkg-reconfigure tzset

WRut
28th-Jun-2012 11:24 am (UTC)
Quite right, I must have added tzset at the point I wrote that, tzdata is correct.
This page was loaded Dec 20th 2014, 2:56 am GMT.