HOWTO: Headless Raspberry Pi Server

This how-to assumes you will be creating the Raspbian boot SD card on an existing Linux system since many of the utilities/tools that are needed are already installed or easily available. The how-to was created using a laptop running Ubuntu 12.04 LTS.

Step-by-Step Procedure:

  1. Download Raspbian "wheezy" from www.raspberrypi.org/downloads. Either the hard-float ABI (Raspbian default) or soft-float ABI if you plan on running an Oracle JVM which does not yet support the hard-float ABI.

  2. Extract the disk image from the zip file -- as of this writing the current Raspbian image file is 2013-02-09-wheezy-raspbian.zip.

    $ unzip -d /tmp <path to image>/2013-02-09-wheezy-raspbian.zip

    This will create a file called 2013-02-09-wheezy-raspbian.img in the /tmp folder.

    Note: This is a 2GB disk image. If you write it directly to an SD card / USB stick larger than 2GB using the 'dd' command, you will only see it as a 2GB filesystem.

  3. At this point you can simply 'dd' the disk image directly to a 2GB or larger SD card and you should be able to boot it. Before writing the image with 'dd', make sure to first unmount any partitions from the SD card that may have been auto-mounted.

    The default SD device is usually /dev/mmcblk0.

    $ sudo umount /dev/mmcblk0p* $ sudo dd bs=1M if=/tmp/2013-02-09-wheezy-raspbian.img of=/dev/mmcblk0

    If you want to use a larger SD card larger than 2GB and utilize the full size or use a USB stick for you root partition you will either need to resize the partition after installation or mount the root partition (2nd partition in the image) and copy its contents to the larger pre-formatted partition on your SD card or to the USB stick.

    Below, we'll use the mount & copy approach as it is much more flexible and allows you to use a USB stick as the root partition. (see recommendations)

  1. Get the partition details for the disk image using 'parted'. If you don't have parted installed, on Ubuntu simply sudo apt-get install parted. For other Linux distros, install parted using your preferred method.

    $ parted /tmp/2013-02-09-wheezy-raspbian.img unit B print

    You should get some output like this:

    Model: (file) Disk /tmp/2013-02-09-wheezy-raspbian.img: 1939865600B Sector size (logical/physical): 512B/512B Partition Table: msdos
    Number Start End Size Type File system Flags 1 4194304B 62914559B 58720256B primary fat16 lba 2 62914560B 1939865599B 1876951040B primary ext4

    This will tell you where the disk partitions start (in bytes) in the image file and allow you to mount the filesystems.

  2. Mount the partitions on loop devices using the partition offsets we found above.

    $ sudo mkdir /mnt/partition1 /mnt/partition2 $ sudo mount -o loop,ro,offset=4194304 /tmp/2013-02-09-wheezy-raspbian.img /mnt/partition1 $ sudo mount -o loop,ro,offset=62914560 /tmp/2013-02-09-wheezy-raspbian.img /mnt/partition2

  3. Create a partition to be used as the root partition on your USB stick device. On most Linux systems used for this how-to, this will probably be /dev/sdb but substitute accordingly if it is not in your case.  Here we use a 16GB USB stick for our root filesystem:

    $ sudo fdisk /dev/sdb
    Command (m for help): p
    Disk /dev/sdb: 16.2 GB, 16173236224 bytes 64 heads, 32 sectors/track, 15424 cylinders, total 31588352 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: 0x00000000
    Device Boot Start End Blocks Id System
    Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-31588351, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-31588351, default 31588351): Using default value 31588351
    Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table.

    You should end up with a partition table that looks something like this:

    $ sudo fdisk -l /dev/sdb
    Disk /dev/sdb: 16.2 GB, 16173236224 bytes 64 heads, 32 sectors/track, 15424 cylinders, total 31588352 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: 0x00000000
    Device Boot Start End Blocks Id System /dev/sdb1 2048 31588351 15793152 83 Linux

  4. Make a new ext4 filesystem without a journal (to avoid excessive wear), 1% reserved for root and a label of PiRoot:

    $ sudo mkfs.ext4 -O ^has_journal -m 1 -L "PiRoot" /dev/sdb1
    mke2fs 1.42 (29-Nov-2011) Filesystem label=PiRoot OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 987360 inodes, 3948288 blocks 39482 blocks (1.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4043309056 121 block groups 32768 blocks per group, 32768 fragments per group 8160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
    Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done

  5. Mount the newly created & formatted USB partition and copy the Raspbian root partition files to it:

    $ sudo mkdir /mnt/piroot $ sudo mount dev/sdb1 /mnt/piroot $ sudo cp -pr /mnt/partition2/* /mnt/piroot

  6. Sync and uUnmount the USB partition:

    $ sync $ sudo umount /mnt/piroot

  7. Change the Rpi boot configuration to mount the root partition from the USB stick instead of the SD card:

    Edit file 'cmdline.txt' on the primary SD card partition (fat32 partition) and change 'root=/dev/mmcblk0p2' to 'root=/dev/sda1'.

    Note: The first partition on the USB stick will be assigned /dev/sda1 on the Rpi (as long as there are no other USB sticks plugged-in).




To be continued....



Recommendations:

  • Put the root filesystem on a USB stick instead of the SD card. This avoids any SD card corruption problems on Rpi reboot/power-off. (This increased my system stability incredibly -- HIGHLY recommended)

  • If you are not going to be running a GUI (Xorg), disable the D-bus message bus service by executing:

    $ sudo update-rc.d -f dbus remove

    This will conserve quite a bit of system memory by disabling lots of other services which depend on dbus (i.e. ConsoleKit).

  • Use the config option "gpu_mem" to reduce the amount of memory allocated to the GPU (i.e. gpu_mem=32 will assign only 32 MB to the GPU and the rest to the CPU). See http://elinux.org/RPi_config.txt#Memory.


Syndicate content
Listed on: link directory