Archive

Archive for the ‘Hardware’ Category

Raspberry Pi with Arch Linux

November 26th, 2012 1 comment

Installation on SD-card

Installed Arch Linux on my raspberry pi. I didn’t want any gui schmui and this image seemed like a pretty clean option to me.

Downloaded the image, checked the sha1sum and dd’ed the file onto an sd card. (Determined the /dev/yoursddevice name by doing an fdisk -l)

sudo dd bs=4M if=/path/to/your/image/arch-linux.img of=/dev/yoursddevice

Waiting a few minutes, drinking some beer. Done.

Expanding the root partition

My card was 4GB and the downloaded img is only 2GB. This would result in some unused space and I wanted to use it. Add another partition or resize the current. Now is a good time as the device is not in use.

sudo fdisk -uc /dev/mmcblk0
 
Command (m for help): p
 
Disk /dev/mmcblk0: 3904 MB, 3904897024 bytes
64 heads, 32 sectors/track, 3724 cylinders, total 7626752 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: 0x0004f23a
 
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      186367       92160    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          186368     3667967     1740800   83  Linux
 
Command (m for help): d
Partition number (1-4): 2
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
 
# !!! Make sure next value is the same as the start of the deleted partition !!!
First sector (186368-7626751, default 186368): 186368 <-- That value! Same in this case, but can be different.
Last sector, +sectors or +size{K,M,G} (186368-7626751, default 7626751): 
Using default value 7626751
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

Wanted to run resize2fs but it prompted me to run e2fsck first.

sudo e2fsck -f /dev/mmcblk0p2

Resize the partition. (-p shows progress bar)

sudo resize2fs -p /dev/mmcblk0p2

Awesome, full SD-card will be available now. Unmount and put it in the rpi.
(I used a microSDHC (4GB, class 4) card from kingston with adapter which didn’t work. So I bought a set of regular 4GB class 4 SDHC cards from kingston)

Wireless

In my first installations I just used the HDMI interface and an ethernet cable. Later I decided that it would be nice to have wifi as well. So I picked up an Edimax EW-7811Un Wireless USB Adapter.

You can set up your wireless interface in advance by mounting the new partition after writing the downloaded image with dd. Paths mentioned after this are of course relative to /mnt/sdcard

sudo mkdir /mnt/sdcard
sudo mount /dev/mmcblk0p2 /mnt/sdcard

To use it with the rpi I edited the /etc/conf.d/netcfg file and added ‘wireless-wlan0‘ to the networks array. I also added a DHCP_TIMEOUT=30 to allow for a bit more time for the wireless interface to get an IP-address.

# Enable these netcfg profiles at boot time.
#   - prefix an entry with a '@' to background its startup
#   - set to 'last' to restore the profiles running at the last shutdown
#   - set to 'menu' to present a menu (requires the dialog package)
# Network profiles are found in /etc/network.d
NETWORKS=(ethernet-eth0 wireless-wlan0)
 
# Specify the name of your wired interface for net-auto-wired
WIRED_INTERFACE="eth0"
 
# Specify the name of your wireless interface for net-auto-wireless
WIRELESS_INTERFACE="wlan0"
 
# Array of profiles that may be started by net-auto-wireless.
# When not specified, all wireless profiles are considered.
#AUTO_PROFILES=("profile1" "profile2")
 
DHCP_TIMEOUT=30

I then copied an example config:

cp /etc/network.d/examples/wireless-wpa /etc/network.d/wireless-wlan0

Originally it looks like this:

CONNECTION='wireless'
DESCRIPTION='A simple WPA encrypted wireless connection'
INTERFACE='wlan0'
SECURITY='wpa'
ESSID='MyNetwork'
## Uncomment if the supplied ESSID is hexadecimal
#ESSID_TYPE='hex'
KEY='WirelessKey'
IP='dhcp'
# Uncomment this if your ssid is hidden
#HIDDEN=yes

I only changed the ESSID and KEY values to match my wireless network settings. This is probably the most basic setup. For more advanced setups check out the netcfg and wireless sections in the arch wiki.

Reducing write cycles

I am not running any production-critical apps on my raspberry nor do I use any programs that require atime/relatime to be running. So I enabled the noatime option for the root partition and mounted /var/log as tmpfs as I don’t have any interest in these logs. (/tmp was already mounted as tmpfs)

My new /etc/fstab now looks like this:

#
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
/dev/mmcblk0p1  /boot           vfat    defaults        0       0
/dev/mmcblk0p2  /               ext4    defaults,noatime        0       0
tmpfs           /var/log        tmpfs   defaults,noatime,mode=0755,size=5%      0       0

Further installation

Inserting the sd-card into the Raspberry Pi. It booted okay. (If it is not check this list to see if your SD-card is compatible) Hostname was alarmpi at that moment so I just ssh-ed into it. You can scan with nmap if you don’t now which address your machine got. (Or check your router). Do this only when you have permission to scan the network. The command you could use looks something like this:

nmap -p 22 --open -sV 192.168.1.0/24 | less
# My raspberry was listed as:
# 22/tcp open  ssh     OpenSSH 6.1 (protocol 2.0)
# MAC Address: B8:27:EB:XX:XX:XX (Unknown)
ssh root@alarmpi
   #password = root, so you probably want to change that asap. :)
passwd
   #and then create a new user so you don't have to login with root
useradd -m yourUserName
passwd yourUserName

I then ran a system update to prevent unfound packages later on:

pacman -Syu

I then installed vim. As my favorite editor.

pacman -S vim
ln -s $(which vim) /usr/local/bin/vi
ln -s $(which vim) /usr/local/bin/view

Changed the hostname to something else. (jukepi in my case, I want to use this one as a jukebox)

vi /etc/hostname
    #alarmpi -> yourHostName

I then disabled root login with SSH. (After testing my new account worked)

vi /etc/ssh/sshd_config

Uncommented PermitRootLogin and changed to ‘no’

PermitRootLogin no

Save and restart sshd

systemctl restart sshd

Changed my timezone with tzselect

tzselect
    # Get the options

I modified /etc/timezone and added the outcome to the generic profile in /etc/profile

...
 
# Set our default path
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
export PATH
 
# Set timezone
TZ="Europe/Amsterdam"
export TZ
 
# Load profiles from /etc/profile.d
...

Reloaded the profile

source /etc/profile

Modified the /etc/ntpd.conf by adding a few ntp server to sync with.

server 0.nl.pool.ntp.org
server 1.nl.pool.ntp.org
server 2.nl.pool.ntp.org
server 3.nl.pool.ntp.org

And restarted the ntpd daemon

systemctl restart openntpd

And checked if date was correct by running date.

date
#Mon Nov 26 22:46:14 CET 2012

Installed alsa-utils and mpg123 for sound

pacman -S alsa-utils mpg123

Make sound module to auto-load. (It isn’t by default)

vi /etc/modules-load.d/snd_bcm2835.conf
 
# Load Sound
snd_bcm2835

To play sound through jackplug: (Found this info here)

amixer cset numid=3 1

Or to play sound through HDMI:

amixer cset numid=3 2

Add your user to the audio group to have it play sounds.

usermod -G audio -a yourUserName

And test it if you like:

wget http://www.freespecialeffects.co.uk/soundfx/sirens/police_s.wav
aplay police_s.wav

If you get this error:

ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4725:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:696: audio open error: No such file or directory

Then you need to add your user to the audio group. 🙂

usermod -G audio -a yourUserName
 
# to apply the group directly, you can start a new login shell
# su -l yourUserName

VLC (As a service)

Because I couldn’t play every audio stream I decided to install vlc. (Which conveniently comes with a web interface)

pacman -S vlc

I got some 404 messages while installing for several packages so I looked them up on google and downloaded/installed them by hand. (Presumably because my install was not up-to-date atm. Run pacman -Syu to upgrade to latest version)

wget ftp://blablabla/missing-packagename-version.pkg.tar.armv6h.pkg.tar.gz
pacman -U missing-packagename-version.pkg.tar.armv6h.pkg.tar.gz
 
pacman -S vlc

After running cvlc I got some pulseaudio messages. Stating that it was missing. 🙂

pacman -S pulseaudio pulseaudio-alsa
 
# libao to make mpg123 work with pulse
pacman -S libao
# change /etc/libao.conf 'alsa' => 'pulse' to make it work with pulse

After that I rebooted to make sure everything was loaded/working ok. (And it did, used paplay police_s.wav to test)

I edited the vlc http .hosts file to allow access from my network:

vi /usr/share/vlc/lua/http/.hosts
 
# And added
192.168.1.0/24

To run vlc headless with http interface:

cvlc --intf http --http-host <yourIpHere> --http-port 8080 <fileName|streamUrl>

Running VLC + PulseAudio is lot heavier than just mpg123 (~40% for VLC + ~10% for Pulse vs ~10% mpg123) but I like the flexibility it gives me.

I want to create some kind of jukebox so the next thing to do is to create a systemd service to run vlc.
We will first create the script which we will place in /etc/rc.d

sudo vi /etc/rc.d/vlc
 
#!/bin/sh
 
case "$1" in
        start)
                echo "Starting VLC"
		su -l -c "/usr/bin/cvlc --intf http --http-port 8080 <fileName|streamUrl> &" <yourUsername>
                ;;
        stop)
                echo "Stopping VLC"
		killall vlc
		;;
        restart)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)
                echo "usage: $0 {start|stop|restart}"
esac
exit 0

Now we will create a systemd service file.

vi /usr/lib/systemd/system/vlc.service
 
[Unit]
Description=VLC Daemon
Wants=iptables.service
After=iptables.service
 
[Service]
ExecStart=/etc/rc.d/vlc start
ExecReload=/etc/rc.d/vlc restart
ExecStop=/etc/rc.d/vlc stop
KillMode=process
 
[Install]
WantedBy=multi-user.target

The last step is enabling the service.

systemctl enable vlc.service

Google Go

The next one to install is Google Go. I wanted to be able to spend the rest of the cpu power as effectively as possible.
At the moment there is no (official) package available for Google Go so we will have to build it from source.
I used Dave Cheney’s excellent tutorial to install it but then for Arch Linux. (No need to install libc6-dev btw) I made symbolic links in /usr/bin to the compiled binaries go, godoc and gofmt.

Backup

After completing your setup it might be a good idea to create a backup which you can tuck away for a rainy day. My previous SD-card was unrecoverable after some ungrateful and ungraceful shutdowns. To be able to get the system up and running asap we will create a gzipped image. Shutdown your rpi gracefully and let’s create an image of the sd-card.

dd if=/dev/mmcblk0 conv=sync,noerror bs=1M | gzip -c  > /mnt/yourbackuplocation/rpi.img.gz

Restoring the file:

gunzip -c /mnt/yourbackuplocation/rpi.img.gz | dd of=/dev/mmcblk0 conv=sync,noerror bs=1M

Enabling Wake-on-LAN on your local machine (Windows)

January 29th, 2008 1 comment

Well ain’t it all a bit nasty? You are at work and you left some important files on your home pc because you were working on it last night. You are starting to pull out your hair because you now either need to drive back to fetch it or do all your hard work again.

But not any more. We arrived in this new millennium and we want to automate everything as much as possible. (Well my inner geek at least 😉 )

Let’s start with enabling Wake-on-LAN (WOL) on your home pc.

Well Wake-on-LAN already states it. You will need to boot from a LAN machine in order to make this work. I use my router to be able to do this trick. It is a Linksys WRT54GL with DD-WRT flashed on it. It will allow me to log in with ssh or putty and load the webinterface so I can wake up my pc. In this case an Asus P5K-E.

Before we can boot this baby we need to make sure WOL is enabled in the BIOS. So boot it and get into the bios by pressing whatever button you need to at startup.
Start to look for something like Wake-on-LAN or PME (Power Management Event) in your BIOS. Depending on your hardware it will have different settings. In my case I had to enable PME events on PCIE devices as my ethernet was a PCIE device.

After enabling it save your settings and boot into windows. (used for this example, for linux do a bit of research on the net)
With the most common options you only need to do a proper shutdown from windows in order to make your WOL work. In some cases you will have to do some extra work by configuring your ethernet device. I have some screenshots of this event from the control panel.

WOL1

WOL2

So go to your network connections. Right click on your connection and open the properties. Then configure your network adapter and search for Wake from Shutdown / Wake-on-LAN or something similar and enable it. Also make sure that your wake-up options is set to ‘Magic Packet’ and not ‘Pattern Matching’. It caused my pc to boot when I did not want it to boot. After that shutdown your machine and try to boot it from LAN. There are a lot of programs out in the wild being capable of sending magic packets across the network. For debian based machines there are etherwake /wakeonlan and for windows winwake / magic packet sender. A bit of searching on the net might get you some of the wake-up clients you need. Have fun!

Managing the electricity bill

October 4th, 2007 No comments

Energy Cost Meter

Ok I wasn’t actually looking into saving a quick buck but well good things happen sometimes. 😉

I bought this meter to measure how much power an electronic device uses. I was especially interested in my new VIA Epia board. It measured a mere 17W average after booting. I was quite satisfied by the results at this point. (Via Epia EK8000EG, 1GB Kingston RAM, Samsung 2.5″ 120GB hdd)

Less satisfied I was with my printer, a HP 7310 which apparently still used 9W while being turned off completely. Quite angry I pulled the electrical cord, no more power flowed towards this device now. A short click was the last response it gave to my action…

Categories: Hardware Tags:

Getting it up and running

September 10th, 2007 No comments

Last week I finally received my new hardware. Eager to get it all running I started with the base install of Debian (4.0).

First I installed the subversion server as follows:

  1. run ‘apt-get install subversion’
  2. run ‘svnadmin create /path/to/repository’
  3. update the config files in /path/to/repository/conf
  4. create a start script for the svnserve daemon, containing something like: ‘svnserve -d -r /path/to/repository/’
  5. wow it works! 😛

Installing Apache2, PHP5 and MySQL 5 was also really easy.

  1. run ‘apt-get install apache2 php5 mysql-server-5.0 libapache2-mod-php5 php5-mysql’

Installing Tomcat was a bit harder. I first installed lynx so I could download jdk 1.5 from java.sun.com. After downloading it I installed it into /opt. After that I created a symbolic link from /opt/java pointing to the jdk 1.5 folder. After that setting the JAVA_HOME environment variable to it and exporting JAVA_HOME/bin to the path.

After that I also downloaded the Tomcat 5.5 tar.gz file and untarred it into the /opt directory on the harddrive. After that I created a similar symbolic link to /opt/tomcat referring to the tomcat install location. After that I tested the install and it worked ok. Because I didn’t want to run Tomcat as root I created a tomcat user and modified the startup script to run as the tomcat user using the ‘su -p tomcat’ command.

Categories: Coding, Hardware Tags:

Via Epia EK8000EG

August 1st, 2007 No comments

Via Epia EK8000EG

 

 

Ordered a Via mainboard today with some other stuff which I will use for my new 24/7 server.

 

 

 

 

 

 

 

It will be running debian with the following programs:

  • Apache Http Server
  • PHP
  • MySQL
  • Tomcat
  • Subversion
  • Local Maven Repository
  • And some other useful stuff like rsync 😉

Product Specification

Categories: Hardware Tags: