Sunday, October 13, 2013

Kindle, jailbreak, ads and custom screensavers!

I said I was thinking about buying an ereader but I had some other financial priorities... Well, my sister was going to spend a week in the USA and I asked her to bring me a Kindle Paperwhite (the old one, not the recently launched one).It's great. It's VERY comfortable reading on it, whether with natural lighting or using the built in LEDs. I ended up also getting the official Amazon cover, although I did find it very expensive. The Kindle PW's price is US$ 120,00 (ad supported, no 3G) and the cover costs US$ 40,00, one third of the price of the Kindle! Anyway, the whole toy ended up costing US$ 160,00.

The first thing I did when I got my hands on it was to load some books with Calibre. It was very straightforward, no problems there. But searching around the web, I started reading about jailbraking and some nice programs you can run on your Kindle once it's jailbroken. So, I absolutely had to jailbreak it! My first goal was to run the custom screensaver hack, which enables you to use custom screensavers (duh!).

I'll post all the stuff I did to my Kindle PW (KPW for now on, OK?), some kind of "tutorial". Bear in mind that I do not guarantee this will work on any other KPW. If you try to follow these steps and your Kindle ends up bricked or screwed up in anyway, it was your own fault (not mine, your fault)! All the steps were done on a Linux box (Arch Linux box!). Oh, and an advice one should always follow: read the readme files for everything you want to install on your Kindle!

So, the first thing was to downgrade the firmware. It's only possible (at the moment, at least) to jailbreak a KPW on the following firmware versions: 5.2.0 - 5.3.1, 5.3.4 and 5.3.5.  Mine came with the version 5.3.6 so I had to downgrade it to 5.3.5, at least. So that's what I did, downgraded the firmware to version 5.3.5. To check the firmware version on a KPW, just go to Settings -> Device Info. One can google for links to the firmware files, but I got mine here. I just downloaded the update_kindle_5.3.5.bin file, placed it the "root" (see note 1 below) directory and went to Settings -> Update Your Kindle. After a few minutes the KPW restarts and one can check (as already mentioned) that it's running the older firmware. A few notes on the procedure I just described:

1) What I meant but "root" was the root directory when one plugs the KPW on a usb port. The KPW is recognized as a disk so the file update_kindle_5.3.5.bin should be put on this root dir, but it's not the root dir of the KPW (if you follow this "tutorial", you'll be able SSH or telnet into the Kindle and you'll be able see the actual root :P).

2) It's a good idea to turn on the Air Plane mode while updating/hacking your Kindle. You never know when Amazon is going to try to push an update on your device (there's a easy way of blocking this, which I'll get to later) or what the hell your Kindle is going to download from Amazon's servers at a random time (ads, special offers, etc.).

3) I searched the web but I couldn't find the md5sum of the file (or any other), so in case anyone is interested:

$ md5sum update_kindle_5.3.5.bin 
b1b4b304fa0751c9b00f826a10af2e6f  update_kindle_5.3.5.bin

$ sha256sum update_kindle_5.3.5.bin
4b4d4af9ac88244bae1ae0a8d256431b951f74df069829ed3bbe9c2a880ef5aa  update_kindle_5.3.5.bin

This post has the files for the jailbreaking and all the info on how to do it. It's quick, easy and painless. What the jailbreak actually does is enable your Kindle to run code that is not signed by Amazon. The jailbreak installs:

1) The jailbreak itself;
2) The jailbreak bridge (to allow your device to keep jailbroken after and update);
3) Kindlet dev certs (certificates of developers from http://www.mobileread.com) (Kindlet = Kindle apps);
4) The Rescue Pack (this allows one to SSH to the Kindle on diagnostics mode);

Anytime one updates the firmware, it's necessary to install the dev certs and the rescue pack again (the rescue pack is optional, but the developers highly recommend to install it). The standalone versions of these apps are on the jailbreak post I linked above.

Next I installed KUAL, the Kindle Unified Application Launcher. This is an application that launches other applications (Kindlets). This post has all the files and details needed. Again, easy and quick to install. Read the instructions and the readme files.

Next, I wanted to install the screensaver hack, but there was a problem: my KPW is ad supported. What this means is that the screensavers always show Amazon ads and the screensaver hack does not overcome theses ads. So I had to disable them. Searched the web and found this. To disable the ads, I had to install USBNetwork, which enables one to SSH into the Kindle. Download the Kindlet from this post and read the readme (and I mean really read it!).

After installing it, I plugged my KPW on the usb port and copied my authorized_keys file from my desktop to the usbnet/etc/ dir on the KPW. Now my I can use my RSA key to SSH into the Kindle. Then I had to actually login to the KPW. So I ejected it and typed the following on the KPW search field to start the USBNetwork:

;un

On KUAL, I checked the USBNetworking status and indeed it was on. Now I had to "give" an IP address to the KPW's usb interface. To find out it's name, simply do a dmesg | tail:

[  985.062730] sd 6:0:0:0: [sde] Synchronizing SCSI cache
[  985.062814] sd 6:0:0:0: [sde]
[  985.062817] Result: hostbyte=0x01 driverbyte=0x00
[ 1051.320899] usb 5-1.3: new high-speed USB device number 7 using ehci-pci
[ 1051.422464] cdc_subset: probe of 5-1.3:1.0 failed with error -22
[ 1051.423861] cdc_subset 5-1.3:1.1 usb0: register 'cdc_subset' at usb-0000:00:1a.0-1.3, Linux Device, 16:5e:0f:19:78:6a
[ 1051.423891] usbcore: registered new interface driver cdc_subset
[ 1051.423935] cdc_ether: probe of 5-1.3:1.0 failed with error -16
[ 1051.423980] usbcore: registered new interface driver cdc_ether
[ 1051.442298] systemd-udevd[8832]: renamed network interface usb0 to enp0s26u1u3i1

Okay, here's the KPW: cdc_subset 5-1.3:1.1 usb0: register 'cdc_subset' at usb-0000:00:1a.0-1.3, Linux Device, 16:5e:0f:19:78:6a

And the name of the usb interface: systemd-udevd[8832]: renamed network interface usb0 to enp0s26u1u3i1

OK, now let's give and IP address to the interface:

sudo ifconfig enp0s26u1u3i1 192.168.15.201

Now to SSH to the KPW:

ssh root@192.168.15.244

Or, you can telnet into the KPW with telnet 192.168.15.244. Telnet logs you in as root and will ask for no passwords. It's best to make sure SSH works, so that one can later enable SSH over Wifi and disable the telnet daemon for good (read the f***ing readme file!!!!).

Now that SSH works, to set up my public key on the SSH server, I simply copied my ~/.ssh/authorized_keys on my desktop to usbnet/etc/authorized_keys directory on the Kindle (path relative to mounting the Kindle as a mass storage device). The authorized_keys is just a text file that lists the public keys allowed to be used on authenticating incoming connections. Although, remember that the public key stays on the server and the private with the client. Also, keep your private key safe and change your key pairs periodically.

All right, at this point, I was able to SSH to my jailbroken KPW running firmware 5.3.5 with my RSA key through the usb interface. Now it was time to see if the ad disable hack would actually work, because only then I would be able to use custom screensavers. After SSHing to the KPW I did the following commands (in parenthesis is the description of each command):

mntroot rw (to make the filesystem writable, just like the big notice says);
cd /var/local (change dir to /var/local :P);
ls -l (just a ls... :P);
stop framework (this stops the Kindle framework!);
mv adunits adunits.bak (renames the directory adunits to adunits.bak);
touch adunits (creates a file named adunits);
chmod 000 adunits (makes the file adunits unreadable, unwritable and unexecutable to every user);
start framework (restarts the framework);
exit (closes SSH connection :P)

So what was actually done? The dir adunits was renamed (in case one wants to undo the deed) and a unreadable, unwritable and unexecutable file named adunits takes its place. Now, the ads were over (except for the one in the bottom of the home screen, but as far as I know, every Kindle has this, even the ones that are not ad supported).

OK, now that the ads are gone and the regular screensavers appear, it's time for the custom screensaver hack! This post has everything needed to install the custom screensaver hack, the files and the instructions. It's pretty straightforward.

Anyway, this is written on the readme:

One the PaperWhite: PNG files, 758x1024. Grayscale if possible, but color works too (you can even play with an alpha channel if you like).

I wanted to use Escher's drawings as my screensavers, as he's drawings are fantastic and most of them are grayscale! So I went to google images and got some Escher's drawings (actually I got them all from here). The problem was that they were all jpeg files and none matched the desired resolution (one has to read the readme files!). So, I had to convert them. To do this, I used imagemagick. I already talked (briefly) about it on some other post, I don't recall which. Anyway, I simply put all the .jpg files on a directory (~/test), created a dir name resized inside the ~/test dir and did the following command inside ~/test:

for i in $(ls *.jpg); do convert $i -resize 758x1024\! ./resized/$i.png; done

OK, so this does is a for loop and runs the command "convert $i -resize 758x1024\! ./resized/$i.png" where $i is each file that ends with a .jpg (see the ls *.jpg). This program "convert" comes with imagemagick and it converts each .jpg file to a .png file with the 758x1024 resolution and places the new png files on the resized dir. The \! after the 758x1024 resolution tells convert to ignore the aspect ratio, so yes, some files are kinda distorted but nothing too drastic.

Now I had the .png files I wanted on the correct resolution, but there was still something that irritated me: the files names were something.jpg.png, and I wanted to get rid of the .jpg in the middle of them! So had to do the following inside the ~/test/resized dir:

for i in $(ls *.png); do mv $i ${i/.jpg/}; done

This does is a for loop and renames the something.jpg.png files to something.png files, it simply replaces the .jpg with nothing (it dumps the .jpg string). For more information, check the String Replacement topic here.

Now I had to simply plug my KPW on the usb port and copy the .png files with the correct resolution on the linkss/screensavers folder. In case anyone wants my converted Escher's drawings, they are here (some are colored, but they do work). They're already on the correct format and resolution.

Great, now I had the custom screensavers and I wanted to test if the ads hack indeed worked. So I turned on the Wifi (remember, leave the Airplane Mode on when hacking/updating the Kindle!) and left it alone for a few minutes. The KPW downloaded the usual ads (those on the bottom of the home screen) but not the screensaver ones. Great, it had worked!

So I left the KPW alone (with the Wifi on) and had dinner with my wife. After the dinner, I noticed that I couldn't get into KUAL. When I checked the firmware version, I found out it had been updated to version 5.3.8. F***ing Amazon! This is what I see when I do a ls -l on the /var/local dir of the KPW:

drwxr-xr-x    X root     root          XXXX Month  X ZZ:ZZ adunits
drwxr-xr-x   XX root     root          XXXX Month  X ZZ:ZZ adunits.bak
and some other stuff...

The file adunits was removed and the adunits dir is there again (see the d in drwxr-xr-x for adunits?). So, I had to downgrade the firmware again and reinstall pretty much everything, but this time I also installed the BackDoorLock hack to prevent Amazon's silent firmware upgrade pushes. Since I had to downgrade, I went to firmware version 5.3.4 in order to try JBPatch. This program enhances the Kindle experience enabling hyphenation and other cool features Amazon doesn't enable with their firmware. Again, I couldn't find the md5sum (or any other) of the 5.3.4 firmware update. In case anyone is interested:

$ md5sum update_kindle_5.3.4.bin
579c8d8f6f38111e1e02105349505b42  update_kindle_5.3.4.bin

$ sha256sum update_kindle_5.3.4.bin
0ae75cb10e29f288d3244a8a0619b31a2fa59eef3cf30cdca3fdfdc2ee33201d  update_kindle_5.3.4.bin

Anyway, after downgrading to 5.3.4, I installed JBPatch, and I have to say it rocks! For now I only fiddled with the hyphenation patch and it works great.

Also, after looking some more about removing ads, I saw some posts (this and this) about the .assets directory under the system dir when you plug the KPW on the usb port (full path: /mnt/us/system). So I SSHed into the KPW and renamed the .assets dir to assets.bak and created a .assets file to take it's place. I turned the Wifi on for a few hours and so far no ads whatsoever, even the ones on the bottom of the home screen are gone (there's just that message "make sure your kindle is connected to the internet", or something like that)! So, considering the 5.3.4 firmware version, apparently, doing these two things (/var/local/adunits chmodding and /mnt/us/system/.assets replacement) make all ads disappear.

So, I guess that's it. I spent too much time hacking the KPW, time to do some actual reading!

Edit1: Forgot to mention how I set up my public key on the SSH server on the Kindle PW.
Edit2: Since md5 is broken (for some time already), I also posted the sha256 sums of the two firmware files I used.

Saturday, September 7, 2013

It's been a while... but there's new stuff!

So, my last post was made on december 2012, it's been nine months since I haven't posted anything. It's not because I didn't want to, but because nothing new happened.

On my last post I said that I had bought a 500GB USB HDD to use as the rootfs of my Arch Linux ARM RaspberryPi (RPI), but around february of 2013 I bought a 2 GB one. So I replaced the old HDD with the 2 GB one and kept the 500 GB HDD as my personal backup media.

That's the only new thing that had happened, until today.

I always loved reading books. I have probably around 200 (or more) books at home. I never thought this day would come but recently I got interested in getting myself an ereader and start going in the direction of ebooks. I always thought that turning a page was something unreplaceble, but I'm reading my first ebook on my android phone and I have to say I was wrong. It's quite comfortable. I wonder how comfortable it actually is read to on an ereader, certainly better. I plan on buying an ereader, but there are other financial priorities right now.

Anyway, surfing the internet I found out about calibre. I had actually heard about it before, but since I was not into ebooks, I never gave it much attention. I installed it on my desktop and it's actually pretty cool. It enables you to manage your ebook collection and it syncs ebooks with a lot of different ereaders/tablets.

So I thought: would it be possible to keep my ebooks on my raspberry pi and access them from the web? It turns out the answer is yes, and the best part, it's very simple. I'll describe what I did to turn my RPI that's running Arch Linux ARM into an ebook server.

The first thing was to create a database on the RPI using calibre. I actually ran calibre on my desktop, created a database and then copied it to my RPI.

One could run calibre with it's heavy GUI, but it's not a good idea. RPI's CPU is not strong enough, it would be a pain to run calibre like this. So what I did was use a command line tool that is shipped with calibre called calibre-server. What this tool does is run a web server where you can search and download the ebooks that are on it's database. The confirguration is very simple (check this link), but I wanted it to run everytime the RPI booted, and for that I had to create a .service file for systemd. I looked around the net and found two pages: this one and this one. So here's my final calibre.service file. Just save it on /lib/systemd/system/.

[Unit]
Description=Calibre-Server
After=network.target

[Service]
Type=forking
PIDFile=/run/calibre-server.pid
ExecStart=/usr/bin/calibre-server \
        --daemonize \
        --port=portnumber \
        --pidfile=/run/calibre-server.pid \
        --with-library=/path/to/library/ \
Restart=on-abort

[Install]
WantedBy=multi-user.target

# Useful options for calibre-server
#--password=passy
#--username=user

Edit the text in italic. A few notes on these settings:

1) Username and password are optional. With the current Arch Linux packages, setting a username and password will result in a non working server because of a bug on cherrypy 3.2.3 (web framework used by calibre). I got this info from this post. I looked for the cherrypy 3.2.2 Arch Linux ARM package but I could not find it. Appearantly the binary package provided by the official calibre site doesn't have this bug but I'm kinda lazy, I prefer using regular Arch packages. Anyway, this is not THAT much of a problem, since if a unauthorized person finds my server, the only thing he/she'll be able to do is download my books.
2) Run this server on a unsual port. As I mentioned on a earlier post, when I first started running a SSH server, it kept getting hammered (I did use ssh keys, which is a good thing). Once I changed the port number, all the hammering was gone. Now, I use unusual port numbers for every server I run on my home.

Now, to start the server simply type:

sudo systemctl start calibre.service

To stop the server:

sudo systemctl stop calibre.service

To run the server on every boot:

sudo systemctl enable calibre.service

That's it!

Also, while I was watching a movie on the RPI, I used my phone to access the web server and make some queries, the movie did not strutter. I didn't download any files, but the CPU managed the extra load.

There's a small problem with this setup: how to manage the database if running calibre GUI on the RPI is insanely slow (for adding books, for example)? One can do it with the command line tools calibre has but I reckon it'd be a pain. I did it by running calibre on my desktop and mounting the RPI filesystem on the desktop using NFS. Calibre devs say that running the database on a network drive is not supported but I did not encounter any problems. Just for the sake of safety, I did make a backup of the database before changing it.

Well, that's it. I hope this post ends being useful to anyone.

Monday, December 3, 2012

Raspberry Pi with some goodies!!!

All of the stuff I ordered from dealextreme has finally arrived. I'll address on how I got each time working. I didn't buy any of the following item at random. I looked at this list and looked at the comments of the products on dealextreme to find out if anyone had tested it on a RPI.

0) PSU (Power source)


I ordered this power source because it's rated at 5V, 2.1A, which seemed more than enough. The problem was that this PSU has a pretty bad voltage regulation (closed circuit voltage / open circuit voltage) and while it delivers 5.2 V with no load connected, while my RPI was idle the voltage measured between TP1 and TP2 was only 4.75 V, the bare minimum recommended.


Lucky me I had the charger of my former HTC cell phone handy. It's output plug is miniUSB but I had bought a miniUSB-microUSB adapter so I could easily use it to feed my RPI. Using this HTC cell phne charge, while the RPI is idle, the voltage measured between TP1 and TP2 is 5.03 V.


1) 16GB Class10 Kingston SD card (SD10V)


Since I had an install going on my 2GB SD card, I dd'ed an image of it to my HDD (dd bs=1M if=/dev/sdd of=./arch-arm.img, /dev/sdd on my case, use lsblk to list all disks) and then dd'ed this image to my 16GB card. Then using Gparted I resized the EXT4 partition. Tried the card on the RPI but it didn't work. Dd'ed the image again but this time I didn't resize the EXT4 partition. Didn't work either.


What happens is that even though systemd started the login service, the login prompt was never displayed. I asked for help on the Arch Linux ARM (ALARM) forums. One of the developers helped me out and I thought it was just a PSU problem, but it wasn't. My current PSU keeps 5.03 V on the RPI on idle (measured from TP1 to TP2) so I reckon it's just the card reader that doesn't like it. I ended up swapping this SD card with the 4GB Class4 one of my Wii and I'm using a USB stick as the rootfs (just formatted it as EXT4, copied the files with "cp -ar"  from the SD card to it and changed /etc/fstab so that /dev/sda1 was mounted as root).


The reason for running the rootfs from a USB stick was just speed, as I'm using a 4GB one and also have a 4GB SD card. I did some benchmarking using the dd command and regarding the write speed (writing a 512 MB file) I could only achieve 3.6 MB/s on the C4 SD card but got 8.1 MB/s on the USB stick. I did the same benchmark on my USB hdd (Seagate Expansion 500 GB) that I use on my Wii and managed to get 22 MB/s. Next week I'll buy a 1 TB USB hdd just for the RPI and I'll run the rootfs from there. Of course, it'll also be used to store my bittorrents downloads.


2) USB Hub


I ordered this guy. The power source of this USB hub is rated at 5 V, 4 A. Good enough, I guess. Everything I plugged on this USB hub worked properly (wifi dongle, bluetooth dongle, external hdd, wireless keyboard, etc.)


3) Wifi dongle


I ordered this one. It uses the well known RTL8188CUS chip and worked out of the box. To configure the wifi connections I used netcfg, a easy to use and lightweight solution, great when you're not using a mobile device, just set the ESSID and password for the connection and you're good to go. I'll not explain step-by-step because the Arch Wiki entry is pretty clear.


4) Wireless keyboard with touchpad


I ordered this one. It's very small, not so comfortable if you need to write a lot because only the thumbs are used to type but it's great for browsing the web, writing quick commands or using as a remote on XBMC. Also, I think the wifi signal sometimes interferes with the keyboard signal, but nothing majorly annoying.


5) Bluetooth dongle


I ordered this one. Cheap as hell and worked like a charm, Wiimote + classic controller recognized by RPI and ready to be used.


6) Heatsinks


I ordered this. It comes with 8 small heatsinks that fits perfectly the ARM CPU. I only installed a heatsink on the CPU but I also intend to install one on the USB controller and another one on the voltage regulator. These last two ones will need some customizing, I'll need to cut the heatsinks as they're too big.


---------------------------------------


Ok, so I got all the hardware I wanted (actually, I also ordered a case from modmypi.com around 10 days but it hasn't arrived yet) now I can get to the software configuration part.


Two posts ago I listed what I wanted to do with the RPI:

1) Old console emulator (mainly MAME and SNES);
2) Media center (streaming media from my desktop);
3) Torrent box (saving stuff on the SD card then ssh or ftp the stuff to my desktop);
4) Printer server (my printer is currently connected to my desktop, so if my wife wants to print something from her laptop, she needs to turn on my desktop).

Number 4 will not happen. Wifey don't want no printers in the living room.


Didn't have enough time to mess around and get number 1 working (didn't even TRY to get it working yet).


I did manage to get number 2 and 3 working properly. Like I said on my previous post, I'm using XBMC for playing H264 encoded HD videos, and it's working great.


As for number 3, I'm using Transmission. I've used Transmission ever since I ditched Windows for Linux (on Windows I used utorrent) but I've been using the regular gtk client (transmission-gtk package). What I'm using on the RPI is the transmission-cli package, running transmission as a daemon. This package also comes with transmission-remote which enables you to control the transmission-daemon from the CLI. Transmission-daemon also comes with a WebUI in case you want to control it through a web browser. As for configuring transmission, refer to the Arch Wiki entrySo, this is my basic setup, but there are some security considerations that have to be made.


About Transmission's WebUI: it supports authentication but it does not support SSL (https) connections natively (you have to so some extra work yourself, like putting a proxy in front of your server) so if you want to monitor your server from a remote network, then using this authentication is not very secure, someone eavesdropping can get your username and password and screw your server. Of course, when monitoring transmission-daemon from the LAN, there are no security problems (except for the fact that someone can break into the router by cracking your wifi signal). I want to be able to remotely check that status of my RPI Transmission-daemon, but I wanna do it in a secure manner. I decided to set up a SSH server (using SSH Keys, not username and passwords, check Arch Wiki) so I could monitor and interact with transmission-daemon using transmission-remote.


I'll not post a guide on how to setup Transmission or SSH server because the Arch Wiki entries (SSH, SSH Keys, Transmission) are very well explained. I'll just make a few remarks regarding some choices I made when configuring these servers and some stuff that people sometimes overlook:


1) When setting up a SSH server, choose a random port to run it from, don't use the default one (port 22). I ran a SSH server on my desktop one time using port 22 and going through the logs (/var/log/auth.log) I saw serveral login attempts. Changing the port eliminated the problem.
2) If you want to be able to login from outside your LAN, remember to forward the port on the router.
3) As for SSH keys, I made a 1024 bit long RSA pair. I had use RSA because I wanted to access my SSH server from a windows box (from work) using PuTTY. PuTTY doesn't support the regular OpenSSH key format, just his own key format generated using the PuTTYgen utility, and PuTTYgen only supports RSA and DSA keys. So, I had to take my private key and generate a PuTTY compatible one using PuTTYgen.
4) Since my Transmission server WebUI is not accessible from outside my LAN, I used the default port (9091) just to make things easier.
5) Remember to forward the listening port used by Transmission.

I guess that's it for now. See ya.

EDIT: I forgot to mention I signed up for a free DNS service called no-ip.com. It's working great so far and it was a breeze to install: simply install the noip client from the arch linux arm repo (pacman -S noip), run it (watch the instructions displayed after it's installed by pacman) and enable the daemon on systemd (systemctl enable noip2.service). 

EDIT 2: My RPI case from modmypi.com arrived. I really recommend it. It fits very well and even though it doesn't use any screws, it's closed tight.

EDIT 3: I said I'd buy a 1TB USB hdd and run the rootfs of the RPI from there. I ended up buying a 500GB Western Digital My Passport USB 3.0 drive, even though the RPI doesn't support USB3. Anyway, it's WAY faster than running from a C4 SD card or from a USB stick. The boot is VERY fasy and the programs also load faster. Also, I'm overclocking the RPI with the following settings:

arm_freq=1000
core_freq=500
sdram_freq=500
over_voltage=6


With that and the default cpu scaling governor being "on demand", the RPI runs at 700MHz whe the CPU load is low and at 1000MHZ when the CPU load increases.

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.

Sunday, October 14, 2012

Arch Linux News, a Raspberry Pi story and my plans for it!

Now it's official, systemd is now default on new installations. If anyone plans on using the last post as a guide to installing Arch Linux using the lastest install medium, the part "RUNNING A PURE SYSTEMD SYSTEM" can be skipped, as well as inserting (and removing) the line "init=/bin/systemd" in /etc/default/grub. I don't know if syslog-ng, cronie and dhcpcd@eth0 are loaded by default on the new installation. It can be easily checked though: just do a sudo systemctl list-unit-files (then press q to quit).

Unless you have been living under a rock or is not as nerdy as I am, you probably have heard about the Raspberry Pi (from now on I'll just call it RPI). It's a US$ 35 credit card sized LINUX computer with a 700 MHZ ARM CPU, 256 MB of RAM and a GPU capable of decoding H264 video files (also MPEG2 if you buy the license for it). It comes with 2 USB ports, an ethernet port, a HDMI out (full size), a composite video out, a stereo audio out and some GPIOs (general purpose I/Os) . Also, it only consumes around 3.5 watts on idle. Considering the power source efficiency, other peripherals connected, etc. let's round it up to 5 watts. This means that it costs (in Recife, Brazil) US$ 0,94 a month (R$ 1,87, US$ 1 = R$ 2) to keep it turned on. This makes a pretty cheap server!

I was thinking of importing one myself, but I found this page (it's in portuguese though). You see, here in Brazil the taxes are insanely high, so importing a US$ 35 RPI would mean I'd have to pay almost US$ 150 (R$ 300) for it, converting the brazilian currency (Real) to US dollars. The main reason being: not only the taxes are high but I'd have to pay taxes over the RPI AND the shipping service, which is even pricier than the RPI (around US$40).

I looked a Mercado Livre, the brazilian ebay, and found some RPIs being sold for around US$ 125 (R$ 250). That's cheaper and the RPIs were already in Brazil, so I woundn't have to wait so much. I "bought" one. The next day though, as I got to work, I encountered a friend of mine and told him how I "got" the RPI for around US$ 125 (R$ 250). Then he turned to me and said: "Dude, Farnell Newark Brazil is selling it for US$ 87,50 (R$ 175)".

This friend of mine ended up buying one as well, so we got two RPI and shared the shipping service bill. So, I ran to my computer and cancelled my original order. The RPI ended up costing US$ 93,16 (R$ 186,32). Considering my options, not bad right?

The RPI will probably get here in the middle of this next week, but I'll be travelling for the next two weeks. In the mean time, I have already made a list of all the stuff I'll need. Since it's so cheap to keep it turned on (also, using less energy is the green thing to do!) it makes a perfect little server. I'll hook it up on my 32" LCD TV on my living room. I plan on using my RPI as a: (not listed in order of importance):

1) Old console emulator (mainly MAME and SNES);
2) Media center (streaming media from my desktop);
3) Torrent box (saving stuff on the SD card then ssh or ftp the stuff to my desktop);
4) Printer server (my printer is currently connected to my desktop, so if my wife wants to print something from her laptop, she needs to turn on my desktop).

Since it runs Linux, the possibilities are... many. I plan on using Arch Linux ARM (ARM port of Arch Linux!) with Fluxbox as WM. Later, I plan on using Xmonad or Awesome WM.

For the RPI to do those 4 things I listed, I reckon I'll need:

1) Power supply

Power is supplied to the RPI by a mini-USB port. The RPI manufacturers recommend using a supply with 700mA of rated current. I found one on the web that is able to supply 1,5A. I'll also need a full USB to mini-USB cable. I do have two spares here already, so that's taken care of.

2) SD card

The RPI doesn't have any internal memory (aside from RAM). The operating system has to be installed on a SD card for the RPI to boot it. I'll get a 16 GB class 10 Kingston SD card.

3) Keyboard and Mouse

I'll just get a USB cordless keyboard with a touch pad attached.

4) Wifi dongle.

I don't want the ethernet cable running through the living room (the router is far from the living room TV).

5) Joypad and Arcade Control (and a bluetooth dongle for Wiimote support)

I don't have a USB joypad but I have a arcade control I made several years ago (I think it was in 2002, ten years ago!):




It's simply a wooden box with arcade buttons and microswitches soldered to a generic USB joypad. Since it's been some time since I last used it, some solders have gone bad but it can be easily fixed.

Also, cwiid is also available for Arch Linux ARM! I know it's somewhat outdated but it works. I can use my wiimote + classic controller as joypad. For that to work a bluetooth dongle is needed, I do have one but sometimes my wife wants to use it on her laptop, so I'll just get a new one.

6) External HD and External DVD drive.

These are for later. My external HD is being used on my Wii at the moment and at first the 16GB SD card will do the job. A external DVD drive is simply a good addition (and if you buy the MPEG2 license, RPI will turn into a DVD player!)

7) USB Hub with external power source.

To connect all this USB stuff, nothing better than a good quality USB hub with a extrenal power source. The two USB ports of the RPI are limited to 140mA.

8) HDMI cable. Already have one lying round here unused.

What I'll need to get as of right now (prices rounded up):

1) Power supply (R$ 34);
2) 16GB class 10 SD card (R$ 70);
3) Cordless keyboard + touchpad (R$ 132);
4) Wifi dongle (R$ 60)
5) Bluetooth dongle (R$ 20)
6) USB Hub with external power source with 7 ports (R$ 54)

That comes to a total of R$ 370 (US$ 185). With shipping: R$ 428 (US$ 214) (Buying from two different online stores, so I kinda have to pay twice the shipping bill).

Anyway, a RPI + a bunch of stuff needed to get it to do what I want: R$ 186,32 + R$ 428 = R$ 614,32 (US$ 307,16). That's actually pretty expensive. The RPI in Brazil is not a low-budget computer, considering a ASUS netbook with HDMI out here in Brazil costs R$ 900 (US$ 450) and it has everything my RPI will have and more, a R$ 285 (US$ 142,50) difference.

Comparing the two situations:

Advantages of MY future RPI system (emphasis on MY because the RPI cannot be generally compared to a netbook, but considering what I want to use it for, the comparison is valid):

1) The most expensive part are the accessories, which can be used somewhere else, and if my RPI dies, I can just get a new one and hook everything up again, but with the netbook, it's all or nothing;
2) 5 watts of power consumption versus 30 watts for the netbook;
3) Comes with GPIO (not that I'll use it right away, but I'll think of something);
4) How cool is it to have such a tiny computer?!?!?!?

Advantages of the Netbook:

1) It's way faster;
2) Battery "out-of-the-box". You can adapt batteries for the RPI, but you'll need to do it yourself;
3) Comes fully finished and the RPI doesn't even come with a case;
4) Regular x86 architecture, regular Linux distro can be used, and the RPI uses ARM processor, which limits the choice of distros;
5) Has it's own display and the RPI needs a external one;

The hdd and webcam of the netbook are actually not a advantage, because I could buy a good USB hdd and a good webcam for the RPI and it's still gonna be cheaper. Also, I'm not counting the fact that a netbook is a great mobile solution because what I wanna do with the RPI doesn't need mobility. But, in the end, the advantage number 4 for the RPI is what counts!

Anyway, what is missing for my future RPI is the case. I have no idea how I'm gonna solve this yet. I'm aware of this, but I'm terrible with my hands :p. I'll figure something out though.

As soon as I start working on the RPI I'll post my progress here.

Friday, September 28, 2012

Archlinux + Systemd + Fluxbox + Old laptop = Impressive Speed

Alright, around two/three weeks ago I uninstalled wattOS R5 from one of my old laptops and decided I'd get Arch on it, and since I liked Fluxbox on Ubuntu so much, why not do exactly that: Archlinux + Fluxbox on this oldie laptop? Anyway, I'll try to write a guide on getting a basic Archlinux with Systemd set up. Then we'll get to a point where I install the applications (including Fluxbox) I use, you can install whatever you like though, just adapt it for your system.

"Everything" (as far as I can remember) I did I wrote on a text file so I'll post step by step what I did, but be advised, I did this a few weeks ago so I cannot be absolutely sure that EVERY command is listed here and since I don't know the specs of your computer, what's written here may not work for you. With this disclaimer: in case anyone wants to try this out and gets stuck remember that Archwiki is your friend! I didn't make any of this up, I just followed the Archwiki guide.

Also, one more advice: if you really want to do this, read the whole post before attemping to do this!

So here we go!

PRE-INSTALL

0) First download the iso boot it. :)

After booting you'll be presented just with a terminal. Don't be scared, in no time we'll have a system running.

1) First thing we do is loading the proper keyboard layout with the loadkeys command. You can load any keyboard layout listed on /usr/share/kbd/keymaps/. In my case, it's a br-abnt2 keyboard. Simply type:

loadkeys br-abnt2

2) Then we need to partition the drive(s). The tool included on the Arch cd is fdisk. Before using fdisk though, you may want to see what your current partitions are, and for that just use the lsblk command. I just erased all partitions I had and created 2: the root (/) partition and a swap partition. This lappy only has 512MB (shared with video card) of RAM so I need a swap partition. Anyway, just type:

fdisk /dev/sda

and follow the instructions. Fdisk may seem wierd if you have never used it, but with a little patience you'll get there. I'd post every step I took during the execution of fdisk but I didn't take notes of them (sorry...). Alternatively you can boot any livecd of your choice (Ubuntu is a good and popular one, it has gparted, which is a pretty stright forward partitioning program) and partiton your hard drive(s) on a graphical interface program. If you're gonna run Arch, you might as well learn to use fdisk!

3) Since I used fdisk, I now had two partitons: one with 39GB (/dev/sda1) which I had to turn into a ext4 root partition and one with 1GB (/dev/sda2) which I had to turn into my swap partition. Now this is very easy:

mkfs -t ext4 /dev/sda1

The above command creates a ext4 file system on /dev/sda1.

mkswap /dev/sda2

The above command creates swap area on /dev/sda2.

swapon /dev/sda2

The above command activates the swap area.

INSTALLING A BASE SYSTEM

Now we're ready to install a base system. But before that, we'll need to get the internet connection working. The easiest way (and the way I did it) is having a cabled connection to a router running a DHCP server. After getting networking working, we have to mount the root partition somewhere on our basic system, copy stuff there and then chroot into it.

4) Next we mount the hdd on /mnt of our system:

mount /dev/sda1 /mnt

5) Then we ask for a IP address from the DHCP server:

dhclient

If you wish to use a static ip address, check Archwiki for more details.

Now, before proceeding let's test if the internet connection in working:

ping -c 3 google.com

If all goes well, we can proceed.

6) Now we can install a very basic system to our hdd that is mounted on /mnt:

pacstrap /mnt base base-devel grub-bios

7) Next we have to generate a fstab file. To do it:

genfstab -p /mnt >> /mnt/etc/fstab

8) Now we're ready to chroot into our new system! In case you don't know what chroot is, check out Archwiki. Anyway, now we do:

arch-chroot /mnt

9) We're almost there! Now we're on the root of our new system! There's a lot of quick stuff to do:

9.1) Write your hostname to /etc/hostname file. Just type anything you want, mine was hp-laptop (creative right?).

9.2) Symlink /etc/localtime to /usr/share/zoneinfo/Zone/SubZone. Replace Zone and Subzone to your liking. In my case:

ln -s /usr/share/zoneinfo/America/Recife /etc/localtime

9.3) Set locale in /etc/locale.conf. Even though I'm Brazilian I use default english US as my locale (I don't want software translated). So I just wrote "LANG="en_US.UTF-8"" to my /etc/locale.conf, without the outter quotes.

For my Brazilian friends, these might work:

LANG="pt_BR.UTF-8"
LANG="pt_BR ISO-8859-1"


9.4) Add console keymap and font preferences in /etc/vconsole.conf. Check the Archwiki for more details. I used:

KEYMAP=br-abnt2
FONT=default8x16

9.5) Uncomment the selected locale in /etc/locale.gen and generate it with locale-gen:

locale-gen

9.6) Now we have to configure /etc/mkinitcpio.conf and create an initial RAM disk. I used the default one, except that I added consolefont keymap to the end of the HOOKS array. Then we have to run:

mkinitcpio -p linux

Great! RAM disk is created, now we only need to install and configure grub2 so we can reboot and have a very basic system!

9.7) Now, to install grub2 on the MBR (Master boot record) of the hdd:

modprobe dm-mod
grub-install --target=i386-pc --recheck --debug /dev/sda
cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo


Now we have to edit /etc/default/grub and add the following to the GRUB_CMDLINE_LINUX line:

init=/bin/systemd

Also, I took quiet out of the GRUB_CMDLINE_LINUX line.

This will make your system run on a systemV/systemd hybrid setup. Later we'll make it systemd pure!

9.8) Now we have to make the grub config file:

grub-mkconfig -o /boot/grub/grub.cfg

Grub2 should be working! Now we only need...

9.9)... to setup a root password!

passwd

9.10) Now we get out of the chroot environment with Crtl+D and unmount the hd file system:

umount /mnt

Now we can reboot!

reboot

Now take that cd out of the drive and grub2 should boot!

RUNNING A SYSTEMD PURE SYSTEM!

10) Ok, so now systemd is getting its info of which daemons to run from the /etc/rc.conf file and we'll fix that. The deafult rc.conf file only has 3 daemons on the DAEMONS array: syslog-ng, network, crond. What we'll do is enable these services on systemd so we can ditch the rc.conf file:

systemclt enable syslog-ng
systemclt enable cronie
systemclt enable dhcpcd@eth0


Like I said, I have a router with a DHCP server, so the last line means exactly that: ask the DHCP server for an ip address. If you're using static ip address, check the Archwiki.

I'd like to spend some time here and explain something really important. In Arch, on the contrary of Debian, Ubuntu, Fedora, etc, the system will only run programs you tell it to run. I mean, on the course of this tutorial we'll install some other daemons and for each one we'll have to enable them manually. I (and I reckon all other Archers :P) like this because everything that's running it's because you told the system to do so.

Now reboot just to check if everything is working (and it should be!)

11) Now remove the init=/bin/systemd entry on /etc/default/grub and run:

grub-mkconfig -o /boot/grub/grub.cfg

12) Configure the package manager (pacman) by editing /etc/pacman.conf. I didn't change the default settings for now. I just ran:

pacman -Syy
pacman -Syu


13) Now, for a pure systemd system:

pacman -Rsn initscripts
pacman -S systemd-sysvcompat


Now reboot. If your computer booted (and it should have), then you're running a pure systemd system. Enjoy the full speed boot!

ADDING A USER, SOUND, VIDEO, ETC.

All right! Now he have a base system booting with grub and systemd. Now we can add a regular user (you shouldn't run as root!), sound, video, wifi, desktop environment / window manager, apps, etc.

14) Firstly, we add our usual user :P. Just run the command below and change the last word "username" for the username that you want.

useradd -m -g users -G audio,games,lp,optical,power,scanner,storage,video -s /bin/bash username

To add a password:

passwd username password

Of course, change "username" for your username and "password" for your password. :P

15) Ok, so you created your username, but having to change to root everytime you need root access is a pain. Let's install sudo:

pacman -S sudo

Now we have to edit the /etc/sudoers file and add the regular user's username to the list of sudoers. Simply run:

visudo

You should always edit the sudoers file using visudo because after editing it, it checks the file for any errors. Also, learn to use vi (or vim), I am begining to and I can already see why people like it so much.

Now, just below this line:

root ALL=(ALL) ALL

Add:

username ALL=(ALL) ALL

Again, change username to your username. Great, now we have sudo installed, so type:

exit

And login using your username and passy. Now we can use sudo everytime we need root access.

16) Ok, now we'll get sound working. But before that I'll explain the very basics of how to use pacman, Arch's awesome package manager. I'll just show the most basic commands: install packages, search packages, remove packages and do system upgrades. You'll get to learn how to use pacman by using it later. So, the basic commands:

To install packages:
pacman -S package1 package2 package3...
You can install any number of packages you want using a single line.

To search for packages to install:
pacman -Ss string
string can be the package name or discription. Each package has a brief discription and this command searches these discriptions. Any matches are then displayed.

To uninstall packages:
pacman -Rsn package1 package2 package3...
The -R is for removal, s for removing any unnecessary dependencies and n for removing the configuration files of all packages removed.

To fully upgrade the system:
pacman -Suy
Remember: Arch is a rolling release bleeding-edge distro. Before updating, check the forums to see if any new package is braking peoples systems. It NEVER happened to me, but some people have complained about it, so you never know.

Back to the tut: simply install the alsa packages by running the command below:

sudo pacman -S alsa-utils alsa-plugins alsa-oss
alsamixer


I can't remember if alsamixer has to be run as root or not. Try as your regular user, if that doesn't work, then sudo it. A ncurses user interface is shown to you, so set your volumes and unmute the channels. Now run:

sudo alsactl store

I had to reboot my laptop at this point so my channels would actually unmute.

17) Now we have to install X server and the video driver! Easy enough:

sudo pacman -S xorg-server xorg-xinit xorg-server-utils mesa mesa-demos

Now we need to find out which graphics card the computer has by doing:

lspci | grep -i vga

Mine is a ATI XPRESS 200M 5955 so I have to install the ATI driver. In my case:

sudo pacman -S xf86-video-ati

To get a list of available drivers do:

sudo pacman -Ss xf86-video | less

Hit q to quit. Now you probably know which driver to install. These are open-source drivers. If you want to install proprietary ones, check the Archwiki for the particular manufacturer of your graphics card.

18) Since I'm installing Arch on a laptop, I need synaptics for the touchpad:

sudo pacman -S xf86-input-synaptics

I used the "default" configuration listed on Archwiki. Simply add those lines to /etc/X11/xorg.conf.d/10-synaptics.conf:

To properly setup your keyboard on X, paste the contents of this link on /etc/X11/xorg.conf.d/10-evdev.conf

The "XkbLayout" and "XkbVariant" values depend on your keyboard mapping. Check Archwiki for more info, but everything you need to know is the /usr/share/X11/xkb/rules/base.lst file. You'll figure it out. At first I used "br" and "nodeadkeys" for "XkbLayout" and "XkbVariant", respectively. But the ^'~ type chacracters did not work well (for portuguese writng, that is). To fix it, I just took the "XkbVariant" out.

19) Now we install 3 more basic X packages and then we're ready to test X:

sudo pacman -S xorg-twm xorg-xclock xterm

Make sure there is no .xinitrc file on your user's home folder:

make sure: rm ~/.xinitrc

Now we can test X by running:

startx

You should see 3 terminals running. Exit the leftmost of them and you'll return to the CLI. If X failed, try to reboot and try again. If it still doesn't run, you (or me!) probably forgot to do (write) something. But everything should be ok.

20) Now we install some fonts to make our future desktop look better :)

sudo pacman -S ttf-dejavu ttf-inconsolata ttf-liberation ttf-ubuntu-font-family

21) Ok, so now I had to get AUR (Arch User Repository) working because my wifi card is really annoying and I need some aur packages to get it working. So, what is AUR you ask, it's a repository with packages made by fellow Archers that are good enough to help us less knownledgeable users to get software that's not on the main arch repos.

To get AUR working, just add this to end of your /etc/pacman.conf file:

[archlinuxfr]
Server = http://repo.archlinux.fr/$arch


Now run:

sudo pacman -S pacman-color yaourt

pacman-color is a cool program: it's pacman, with colors! :P

To use it more easily simply alias it to pacman so it gets executed instead of the regular pacman when you call pacman. Simply add this to the end of the ~/.bashrc file:

alias pacman='sudo pacman-color'

This way, everytime you type pacman, the shell interprets as being "sudo pacman-color". Cool right?

yaourt is the program used to install, update, search and remove aur packages. It has the same syntax of pacman but you should NEVER run it as root!

So, my wifi card is (just ran lspci | grep -i wireless):

Network controller: Broadcom Corporation BCM4318 [AirForce One 54g] 802.11g Wireless LAN Controller (rev 02)

I needed to install the package b43-firmware from aur:

pacman -Suy
yaourt -S b43-firmware


Also, I blacklisted b43legacy module by adding "blacklist b43legacy" (wthout the quotes) to the file /etc/modprobe.d/wifi.conf

Wifi cards are always a pain, I do expect that your wifi card setup isn't as bad as mine. Anyway, the wifi led on the laptop went on but configuring a wifi card on CLI is a pain so I waited till my window manager (Fluxbox!) was installed so I could do it on a graphical environment.

22) Now that we have a basic system with pacman and network we're ready to install Display Managers, Desktop Environments or Window Managers and all kinds of applications! Like I said in the very first paragraph of this post: this is a matter of personal taste. You can use any programs you feel comfortable. Wanna use KDE, install KDE. Wanna use Gnome, install Gnome.

For now, let's focus on the DE/WM and DM. As I already said, I'm gonna use Fluxbox as my WM. To install it:

pacman -S fluxbox

Secondly, let's install the Display Manager. I chose (as always) SLiM. As the name says, it's the slimmest DM I know, and since the only thing a DM does is manage your logins, I see no purpose on having a fancy DM. So, to install SLiM (and some themes that go well with it):

pacman -S slim slim-themes archlinux-themes-slim

Now, to configure SLiM (we will configure Fluxbox once we boot into it) we just have to edit /etc/slim.conf. It's all there, but I usually change just two lines (and remove the # from the begining of the lines, where applicable): default_user (change it to you own instead of the one written there) so that when SLiM boots your username is already typed and current_theme (you can choose themes from /usr/share/slim/themes, but always use the "archlinux-simplyblack" theme).

Next we copy the default .xinitrc file to your user's home dir:

cp /etc/skel/.xinitrc ~/.xinitrc

Then we have to add a line at the end of ~/.xinitrc so that SLiM can launch the WM/DE that we have installed. In this case:

exec ck-launch-session startfluxbox

We have to add the ck-launch-session to get automount to work (as in automounting USB keys, DVDs, etc.).

Only one more step to go, enable SLiM on systemd:

sudo systemctl enable slim.service

If we rebooted the computer now, then SLiM would boot and after logging in SLiM would execute Fluxbox. But, let's stick to command line some more.

23) Since I'm on a notebook, I need a wifi connection manager. I'll use wicd. To install it:

pacman -S wicd wicd-gtk

To make wicd starts after boot, well add it to systemd's services:

sudo systemctl enable wicd.service

24) Now let's make sure our clock will always be synced. Let's install ntpd (NTP Daemon):

pacman -S ntp

Now we edit /etc/ntp.conf

And since I'm in South-America I added the following to my ntp.conf:

server 0.south-america.pool.ntp.org iburst
server 1.south-america.pool.ntp.org iburst
server 2.south-america.pool.ntp.org iburst
server 3.south-america.pool.ntp.org iburst

To know the actual server of your continent check this out.

Now we add ntpd to systemd's services:

sudo systemctl enable ntpd.service

25) This step is optional though. There's one program I found out about recently called preload. This program "learns" which other programs you most often use and preloads some libraries they need to RAM, making them startup faster. Since I'm going for a "minimalistic" install (it could get more minimalistic, but for me this is minimalistic enough), I have some RAM to spare, and since the processor and hdd of this laptop are slow, preload comes in handy. To install it:

pacman -S preload

As usual, we add this to systemd's services:

sudo systemctl enable preload.service

I didn't mess with the config, but if you're willing, it's located in /etc/preload.conf

26) Fantastic! Now the only thing missing are the actual programs, icons, etc. we're going to use! Again, this is a matter of personal taste. If you want chromium as your browser instead of firefox, just install it and leave firefox out. To find out the name of the package of a certain program/icon them/font/etc just use:

pacman -Ss search_string

I'll list the programs I installed like this:

"Category" or "Why do I need it" - package(s) name

Also, Archwiki has a page that lists some common programs you may want. So, let's begin.

Makes it easier configuring the UI - lxappearance

Icon themes - gnome-icon-theme gnome-icon-theme-extras hicolor-icon-theme human-icon-theme tangerine-icon-theme azenis-icon-theme

Cursor themes - xcursor-vanilla-dmz xcursor-vanilla-dmz-aa xcursor-themes xcursor-bluecurve xcursor-flatbed xcursor-premium xcursor-flatbed xcursor-pinux

Bittorrent client - transmission-gtk

Web browser (Uzbl as main and Firefox as fallback) - uzbl-core uzbl-browser firefox

Download manager - fatrat

FTP client - filezilla

Picture viewer (feh can be used to set backgrounds easily) - gpicview feh

Take screenshots (just do import /path/to/file.jpg to take a screenshot, but actually, imagemagick does much more) - imagemagick

Music player - audacious

Video player - vlc

CD/DVD burning - xfburn

Un/compress utilities - p7zip file-roller unrar unzip

Run graphical programs as root - gksu

File manager (PCManFM) + ability to mount samba shares - pcmanfm gamin gvfs gvfs-smb smbclient

PDF reader - evince

Office suite - libreoffice

SSH client - putty

Calculator - galculator

Conky (needs no introduction I guess) - conky

Terminal emulator - roxterm

Text editor (like I said, I'm trying to learn vi(m), for a more usual program, you could get leafpad or mousepad) - gvim

NOTE: givm package now includes vim.

Programming IDE - geany

Task manager - lxtask

Screensaver (and lock screen!) - xscreensaver

Volume icon for the system tray (not needed if you install some fancy DE like gnome or KDE) - volumeicon

Battery indicator (form AUR) - sudo yaourt -S slimebattery-git

Java, flash and other plugins - jre7-openjdk jr7-openjdk-headless icedtea-web-java7 flashplugin gecko-mediaplayer gstreamer0.10-plugins

NOTE: I had to install jr7-openjdk-headless twice on the first time it was in conflict with some other package I can't remember.

Ok! That was a lot of packages. To install all that:

pacman -S lxappearance gnome-icon-theme gnome-icon-theme-extras hicolor-icon-theme human-icon-theme tangerine-icon-theme azenis-icon-theme xcursor-vanilla-dmz xcursor-vanilla-dmz-aa xcursor-themes xcursor-bluecurve xcursor-flatbed xcursor-premium xcursor-flatbed xcursor-pinux transmission-gtk uzbl-core uzbl-browser firefox fatrat filezilla gpicview feh imagemagick audacious vlc xfburn p7zip file-roller unrar unzip gksu pcmanfm gamin gvfs gvfs-smb smbclient evince libreoffice putty galculator conky roxterm gvim geany lxtask xscreensaver volumeicon jre7-openjdk jr7-openjdk-headless icedtea-web-java7 flashplugin gecko-mediaplayer gstreamer0.10-plugins

sudo yaourt -S slimebattery-git


27) One final thing before booting into Fluxbox: to get wicd's icon, slime's icon and volumeicon's icon to show on the system tray and to make xscreensaver launch on startup, one just has to add the following to ~/.fluxbox/startup file (to find out where it should go, just read the file):

wicd-client -t &
xscreensaver -nosplash &
slimebattery --change-icon --interval 60 &
volumeicon &


That "--interval 60" option on slime means that the battery charge level will be updated every 60 seconds.

28) Now we're ready to boot into Fluxbox (or whatever DE/WM ytou chose). Just:

sudo reboot

And login!

29) Great, now you logged in to you DE/WM. Congrats. Now the only thing that needs to be done is configuring your DE/WM. As for configuring Fluxbox, I did something very similar to my post "Fluxbox: I liked it! :)" (post before the previous one). To get more Fluxbox styles, check this page out. To install styles, simply copy them to ~/.fluxbox/styles.

Also, the default menu is very poor. To make a new one, firstly you can do the following:

pacman -S archlinux-xdg-menu
xdg_menu --fullmenu --format fluxbox --root-menu /etc/xdg/menus/arch-applications.menu >~/.fluxbox/menu


And then you edit your ~/.fluxbox/menu to include your custom entries.

30) One last optional thing: after configuring everything, I ran conky and the CPU's frequency was set to 800MHz, but the rated frequency of this laptop's CPU is 1600MHz. After some researching, I found out that CPU scaling is enabled by default in current kernels (remember Arch is bleeding edge!) and it works like this: until your CPU reaches a certain load, the kernel keeps it in a low frequency state and when the load increases, it increases the CPU's frequency, that's called the "on-demand" governor, and that's the default setting set by the kernel. I'm ok with that, since lower frequency means less energy spent. But I wanted to have a way to fix it anyway, I wanted to find a way to set my governor to "performance" (rated frequency at all times). All details are here. So I just needed to install the cpupower daemon and make sure that systemd was told to run it as startup. So, here are the commands:

sudo pacman -S cpupower
sudo systemclt enable cpupower.service


And to switch between "on-demand" and "performance" governors I just added the following to my ~/.fluxbox/keys file.

Mod4 p :ToggleCmd {Exec sudo cpupower frequency-set -g ondemand} {Exec sudo cpupower frequency-set -g performance}

That means that pressing the super key + p switches between the "on-demand" and "performance" governors. Of course, I had to add to add the following to my sudoers file:

myusername ALL=NOPASSWD:/sbin/shutdown,/sbin/reboot,/usr/bin/cpupower

Or else I'd have to keep inputting my password. The shutdown and reboot commands are there also so I can use those commands on Fluxbox's menu without supplying password (see my "Fluxbox: I liked it! :)" post)

31) One final tip: it's possible to issue Fluxbox commands through bash shell using the fluxbox-remote command. I used on a script that sets my VGA-out. Everytime I returned to the native resolution of my LCD screen Fluxbox would display the task bar in the middle of the screen. It can be easily set it back to it's right place by issuing the Reconfigure command on Fluxbox's menu, but I wanted to include this on the script so it would be done automatically. Anyway, here's the command I used on the script:

fluxbox-remote Reconfigure

It took me a while to find this command. I found it on the Arch Forum but I could not find it on the Fluxbox documentation.

32) I think that's it. That's the longest post I ever did, it took me around 4 nights (kinda) to get it done and I hope it helps someone. If you have any doubts about this "tutorial" (it's a lot of info!) you can drop a comment and I'll try to help.

In the end, here's my clean desktop :P


Arch is indeed fast. Not because it's actually faster than other distros, it's just because it runs what you tell it to run, no more, no less. Just so we can get a rough figure, on my post "Fluxbox: I liked it! :)" I wrote the RAM used just after logging in on Xubuntu and on my "Xubuntu turned Fluxbox" lappy. Just so you know, here are the number again:

Xubuntu (with compositing disabled) - 165.1 MB
"Xubuntu turned Fluxbox" - 95.8 MB
Archlinux with Fluxbox described above (and with preload running) - 69.3 MB

This old lappy is blazing fast again. :)

PS: I know that I said I was gonna try Slackware, and I was really gonna, but when I looked it up on the web, I found out that the Slackware team is already almost launching Slackware 14 (rememebr that was two-three weeks ago. Funny though, TODAY, Slackware 14 was released.