Linux notes

... and notes on other Unix-like systems

Introduction

In 2001 I was getting more and more frustrated with the problem of getting Windows to work the way I wanted it to, and decided to try this new "open" operating system that everyone seemed to be talking about - Linux. Several attempts to install the Debian distribution failed miserably, and I decided I needed to learn more about Linux before trying it.

After reading a couple of books and looking around on the Internet, I discovered the Linux from Scratch (LFS) project, which shows you how to build a working Linux system from the source code. With the help of detailed instructions, it gives you an insight into how Linux works, and - most important of all - if you run into difficulties, there is a mailing list to which you can post a request for help. The project is supported by a large community of Linux experts who give lots of time and energy in order to help computer enthusiasts like me who have more enthusiasm than competence.

Once you have built the base system, you have a Linux box which you can use to play with the myriad command-line possibilities, but no software. Logically, there is a second project, Beyond Linux from Scratch (BLFS), which gives you step-by-step instructions on how to build many common programs for e-mail, Web browsing, multimedia and so on.

My first LFS system was 3.0, and I have now (March 2005) just finished building 6.0, in order to upgrade to the 2.6 kernel. Since I have both version 5.0 and version 6.0 running, this seemed a good time to start making a few notes that might help others finding their way through the Linux jungle. Just after building LFS 6.0 I also installed another Unix-derived OS, OpenBSD (version 3.6), so I may add a few remarks on that as well.

Browsing the Web with w3m

The basic LFS system has only text consoles, no graphics. If you want to see pictures, you have to either install the X windows system, or compile the kernel to include support for the framebuffer, which can display graphics on the "text" console. One of the first programs I install after the basic build is w3m, a text-based Web browser which, in newer releases, has included limited graphics support. However, when playing with pre-compiled distributions, I discovered that in Debian and similar distibutions (eg Knoppix, Ubuntu) you can install not only w3m but also w3m-img using

apt-get install w3m w3m-img

and you can then display graphics, not only in X windows, but also on the framebuffer.

For a long time I have been trying to get this to work in an LFS system, without success. w3m is an excellent browser but the English-language documentation is sparse (the author of the program is Japanese) and I had to work with various hints picked up from Web searches and the minimal README files in the distribution. But at last I've worked it out. For those of you who want to do it, here's what I did on my LFS 5.0 system (I was practising for the version 6.0 installation).

But, to start with, the bad news. You can't use w3m to display images in the framebuffer unless you have X installed. This sounds a bit crazy, but the program that displays the images, w3mimgdisplay, depends on two X libraries, libX11 and libXext. Incidentally, the w3mimgdisplay program is installed to a library directory, /usr/lib/w3m/ (or maybe /usr/local/lib/w3m, depending on the parameters passed to "configure"), so "whereis w3mimgdisplay" won't find it. That confused me for a while.

So, first of all install an X windows system, either XFree86 or Xorg. I have XFree86 version 4.3.0.1 installed using instructions from the BLFS book, which helpfully tells you that, before building XFree, you have to build the PNG library, libpng. (The same is true if you build Xorg.)

Then, again following the BLFS book, I installed the following, in this order:

After installing each library you need to issue the command "ldconfig" as root.

Now you can build or rebuild w3m. I followed the instructions in BLFS except that I added explicit instructions to configure for both X and the framebuffer; I don't know if this is necessary, but it certainly can't do any damage. So the configure step becomes:

./configure --prefix=/usr --libexecdir=/usr/lib --sysconfdir=/etc --enable-image=x11,fb

At this point, I restarted w3m and - no images. After some more Web searching, I su-ed to root and launched w3m and it worked. In LFS 5.0, the framebuffer device /dev/fb0 has permissions -rw-------, so that only root can read and write to it. I did

chmod 666 /dev/fb0

and it worked, though I suppose I could also have done chmod 664 and added myself to the "tty" group, which in LFS 5.0 is the fb0 group. In LFS 6.0 it's video.

If it dosn't work for you, make sure you have enabled automatic display of inline images in the w3m options.

The above method will also work with LFS 6.0, except that you will have to edit the LFS permissions file in /etc/udev/permissions.d/ Change the permissions of the fb devices to 660 and add yourself to the video group.

Patches are available on Japanese sites to enable w3m to compile against glib-2.x and GTK+-2.x, but I haven't been able to get them to work. However you can safely install glib-1.x and GTK+-1.x libraries alongside the glib-2.x and GTK+-2.x libraries.

Viewing images in the text console

If you have built w3m according to the above method and you want to view images in the text console without starting w3m, you can build a useful program called fbv. It will display jpeg, tiff and png images, rotate them, fit them to the screen, and show multiple files as a slidshow. But on my LFS 5 system it needed some tweaking to build properly.

I ran ./configure but it didn't find libpng, and "make" exited with a list of unresolved references. If this happens to you, run configure, then open Make.conf with your text editor. The line starting "LIB = " should read

LIB = -ljpeg -ltiff -lpng -lz -lm

If it doesn't, edit it by hand. Then do make and make install. Say "fbv" and you will see a list of command-line options followed by an error message (because you haven't specified a file).

On LFS 6 the program compiles without any problems. I just wish I knew why!

Another look at xpdf

With these graphics librarires installed and a viewer such as gtksee you can view images attached to emails. But what about PDF files? I decided to have a go at installing a PDF viewer, xpdf. To be honest, I hadn't noticed that it is included in the Beyond Linux from Scratch book (it's right at the end!). The way I installed it is a bit different from the BLFS way, but it works. There are a couple of things you need to know, which I had to figure out for myself.

First, as the BLFS book says, you need X Motif or its open source equivalent, LessTif. Install LessTif according to the book, which uses version 0.93.94. Don't forget to run ldconfig afterwards.

Also, xpdf version 3 no longer uses X fonts; I have no idea why. If you don't have the ghostscript printing system installed, you will need to install the ghostcript fonts. This is easy. As root, create the directory /usr/local/share/ghostscript/fonts and download the file

http://ftp.gnu.org/pub/gnu/ghostscript/ghostscript-fonts-std-5.10.tar.gz

to that directory, then untar it into the same directory (there is no path stored in the tar file).

The BLFS book says that ghostscript is an optional dependency, but if you don't have these fonts xpdf will generate a lot of error messages and some PDF files won't display properly.

You also need Freetype2; if you have installed XFree (or Xorg) according to BLFS, you have it already.

Now for xpdf. At the moment there are three patches to download as well as the tarball. The patches are not applied in the same way as LFS and BLFS patches. The files to be patched, XRef.cc Gfx.cc and GfxState.cc are not in the xpdf-3.00 build directory, but in a subdirectory, xpdf. So once in the build directory you have to say

cd xpdf

and then

patch -i ../../xpdf-3.00pl1.patch

and similarly for the other two patches. Don't use the -Np1 option, it will exit with an error message.

Now go back to the build directory with cd .. and do the configure step. I'm assuming you'll want to follow the BLFS convention of putting the executable in /usr/bin/ rather than /usr/local/bin, which is the default, and of putting the configuration file in /etc. But BLFS has also installed Freetype and LessTif in nonstandard locations, and the configure program won't find them automatically. So you need to say

./configure --prefix=/usr --sysconfdir=/etc --enable-a4-paper \
--with-freetype2-library=/usr/lib/ \
--with-freetype2-includes=/usr/include/freetype2 \
--with-Xm-library=/usr/lib/ --with-Xm-includes=/usr/include/Xm

If all has gone well, configure will find everything it needs and tell you that it can compile xpdf and several other programs. Then just do make and make install.

Finally, edit the /etc/xpdfrc configuration file by uncommenting the lines giving the path to the ghostscript fonts. Leave the paths to the X fonts commented out; someone must have forgotten to delete them! If you uncomment them, you will get a string of error messages telling you thet xpdf version 3 no longer supports X fonts (thanks ...).

You can now read PDF files attached to e-mails by for example adding the following line to .mailcap, if you use mutt:

application/pdf ; xpdf -q %s ; copiousoutput

The -q option stops error messages appearing on the screen. When xpdf exits it generates several lines of warnings concerning XtRemoveGrab; this is a known issue with LessTif and apparently has not yet been corrected. However it doesn't prevent xpdf from working properly.

OpenBSD 3.6: installation

OpenBSD is a version of Unix which is very secure and often used on servers. But I was interested to see how it performed on a desktop PC and how it differs from Linux. When I discovered that I had bought a German computer magazine which came with a CD-ROM containing a basic version of OpenBSD 3.6, I couldn't resist trying it.

The installation itself is very easy; it is slightly more complicated to get OpenBSD to dual-boot with other systems. If you look around the Internet, you will find some quite scary articles about this. I can only say that I had no problems; perhaps I was lucky. Obviously you should back up critical data before you install OpenBSD; but then, you should back up critical data anyway, shouldn't you? Back up your MBR and have a GRUB boot diskette handy, just in case. Also read this useful article on the OpenBSD site.

First of all, you need to read the small print to find out something important: OpenBSD, unlike Linux, will not install to a logical partition. This means that, in Linux-speak, you have to install it to hda1 hda2 or hda3 (or hdb1-3 if you have a second hard disk). Notice that BSD calls the disks wd0 and wd1, and the corresponding devices are /dev/rwd0 and /dev/rwd1. BSD comes with an fdisk program, but it is not very user-friendly; it is far easier to use your Linux fdisk or cfdisk program to install a primary partition and to change the partition type to A6 for OpenBSD. OpenBSD also requires it partition to be marked as bootable, but you don't need to do that with cfdisk, GRUB will do it for you. Make a note of the start and end sectors of the OpenBSD partition.

Now all you need is an OpenBSD bootdisk, which you can get from www.openbsd.org. This site also has an excellent FAQ including detailed installation instructions. At the beginning of the installation you choose your keyboard type and the disk you want to install to (remember that they are called wd0 and wd1 if you have two hard disks). The BSD fdisk will then run and most of the information will scroll of the screen before you can see; don't worry, you can use PageUp to review it. If you have already set up a primary partition for BSD from within Linux, it should be recognized, and you can just quit fdisk with "q".

Now you use disklabel to set up the BSD partition; I just used the defaults given in the FAQ. My German computer magazine warned me that disklabel can corrupt adjoining non-BSD partitions, but this didn't happen to me; when I tried to create a slice that was too big, it warned me. But check with the start and end sectors that you noted earlier.

Once the partition is set up, the rest is very easy. If you don't have the OpenBSD CDROM, but you do have ADSL, just configure the network from the install program and download the packages (if you don't need multiprocessor support, uncheck bsd.mp).

At the end of the installation, reboot and use GRUB to start OpenBSD. On my PC the OpenBSD partition is the third primary partition on wd1, so the commands are:

root (hd1,2)
makeactive
chainloader +1

Then consult the section "After you reboot" in the installation instructions. Things I wish I'd known for a single-user PC:

1. You say "adduser" to create your non-root account. At the question "Invite [name] into other groups:" answer wheel. Then say "visudo" to edit the /etc/sudoers file so that you can perform all root actions using sudo.

2. The default shell for root is csh. It's not easy to use; that's why you'll find it easier to use sudo. Don't change .cshrc unless you know what you're doing (I didn't).

3. The default user shell is ksh. If you really must have the Bash shell, make sure you install the static package. (Or stick with Linux!)

4. You must use visudo to edit /etc/sudoers and you must use vipw to edit /etc/passwd and /etc/master.passwd

5. If (like me) you find the vi editor incomprehensible, you can either download the emacs package or use mg, a small emacs-like editor included in the basic installation.

6. OpenBSD uses the Unix FFS file system. Some Web sites will tell you that you can read Linux partitions from OpenBSD but you can't read OpenBSD partitions from Linux; this isn't true (see below, dual-booting).

7. BSD will help you to understand MacOS X - but not much. :-((

OpenBSD: dual-booting with Linux (kernel 2.6) and Windows

If you dual-boot only with Linux, you probably keep your hardware clock set to UTC, which is what OpenBSD expects. If you boot Windows as well, and you want to set your hardware clock to local time, OpenBSD now supports this. See the FAQ and note that config requires root privileges.

OpenBSD can read your Linux ext2fs partitions "out of the box": mount [device] [mountpoint] will recognize the filesystem and mount it.

Reading partitions in the OpenBSD slice from Linux is a bit more tricky; if your boot-time messages say nothing about BSD partitions, you will need to recompile your kernel. First, the kernel has to include support for the Unix filesystem (ufs); this is in File Systems --> Miscellaneous file systems. You have the choice between read-only (safer) or read-write. Secondly, you must also include support for BSD disklabels; for reasons I cannot fathom, this is hidden under Partition types --> Advanced partition selection --> PC BIOS (MSDOS partition tables) support --> BSD disklabel support. (Linus says, "I don't use the BSDdisklabel stuff myself"!)

After recompiling, the BSD partitions should be recognized at boot-time and they will be allocated device numbers after the other partitions; for instannce, on my second hard drive, hdb1 and hdb5-9 are Linux partitions, hdb2 is the Linux swap partition, and hdb3 is the OpenBSD slice, but the OpenBSD partitions are allocated to hdb10-15. Since I compiled read-only support for ufs into the kernel, the command to mount my BSD /home/paul partition in Linux is

mount -r -t ufs -o ufstype=44bsd /dev/hdb15 /mnt/bsd

 

27 Apr 2006