Turning My SheevaPlug Into A Web Server
After I got Ubuntu running on my Plug, I started going about turning it into what I originally planned for it: LAMP, UPnP, and Torrent server.
I first found a great resource for playing with the plug: OpenPlug.org. The wiki in particular has some good tips, the first of which I followed below.
Install Root FS on SDHC Card
By default, the SheevaPlug has 512MB of NAND flash memory for storage, and 512MB or RAM. When you boot your plug from NAND it copies the necessary files to a RAM disk (a virtual disk on RAM which disappears when the plug is powered off). If I understand correctly, this will in effect reduce the available RAM since some of it is used by the file system.
By following the tutorial found in the OpenPlug.org wiki, I was able to instead copy the filesystem to the SDHC card (I used a 4GB Sandisk Extreme III Class 6) and then boot from it.
Edit 5/22/2009: It appears they’ve edited the wiki, and while you can look at the history of the article I linked to, I’ll post the instructions here for posterity. Please follow the steps carefully.
Make an SD card** be the root filesystem**
Prerequisites:
- SD card ( 512mb or bigger )
- working serial console
- a working system with
cat /proc/mtd
showing a rootfs (for me it was mtd1)
Format your SD card to a filesystem that supports permissions (far as I know fat32 will not work, but I didn’t try) - I used fdisk /dev/mmcblk0
and formatted the partition with ext3 filesystem mkfs.ext3 /dev/mmcblk0p1
Copy the existing root filesystem into the SD card. (assuming mtd1 is your rootfs device)
mkdir /mnt/sd
mkdir /mnt/tmproot
mount /dev/mmcblk0p1 /mnt/sd
mount /dev/mtdblock1 /mnt/tmproot
cp -av /mnt/tmproot/* /mnt/sd
umount /mnt/tmproot
Update the SD cards fstab to mount itself as root:
vim /mnt/sd/etc/fstab
change
rootfs / rootfs rw 0 0
to (assuming ext3 filesystem)
/dev/mmcblk0p1 / ext3 rw 0 0
umount /mnt/sd
reboot
Get to the u-boot prompt (Marvell») - this can be done by having the serial console connected while rebooting the device, it gives you 3 second to hit any key, just hit a key.
Backup bootargs_root and bootargs settings.
printenv bootargs_root
Mine:
bootargs_root=root=/dev/mtdblock2 ro
printenv bootargs
Mine:
bootargs=console=ttyS0,115200
mtdparts=nand_mtd:0x400000@0x100000(uImage),
0x1fb00000@0x500000(rootfs)
rw root=/dev/mtdblock1 rw ip=10.4.50.4:10.4.50.5
:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none
Change the root filesystem to the SD card.
set bootargs_root 'root=/dev/mmcblk0p1'
set bootargs=console=ttyS0,115200 mtdparts=nand_mtd:0x400000@0x100000(uImage),0x1fb00000@0x500000(rootfs) rw root=/dev/mmcblk0p1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none
saveenv
reset
The output of df -h
now shows (for my 8gb SD card):
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p1 7.4G 487M 6.6G 7% /
tmpfs 252M 0 252M 0% /lib/init/rw
varrun 252M 36K 252M 1% /var/run
varlock 252M 0 252M 0% /var/lock
udev 252M 16K 252M 1% /dev
tmpfs 252M 0 252M 0% /dev/shm
If something goes wrong and it does not work, you should be able to set the bootargs_root and bootargs back to what they were.
The performance increase was surprising and immediate. My plug booted I would guess 4 times as fast as before.
Install Lighttpd, MySQL and PHP5 for WordPress and sub-domains
I was originally going to use Apache, but after hearing the performance benefits of lighttpd over apache, not needing the robustness of apache, and after verifying that lighttpd will work with wordpress, I jumped.
Instructions on how to do so are also found on the OpenPlug.org wiki.
Since I run two wordpress blogs off of my server, I made the following additions to my /etc/lighttpd/lighttpd.conf file
$HTTP["host"] == "bradford.la" {
server.document-root = "/var/www/bradford.la"
server.errorlog = "/var/log/bradford.la"
accesslog.filename = "/var/log/bradford.la"
dir-listing.activate = "disable"
url.rewrite-once = (
"^/(.*)?/?files/$" => "index.php",
"^/(.*)?/?files/(.*)" => "wp-content/blogs.php?file=$2",
"^/(wp-.*)$" => "$1",
"^/([_0-9a-zA-Z-]+/)?(wp-.*)" => "$2",
"^/([_0-9a-zA-Z-]+/)?(.*.php)$" => "$2",
"." => "index.php"
)
}
else $HTTP[host] == "..."
The first line defines one virtual server (in Apache terms). There are lines in there to set up logging for the virtual server. The line dir-listing.activate = disable
is important, since lighttpd will allow directory listing by default. The url.rewrite-once is necessary to have your wordpress blog work with url-rewriting. After that, the last line of the above example shows how you can define further sites using else statements.
Installing MySQL was as simple as
apt-get install mysql-server mysql-client
and following the on-screen instructions for setting up your MySQL passwords.
I did toy with using sqlite for a more efficient server, however I couldn’t get it to work with wordpress. There is a wordpress plugin for switching to sqlite, however it didn’t work with my setup. After optimizing mysql, the memory footprint was manageable.
I installed phpmyadmin, and imported my sql tables from my old server. Everything imported well, and after disabling and re-enabling my plugins my sites were up and running even better than before. I’m very impressed with the performance of LLMP (Linux, Lighttpd, MySQL, PHP) on my Plug.
I’ll cover installing a torrent client (I am thinking Deluge) and UPnP (MediaTomb?) in my next post.