Saturday, November 17, 2012

Two Arch Linux updates and a guide on how to get Arch Linux ARM running on a Raspberry Pi.

I spent three weeks travelling because of work and the last week I was busy playing with my Raspberry Pi. I'll do a quick guide on how I got my RPI working, what packages I installed and what I could manage to do on it. But before that, I'll quckily comment on two news on the Arch Linux site:

1) ConsoleKit was replaced by logind

Anything that depended on ConsoleKit now depends on logind. This means that you can take that "ck-launch-session" from your ~/.xinitrc file if you're using systemd.

2) Support for Initscripts was dropped

I knew it was going to happen sooner or later, but I do think it was too soon. Anyway, fellow Archers, you need to adopt systemd at once!

With that said, let's go to the RPI! :)

I ordered a LOT of stuff from dealextreme, but on this post I won't cover this stuff, just the bare essentials (regular USB keyboard, regular USB mouse, wiimote as mouse and ethernet). I ordered a 16GB C10 SD card, a cordless keyboard with a touchpad, power source (microusb, 5V, 2A), externally powered USB hub, Wifi USB dongle, Bluetooth USB dongle, etc. For now, I ended up buying a usual USB keyboard and a usual USB mouse so I could start playing around. I already had an unused 2GB C4 SD card and a HDMI cable. While I was travelling I also bought a cheap 5V 1A power source (raspberrypi.org recommends at least a 700mA one).

Well, I downloaded the lastest Arch Linux ARM image from their site and followed the instructions to dd the image to the SD card. That was a piece of cake. Hooked everything up for the first boot: ethernet cable, HDMI cable, keyboard, mouse and cheap power source. The RPI didn't boot. Searching the web I found out that the most common cause for this was the quality of the power source, and I knew mine was... kinda crappy. So I had to go to bare essentials and see if it worked: HDMI cable and keyboard (took the ethernet cable and the mouse). The RPI booted.

There I saw the RPI symbol and systemd started loading a lot of stuff, including the NTP daemon and a SSH server. Right there I realized: the image is a pre-built arch install, I wouldn't have to go through all the hassle of setting everything up, just adjust the config files (vconsole.conf, set timezone and locale, etc.) and install the applications I wanted. So I logged as root (password is also root) and browsed around. The default resolution (1080p) is so high that I could barely read what I was typing on my FullHD 32" TV. So the first thing I did was lower the resolution to 720p on the /boot/config.txt file (both nano and vi are available on the base system). All parameters can be found here. After rebooting I could read everything but there were two "stripes" of unused lines on the TV, one at the bottom and one the top of the screen. I figured I'd take care of this later (and I'll show how).

So, what can one do with a Linux box without networking (remember I had to disconnect my ethernet cable so my RPI would boot)? Not much. I then remembered that I had a cellphone charger that is a microusb one rated at 5V, 850mA. This one was able to hold the ethernet and mouse. Now I was all set! I'll list everything I did to get stuff working.

-1) You'll need a GOOD power source (PSU). Most RPI problems are related to poor PSU quality. I had two problems with the cell phone charger I mentioned (one was already mentioned and the other will be covered on the next post). Get a GOOD PSU.

0) Installation

Simply download the image on this link and follow the instructions listed there. The image you'll write to your SD card will have two partitions: a FAT one (/boot) and a EXT4 one ( / ).

1) Lower the resolution

1080p is the default resolution for the RPI HDMI output. As I already said, I had to lower the resolution so I could see what I wrote. If you can see what you're writing, the resolution is good enough and you can skip this step. On this link all possible values are listed. I simply added the following to my /boot/config.txt:

hdmi_group=1
hdmi_mode=4

Like I said, this changes the resolution to 720p but still got two "stripes" of unused lines on the TV, one at the bottom and one the top of the screen. To get rid of them I added the following lines to my /boot/config.txt. I did get to these values after getting X11 running so I could be confident they were correct.

disable_overscan=1
overscan_left=37
overscan_right=37
overscan_top=23
overscan_bottom=23

2) Configuring the keyboard

Now that I could see what I wrote, I had to configure the keyboard configuration. This is done the same way as the usual arch install (using the loadkeys command and editing /etc/vconsole.conf). Check this post for details.

3) Set timezone and locale

Like the previous step, this is done just like the usual arch install. Check this post for details.

4) Change hostname

The default hostname is alarmpi. You can change this if you like:

hostnamectl set-hostname yourhostname

Of course, change yourhost name to the hostname you want.

5) Change root password and add a regular user.

This is important. The default root password is also root. You should change that. Also, add a regular user for you to use. Check this post for details.

6) Next I disabled the SSH server (don't need it at the moment, and I don't know about the default config). If you want to keep it running, simply skip this.

systemctl disable opensshd.service
systemctl stop opensshd.service

7) Sudo

Now we install sudo, edit the sudoers file (with the visudo command) and simply stop using the root user. Check this post for details.

8) Packages!

All right! Now for the best part. I'll list the packages I installed and why I installed them. You can install packages the the usual way: pacman -S packagename (of course, you'll need to do a pacman -Suy first) and search for packages using pacman -Ss packagename.

8.1) Sound

I installed the alsa-utils and alsa-plugins packages. In addition, you'll have to do type the following command as root (or sudo it) for sound to work (it loads the sound module):

modprobe snd-bcm2835

You may need to unmute the sound using alsamixer.

To make it load on startup, create the following file: /etc/modules-load.d/snd-bcm2835.conf. Then add snd-bcm2835 to it.

8.2) X11 basics

Raspberry Pi video driver: xf86-video-fbdev;
Xorg: xorg-server, xorg-server-common, xorg-server-utils, xorg-xinit;
For input: xf86-input-keyboard, xf86-input-mouse;
Basic fonts: xorg-font-utils, xor-fonts-100dpi;

8.3) Fonts, cursors, themes, etc. And lxappearance

This post has some fonts, cursors and themes you can install. I don't know if all of them are available in the Arch Linux ARM repos. Anyway, you can search for the available ones easily. Also, install lxappearance to easily configure themes, cursors, etc. Just install whatever you think looks good. :P

8.4) Applications.

I'll list what apps I installed, but you can install whatever you like. As usual, I stuck to Fluxbox as WM, but this time I won't use a login manager (usually I use slim). I used this method to login directly to X. The reason for this is that this system needs to be VERY light.

WM: fluxbox;
Utilities: galculator, thunar, vim, leafpad, feh, dmenu, gksu;
Browsers: uzbl-core, uzbl-browser, dwb;
Audio player: xmms;
Video player: xbmc-rbp-git;

I configured Fluxbox as I usually do. This post shows how I usually do it. I did swap a few applications: xfc4-appfinder for dmenu and gpicview for feh, etc. But this is because only VERY lightweight stuff must be installed on RPI (exception for XBMC which I'll talk about in a minute).

Side note: I didn't install conky, but intend to.

8.5) XBMC

As you should well know, the RPI GPU can do hardware decoding of H264 video. The "problem" is that, as far as I know, only two players can currently use the GPU instructions to do proper H264 FullHD video playback using the RPI: XBMC and OMXPlayer. OMXPlayer a CLI utility and XBMC is a fullblown Media Center. I chose XBMC because it would be easier to install (XBMC is available on the repos, OMXPlayer needs to be compiled from source).

It runs great anyway. I managed to watch The Avengers movie on 1080p. It's fantastic.

One note on XMBC: you NEED to set 128MB of RAM to the GPU for it to playback video properly. To do this, add the following to your /boot/config.txt:

gpu_mem=128

In the end, this is how the top of my /boot/config.txt file looks like (the rest of the file is commented, no use in posting it here):

# SETS GPU RAM AND RESOLUTION! 

# For watching movies (128MB VRAM and 1080p resolution)
#gpu_mem=128
#hdmi_group=1
#hdmi_mode=16

# For computing (8MB VRAM and 720p resolution)
gpu_mem=8
hdmi_group=1
hdmi_mode=4
disable_overscan=1
overscan_left=37
overscan_right=37
overscan_top=23
overscan_bottom=23


As the comments say, I have two groups of settings: one for watching movies and one for general computing.  The first group sets 128MB of RAM for the GPU and 1080p resolution. The second sets 8MB of RAM for the GPU (leaving more RAM for the Operating System) and 720p resolution so I can actually read stuff.

8.6) CwiiD

CWiiD enables you to use wiimote (plus nunchuck or classic controller) as input devices, provided you have a bluetooth USB dongle for the RPI. I used a regular cheap-ass one. Simply swapped the mouse for the bluetooth dongle. You only need to install the cwiid package and do some configuration. This link will tell everything you need to know to configure it. The only thing you won't find there is that you need to enable the bluetooth service:

sudo systemctl enable bluetooth.service

The next time you reboot, it'll be started. If you want to start it now:

sudo systemctl start bluetooth.service

Just as example, here's my /home/username/.cwiid/wminput file, I'm only using my wiimote as mouse.

#IR pointer 

Plugin.ir_ptr.X = ABS_X
Plugin.ir_ptr.Y = ABS_Y

#buttons

Wiimote.A        = BTN_LEFT
Wiimote.B        = BTN_MIDDLE
Wiimote.Up       = KEY_UP
Wiimote.Down     = KEY_DOWN
Wiimote.Left     = KEY_LEFT
Wiimote.Right    = KEY_RIGHT
#Wiimote.Minus   = KEY_BACK
Wiimote.Plus     = BTN_RIGHT
#Wiimote.Home    = KEY_HOME
#Wiimote.1               = KEY_SLASH
#Wiimote.2               = KEY_SPACE

#Nunchuk.C              = BTN_LEFT
#Nunchuk.Z              = BTN_RIGHT
#
#Classic.Up             = KEY_UP
#Classic.Down   = KEY_DOWN
#Classic.Left   = KEY_LEFT
#Classic.Right  = KEY_RIGHT
#Classic.Minus  = KEY_BACK
#Classic.Plus   = KEY_FORWARD
#Classic.Home   = KEY_HOME
#Classic.A              = BTN_LEFT
#Classic.B              = BTN_RIGHT
#Classic.X              = 
#Classic.Y              = 
#Classic.ZL             = 
#Classic.ZR             = 
#Classic.L              = 
#Classic.R              = 


[end of tutorial]

That's it, pretty simple aye? The RPI is amazing. It's so small and can do so much. For now, I managed to playback some 1080p video, playback some mp3s, use my wiimote as mouse and browse the web. It's a full featured computer, you can do whatever you want with it. On the next post I'll tinker with the stuff I bought on dx.com to enhance my RPI experience.