FreeBSD

Getting back into the swing of things

So I got my main computer running FreeBSD again. Except I'm using KDE for the desktop environment, instead of icewm. It has been a few years since I gave KDE a fair trial, and after compiling it a couple of days ago. I must say I am blown away by how awesome it is.

It might turn out that I get sick of it and go back to icewm, but so far so good.

Took me a while to get this FreeBSD box up and running. A long while. I had to acquire a second SSD for it, and then a compatible graphics card. So plucking up the courage to pay for those items took me about 6 months. Various other things got in my way too.

But now, the machine is up and running and I haven't booted into Windows 7 since. Not that I won't do again. I love computers, and pretty much like to use all OS I can get my hands on. Diversity is important. I've never owned a MAC however as I cannot afford one. I do have an DEC AlphaStation 255, but that's another story.

Anyway, I'm rambling.

The title of this post is about my long struggle to get my evolutionary art system up and running again. Not that I couldn't have gotten it going in a day if I had really wanted to, it just seems to have taken forever to get to the point where I was motivated enough and had the environment setup (i.e the FreeBSD box), to get going.

Well I dusted off the code tonight, and it compiled with a couple of modifications to account for some library changes. The next step is to start evolving images again, and also to relearn my codebase so I can continue advancing the code in new directions. All this inevitably is going to take another 6 months for no real reason, I feel. I'll get there eventually, I suppose :)

FreeBSD i386 Install (Part 3, Xorg)

So in the last part, wireless internet was setup. Great. Can't live without the internet!

In this glimpse into the world of FreeBSD, the X server will be setup and some other GUI stuff. It is worth bearing in mind, that if this machine was being setup as a server, none of this would be necessary.

The first thing to do, before anything else, and I am surprised that it has been tolerated this far in, is to get rid of that stupid terminal beeping.

$ su
Password:
# sysctl -a | grep bell
hw.syscons.bell: 1
# sysctl hw.syscons.bell=0
hw.syscons.bell: 1 -> 0

So that bastard has been found and disabled. But heaven forbid it it comes back on next boot:

# echo "hw.syscons.bell=0" >> /etc/sysctl.conf
# cat /etc/sysctl.conf
# $FreeBSD: src/etc/sysctl.conf,v 1.8.34.1.2.1 2009/10/25 01:10:29 kensmith Exp$
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#

# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0
hw.syscons.bell=0

Good. Now to get this system up to date with freebsd-update:

# freebsd-update fetch install
Looking up update.FreeBSD.org mirrors... 3 mirrors found.
Fetching metadata signature for 8.0-RELEASE from update5.FreeBSD.org... done.
Fetching metadata index... done.
Inspecting system... done.
Preparing to download files... done.

No updates needed to update system to 8.0-RELEASE-p2.
No updates are available to install.
Run '/usr/sbin/freebsd-update fetch' first.

The system was already up to date so it doesn't show any updates, but you get the idea. Now to automate this so that updates will be fetched every night via a cron job. Cron will send root an email if something needs installing (which then should be done manually via freebsd-update install) :

# echo "@daily root freebsd-update cron" >> /etc/crontab

OK the next thing to do is get the ports up to date. FreeBSD ports is a wonderful system which allows tons of software to be compiled and installed from source code. The whole collection exsits in /usr/ports by default. It was selected during installation so it should be there, but it won't be up to date. Ports can be updated using cvsup or portsnap, and probably also git if you can be asked, but here portsnap will be used because it is quick and saves bandwidth both on here and over at the FreeBSD mirror. To get the first portsnap:

# portsnap fetch extract

And then in the future, keep this updated with:

# portsnap fetch update

Now that ports is up to date, it is time to build the Xorg port. The alternative is just to use pkg_add -r to add a precompiled package. But I prefer to build from source wherever possible so as to be able to choose various compile time options and so on.

Go into the ports directory for xorg (as root). Actually, I hate this shell, and I want one with tab completion, so first of all install bash:

# cd /usr/ports/shells/bash
# make install clean

This will go and dilligently fetch, compile, and install the port. It might ask some questions along the way. To use bash by default (at login), edit /etc/passwd using vipw. Change the shell entry (the last entry in the line) for the users that you want to use bash. The default install of bash will be at /usr/local/bin/bash.

Great. Logged back in under bash, and su'd to root. Now to install Xorg. This is going to take a while, so better to preconfigure all options in advance before doing the make install clean:

[root@ ~]# cd /usr/ports/x11/xorg
[root@ /usr/ports/x11/xorg]# make config-recursive
===> Setting user-specified options for xorg-7.5 and dependencies
[root@ /usr/ports/x11/xorg]# make install clean

Once that build is complete, and only very rarely does something go wrong with FreeBSD ports, it is time to configure X. OK, the manual says that startx might work on its own, in which case, great. Otherwise, do this:

[root@ ~]# X -configure
[root@ ~]# X -config xorg.conf.new -retro

The retro switch should result in a black and grey grid, instead of a blank screen if it is omitted... Note I didn't want hald and dbus because I'm not that kind of guy. But this kind of tomfoolery requires adding:

Section "ServerFlags"
	Option "AllowEmptyInput" "False"
EndSection

To the config file, otherwise X will start crying. Here is the whole file for the Acer Travelmate 2303LCi:

Section "ServerFlags"
	Option "AllowEmptyInput" "False"
EndSection

Section "ServerLayout"
	Identifier     "X.org Configured"
	Screen      0  "Screen0" 0 0
	InputDevice    "Mouse0" "CorePointer"
	InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
	ModulePath   "/usr/local/lib/xorg/modules"
	FontPath     "/usr/local/lib/X11/fonts/misc/"
	FontPath     "/usr/local/lib/X11/fonts/TTF/"
	FontPath     "/usr/local/lib/X11/fonts/OTF"
	FontPath     "/usr/local/lib/X11/fonts/Type1/"
	FontPath     "/usr/local/lib/X11/fonts/100dpi/"
	FontPath     "/usr/local/lib/X11/fonts/75dpi/"
	FontPath     "/usr/local/lib/X11/fonts/URW/"
EndSection

Section "Module"
	Load  "dbe"
	Load  "dri"
	Load  "dri2"
	Load  "extmod"
	Load  "glx"
	Load  "record"
	Load  "freetype2"
EndSection

Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
	Option "XkbLayout" "gb"
EndSection

Section "InputDevice"
	Identifier  "Mouse0"
	Driver      "mouse"
	Option	    "Protocol" "auto"
	Option	    "Device" "/dev/sysmouse"
	#Option	    "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
	Identifier   "Monitor0"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"
EndSection

Section "Device"
        Option     "DRI"
	Identifier  "Card0"
	Driver      "intel"
	VendorName  "Intel Corporation"
	BoardName   "82852/855GM Integrated Graphics Device"
	BusID       "PCI:0:2:0"
EndSection

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
	SubSection "Display"
		Viewport   0 0
		Depth     24
		Modes "1024x768"
	EndSubSection
EndSection

Great, everything should work now, so copy the file to it's default position:

[root@ ~]# cp xorg.conf.new /etc/X11/xorg.conf

I also want a GUI login screen at boot. For kicks, I used slim because I thought it looked nice and slim:

[root@ ~]# cd /usr/ports/x11/slim/
[root@ /usr/ports/x11/slim]# make install clean
[root@ ~]# echo "slim_enable=\"YES\"" >> /etc/rc.conf

I even made a custom theme:

This is just a knock off of this theme called Rear Window by a guy called slackhack, combined with this logo. To install the theme do this:

[root@ ~]# cd /usr/ports/ftp/wget
[root@ /usr/ports/ftp/wget]# make install clean
[root@ /usr/ports/ftp/wget]# cd /usr/local/share/slim/themes/
[root@ /usr/local/share/slim/themes]# wget www.ashleymills.com/misc/bsd.tar.gz
--2010-05-10 22:54:02--  http://www.ashleymills.com/misc/bsd.tar.gz
Resolving www.ashleymills.com... 109.74.199.96
Connecting to www.ashleymills.com|109.74.199.96|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 132189 (129K) [application/octet-stream]
Saving to: `bsd.tar.gz'

100%[======================================>] 132,189      247K/s   in 0.5s    

2010-05-10 22:54:02 (247 KB/s) - `bsd.tar.gz' saved [132189/132189]

[root@ /usr/local/share/slim/themes]# tar xzvf bsd.tar.gz 
x bsd/
x bsd/slim.theme
x bsd/panel.png
x bsd/background.png
[root@ /usr/local/share/slim/themes]#

Then edit /usr/local/etc/slim.conf and change the current_theme value to bsd. Don't ask my why slim puts its config there.

Almost done, but I forgot that X isn't much use without a window manager. You could use twm, but I want to use icewm:

[root@ ~]# cd /usr/ports/x11-wm/icewm
[root@ /usr/ports/x11-wm/icewm]# make install clean

Now make sure icewm starts when you login from slim. Do this as the normal user:

[you@ ~]$ echo "exec icewm-session" > .xinitrc
[you@ ~]$ cat .xinitrc 
exec icewm-session
[you@ ~]$ 

I think that is everything. Reboot and it should boot into slim login manager, after which logging in will load icewm.

[you@ ~]$ su
Password:
[root@ /home/you]# reboot

Simple volume control for icewm on FreeBSD

icewm is probably my favourite window manager for X. When I'm using a UNIX system. Here is a screenshot:

Why do I love it? Well, for one thing on my system it is consuming about 10MB of RAM. Actually I'm running icewm-session so it's a bit more but really I only need the icewm part. So that is one reason, here are two others:

  • CTRL-ALT-SPACE brings up a command execution input field on the taskbar. This really useful for launching programs and so on. Much quicker than navigating a menu. For example I've aliased firefox3 to ff, so the launch is just CTRL-ALT-SPACE in one strike, ff, enter, and that's it..
  • Multi desktop support is builtin by default, and 4 desktops is the standard. It is easy to switch between by using CTRL-ALT-LEFT or CTRL-ALT-RIGHT. A window can be moved into another desktop just by adding a SHIFT into those commands.

OK so these are mainly about key bindings, but I just find that these defaults come naturally to me, and I find using icewm much more productive and straightforward than other wm. Mainly because I don't really need a menu and all that crap, I just need lots of shells and a way to switch between windows.

Anyway, to get the point of this post, icewm doesn't have a volume control thing. Lots of people have written them but it occurred to me that I didn't want to waste resources running some stupid thing just to change volume. I mean, how often do I change volume? Not very often. So why have an app running in the background dilligently waiting for my commands? No, it would be a waste.

On FreeBSD, controlling the volume of the soundcard is done via the mixer command. It is simple, mixer on its own lists all of the soundcard mixer values: line in, cd, pcm, etc. And changing say the volume is done by "mixer vol 30" to set it to 30. So I thought, fuckit, why not just write something in python in a few minutes to do this with a slider. Well here it is:

#!/usr/local/bin/python
import commands
from Tkinter import Tk,IntVar,Scale

def adjustVol(vol):
   commands.getoutput("/usr/sbin/mixer vol "+vol)
   return

root = Tk()
root.geometry('50x100+80+620')
vol = IntVar()
scale = Scale(root,variable=vol,from_=100,to=0,command=adjustVol)
scale.set(commands.getoutput('/usr/sbin/mixer -S').split(':')[1])
scale.pack()
root.mainloop()

mixerapp.py

That's it! The code simply creates a Tk window with a slider and sets the value accordingly. Since I wasn't making it generic, I just hard coded the screen position so that it came above the volume icon I added to the icewm toolbar. Here it is in action:

icewm toolbar then has an entry like this:

prog MixerControl vol_16x16.png /path/to/mixerapp.py

I got the icon image by searching on google images using the imagesize:16x16 modifier.

FreeBSD i386 Install (Part 2, Internet)

After the FreeBSD system has booted for the first time, after logging in as the non-root user created, the first thing needed in the modern world is internet access, since I had a cheapo TP-LINK TL-WN321G hanging around, which is based on the Ralink chipset I just used that.

After inserting the thing into the USB, see if it is recognized, by looking at the system message buffer via dmesg, and pipe it to tail in this case since I only care about the last few lines:

$ dmesg | tail -n 3
ugen3.2: <Ralink> at usbus3
rum0: <Ralink 54M.USB......., class 0/0, rev 2.00/0.01, addr 2> on usbus3
rum0: MAC/BBP RT2573 (rev 0x2573a), RF RT2528

OK, so it is a rum0 device, so let us have a look, we are going to need to su to root at some point so we will do that now too:

$ su
Password:
# ifconfig rum0
rum0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 2290
        ether 00:1f:e2:3d:40:05
        media: IEEE 802.11 Wireless Ethernet autoselect <adhoc> (autoselect <ad
hoc>)
        status: no carrier

Not really my MAC of course. FreeBSD requires the creation of a pseudo wlan device for wireless:

# ifconfig wlan1 create wlandev rum0

Which says to create the pseudo-device wlan1 using the parent device rum0. Note that I already had another device setup when I was writing this, so I used wlan1 instead of wlan0, since the latter already existed. Sometimes the devices don't go UP, so just to be sure:

# ifconfig rum0 up
# ifconfig wlan1 up
rum0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 2290
        ether 00:1f:e2:3d:40:05
        media: IEEE 802.11 Wireless Ethernet autoselect mode 11g
        status: associated
# ifconfig wlan1
wlan1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:1f:e2:3d:40:05
        media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
        status: no carrier
        ssid "" channel 4 (2427 Mhz 11g)
        country US authmode OPEN privacy OFF txpower 0 bmiss 7 scanvalid 60
        bgscan bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5
        protmode CTS bintval 0

So you can see both devices are UP. Now you need information about the network you are connecting to. I'm connecting to a WPA2 encrypted network. If you already know the SSID, great, otherwise you need to scan:

# ifconfig wlan1 list scan
SSID/MESH ID    BSSID              CHAN RATE   S:N     INT CAPS
WIFIGATE        00:15:31:b4:82:90    1   54M -87:-95  100 EP   WPA

Now edit /etc/wpa_supplicant.conf to provide some data about the access point. There are a ton of options, but for a standard WPA2 AP you can hopefully get away with the following:

network={
   ssid="WIFIGATE"
   psk="PASSWORD"
}

Note "network={" can have no spaces. Now you need to start wpa_supplicant:

# wpa_supplicant -iwlan1 -c /etc/wpa_supplicant.conf
CTRL-EVENT-SCAN-RESULTS 
Trying to associate with 00:15:31:b4:82:90 (SSID='SKY01839' freq=2412 MHz)
Associated with 00:1f:e2:3d:40:05
WPA: Key negotiation completed with 00:1f:e2:3d:40:05 [PTK=TKIP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 00:1f:e2:3d:40:05 completed (auth)
[id=2 id_str=]

I did that in the foreground because I wanted to watch it, you can use -d for additional information. Now that it is connected, we need to get an IP, suspend wpa_supplicant with CTRL-Z it and then put it to the background:

 ^Z[1] + Suspended               wpa_supplicant -iwlan1 -c /etc/wpa_supp
licant.conf
# bg
[1] wpa_supplicant -iwlan1 -c /etc/wpa_supplicant.conf

Get an IP using dhclient:

# dhclient wlan1
DHCPREQUEST on wlan1 to 255.255.255.255 port 67
DHCPACK from 192.168.0.1
bound to 192.168.0.6 -- renewal in 43200 seconds.

Test:

# ping -c 2 www.google.co.uk
PING www-tmmdi.l.google.com (66.102.9.103): 56 data bytes
64 bytes from 66.102.9.103: icmp_seq=0 ttl=55 time=38.546 ms
64 bytes from 66.102.9.103: icmp_seq=1 ttl=55 time=37.888 ms

--- www-tmmdi.l.google.com ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 37.888/38.217/38.546/0.329 ms

Now you might get annoyed by messages from wpa_supplicant, even though it is in the background, so you probably want to run it with the -B flag for daemon operation in the future. Of course, you don't really want to have to do this ever again, but it is worth seeing how to do it (because for some reason you will end up doing this many times on many machines for various stupid reasons). To make all this happen automatically at boot, add the following to /etc/rc.conf :

wlans_rum0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"

Which says to create the pseudo device wlan0 attached to rum0 and then configure it automatically via wpa_supplicant and dhclient. The synchronous_dhclient it I needed because background dhclient didn't seem to work for me, perhaps you will have more luck.

Now I don't use this rum0 because it sticks out of the laptop which is annoying. Instead I have a mini-pci:

iwi0: <Intel(R) PRO/Wireless 2200BG> mem 0xe0105000-0xe0105f4a irq 10 at device
4.0 on pci2

Which uses the antenna built into the laptop. I bought this of ebay for six pounds inc delivery. The laptop did have an Ambit T60N871 inside it, but I couldn't get WPA2 to work with ndiswrapper and the ancient Acer windows drivers, so I thought fuckit and just bought the 2200BG which I looked up to be supported withFreeBSD. Hint: you might need to turn the device on first, check for a 1 with sysctl:

# sysctl -a | grep iwi | grep radio
dev.iwi.0.radio: 1

OK well that is it, connected to the internet, if you wanted to use ethernet it should be as simple as typing ifconfig to see what the device is, and then dhclient-ing it. Right, so we now have a non-gui box, connected to the internet, woo hoo. Next time, setting up the GUI and some other stuff.

FreeBSD ZFS Root Install

NOTE: this is unrelated to the i386 installation we were going through in another post. That series will continue on its own.

OK so I found out about Sun Microsystems Zeta File System (ZFS) a while ago, and after being blown away by its blisteringly fast perforance on Opensolaris, I knew I had to run an OS that used it.

Now, Opensolaris is pretty badass, don't get me wrong. But I don't know, the feel of the OS, I just prefer FreeBSD. Now FreeBSD being the great project it is, ported ZFS a while ago. Unfortunately the encumbered sysinstall hasn't been upgraded to support it.

I tried a few tutorials to setup ZFS manually, but they never worked, and although I read the manpages and tried to work it out I gave up due to time and couldn't be bothered restrictions.

Luckily I came across this script from some random elite: http://myconan.net/blog/archives/1794. Note that this guy describes his blog as "animeBSD. Your source for random craps everyday.", which made me laugh.

But anyway, the script actually works!

Well OK, I had to make one modification to the script. I had to set SRCLOADER=0 for it to work. I also changed a few things like instead of /usr/home I used /home, but otherwise just used the script directly. BTW make sure you use "sh zfsinstall.sh" an not "./zfsinstall.sh" because the latter did not work for me for some reason.

To actually run this, you just DL the FreeBSD usb image, copy it to a usb stick with "# dd if=8.0-RELEASE-amd64-memstick.img of=/dev/da0 bs=10240 conv=sync", mount the USB, copy the edited script onto it, umount it. Reboot from the USB, go into fixit console from sysinstall, and then run the script, et voila!

FreeBSD i386 Install (Part 1, Install)

What's the point of this post? Well to quote David Mackay "When I acquire information, I usually put the details on a webpage, so that I don't need a memory, and so that other people can use this information too.". Besides, I thought it might be interesting for Windows users to get some insight into a different world.

Below I chronicle the installation of FreeBSD on an old Acer Travelmate 2303LCi laptop running at 1500Mhz, with 256MB ram, and a 40GB hard drive. Full instructions for installing FreeBSD can be found here. Incidentally I've never read them. After booting up the CD and selecting the correct language you will see the following:

OK, so you've seen now howto setup a basic FreeBSD system. Pretty straightforward right? Note that this system installed has no GUI as yet.

What I love about FreeBSD is that everything is straightforward and clean. Because you have to setup everything yourself, it forces you to learn what is going on. Perhaps this sounds daunting but once you get your hands dirty you realize that it is all very straightforward. Then you feel much better knowing that you understand what is going on rather than just using some system you don't have a clue about.

However, if you are into having things done for you, why not checkout PC-BSD: http://www.pcbsd.org/

Syndicate content