Using Gentoo on the Plug Computer

From PlugWiki
Jump to: navigation, search

Contents

Using the Gentoo Software Distribution (ie., Portage) on the Plug Computer

The Gentoo [1] Linux distribution provides a stable and flexible interface into adding functionality onto the Plug Computer. You can get all the basics for booting the Plug Computer via TFTP and NFS or the JFFS2 to flash the plug at the SELinux Plug Computer Gentoo Distribution page. The Plug Computer has 512 MB of flash you can use for downloading the Gentoo Portage, but due to the flash size, we recommend another option to relocate the /usr/portage contents onto a USB flash disk or any USB storage device if possible.

You also have the option of downloading some binary packages we already made.

Using Prebuilt Ebuilds from OpenPlug.org

Downloading Binary Ebuilds: Space Constraint Considerations

First, before you start downloading things, you may decide you want the ebuild temporary directory, ie., where downloads are stored, in a different location (ie., a USB stick). You could do one of these options:

  * Just make the existing PACKAGE_TMPDIR specified in /etc/make.conf
     * mkdir /usr/portage/tmp
  * Plug in a USB stick and mount it under /usr/portage/tmp, with:
     * fdisk /dev/sda (make a partition if not partitioned already)
     * mkfs.ext3 /dev/sda1 (if no file system if needed)
     * mount /dev/sda1 /usr/portage/tmp
     * Run the commands below to use the OpenPlug.org site

Editing the make.conf File

There should be no reason to edit the make.conf to download OpenPlug.org binary Gentoo ebuilds, but just in case you want to check the configuration, the PORTAGE_BINHOST should be set in the /etc/make.conf file (e.g. to check, grep "PORTAGE_BINHOST" /etc/make.conf).

You can edit the make.conf file to use the OpenPlug.org site if not already configured, but as of gentoo_sheevplug_66M_selinux.jffs2, the OpenPlug.org site with Gentoo packages is up and working.

  * nano -w /etc/make.conf
  * change the PORTAGE_BINHOST value to
     * PORTAGE_BINHOST="http://www.openplug.org/data/distributions/gentoo/binpkgs/"
  * test it out: emerge --ask --getbinpkg samba

This is what you should see from the test:


PlugGentoo ~ # emerge --ask --getbinpkg samba
These are the packages that would be merged, in order:
Calculating dependencies... done!
[binary N ] sys-libs/libcap-2.15 USE="pam" [0]
[binary N ] sec-policy/selinux-samba-20080525-r1 [?]
[binary N ] net-fs/samba-3.0.33 USE="-acl -ads -async -automount caps -cups -debug -doc -examples -fam -ipv6 -ldap -oav pam python -quotas readline (selinux) -swat -syslog -winbind" [0]
Total: 3 packages (3 new), Size of downloads: 0 kB
Portage tree and overlays:
[0] /usr/portage
[?] indicates that the source repository could not be determined
Would you like to merge these packages? [Yes/No]

OpenPlug.org Binary Ebuilds

You can see the list of Packages on the OpenPlug.org Gentoo binary packages site. Here are some of the commonly used Packages and a short discussion on each of them.

Issues with Binary Ebuilds on OpenPlug.org

If the binary ebuilds on OpenPlug.org do not work, there will be an alternative site soon.

Gentoo Developers on the Plug Computer

Downloading Pre-Built Development Ebuilds

To download the Portage ebuild tree, you will want to do the same thing discussed above to add a USB storage location for /usr/portage. First, get a USB flash drive or a full-fledged XXXX GB USB external drive.

As a consequence of trying to make the JFFS2 image as small as possible, you will need to download some development Gentoo binary ebuilds to even use gcc correctly or for that matter, build anything correctly. Here is a list that was tested, and even though some of the ebuilds are already installed, the include files and static libraries were removed.

  * emerge --ask --getbinpkg bison bzip2 gettext glibc binutils gcc linux-headers
  * emerge --ask --getbinpkg binutils-config flex gcc-config libtool lzma-utils m4 patch
  * emerge --ask --getbinpkg curl expat libmcrypt libselinux libsemanage libsepol libxml2 openssl zlib
  * emerge --ask --getbinpkg gdbm libpcre pam popt procps python selinux-base-policy tcp-wrappers

As you can see, you will need to add many header files and static libraries (e.g., libc_nonshared.a) that were removed manually. However, once the packages above reinstalled, the Portage tree builds should be available again to compile most additions that will fit within the 512MB flash.

It should be noted though that once you do this, the size of the JFFS2 file system will double to about 150+ MB on the Plug Computer flash.

If you feel like building the NTFS-3G support based on the fuse kernel module (already on the image), then you may want these binaries as well. The process of building kernel modules is discussed at the bottom of the page.

  * emerge --ask --getbinpkg device-mapper e2fsprogs e2fsprogs-libs readline udev

Then, you will be able to build ntfs3g if you get the Marvell LSP Linux kernel sources at the bottom of this page.

Setting Up a make.profile

With the Gentoo Plug Computer release, there is an "orion5x" profile in /usr/portage_overlays/plugtop/profiles. We would like to thank the excellent documentation of the NAS Central site, and specifically, Zoolook and friends for making a Gentoo Buffalo Linkstation, GenLink, distribution. The make.profile from that location is the basis for the Sheeva Plug Computer make.profile found in /usr/portage_overlays/plugtop/profiles.

The current JFFS2 image has /etc/make.profile pointing to the /usr/portage_overlays/plugtop/profiles/selinux/2007.0/orion5x. However, after the Portage tree is synchronized, it might be worth copying over the orion5x profiles in portage_overlays/plugtop into /usr/portage/profiles/orion5x and /usr/portage/profiles/selinux/2007.0/orion5x, respectively. Even though these profiles are removed each time the Portage tree is synchronized, it is sometimes beneficial for the parent profile parameters that selinux/2007.0/orion5x references to be in the same directory and may, in fact, change.

What to do First?

As a last step before synchronizing the Portage tree, you probably want to add your favorite editor, vi or vim.

  * emerge --getbinpkg vim

There are syntax files in /usr/share/vim so you should get full color in vim files for modifying ebuild files.

Developing Gentoo Ebuilds on the Plug Computer

Synchronizing with the Gentoo Portage Tree

Of course, one can run emerge --sync and be rewarded with a completely filled root partition. Without JFFS2, which makes things more compressed, this is what happens if you use emerge without a secondary file system on the Plug Computer USB connection or a network file system location (e.g., NFS).


emerge --sync
linux-ezr7:/share/nfsroot # du -h -s gentoo_sheevaplug_188M_selinux
759M gentoo_sheevaplug_188M_selinux


How to Setup an External USB Drive for Gentoo Portage

As with all newer Linux distributions, udev, allows USB storage hot plugging. The USB storage only needs plugged into the Plug Computer external USB connection. Unless you are going through a USB hub, the USB storage will show up as /dev/sda, which dmesg will verify, dmesg.

A 4 GB USB flash disk or larger (and faster) is recommended. Although a small flash disk could work, we find that 4 GB is still inexpensive and allows some flexibility as opposed to 1 or 2 GB, which also don't seem to do well because of a common issue of the flash holding less than advertised. In fact, after adding various Linux kernels and other sources building many ebuilds, you may use 4 GB or more.

Partition and Format the USB Storage: /dev/sda1

From the Gentoo distribution presented here, the partitioning programs, fdisk and sfdisk, are both available. Or, as below, a USB storage drive with existing partitions can be formatted so the Gentoo-Marvell kernel recognizes the file system. VFAT and MSDOS file system support is included in the Gentoo-Marvell kernel configuration.

If the USB thumb or disk drive is new (ie., out of the box), you should do a dd if=/dev/zero of=/dev/sda bs=512 count=1000 and repartition the drive with standard tools like fdisk or parted rather than just formatting an existing FAT partition from the factory.

In the example below, Ext2 is used to format an existing partition, /dev/sda3.

# mkfs.ext2 /dev/sda3 (or mkfs.ext3, of course, but you may not want to give up space)

The one problem is that mount did not immediately recognize the file system type and mount it without specifying the file system type, e.g., -t ext2. Just to speed things along, run depmod and modprobe first.

# depmod -ae
# modprobe ext2
# mount -t ext2 /dev/sda3 /mnt/xtra/
# mount
rootfs on / type rootfs (rw)
/dev/root on / type jffs2 (rw)
none on /selinux type selinuxfs (rw)
/proc on /proc type proc (rw,nosuid,nodev,noexec)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec)
udev on /dev type tmpfs (rw,nosuid)
devpts on /dev/pts type devpts (rw,nosuid,noexec)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec)
none on /dev/mqueue type mqueue (rw)
usbfs on /proc/bus/usb type usbfs (rw,noexec,nosuid,devmode=0664,devgid=85)
securityfs on /sys/kernel/security type securityfs (rw,noexec,nosuid,nodev)
/dev/sda3 on /mnt/xtra type ext2 (rw)
A Quick Tour of the Pre-Sync Gentoo Plug Computer Portage and Profiles

It is worth explaining what is in the Gentoo Distribution for the Plug Computer before modifying it with emerge --sync.

# cd /usr/portage
ls
profiles tmp
cd ..
ls
armv5tejl-softfloat-linux-gnueabi bin lib local portage portage_distfiles portage_overlays sbin selinux share src tmp var
Reconfiguring the Portage Location without Editing make.conf
  * # mkdir /mnt/xtra/sheevaplug
  * # mv /usr/portage /mnt/xtra/sheevaplug/
  * # mv /usr/portage_distfiles /mnt/xtra/sheevaplug
  * # mv /usr/portage_overlays /mnt/xtra/sheevaplug
  * # ln -sf /mnt/xtra/gentoo_minisheeva/portage /usr/portage
  * # ln -sf /mnt/xtra/gentoo_minisheeva/portage_distfiles /usr/portage_distfiles
  * # ln -sf /mnt/xtra/gentoo_minisheeva/portage_overlays /usr/portage_overlays
  * # mkdir -p /usr/portage/tmp
  

Now, we are ready for the Gentoo Portage tree to do ebuilds:

  * # emerge --sync

By doing this, we put the portage tree on the external USB drive and avoid filling up the Plug Computer 512 MB of flash. You may also want to mv /usr/src to /mnt/xtra/sheevaplug and put a soft link to the new location if you plan on doing any potential kernel modules (or related) that then insist on downloading the sys-kernel/vanilla-sources and unpacking them in /usr/src/.

Adding Gentoo Ebuilds to the Plug Computer

Now, the Plug Computer should be capable of all the Gentoo Portage ebuilds except for a few items. Those are discussed below.

Getting the Base Kernel for 2.6.22.18-6plug

The Marvell LSP Linux kernel sources overlay is the basis of the Gentoo uImage. The Gentoo Marvell LSP Linux kernel sources you need to replace the Gentoo vanilla-sources are provided so you can build things like another fuse kernel module or iSCSI support. The Gentoo Marvell LSP Linux kernel sources that produced the uImage.6plug can be downloaded and soft linked to /usr/src/linux. The soft link to linux-2.6.22.18_ferocean_4_2_7_KW_20090310 (wherever you put it, e.g., ln -sf /mnt/xtra/sheevaplug/src/linux-2.6.22.18_ferocean_4_2_7_KW_20090310 /usr/src/linux) then allows the kernel source references you need for some other ebuilds.

The Gentoo Linux kernel 2.6.22.18-6plug was cross-compiled on a x86 Gentoo 2008.0 system as discussed on the Marvell support page. If you want to rebuild the kernel for TFTP/NFS or reflashing the Plug Computer, you will want the following packages from the Marvell Sheevaplug page (the links are at the bottom).

  * Linux Support Package (recommended cross-compiler, gcc.tar.gz)
  * Documentation Package (described how to use the Linux support package and Marvell Linux sources)
  * Linux LSP Linux kernel sources (the files you overlay onto the pristine linux-2.6.22.18.tar.bz)
     * You can use cp -a ./* [location]/linux-2.6.22.18/ to overlay the LSP changes

Setting up the Base Kernel for 2.6.22.18-6plug for Other Kernel Modules

After setting up the LSP sources above, you can use the native development tools to reference these sources with the correct .config file and dependencies.

  * cd /usr/src/linux
  * vim Makefile
     * comment out the existing ARCH and CROSS_COMPILE defines and uncomment the defines above these
        * #ARCH=arm
        * #CROSS_COMPILE=arm-none-linux-gnueabi-
ARCH  ?= $(SUBARCH)
CROSS_COMPILE  ?=
#ARCH  ?= arm
#CROSS_COMPILE=arm-none-linux-gnueabi-
  * make clean; make mrproper
  * cp sheevaplug-.config .config
  * make oldconfig; make uImage (and stop the compiling after version.h is created, if you want, with Ctrl-C)

This should provide the .config and version.h files for reference on other modules (e.g., ntfs3g).

plugtop Overlay: sys-fs/fuse on OpenPlug.org

Since the fuse.ko kernel module is already on the Gentoo Plug Computer distribution, a plugtop_overlay ebuild is made for sys-fs/fuse. The use package, fuse-2.7.4-r1, is located on OpenPlug.org and available by emerge --ask --getbinpkg sys-fs/fuse. The user-space fuse components contained in fuse-2.7.4-r1.tbz2 were made after adjust the /usr/src/linux kernel tree to use the Gentoo Marvell LSP Linux kernel sources as discussed above. The same procedure should allow you to build other kernel modules as well.

We modified the fuse ebuild file to NOT build the kernel module by changing the kernel version if statement to exclude any kernel version equal to or above 2.6.22. This means the binary package version 2.7.4-r1 we build ONLY has the user-space tools.

  * emerge --ask --getbinpkg sys-fs/fuse
Building ntfs3g: Using the Marvell LSP Linux Kernel Sources

After configuring the Marvell LSP kernel sources so that /usr/src/linux points to version 2.6.22.18-6plug, the NTFS support based on the Fuse kernel module (in JFFS2 image) and user-space utilities above. This served as a good test that we had everything setup to build correctly for almost everything in Portage.

  * emerge --ask ntfs3g

Or, if NTFS support is important right away, please pull down the binaries (and the dependencies):

  * emerge --ask --getbinpkg ntfs3g

This allows us to make and mount NTFS USB thumb drives.

Baseline Gentoo Distribution

Now, the discussion has come back to the "Baseline" Gentoo Plug Computer distribution because the Baseline Gentoo distribution is all the development packages and the NTFS-3g support listed above on this page. The Baseline Gentoo distribution does not include the kernel sources or even the stripped down /lib/modules/2.6.22.18-6plug/build link in most distributions only because of the space constraints. If you want to add the kernel sources, you still need to add them from the link above.

Re-Establish all the Dependencies: revdep-rebuild

At the end of setting up the Gentoo Plug Computer distribution for development, you may want to do a revdep-rebuild just to make sure all the libraries dependencies are aligned.

  * emerge --ask --getbinpkg gentoolkit
  * revdep-rebuild -- --ask
This is a good way to test your build environment and make sure all the binary downloads are in alignment.

Personal tools