|Note: This tutorial assumes that you have completed the previous tutorials: Ubuntu on Atoms, Ubuntu in a Chroot.|
|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Ubuntu on Pen DrivesDescription: Part three of a three part tutorial illustrating how to install, maintain and deploy a stripped down ubuntu (lucid) on pen drives for intel atoms using an i686 intel build platform. This one covers bulletproofing deployment on pen drive using a union filesystem.
Tutorial Level: INTERMEDIATE
Running installations from a pen drive is cheap and convenient, but has its hazards.
- The write lifetime of a pen drive isn't long - even if you use slc types.
- It is sensitive to unclean shutdowns.
The following method shows how to bulletproof such a system by deploying a read only root filesystem with a writeable overlay (the overlay can be on a second pen drive or a temporary filesystem in ram).
The kernel aufs module can easily support switching between the following configurations:
- Read-write root filesystem
- Read-only root filesystem + writeable overlay on another disk
- Read-only root filesystem + writeable tmpfs
Download mount_root_aufs to /etc/initramfs-tools/scripts/init-bottom.
- Add aufs to the modules to be loaded by the initramfs.
sudo echo aufs >> /etc/initramfs-tools/modules
- Update the initramdisk.
update-initramfs -k all -u
The above just gives you the potential to boot a union filesystem. To actually get it to boot such a system, you now need to edit grub and provide it the information about the union.
The following is actually a bad way to do this as you should hack grub default configuration files instead (maybe todo this later).
Simply look for your default boot option in /boot/grub/grub.cfg and append an additional kernel option to it as follows. i.e. Change
linux /boot/vmlinuz-2.6.32-24-generic root=LABEL=ros ro text
to one of the following:
# For a single writeable root filesystem # linux /boot/vmlinuz-2.6.32-24-generic root=LABEL=ros rw text # For a ro root and rw overlay on a second drive, one of either # linux /boot/vmlinuz-2.6.32-24-generic root=LABEL=ros ro text debug aufs=/dev/sdb1 linux /boot/vmlinuz-2.6.32-24-generic root=LABEL=ros ro text debug aufs=LABEL=ros_write # Alternatively a rw tmpfs overlay # linux /boot/vmlinuz-2.6.32-24-generic root=LABEL=ros ro text debug aufs=tmpfs
Note the debug option lets you log initramfs output from the unionfs script to /dev/.initramfs/initramfs.debug. You have now prepared your image for a ro root filesystem solution! If you're in a chroot doing this, drop out and make a tarball snapshot. You can now deploy.
Dual Pen Drives
This will set up a second pen drive as the rw overlay for the union filesystem prepared above. Alternatively, you can use a single drive and simple configure the overlay as a tmpfs in ram.
To be safe, we can use 2G for each, though we can make them smaller if need be.
Partitioning and Formatting
Here we'll assume the first drive is on /dev/sdb and the second on /dev/sdc. The following fdisk input scripts (root.input, write.input) simply clear whatever is there and make a single bootable linux partition on the first drive and a single non-bootable partition on the second drive.
sudo fdisk /dev/sdb < root.input sudo mkfs.ext4 /dev/sdb1 sudo e2label /dev/sdb1 ros
sudo fdisk /dev/sdc < write.input sudo mkfs.ext4 /dev/sdc1 sudo e2label /dev/sdc1 ros_write
- Extract a snapshot from your chroot.
- Extract this to our first pen drive and load grub into the MBR as follows.
sudo mkdir -p /mnt/ros sudo mount /dev/sdb1 /mnt/ros sudo tar -xvzf lucid-xxxxx.tar.gz -C /mnt/ros sudo grub-install --root-directory=/mnt/ros /dev/sdb sudo umount /mnt/ros
Simply plug'n'play. Possibly the only problem you might have is the bios trying to boot from the wrong drive. Simply enter bios and order the boot sequence appropriately.
We're also using this on DOM drives for a little bit more stability (particularly with respect to vibration) in an embedded environment than a pen drive.
I'm currently experimenting without swap for the time being - seeing as flash writes are pretty slow anyway and it only helps kill off the flash drives more quickly. If you have a tmpfs, then you're not worrying about swap anyway.
Will update this again if there is trouble not having swap available.