Add Packages To Ubuntu Preinstalled Images

Ubuntu delivers pre-installed images for OMAP3 and OMAP4, in particular on http://cdimage.ubuntu.com/ubuntu-netbook/ports/releases/.

These images are much faster to install (10 to 20 minutes) than standard "live" images (up to several hours). That's why these images for shipped by default. See this page and this page for details.

Here are instructions to add your own packages to the pre-installed images. They assume that sufficient space is available. At the moment, the pre-installed root partition has 200-300 MB of free space.

Requirements
You need to run of the below instructions on an  board (like OMAP3 and OMAP4 ones) running a GNU/Linux distribution. That's because we are going to  to an   rootfs.

= Procedure =

Making the pre-installed rootfs bigger
This can be needed if you have a significant number of packages to add. Currently, Ubuntu's pre-installed images just have between 200 and 300 MB of free space.

Here is a script that you can use to make the rootfs part of these images bigger. It can be run on your x86 workstation.

# # INPUT=$1 OUTPUT=$2 TMP=${OUTPUT}.tmp SIZE=$3 DD=/bin/dd CAT=/bin/cat RM=/bin/rm SUDO=/usr/bin/sudo LOSETUP=/sbin/losetup RESIZE2FS=/sbin/resize2fs FSCKEXT3=/sbin/fsck.ext3 FDISK=/sbin/fdisk TAIL=/usr/bin/tail AWK=/usr/bin/awk echo "Copying $INPUT to $OUTPUT and adding zeros at the end..." $DD if=/dev/zero of=$TMP bs=1M count=$SIZE $CAT $INPUT $TMP > $OUTPUT $RM -f $TMP echo "Going to need your password to run a few commands with sudo..." LOOP=`$SUDO $LOSETUP -f` $SUDO $LOSETUP $LOOP $OUTPUT $CAT <<END |$SUDO $FDISK $LOOP d 2 n p 2 w END $SUDO $LOSETUP -d $LOOP start=`$FDISK -lu $OUTPUT | $TAIL -1 | $AWK '{print $2}'` LOOP=`$SUDO $LOSETUP -f` $SUDO $LOSETUP -o $(($start * 512)) $LOOP $OUTPUT $SUDO $FSCKEXT3 -f $LOOP $SUDO $RESIZE2FS $LOOP $SUDO $FSCKEXT3 -f $LOOP $SUDO $LOSETUP -d $LOOP echo "Resizing complete"
 * 1) !/bin/sh
 * 2) Grows a disk image by the specified number of megabytes
 * 1) Assumptions: an image with 2 partitions, the 2nd one
 * 2) in ext3 format.
 * 1) Example: grow-disk-image infile.img outfile.img 512
 * 1) Copying the initial image + SIZE zeros at the end
 * 1) Modify the partition table - Delete the 2nd partition
 * 2) and create it again with all available space
 * 1) Before this, find the first available loop device
 * 1) Free the loop device
 * 1) Now, access the second partition on the card
 * 2) First, compute the offset corresponding to the 2nd partition
 * 1) Running this again. Another loop device can have been used in the meantime
 * 1) Resize at last!
 * 1) Just to be sure, fsck the partition again
 * 1) Cleanup

Mounting the pre-installed rootfs
The following instructions should be run on an OMAP4 board running Linux. A simple rootfs with no graphics is sufficient.

Run  and read the starting block for the rootfs partition:

You must set cylinders. You can do this from the extra functions menu.

Disk maverick-netbook-panda_l24.11.img.gz: 0 MB, 0 bytes 255 heads, 63 sectors/track, 0 cylinders, total 0 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 maverick-netbook-panda_l24.11.img.gz.img1  *          63      144584       72261    c  W95 FAT32 (LBA) maverick-netbook-panda_l24.11.img.gz.img2         144585     4401809     2128612+  83  Linux

Now, mount this partition: mkdir -p /mnt/rootfs mount -o loop,offset=$((144585*512)) maverick-netbook-panda_l24.11.img.gz /mnt/rootfs

Modifying the pre-installed partition
Before running, replicate the basic filesystems that Ubuntu mounts:

for f in /proc /sys /dev /dev/pts /dev/shm /var/run /var/lock do  sudo mount -o bind $f /mnt/rootfs/$f done

Without the above, some commands may not work properly, being unable to find data in  and   in particular.

If you are behind a proxy, copy your files defining your proxy settings (typically  and  ) under the same path.

Also copy your name resolution settings to the rootfs: sudo cp /etc/resolv.conf /mnt/rootfs/etc/resolv.conf

Modify the rootfs
sudo chroot /mnt/rootfs/

If you are using a special package source, you can add it to

Now, update your package list and install extra packages. For example:

apt-get update apt-get install openssh-server

Once you are done, exit the chroot:

exit

Closing
sudo rm /mnt/rootfs/etc/resolv.conf

You may also undo your proxy setting changes (typically ).

Then, unmount the filesystems replicated in the chroot:

for f in /var/lock /var/run /dev/shm /dev/pts /dev /sys /proc do  sudo umount /mnt/rootfs/$f done

And umount your filesystem image:

sudo umount /mnt/rootfs

You are done!