FreeBSD review and howtos from a Linux user

3 03 2008

I recently decided to give the new 7.0 release of FreeBSD a go and was fairly impressed. I did use BSD along time ago on a home server for a few months but pretty much forgot everything about it from back then.

FreeBSD Screenshot

Introduction
Firstly FreeBSD refers to both a kernel and userspace tools making it a whole operating system (userspace tools being the basic programs like shells and copy/move commands), this is different to Linux which is just a kernel and distros are technically called GNU/Linux to show that it is using the GNU userspace tools. You can install the GNU userspace tools on FreeBSD and you can also get GNU/FreeBSD hybrids such as the Debian GNU/kFreeBSD, and there was work on a Gentoo/FreeBSD but it never went anywhere, although there not really used much. Theres also not a huge point in either since all the userspace tools are based on the original Unix ones and try to mee POSIX standards etc %90 of the functionality is the same. There are some differences, for instance ‘ls –color’ on FreeBSD is ‘ls -G’, some commands require the flags to be in the correct order so ‘cp /directory /somewhere -rf’ won’t work as -rf is at the end instead of the start befoure the directories, when hitting the down arrow at the end of a man page it will exit on FreeBSD.

The other important difference between BSD’s and Linux is the license they use, Linux uses the GPL and BSD uses the BSD license. The GPL is actually more restrictive but in a way that is designed to guarantee everyones overall freedoms, by enforcing that the source remains open when redistributed. The BSD license basically says you can do whatever you want provided you keep the credits in, including taking the source and closing it or relicensing it. Apple took the FreeBSD userspace tools for OSX (and the Mach microkernel)

The difference in the kernels means that hardware is going to behave differently, device names in /dev/ are diffrent for starters. Ethernet cards have names that match the device model, for instance instead of “/dev/eth0” you might have “/dev/re0”. My harddrive is “/dev/ad10s1” instead of “/dev/sda1” There will be differences in the hardware that is supported, wifi is apparently better on FreeBSD although there has been a lot of work in the Linux area recently and some of the drivers have been ported across (leading to some controversy due to the relicensing of BSD code under the GPL, although it has apparently been resolved).

The overall system feels fairly similar to Slackware and Gentoo, except with better package management IMHO.

Installing
Installing isn’t particularly hard, if you have installed either, its not a Ubuntu style userfriendly distro so you do need to partition and such but it didn’t require heaps of planning and was fairly hassle free. There is also the handy FreeBSD handbook which is actually fairly good, normally when I get told to read opensource documentation I find a bunch of out of date or setup in a completely different way by everyone but the guide writers. You can get away with only getting the 1st CD since that contains the basic system and if you don’t choose much in the way of packages you won’t need the others. If however you do get asked to insert the 2nd or 3rd CDs, at that stage you can just ctrl+c and reboot into a working distro and use ‘sysinstall’ to make any additional changes. Set the root password with ‘passwd’ and add a user account with ‘adduser’.

One installed you need to setup stuff, once again if your a Gentoo user this is familiar. FreeBSD has binary packages that can be retrieved automatically via ftp by using the ‘pkg_add -r ‘ command. FreeBSD however also can compile packages from source using ports, this is similar to Gentoo’s portage which was heavily inspired by ports. Ports seems a simpler and more stable system than portage with which I have had problems maintaining when updating packages can break or lock other packages.

Firstly I had some problems with my USB keyboard, in the end I had to disable USB legacy in the BIOS which was blocking BSD from using it for some reason, this has the unfortunate side effect of disabling the keyboard in the boot loader but its not needed for now.

Ports
Ports is the system that FreeBSD uses to get source code for packages, compile and install it. It is similar to Portage as it used ports as inspiration. Compiling from source has advantages over using binary packages. For instance patent issues aren’t a problem because its the source code, I am not a lawyer but source code itself cannot be patented as its a blueprint not an actual thing, and compiling the code your self is possibly ok since you can apparently violate patents for personal use (not too sure on that, some talk here, at the very least it means that to enfoce the patent requires going after individuals rather than FreeBSD so home users are unlikly to be at risk (unless patent lawyers frequent your premises), it also allows for people in countries without such laws access to the code), but as I said I’m not a lawyer and haven’t bothered to find much in the way sources. Secondly you get more control over what features you want in your program and thirdly you can optimize the program for a specific architecture.

Setting up ports, If you want to grab a new snapshot of ports you will need to run ‘portsnap fetch’ followed by ‘portsnap extract’. If you already have “/usr/ports” perhapses because you chose it when the installer asked you can apparently ‘cd /usr/ports’ followed by ‘make update’. This should use portsnap to update it. The full was about a 50mb download when I did it with ‘portsnap fetch’.

Ports has a similar thing to Gentoo’s portage useflags called KNOBS, you can see a whole list of them in /usr/ports/KNOBS. I believe you can also set CFLAGS like in Gentoo although I havn’t bothered.

Desktop
If your using it on the desktop you will need to install xorg and a desktop environment, you can “pkg_add -r gnome2” to do that, which should pull in all the dependencies. Alternatively to build from source: cd /usr/ports/x11/gnome2 && make install clean
If you want to use gdm add gdm_enable=”YES” to /etc/rc.conf. If you don’t want Gnome you can so whatever other environment you want, Fluxbox, XFCE, KDE, etc… You will need to edit ~/.xinitrc and add “gnome-session”, “fluxbox” or whatever. You can then ‘startx’. At this point there will be a bunch of programs you need to install either from ports or with pkg_add -r such as firefox, pidgin, vlc (although totem should be in if you did gnome2), music players, etc…

Shell
The default shell csh might not be to your liking, a lot of people are experienced with bash which is the choice of most Linux distros although personally I prefer zsh which has better tab completion and fancy prompts included. ‘pkg_add -r zsh’ or ‘pkg_add -r bash’ or install them from ports. Then run ‘chsh’ which will give you a vi window, change the “Shell: /usr/bin/csh” to “Shell: /usr/local/bin/zsh”. Bash users will need to change it to bash obviously. If vi is a problem for you, you can probally edit ‘/etc/passwd’ with whatever you want. You will need to setup your shell rc, ~/.zshrc for zsh (although it has a config window on first time login).

Sound
You will probably need to enable sound, Theres a handy howto here, but basically ‘kldload snd_driver’, ‘cat /dev/sndstat’, look for the driver name right after “kld”, add DRIVERNAME_load=”YES” to /boot/loader.conf

Mount Linux ext3 Drive
Mounting your Linux drive, add the following entry to /etc/fstab: /dev/ad10s2 /mnt/ubuntu ext2fs rw 0 0 with whatever changes you need for your device name or mount point. You will need to make the mount point to with ‘mkdir /mnt/ubuntu’. If you get the error “mount: /dev/ad10s2 : Invalid argument” this could be because your drive is unclean, you will need to install the /usr/ports/sysutils/e2fsprogs/ and run ‘fsck.ext3 /dev/ad10s2’ (Assuming your using ext3).

NTFS read/write with NTFS-3g
Mounting a NTFS drive with read/write is a bit more work, you need to install ‘/usr/ports/sysutils/fusefs-ntfs’, however it needs the userspace source. You can get this with ‘sysinstall’ choosing “Configure>Distributions>src>All”, this will grab all the source its probably not all required but I couldn’t find the specific package and its handy to have the rest around anyway. Once you have that you can ‘ntfs-3g /dev/ad10s1 /mnt/windows’. Adding an fstab entry is again a bit problematic. Under 7.0 the mount command has had hardlinks to what it can call, mount_ntfs-3g isn’t in that list so you either need to patch mount or rename the current mount_ntfs, and link ntfs-3g in its place. Without that this was throwing an “mount: /dev/ad10s1 : Operation not supported by device” error.

nVidia drivers
The drivers work quite well on FreeBSD 7.0 but only on i386 (64bit is out of luck thanks to closed source nvidia drivers, 64bits OS is mostly useless anyway), the official ones refuse to install for me but the ones in ports work. Firstly you need the kernel source code installed, if you followed the NTFS-3g instructions above you will have the source already. If not you can specify just the base and sys source in sysinstall which is all thats needed for the drivers. Then cd /usr/ports/x11/nvidia-driver && make install clean Add this to /boot/loader.conf nvidia_load="YES" Now you need an xorg.conf file, by default BSD just relies on the autoconfig magic in the latest xorg releases so we need to force it to generate one with: Xorg -configure then copy the newly created xorg.conf.new to /etc/X11/xorg.conf. If you don’t want to edit the xorg by hand cd /usr/ports/x11/nvidia-xconfig && make install clean then nvidia-xconfig will change the “nv” driver to “nvidia”.

Compiz Fusion
Firstly if your on nVidia hardware you need to enable some xorg.conf settings, you can do them with nvidia-xconfig if you installed it above nvidia-xconfig --composite && nvidia-xconfig --render-accel && nvidia-xconfig --add-argb-glx-visuals -d 24

Now install Compiz with: cd /usr/ports/x11-wm/compiz-fusion && make install clean When you want to start it use LIBGL_ALWAYS_INDIRECT=1 compiz --sm-disable --replace ccp and for the Emerald decorationsemerald --replace. I had some problems with emerald not starting right away and drawing no decorations but after a while it loaded fine without me noticing and now starts fine. You will probably want to make Compiz start automatically, there are various guides on Compiz around that give you different ways. The config programs should be in System>Preferences for Compiz and Emerald, otherwise use ‘ccsm’ and ’emerald-theme-manager’.

updatedb
For those of you who use ‘locate’ command to find files, you will probably want to update the database, you might have already noticed that ‘updatedb’ isn’t a command. The actual command is ‘/usr/libexec/locate.updatedb’ but this will give you a warning as running it as root will expose hidden files that only root or specific users should see to the database (not such a problem for single users), you can however run the cron job manually for a safer database with: /etc/periodic/weekly/310.locate

Flash
One of the main problems with Desktop FreeBSD is that Flash has no native port for FreeBSD thanks to Adobe (Even though there is a Solaris port thanks to Sun working with Adobe, you can have your say on the flash development blog, also an online petition exists for what little use they are with over 5000 signatures(and spam bots)). There has been some talk on the mailing lists of a native FreeBSD port.

The only real solutions seems to be to use Flash 7 or possibly Windows Firefox under Wine ☹ (PC-BSD Apparently ship a Windows Firefox PBI)

If you want to try the Linux version of Flash 9 which freezes for me (and everyone apparently), you need to install the Linux plugin /usr/ports/www/linux-flashplugin9 and the wrapper /usr/ports/www/nspluginwrapper/. Then run nspluginwrapper -v -a -i to register the plugin. Check in ‘about:plugins’. Alternatively you can try Flash7 with a wrapper, there is also another wraooer /usr/ports/www/linuxpluginwrapper but it wouldn’t install for me.

ETQW [unsolved]
I though I would give ETQW a go under FreeBSD, unfortunately I ran into problems with the Linux compatibility layer, I’ll post the steps here in case its of use to someone trying to do something similar or can offer a solution.

Firstly the installer didn’t give the default path but entering one works however it then failed to make the path so you need to make it manually, then it failed to read from the cdrom (although I didn’t really look into it since you can just copy the files across manually, possibly manually mounting it manually would have solved it). Copy the correct files into the base directory.

When running the etqw binary I get an error about missing sdl libraries “./etqw.x86: error while loading shared libraries: libSDL-1.2.so.0: cannot open shared object file: No such file or directory”, You can fix this with cd /usr/ports/devel/linux-sdl12/ && make install clean

You will need to brand you etqw binaries as Linux ones, change to your etqw directory and run brandelf -t linux * also brandelf -t linux pb/* might be needed.

Then run: portmaster emulators/linux_base-fc4 to get all the Linux compatibility stuff installed (if using portmaster you need /usr/ports/ports-mgmt/portmaster/ installed)

Then there I got “./etqw.x86: error while loading shared libraries: /usr/local/lib/libX11.so.6: ELF file OS ABI invalid”, make sure that /usr/ports/x11/linux-xorg-libs/ is installed.

For the error “./etqw.x86: error while loading shared libraries: libjpeg.so.62: ELF file OS ABI invalid”, make sure you have “/usr/ports/graphics/linux-jpeg”. You can also try ‘sysctl kern.fallback_elf_brand=3’. But those didn’t work for me, I notice that etqw ships its own libjpeg, I tried replacing that with the /usr/compat/linux/usr/lib/libjpeg.so.62 one it seems to work but now I get another error “./etqw.x86: error while loading shared libraries: /usr/local/lib/libX11.so.6: ELF file OS ABI invalid”, possible its loading the ones in /usr/local/lib instead of /usr/compat/linux/usr/X11R6/lib/libX11.so.6 but I don’t know and thats about all I can think of now.

Also make sure you have linux_enable=”YES” in /etc/rc.conf and run ‘/etc/rc.d/abi restart’ to enable the compatibility layer stuff if you didn’t already have it done.

Wine
Wine works fine under FreeBSD, to install: cd /usr/ports/emulators/wine && make install clean

Mounting samba shares
Firstly you need to install Samba with /usr/ports/net/samba3/ && make install clean then you can manually mount it with the following: mount_smbfs //username@host/share /mnt/mointpoint

the -o options that you use in Linux such as username, password, credentials don’t work on FreeBSD’s version. If you want to make it automated, edit /etc/fstab and add: //username@server/share /mnt/mountpoint smbfs rw 0 0 Then edit /etc/nsmb.conf and check the example near the end. Alternatively you can put them in ~/.nsmb.conf for a per user solution.





Things are looking up for Linux game support

22 10 2007

While Linux probably isn’t quite ready to be a operating system choice for gamers, Linux users who happen to want to game are in for a treat.

Recently released was a native client for Enemy Territory: Quake Wars which I have been having fun playing the last couple of days. Many people have been claiming it as a BF2 rip off (mostly BF2 players) however the gameplay itself is completely different even if there are quite a few similarities (plus BF wasn’t the first game to implement its class system or vehicles, just one of the more memorable, also its something that UT2003 already did). Its a much faster passed game so there is very little waiting in a corner waiting for someone to come and capture a flag or running across the map for 5 min until you get to one, although a lot of the team play has been stripped down but this just makes it play more like a standard FPS which isn’t bad, just different. There is a list of important to note differences for BF players here.

And out next month is Unreal Tournament 3 which is getting a native client, theres a Windows beta demo out and a Linux one on its way, when ETQW is mentioned people generally cry that UT3 is better, personally I’m going to buy both although its hard to tell from prerelease hype and a beta demo exactly how good a game is going to be. They both seem like great games, and since UT3 has both FPS and BF style gameplay it should be flexible enough to keep interest.

Source games such as Team Fortress 2 are working great under WINE with the same performance as under Windows (You might loose %5 but make up for it with lower lag, the advanced shaders can apparently be enabled with a setting if you want), with the whole Orange Box going for $50USD (About $56 AUD thanks to America ruining its economy). The latest version of Wine 0.9.47 runs Steam great, although I did run into a problem with purchasing Orange Box through PayPal since it opened PayPal in Firefox but then Firefox wouldn’t execute the steam://paypal/return command, I was worried for a while that it was going to charge me without adding the game but PayPal showed no payment, I coped out and booted to a windows partition and brought it through there but its probably possible to manually pass the command with something like “wine ~/.wine/drive_c/Program Files/Steam/Steam.exe paypal/return” or set the protocol association in Firefox to run the command but I haven’t looked at it too much. now I’m awaiting my TF2 and HL2E2 download, already beat Portal which was a fun game although a bit too short hoping there is a squeal in the not too distant future. Valve recently posted that job for a Linux games programmer and have already ported source to use OpenGL for the PS2 so we could see a native Linux client in the future.

EDIT: I just tried HL2:E2 seems to have some graphical problems with the shaders turning everything bright colours, running without them causes crashes however you can run with the game in DirectX 8 mode and loose some graphical detail, this is probably something that will be fixed fairly soon since it seems like a simple bug, they already fixed some similar problems with Portal.
EDIT2: Use wine 0.9.46 not 0.9.47 this works without the -dxlevel 80 flag, I had the same problem with TF2 that I did on HL2E2, works great with 0.9.46.

Wine’s seems to have most of DirectX emulated, the main problem is a few minor bugs that crop up in games, such as the mouse cursor being stuck or leaving the window etc… Most of the bugs that are left are minor but make games unplayable and are often specific to only the one game. Unfortunately there are enough of these that most games don’t run but its certainly getting there, presumably a lot of these are in the target for Wine 1.0

Wine is improving quite fast, probably faster than new specifications are being produced and with many games ensuring that DX9 is supported due to the slow adoption of DX10 and with the OpenGL 3.0 specification approaching release its might make implementing the DirectX>OpenGL wrapper a whole lot quicker since it seems to support many of the same features, we could see WINE running more games off the shelf than ones that don’t within a few years.

Virtualization could also be another great way to run games under Linux but with %100 compatibility although requiring a copy of Windows, all that would be needed is a way to allow direct access to the video card, this can actually be done under Xen but requires a 2nd video card since the first one will be locked by the BIOS at boot. Alternatively a DirectX>OpenGL wrapper in the windows install could work, I hear this is how parallels works using the WINE one, but it might sacrifice some compatibility and speed. OpenGL can already run from a virtualized environment with VMGL, with this and WINE’s DirectX it might even be possible already. Maybe some official support from nVidia/ATI would expedite things.

Theres some interesting history about WINE’s DirectX implementation and information about a DirectX 10 implementation being underway here.