|/||Home||/||OpenBSD on Flash Memory|
NOTE: this was done with OpenBSD 4.6
This is how I installed and configured OpenBSD 4.6 to run on my Soekris net4511 that I upgraded to 64M. In searching how to do this, I found a few handy references that I took some tips from. One site had some handy tips for installing on flash, and another had some handy tips for installing OpenBSD as a desktop.
First, install OpenBSD however you want. I used PXE booting to install it to the 4G CF card. For help with this step, just do a search or go to the OpenBSD page on the topic. I may create a page on this at a later date.
I created the following partitions:
|b||no swap partition|
|c||this is the entire slice|
I made no swap partition, as the point of this is to minimize writed to the flash memory and a swap partition would just chew it up. The /var and /tmp partitions are just enough to get it running. The /usr takes about half the card and the /home uses the remaining space for home directories. The default install set was good enougn - pretty much everything non-X11. Once it is done, reboot to let it come up so we can make it more flash-friendly.
First, we will tweak the fstab to minimize writes to the card. As root, run the following commands:
# cp /etc/fstab /etc/fstab.rw
# cp /etc/fstab /etc/fstab.ro
This will create two copies of the fstab file. We will leave the .rw copy alone, as this one already mounts everything read-write. It should look like this:
/dev/wd0a / ffs rw 1 1 /dev/wd0g /home ffs rw,nodev,nosuid 1 2 /dev/wd0e /tmp ffs rw,nodev,nosuid 1 2 /dev/wd0f /usr ffs rw,nodev 1 2 /dev/wd0d /var ffs rw,nodev,nosuid 1 2
Edit the .ro version so it looks like this:
/dev/wd0a / ffs ro,noatime 1 1 /dev/wd0g /home ffs rw,nodev,nosuid,noatime 1 2 /dev/wd0f /usr ffs ro,nodev,noatime 1 2 swap /var mfs rw,nosuid,noexec,nodev,-P=/dev/wd0d,-s=10240 0 0 swap /tmp mfs rw,nosuid,noexec,nodev,-P=/dev/wd0e,-s=1024 0 0 swap /dev mfs rw,nosuid,noexec,-P=/proto/dev,-i=128,-s=3072 0 0
The noatime option tells it not to keep track of when each file was last accessed.
The / and /usr partitions set to ro (read only), but /home is still rw so you can work on things there.
The /var, /tmp, and /dev partitions are now mounted as ramdisks using swap.
The -P tells where to get the data to populate the ramdisk after it's created.
The -s is the size in sectors (512 bytes) - and yes, the ramdisks don't match the sizes of the partitions they are representing. I hope to work with these values to find some optimal sizes.
When /dev is mounted to a ramdisk, it is populated from a place that doesn't currently exist. Do the following as root:
# mkdir /proto
# mkdir /proto/dev
# cd /proto/dev
# cp /dev/MAKEDEV .
# ./MAKEDEV all
When this is done, the /proto/dev directory will be populated with the required device nodes.
Now we have 2 different fstab files (fstab.rw and fstab.ro) that can be copied over the main fstab depending if we want the system to use the standard rw filesystem or the more flash-memory-safe readonly system. To make switching between them even easier, we can make a simple script. Create /etc/chfs and give the following script:
#!/bin/sh if [ X$1 = "Xro" ] then cp /etc/fstab.ro /etc/fstab elif [ X$1 = "Xrw" ] then cp /etc/fstab.rw /etc/fstab else echo "'ro' or 'rw'" fi
Now, this will set it to rw mode:
# /etc/chfs rw
and this will set it to ro mode:
# /etc/chfs ro
Just remember you have to do this as root and reboot for it to take effect.
Based on a recommendation from one of the web pages mentioned at the top, I have found it very handy to put the following in /etc/profile:
CVSROOTemail@example.com:/cvs PKG_PATH=ftp://ftp3.usa.openbsd.org/pub/OpenBSD/4.6/packages/i386 alias pkg_list='lynx -dump $PKG_PATH/index.txt >$HOME/pkglist.txt' alias su='su -l' if [ "$USER" = root ]; then PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin PS1="\`hostname -s\`:\`pwd\`# " else PATH=/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:. PS1="\`hostname -s\`:\`pwd\`$ " fi export PATH PS1 CVSROOT PKG_PATH
With this in place, run 'pkg_list' as your regular user in your home directory to create a list of all the packages available to install. This also points to a ftp server so you can install apps with 'pkg_add -r'.
With all this in place, if you need to install an application (such as subversion or emacs), you can easily drop back to rw mode, reboot, install the app, swap back to ro mode, reboot again, and be happily running without worrying about trashing your CF card.