BSD DevCenter
oreilly.comSafari Books Online.Conferences.


Big Scary Daemons

BSD Tricks: Linux Compatibility, the Hard Way


As a consultant, I'm required to be familiar with a variety of operating systems. Rather than keep three computers on hand, I just put a 12-gig hard drive in my laptop, split off a meager five gigs for Windows and Linux, and dedicated the rest to FreeBSD.

This works well enough, and any number of people run their systems in this configuration. It's always irritated me to have two Linux installs on my system, however: one under /linux, and one under /usr/compat/linux. It seems it would be possible to run programs in Linux mode using the existing Linux partition, rather than installing linux_base.

This column heads off into uncharted, unsupported territory. Don't play with this on a production system. Bring aspirin, patience, and lots of Band-Aids. Here be dragons. Bridge Out Ahead. Beware of Postal Workers. You have been warned.

I'm running FreeBSD-current on /dev/ad0s2. Red Hat Linux 6.2 uses /dev/ad0s3. The Linuxulator is based on Red Hat 6.1, meaning that the Linux userland I have is out of sync with the Linux kernel compatibility that FreeBSD provides. This turns out to be the least of our problems.

First of all, if you try to mount the Linux ext2fs partition read-write, you'll get a "permission denied" error. Your error log will show something like:

Oct 5 11:10:19 turtledawn /boot/kernel/kernel: WARNING: R/W mount of #ad/0x40002 denied due to unsupported optional features

A bit of wandering around in the mailing list archives shows that the problem is the new "sparse superblocks" that recent Linux kernels use. This increases the amount of storage space on large hard drives that use ext2fs. You can change this by using Linux's tune2fs and e2fsck.

Do not attempt to use these programs in Linux mode. Linux mode is powerful, but it doesn't address things like system nodes and directly addressing hardware. If you're lucky, you'll panic your machine; if not, you'll silently reboot it. Boot into Linux and log in as root.

First, drop to single user mode with:

shutdown -t 1 now

You need to unmount all of your filesystems, and mount them read-only. You can do this with:

umount -r /

At this point, your file systems will be mounted read-only. Linux's /etc/mtab will still show your root as being mounted read-write, but don't let that bother you; after all, the successful read-only mount means that /etc/mtab can't be updated. You can confirm that each filesystem is read-only; a simple touch /etc/test will give you a "permission denied" error if everything's OK.

You're ready to turn off sparse superblocks. Get your device names from Linux's /etc/fstab. For each device, do a:

tune2fs -s off /dev/hda3

After tuning all the file systems, check them.

e2fsck -y /dev/hda3

When complete, reboot into FreeBSD.

You can now mount your ext2 partition read-write with

mount_ext2fs /dev/ad0s3 /linux

Or you can jump right in. You can safely move the Linux userland without unloading linux.ko.

mv /compat/linux /compat/linux-pkg
mkdir /usr/compat/linux
mount_ext2fs /dev/ad0s3 /usr/compat/linux

Also edit /etc/fstab, listing the Linux partition like this:

/dev/ad0s3   /usr/compat/linux   ext2fs  rw,noauto   0   0

(Why noauto? For now, trust me.)

For a first test I tried that beast of an office suite, StarOffice 5.2. To my surprise, it worked on the first try.

Deeper checks unveiled problems. The files in /compat/linux/home/mwlucas were owned by uid and gid 500, which is what the Linux account "mwlucas" uses. I worked around user files by editing /compat/linux/etc/passwd and /compat/linux/etc/group, assigning myself my BSD uid and gid of 1001 instead of the Linux uid and gid of 500. A few runs of chown -R mwlucas.mwlucas made the problem go away for good, no matter what OS I boot.

More seriously, RealPlayer wouldn't run, failing with complaints about being unable to access the audio device. Linux programs looked in my home directory under /compat/linux/home/mwlucas, rather than under /usr/home/mwlucas. These problems all had a common cause; the Linuxulator looks for files under /compat/linux first, and only checks the rest of the system if it can't find something in its own playground. In the new configuration, dotfiles appeared left and right in the Linux home directory, while Linux programs ignored settings in my .cshrc and other BSD home directory configuration files.

Pages: 1, 2

Next Pagearrow

Sponsored by: