24 October 2014

27 November 2013

Raspberry Pi USB RAID1 root partition

UPDATE: I have since switched back to using the Pi foundation kernel, so I have updated the post accordingly.

I run a webserver on my Raspberry Pi and wanted to get the benefits of the high reliability of a RAID1 on the root (/) partition. I easily found how to hand-off boot to a USB device and also found how to setup a RAID1 as a non-root partition, but I wanted to combine the two. I found one other forum where this had been attempted but it didn't look like they ever completed it so I will share with you how I did this. This method will also work for other raid levels if you adjust the steps accordingly.

First, I'm going to assume you have a recent stock Raspbian install already running on an SD card on your pi and you have two identical USB thumb-drives or SD cards in adapters plugged in (/dev/sda and /dev/sdb). I used two of these plugged directly into the ports on the rpi.

The key to all of this is going to be switching to the Raspbian repository kernel rather than the kernel that comes on the Raspbian image from the Rpi foundation. This is because the Rpi foundation kernel doesn't have the raid1 module compiled in and it doesn't use an initramfs, so there is no way to get your RAID recognized out of the box. The Raspbian repository image uses an initramfs and makes this process incredibly easy. The latest Rpi foundation image supports initramfs and raid1.

Setup the kernel

Update the kernel image

# rpi-update
At this point reboot and make sure that you are booted from the latest kernel

Configure initramfs

Add the following lines to /etc/initramfs-tools/modules
raid1
md_mod
ext4

Update the initramfs

# update-initramfs -c -k `uname -r`
You may see some warnings about symlinks. You can safely ignore these since it is trying to create a symlink on a vfat filesystem which does not support them.

Edit boot configuration

Backup the original config.txt
# cp /boot/config.txt /boot/config.txt_orig 
Use the following command to figure out what kernel version you are running

# uname -r

It will be something in the form of 3.10.XX+. Substitute your version below.

Add the following 2 lines to the end of /boot/config.txt:
kernel=kernel.img
initramfs initrd.img-3.10.XX+ followkernel

Reboot and test

# reboot
# uname -r
You should still see the above kernel version.

Setup RAID1

Install mdadm
# apt-get install mdadm
# modprobe md
# modprobe raid1
Partition drives using fdisk and create a primary partition that uses the whole drive and has a partition system id of fd Linux raid auto

# fdisk /dev/sda

Repeated for /dev/sdb

Destroy any existing superblocks on the drives
# mdadm --zero-superblock /dev/sda1 /dev/sdb1

Create RAID
# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
# cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
# mdadm --examine --scan >> /etc/mdadm/mdadm.conf
# dpkg-reconfigure mdadm

Respond with the following
Ok
all
Yes
Yes
root

Format RAID
# mkfs.ext4 /dev/md0

Mount raid to temporary location
# mount /dev/md0 /mnt/md0

Copy data from live system over to md0
# cp -afxv / /mnt/md0

Make /boot/cmdline.txt look like the following

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/md0 rootfstype=ext4 elevator=deadline boot_delay=32 rootdelay=10 rootwait

Backup fstab
# cp /etc/fstab /etc/fstab_orig

Comment the following lines in /etc/fstab

/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

Add the following line to /etc/fstab
/dev/md0 / ext4 defaults,noatime,errors=remount-ro 0 1

Reboot

Optionally delete the original partition on the SD card.

Now the system will boot from the SD card into initramfs, load the raid modules and assemble then mount the raid. Then it will boot into the system running from the RAID.

Great care must be taken if you decide you want to use rpi-update to upgrade your kernel. After doing so, you must use initramfs-update -c -k xxxxxx+ to create a new initramfs for that kernel. Then you have to go into /boot/config.txt and update the last line to point to the new initramfs.

26 November 2013

How to make your FreedomPop phone awesome

This information pertains primarily to the HTC Evo Design 4G sold on FreedomPop.

Install BlueKingdom ROM

I have tried a few roms for the Design and this one is the best if you like JellyBean. It isn't a true JellyBean ROM as it is still based on ICS according to the phone info, but it has as much of the HTC bloat removed as possible and has many of the JellyBean menus. It is incredibly responsive and looks beautiful. Freedom Phones come with CWM recovery already, so all you have to do to install this ROM is the following:

  1. On wifi on your phone, navigate to http://www.androidfilehost.com/?fid=23159073880932946
  2. Click the green circle to download the file
  3. Shutdown and pull the battery
  4. Put the battery back
  5. Hold Voldown+Power
  6. After it runs its checks, select recovery
  7. In recovery select wipe factory default
  8. Select install zip from SD card
  9. Find BlueKingdom1.4.zip in your downloads folder
  10. When complete, select reboot from main menu

Known issues:

  • Front-facing camera has issues with taking photos, so no selfies just yet 
  • No way to access the built-in Android SIP account settings (System Settings->Phone on ICS)


Put more apps to install to SD Card

Install the HTC drivers and Android SDK and run the following command. It will allow you to put more apps onto your SD card than currently permitted. It will also set the SD card as the default location for new apps.
adb shell pm set-install-location 2
Caveat: Widgets will not work for apps installed on SD card

Install CSipSimple and setup for FreedomPop

FreedomPop's Messaging app is just a custom flavor of the CSipSimple open source SIP app. I would like to assume that they did some tweaking of it to make it work better, but in my testing I have arrived at the contrary conclusion. They seem to have made it so the Messaging app constantly has a wake-lock on which kills battery life. FP doesn't allow you to directly access the settings that it uses to connect to their SIP servers, but it is fairly trivial to get the information necessary to setup the vanilla CSipSimple app.
  1. Backup Messaging app with Titanium
  2. Copy the tar.gz file containing the data for Messaging onto your computer and extract it
  3. Use a sqlite viewer to open the database
  4. Pull your account info from the Accounts table (the main thing you need to get is your password (Field: Data type, a 32-character hex string)
  5. Use the following configuration to create an account in CSipSimple
Create new expert mode
Account name: FreedomPop
Account id: <sip:1XXXXXXXXXX@fp.layered.net>
Registration URI: sip:fp.layered.net
Realm: *
Username: 1XXXXXXXXXX
Data (password):
Data type: Plain password
Transport: TCP
Default uri scheme: sip
Register timeout (sec): 900
Proxy URI: sip:fp.layered.net

Network settings:
Use compact sip: true
Media:
Codecs:
Fast: PCMA, PCMU
Slow: ILBC

Filters:
FreedomPop:
Has exactly N digits 7, Prefix by 1XXX (your area code)
Has exactly N digits 10, Prefix by 1
Use mobile:
Direct call: Is exactly 911
Can't call: All

FP's PBX server requires phone calls to be of the form 1XXXXXXXXXX so the above filter rules will make your native dialer accept 7-digit numbers from your area code and 10-digit numbers as well as 11-digit numbers.
Using CSipSimple does not receive SMS through FP, so you will probably want to switch to Google Voice for SMS.

Install Greenify

This app will selectively hibernate apps when not in use. Make sure you only have it hibernate apps that do not need to be running in the background and don't need to give notifications.

Install HTC Radio app to conserve data

If you like to listen to Pandora or other streaming radio, using the built-in FM tuner on your phone for music can save you a ton of data. Install the HTC Radio app using one of these two files. You can install the zip using CWM or you can install the apk the traditional way. They are both the same version.
htcfmradio.apk
htcfmradio.zip

Setup Wifi Tether

  1. Download
  2. Leave Device-Profile on auto
  3. Set Setup-Method to Netd(master)
  4. Uncheck WiFi-driver reload 2
  5. Configure other settings as you see fit as long as it continues to function
Note: If your connection only seems to last a couple of minutes, try checking WiFi-driver reload

Install 4G toggle app

4G Toggle for EVO
Make sure to move this to internal storage if it installs to SD card or it won't show up in the menu