FreeBSD on a Laptop

These are some notes I made regarding a laptop that I ordered on the afternoon of 27 February, and which I received on the evening of Monday, 05 March, 2001. There isn't much order, in that I tried to preserve the order in which I recorded things, intending to thus provide an out-of-band clue as to what struck me at various stages of obviousness. As should be apparent, I'm running FreeBSD on it.

One of the things I had decided to do on this machine is set it up so I could build & boot from different FreeBSD slices. To that end, I set up the partitioning (then modified it to):

  X		 538 MB	(I'm hoping to make this a "suspend to disk" slice)
  ad0s1a	 160 MB	root/boot for 1st -STABLE
  ad0s1e	1884 MB	/usr for 1st -STABLE
  ad0s2a	 160 MB	root/boot for 2nd -STABLE
  ad0s2e	1884 MB	/usr for 2nd -STABLE
  ad0s3a	 160 MB	root/boot for -CURRENT
  ad0s3e	1884 MB	/usr for -CURRENT
  ad0s3b	1024 MB	swap (common to all; /tmp is an MFS (md, in -CURRENT))
  ad0s3g	1024 MB	/var (common to all)
  ad0s3h	 9.5 GB	/common (just that; contains /home, /usr/local, /cvs, &c.)
[Note that the X slice is pointed to by partition table entry #4, which is why the references to the ad0sxy make some sort of sense... even though the chunk of disk that corresponds to the X slice is before any of the slices that FreeBSD uses. This isn't the original allocation scheme I used: I had allocated only(!) 96 MB for the root filesystems, and that was pushing things rather close on -CURRENT (which is which the machine was running when I did the above df), and it was also cutting things rather close for the /usr filesystems. Note that the process of reorganizing the filesystems was rather painful; it took about 12 hours (even though I used an adapter to connect the laptop's disk drive to a fairly beefy machine at work and did the dumps & restores disk-to-disk). As expected, it's the restore time that really establishes the bottleneck. Things are much better if you do the allocation right to begin with. And now that I've actually populated each of the slices (and booted off of each of the bootable ones), here's what df and swapinfo have to say:

dhcp-140[1] df -k; swapinfo
Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/ad0s3a    158783    69703    76378    48%    /
devfs               1        1        0   100%    /dev
/dev/ad0s1a    158783    41585   104496    28%    /S1
/dev/ad0s1e   1870791   807741   913387    47%    /S1/usr
/dev/ad0s2a    158783    41754   104327    29%    /S2
/dev/ad0s2e   1870791   791718   929410    46%    /S2/usr
/dev/ad0s3e   1870751   743571   977520    43%    /usr
/dev/ad0s3g   1016303    32086   902913     3%    /var
/dev/ad0s3h  10277074  5263328  4191581    56%    /common
procfs              4        4        0   100%    /proc
/dev/md10c     520140       24   478508     0%    /tmp
Device          1K-blocks     Used    Avail Capacity  Type
/dev/ad0s3b       1048448     4176  1044272     0%    Interleaved
dhcp-140[2] uname -a
FreeBSD 5.0-CURRENT FreeBSD 5.0-CURRENT #46: Sat Jun 23 13:23:14 PDT 2001  i386

Here's some narrative about the process I used:

Now, it happened that the install media I had available was 4.1-R. And in running sysinstall, I was finally able to set up that partitioning, but if I tried to tell sysinstall that I wanted to boot off of a slice on ad0s2 or ad0s3, it whined that FreeBSD couldn't cope with that. (For that matter, the partitions on ad0s2 and ad0s3 were created as ad0s2e, ad0s2f, ad0s3e, and ad0s3f. I used disklabel -e to change the names to what made more sense given their intended use. Since this was a simple matter of just changing the partition name, rather than the size or position of a slice, it was pretty straightforward. It was a little more challening to set up the suspend-to-disk ``partition'' so that its table entry was 4th, though the space it occupied on disk was 1st. I actually defined it as 1st, and well after things (other than suspend-to-disk) were working, I booted single-user and ran fdisk to change the 1st partition table entry to have the characteristics of the 2nd; change the 2nd to have the characteristics of the 3rd; change the 3rd to have the characteristics of the 4th; finally, change the 4th to have the (original) characteristics of the 1st. (I used boot0cfg -v to get the characteristics of each tabel entry in a nice, compact display -- on a different vty.) This is a time-consuming, laborious process.

And I set up /etc/fstab so that when I'm booted off of ad0s1a, ad0s2a is mounted as /S2 and ad0s3a is mounted as /C.

But where things get interesting is that after installing 4.1-R on s1, I used dd to copy each of the filesystems on ad0s1 to their respective counterparts on ad0s2. I then re-mounted the filesystems (as /S2 and /S2/usr -- though the latter mount isn't needed for what comes next) and edited /S2/etc/fstab, so that when I boot off of ad0s2a, ad0s1a gets mounted as /S1 (and ad0s1e gets mounted as /S1/usr).

So I re-boot, and get a list of 3 ``FreeBSD'' slices; I hit F2 to select the second one... and everything is Just Fine. :-) (I've done this with another machine, extending the exercise to the ad0s3 slice.)

So the mechanism uses some disk space & takes some time, but it provides for a comparatively easy-to-get-to fallback in case a planned upgrade fails: just boot off of one of the slices, exercise things enough to build confidence, dd the filesystems over, and start the next upgrade cycle.

The machine is generally set up as a DHCP client. And maybe I'm Really Weird, but I don't like the idea of the client specifying a hostname to use. So I cobbled up a bit of shell-scripting called /etc/dhclient-exit-hooks to provide a likely hostname. I set up /etc/rc.conf so that the machine's default hostname is just localhost. That appears to allow most things to work for me (though changing the hostname out from underneath X11 isn't friendly at all...).

Comments? Please send them to David Wolfskill -- thanks!
$Id: laptop.html,v 1.10 2003/03/14 12:52:02 david Exp $