Saturday, February 03, 2007

Part 4: Gumstick Gentoo

To recap, we've built a basic stage3 Gentoo system in a chroot environment. Now, we are ready to deploy that image.

Part 4: Go forth and Multiply (except for snakes... they're adders)
---------------------------------------------------------------------------

Now, we've got a nice prepared stage3 Gentoo ready for deployment. It's even nicer because we have removed our portage tree and have it available for later upgrades.

So now, what do we do? Why deploy our image.

First we need to prep our disk drive. Since Ext3 fs is compiled as a module, this will be a good choice for our final file system. The first step is to create a partitioning scheme. Since flash disk have a limited life span and are damn slow to access, we do NOT want to create a swap partition there. However as a teaser, I'll let you know that it's possible to steal ram from your video card (that's not in use) and turn it into a block device... i.e. perfect swap space.

#fdisk /dev/sd{a,b,c,d}(your drive goes here... and alwas specify it without a number)
fdisk> d(elete all partitions currently on the system)
fdisk> n(ew, create a primary partition that takes up your entire drive)
fdisk> a( set the boot flag on partition 1)
fdisk> w(rite the partition table and exit)

Ok, now we need to create our file system on the new partition, mount the new fs, and deploy our image.

#mkfs.ext3 /dev/sd{a,b,c,d}1 (this time we specify a number because we need the partition)
#tune2fs -c0 -i0 /dev/sd{a,b,c,d}1 (disable error checking... these do have limited writes...

#mount /dev/sd{a,b,c,d}1 /mnt
#cd ~/gentoo
#find . | cpio -pdm{u}{v} /mnt

The command that includes cpio is useful for many reasons. CPIO is an extremely useful backup utility as it can take a stream from FIND and copy the files anywhere you want them. Also, the {u} allows you do to an unconditional overwrite, and the {v} will tell you all about your progress. It should be noted that {p,d,m} are required to maintain your permissions, create needed directories and accept piped names.

Now you have to edit your grub file in such a way that is knowledgeable of the fact that your USB hard drive is trying to be loaded at the same time as you are trying to execute "/sbin/init". I will leave the rest of the configuration up to you except for the usb-specific kernel parameters. The parameter that you will specifically need is "rootdelay={5,10}". This rootdelay command does exactly what it says. It delays trying to activate your root partition for x seconds (5 or 10 as shown above). This will give your kernel enough time to recognize the thumb drive and activate it before the concurrent thread tries to load up your root file system.

After you have configured grub, you can execute the following to attempt an automatic setup.

#grub-install --root-directory=/mnt /dev/sd{a,b,c,}

The root directory tells grub where to look for /boot/grub/ and the other part specifies the MBR of the usb drive you are attempting to set up. If this fails for any reason, you're like going to need to do a manual grub install. That's something for another article.

Now if all went well, you should be able to #umount /mnt and attempt a reboot of your new Gumstick Gentoo.

No comments: