Thursday 31 May 2012

Raspberry Pi compiling and development on Fedora 17

My last post explained how to run Fedora 17 on the Raspberry Pi.  An SD card is OK to run software from, but it is not the best configuration for doing things (like compiling software) that involve lots of random "disk" reads and writes.

If you are going to be compiling lots software it makes sense to use a USB hard-drive.  This guide explains how to boot Fedora 17 from an SD card (the Raspberry Pi must boot from an SD card) but run the root file-system from a USB hard-drive.

In addition to the assumptions in my last post, I am assuming:

  • Your USB hard-drive is /dev/sdb when connected to your computer.   If your USB hard-drive is on a different device file then make sure you work out what it is and use the right file-name in the instructions below - getting this wrong could permanently lose data.
Complete steps 1 and 2 from my last post before continuing here:
  1. Delete the unnecessary root filesystem from the SD card:
    # fdisk /dev/mmcblk0 (commands I entered and comments in bold below)

    Command (m for help): d
    Partition number (1-4): 2
    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.
  2. Update the SD card so that the Raspberry Pi looks for the root file-system on a USB hard-drive:
    # mkdir /tmp/boot_pi
    # mount /dev/mmcblk0p1 /tmp/boot_pi

    # vim /tmp/boot_pi/cmdline.txt (change root=/dev/mmcblk0p2 to root=/dev/sda2 - this really is /dev/sda here as that is how it will appear on the Raspberry Pi)

    # umount /tmp/boot_pi

    # rmdir /tmp/boot_pi
  3. Connect the USB hard-drive to your computer (unmount it if your computer automounts it for you) and write the image to the hard-drive:
    # xzcat f17arm-latest-arm-rpi-mmcblk0.img.xz > /dev/sdb
  4. Delete the unnecessary boot partition from the hard-drive and resize the root file-system:
    # fdisk /dev/sdb (commands I entered and comments in bold below)

    Command (m for help): p

    Disk /dev/sdb: 80.0 GB, 80026361856 bytes
    81 heads, 63 sectors/track, 30629 cylinders, total 156301488 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   *          63     1044224      522081    c  W9...
    /dev/sdb2         1044225     7784447     3370111+  83  Linux

    Command (m for help): d
    Partition number (1-4): 2

    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 2): 2
    The first sector must be the start sector of /dev/sdb2 (above).  This number may be different on your hard-drive.  It should be the default value here - but check it carefully anyway.

    First sector (1044225-156301488, default 1044225): 1044225
    The last sector should be the default if you want to use all available space on the hard-drive.  If the default is what you want just press return.

    Last sector, +sectors or +size{K,M,G} (1044225-156301488, default 156301488):

    Using default value 156301488

    Command (m for help): d
    Partition number (1-4): 1

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.
    # e2fsck -f /dev/sdb2
    # resize2fs /dev/sdb2
    # mkdir /tmp/rootfs_pi
    # mount /dev/sdb2 /tmp/rootfs_pi
    # rm -f /tmp/rootfs_pi/etc/systemd/system/multi-user.target.wants/rootfs-resize.service
    # umount /tmp/rootfs_pi
    # rmdir /tmp/rootfs_pi
  5. Now eject the SD card from your reader and disconnect your USB hard-drive, put the SD card in your Raspberry Pi and connect the USB hard-drive and power up.  Once it has booted log in as "root" using the password "fedoraarm".  (Assuming that you are connected over a wired LAN with a DHCP server) the Raspberry Pi will automatically obtain an IP address and LAN settings (I am going to assume this is the case - if not the process for configuring networking is exactly the same as it is on any other Fedora 17 machine).
  6. Update your packages:
    # yum update

    Don't worry about the fact that a new kernel is installed - even though this new kernel is not Raspberry Pi compatible.  When a new kernel is installed using "yum update" the old one (and it's modules) are not removed.  Also, because of the way the UBOOT partition in the images works, installing a new kernel does not change the default kernel used when you boot.
Job done.  You now have a perfectly usable and up-to-date Fedora 17 Raspberry Pi SD card and USB hard-drive combination.

No comments:

Post a Comment