Sunday, 27 January 2013

Nook - e-reader / Pi Display - Attempt 1.

OK - This isn't strictly related to the Raspberry Pi as such - at least not yet, but it was because of running the weather station software on the Pi that I bought the Nook. - I want to be able to use the Nook as a remote display, pulling data from the weather station's Raspberry Pi, and displaying it remotely - e.g. at my office for example, or stuck on the wall. - I've seen similar things with the Kobo etc.

So, this is step 1. - So far, I've got the Nook, I've rooted it, go the market working, installed Kindle application and then got sidetracked into reading 'Life Of Pi'.

 - The Nook (Nook simple touch) seems easier to hold / read on than my kindle keyboard - It seems lighter, and easy to turn the pages with just a touch rather than using the side buttons as on the kindle, but that's maybe just personal preference.  I can't see me buying much from the B&N Nook store as I've really committed to Kindle previously, although by using Calibre with a decoder, I could install my purchased items onto the Nook. - I didn't want to be tied into one platform in the long term......  Anyway. - This post is just for notes on the install so far.

1. - Register the Nook with B&N having turned it on for the first time and setup connection to Wi-Fi etc.
2. - Download and follow instructions to create an SD card with NookManager on. - See this post -
3. - Reboot the Nook with the NookManager and BACKUP the Nook before proceeding.
4. - Transfer the backup from the SD card somewhere safe.
5. - Repeat steps 3 and 4 so we know we have a backup from which we can hopefully recover the Nook should the root fail but nothing guaranteed.
6. - Reboot with Nook Manager and 'root' the device.
7. - Reboot and verify it's all working OK.
8. - Reboot with Nook Manager - make a backup at this stage.
9. - Install NTGAppsAttack as per -
10. - Assuming this has worked OK we now have market etc installed.
11. - Reboot and install Kindle app from the market. - I've now got that installed and working fine with my Kindle books.

... to be continued.

(28/1/13) Much googling, and playing with the screensaver on the Nook shows that what may be possible is to create a directory on the Nook 'screensavers' directory e.g. /screensavers/weather.  Then, mount the Nook (in this case on the RPi), copy an image file into the 'screensavers/weather' directory on the Nook, then remove the nook. - The Nook will timeout and if you have it to display files from the 'weather' screensaver - Brilliant - it doesn't even need rooting to do that.

Then, I found this from the Kindle. -
Currently trying to get the script running on the Pi to create the image which can then be transferred to the Nook.  Problem I've hit so far is that I can't 'rescan' the USB bus to remount the Nook periodically.  - When it's 'removed' from the Pi, the device files are removed. - I can't find a way to get udev to think it's been replugged ..... yet.

I can force 'removal' of the Nook on the USB with :-

echo 1 > /sys/bus/usb/devices/1-1.2/remove

But can't find a way to remount. - The device files are gone, and I don't know how to rescan the bus to force recognition as if it has been replugged.

I didn't originally want to do it this way because it involves a dedicated Pi for the purpose. - Originally I'd wanted a script running on the Nook which would pull the image from the Pi. - However, I'm a simple guy and I like simple solutions, so this is good enough if it works. - The upside is that I only need one power supply - the Nook charges OK from the Pi. albeit slowly. - I'll just have to get another Pi to use as my general purpose Pi if this project works :)


OK - now looking for the essentials for the Kindle scripts. - namely pngcrush and rsvg_convert. - pngcrush was easy:-

apt-get install pngcrush

rsvg_convert took a little more finding, but I think is provided by librsvg2-bin

apt-get install librsvg2-bin

Run the scripts from the above link and put the resultant image into the screensaver directory on the Nook, et voila:-

OK - It's not entirely what I want, but as a proof of concept it pretty much works OK.  Now I just need to know how to rescan the USB to remount the Nook at intervals....

(Update 3/2/13.) - I could find no way of re-establishing / rescanning the USB devices once one had been removed. - I don't mean just re-mounting a filesystem here, I mean once the device files are removed, I could find no way of getting them recreated / re-establishing as if the device had been replugged. - Anyway, see next post, I'm now getting the file via ftp periodically which is a better solution anyway.

Monday, 21 January 2013


OK - So I've now got a couple of PC's backing up / syncing with the RPi attached to the USB hard drive. - I need to be able to quickly rebuild if this machine fails. - Since I originally created the hard drive filesystem with rsync, it seems reasonable to use this to backup to another machine on the network.  The following command copies the filesystem, and I should be able to use this to recreate the RPi / USB disk system relatively quickly if it fails.  I've also taken a copy of the SD card on a windows machine, so the rebuild procedure will be to recreate a new SD card, if necessary, add a new USB hard drive, and then use my rsync backup to restore the hard drive filesystem. - I really should test this!

~/weatherpi $ rsync -avxS root@weatherpi:/ ./backup --exclude "/My Documents"

The RPi with the hard drive seems to run 'Unison' very well - much more quickly than my old 'Buffalo Linkstation' at any rate.  It initially took around 10 hours to copy >100Gb of data from one PC to the USB attached drive, but did so with no hiccups.  I have then brought in another PC which only took about 20 minutes to do the initial synchronisation of the same data. - We have several PC's around the house, but all the user data - music, photos, documents etc is stored in /My Documents on each, regardless whether they are linux or windows.  Then, I use unison to sync the data across the various machines by syncing with the Rpi box.  For the Linux boxes, I can pretty simply rebuild from a CD.  For the windows machine, I also keep a 'Macrium' backup copy on a portable USB drive.  This strategy means that I have several copies of my data which should provide some resilience against a lost disk etc., and protection against failure on the windows system with a full byte copy of the disk.  (I have tested recovery of this also when I've swapped disks in the machine).

Saturday, 19 January 2013

Raspberry Pi - home server.

So, I've now got a Raspberry Pi which is running from a usb attached hard drive, and it's running weather monitoring software, and a web server which will be 24x7, but generally just for personal use, what else can I do with this?  - Well, for probably the last decade I've been running a 'Buffalo Linkstation' NAS.  This was hacked to allow it to run 'Unison' backup software, 'squid' proxy, and 'Twonky' media server. - It has done this very well during this time, but it's running out of space, and IDE drives are obsolete and expensive.....  The RPI should be able to handle these tasks pretty well.

- Unison was simple. - 'sudo apt-get install unison2.27.57'
sudo unison -socket 1966 >/dev/null 2>&1 &

In due course I will put in an auto startup script so that it's always running, but currently it's duplicating my 100Gb of photo's and music from another PC. - This takes time the first time it's run, but subsequent sync is quick.

- Twonky is available for the Pi - see here  This details relatively simple install. - I need to wait for my media copy to complete before I can configure, but it runs, scans directories, and is visible to the media player devices on my network, so it all looks good - only downside is I might need to buy a new license since the one for Twonky 3.1 on the Buffalo which I bought many years ago is not valid on this install. - Again, I also need to add this for auto startup when I'm happy with the setup, but it looks good.

USB Hard drive

Finally, I got to do something useful with the Pi.  This is one of two useful uses so far :)   For Christmas I got a weather station from 'Maplin' with a USB interface, and it was relatively straightforward to get the Pi pulling data from this and publishing it in a web page using pywws.  I found relatively little on the web about running the Pi from a hard drive, so these notes are my reference if I need to rebuild this. Most of the info can be gleaned from the thread here, though it's a little fragmented and somewhat incomplete -

- It is not possible to 'boot' the Pi from a hard drive - it needs to boot from the SD card, but it can 'run' from a USB attached hard disk. - I was worried that a 24x7 system would quickly wear the SD card, especially as the weather station software processes data and writes to files every minute or so.  This, and improved storage - perhaps as a backup server was my driver for using the external hard disk.  (NB - in fact, the weatherstation died after 4 days and I'm currently waiting on a replacement, but at least I have the logging / publishing framework in place).

 - Experiment with several 2.5" external USB disks show that the Pi doesn't provide enough power to run them without external power supply, but I had a spare 320Gb 3.5" external drive with it's own power which I've now dedicated to this.

- Step1 was to install the system from an image onto the SD card, and get it running and configured with all the software I wanted (primarily pywws and lighttpd), get networking etc configured to my satisfaction.  Now, make a backup of the working SD card before proceeding!

2. - Plug the hard drive into the Pi and create the partitions I needed using fdisk - In my case, I just created a single large partition which will later be the 'root' of the Pi, and a 256Mb swap partition:-

root@weatherpi:/etc/lighttpd# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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: 0xfa24485f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   624617471   312307712   83  Linux
/dev/sda2       624617472   625141759      262144   82  Linux swap / Solaris

3. - mkswap /dev/sda2
4. - mkfs.ext4 /dev/sda1
5. - mkdir /media/sda1
6. - mount /dev/sda1 /media/sda1
7. - cd /
8. - rsync -avxS / /media/sda1 --exclude /media/sda1
9. - cd /media/sda1/etc
10. - update the path of root in fstab to be /dev/sda1 instead of /dev/mmcblk0p2.
11. - cd /boot
12. - edit cmdline.txt and change the root= to /dev/sda1 from /dev/mmcblk0p2.
13. - Cross fingers and reboot.....  I was lucky, and the Pi booted first time and I could access so I didn't have to faff with connecting to a monitor / keyboard etc.

Check that it's actually all configured the way I expect with the huge root filesystem:-

root@weatherpi:/etc/lighttpd# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          294G  1.7G  277G   1% /
/dev/root       294G  1.7G  277G   1% /
devtmpfs        117M     0  117M   0% /dev
tmpfs            24M  220K   24M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            47M     0   47M   0% /run/shm
/dev/mmcblk0p1   56M   17M   40M  30% /boot

All looks good. - My SD card should live a long time as all the 'wear' activity is now on the hard drive.

14. - Now we've got it all booted, remember about the swap partition.....  edit fstab and add in the swap:-

    /dev/sda2       none            swap    sw                 0      0

Now, 'swapon -a'
'free' should now show the swap:-

pi@weatherpi /etc $ free
             total       used       free     shared    buffers     cached
Mem:        237868      53164     184704          0       6808      28580
-/+ buffers/cache:      17776     220092
Swap:       262140          0     262140

Great - final reboot to check this all works OK then I'm happy.

15. - I should also have disabled the auto generation of a 'swap file' now that we have a proper swap partition. - sudo update-rc.d dphys-swapfile disable  Might also remove /var/swap having done swapoff /var/swap. - The auto swapfile generation was running prior to this and it's not necessary.