Xaero.org Tech news, reviews, and whatever else I wanna put here!

14Feb/100

Updating a ZFS on Root installation in FreeBSD 8

Ever since ZFS became production ready on FreeBSD 8 (and backported to 7), I've been itching to switch to using it and getting rid of UFS. For one, UFS is OLD. It was first used in 4.2BSD if that gives any indication. The most salient problem with UFS is the lack of real journaling. True, you have the soft-updates feature, but soft-updates are an alternative to journaling. This may not be a problem for users with older hardware and smaller hard disks, but with today's multi-terabyte drives, a power failure or system crash can lead to painfully long waits as fsck verifies the consistency of your file system.

To that end, I followed this handy guide to installing a FreeBSD system on a pure ZFS-only setup. Note that you'll end up with a system with no traces of UFS whatsoever, meaning you have to use the ZFS bootloader and can't dual boot anymore. If that's not to your liking, have a look at the index of ZFS on root guides. If you need to dual boot, you'll want to follow one of the MBR guides. For my needs, if I find myself needing to boot to another operating system, I simply hit F12 when my system is performing a POST test and choose a different drive to boot to. It's simple and separates your operating systems so they don't affect one another. Another alternative is to use virtualization if your needs aren't too demanding.

One thing none of the ZFS on root guides show you is also one of the most important: how to update and rebuild your system! If you're a developer you probably already know how to do this, but for the rest of us, it's important to know how to properly update your system when needed.

To begin, you'll want to sync your source tree. Instructions for that are located in the handbook, but it really boils down to using csup to synchronize source from a cvsup server to your local machine. If you do anything that requires building a kernel module, you're probably familiar with this. With your source tree synchronized to your desired version of FreeBSD, you can follow the the handbook guide to rebuilding world.

Once you have installed the kernel, reboot into single user mode as the guide tells you. Issue the "mount" command. You'll notice that no filesystems are mounted except for devfs and the root ZFS filesystem you marked as legacy. The handbook tells you to use "mount -a -t ufs" but obviously this won't work since we have banished UFS from our FreeBSD box. To mount all the ZFS mountpoints you have, simply use "zfs mount -a". This should mount everything except for / (root) as read-write. To enable a writable file system root, use "mount -uw /" and then "mount -a" to mount anything else. The "-uw" option unsets any mount options and then sets the write bit so you can write to that mount point. At this point you should be able to use mergmaster and installworld to finish rebuilding your system. One important task you must do before rebooting into your updated system is to install updated boot code. This is done with the following command after installing the new world: "gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 disk" where disk is the name of the drive you installed to (usually ad0). With this, you should have an updated system with ZFS as your file system!

Enjoy!

11Feb/100

Fun with numbers…

So I'm neck deep in my GRE studies. I've already gone through two GRE books and an ebook. I'm close to finishing my third book (this test is NOT easy). I'm learning some interesting properties of numbers such as the following:

Integers:

  • Integers are whole numbers (whether positive or negative)
  • Fractions are not integers
  • Zero is an integer!
  • Positive integers get larger as they move farther from zero
  • Negative integers get smaller as they move farther from zero

Consecutive numbers:

  • Listed in order of increasing value without any numbers missing between them
  • Fractions and decimals cannot be consecutive numbers; only integers can!
  • You can even have consecutive even integers: 2, 4, 6, 8...

Properties of Zero:

  • 0 is even
  • 0 plus any other number is equal to that number
  • 0 multiplied by any other number is equal to 0.

Positives and Negatives:

  • pos x pos = pos
  • neg x neg = pos ("two wrongs make a right" is my memorization tool)
  • pos x neg = neg

Even or odd?

  • Any number that can be cleanly divided by 2 is even (i.e. no remainder)
  • Any number that cannot be cleanly divided by 2 is odd (i.e. has a remainder)
  • Zero is even
  • Fractions are neither even nor odd
  • Any integer is even if its units digit is even, and odd if its units digit is odd
  • Multiplying and adding odd and even integers
  • even x even = even
  • odd x odd = odd
  • even x odd = even
  • even + even = even
  • odd + odd = even
  • even + odd = odd

Absolute Value:

  • Absolute value is how far away a number is from zero
  • Absolute value is always a positive integer whether or not the number in question is positive or not

Prime Numbers:

  • A number is prime when it is only divisible by itself and the number 1
  • Here's all the prime numbers less than 30: 2,3,5,7,11,13,17,19,23,29
  • Zero is not a prime number
  • 1 is not a prime number
  • 2 is the only even prime number
  • Prime numbers are always positive integers. There's no such thing as a negative prime number

Rules of Divisibility:

  • An integer is divisible by 2 if its units digit is divisible by 2. For example, 598,447,896 is divisible by 2 because the units digit (6) is divisible by 2.
  • An integer is divisible by 3 if the sum of its digits is divisible by 3. For example, 2,145 is divisible by 3 because (2+1+4+5 = 12) is divisible by 3.
  • An integer is divisible by 4 if its last 2 digits form a number that's divisible by 4. For example, 712 is divisible by 4 because 12 is divisible by 4.
  • An integer is divisible by 5 if its units digit is either 0 or 5
  • An integer is divisible by 6 if it's divisible by both 2 and 3
  • An integer is divisible by 9 if the sum of its digits is divisible by 9
  • An integer is divisible by 10 if its units digit is 0

Remainders:

  • When one integer cannot be divided evenly by another, the remainder is what is left over after the division
  • When one integer divides evenly by another the remainder is zero (no remainder)

Factors:

  • A number is a factor of another number if the second number can be divided by the first with no remainder
  • Factors of 12: 1,2,3,4,6,12
  • Best to write factors in pairs to make sure you get them all:
  • 1 and 12
  • 2 and 6
  • 3 and 4

Multiples:

  • A multiple of a number is that number multiplied by an integer
  • Multiples of 10: -20 (10 x -2), -10 (10 x -1), 10 (10 x 1), 20 (10 x 2), etc...

There's obviously far more to the GRE than these simple concepts but some are quite handy and will make short work of doing calculations for the GRE. Yea, you can't use a calculator at all. Fire up those neurons!

1Feb/100

Configuring wireless networking on a Thinkpad T40 on FreeBSD 8

I've been happily using FreeBSD 7.2 on my IBM Thinkpad T40 and decided it was time to upgrade to the latest and greatest: FreeBSD 8. FreeBSD 8.0 brings many changes to the base system, but one of the more significant ones is the configuration of wireless (802.11) networking. After a bit of mucking around, I've figured out some interesting things that relate to wireless, especially on the Thinkpad T40.

The biggest change is that you no longer configure the physical device interface. That is, no more "ifconfig_" where interface is either ath or ipw or some variation. Instead, you create a pseudo-interface, map it to the physical interface, and from there, configure your IP settings on the pseudo interface.

Another important point is the the existing ipw2100 driver that the Thinkpad relies on is horribly broken in FreeBSD 8. This means we'll have to configure the interface using NDIS instead. Don't worry though, it's not that difficult.

To begin, go to the Lenovo website and download the wireless drivers. There are several there, so be sure to grab the one for the Intel 2100 802.11b wireless interface. The filename should be 1rwc89ww.exe. Unfortunately, you'll need a nearby Windows machine to decompress the executable. Alternatively, you could probably download the same driver from Intel's website directly, but it's likely to be a self-extracting executable as well. Regardless of which method you use to obtain the driver, the two files we're interested in are named W70N501.INF and W70N51.SYS. The first file describes how to install the driver on a Windows computer and the second file is the actual driver itself.

Next, we need to convert the Windows driver to a kernel module that FreeBSD understands. To do this, go to the directory containing the two files mentioned above and type "% ndisgen W70N501.INF W70N51.SYS". From here, the ndisgen utility will prompt you for a few questions. Just continue to keep hitting enter. Note that you'll want to have a source tree on your system that is in sync with your kernel so ndisgen is able to build a kernel module. Consult the FreeBSD handbook in order to learn how to synchronize a source tree to your system. When finished, you should see a new file named W70N51_SYS.ko in your directory. Copy this file to the /boot/modules directory. You might even convert it to lower case to make things easier.

Now that we have a suitable driver in place, we need to load up the ndis API. To do this, type "sudo kldload if_ndis" and "sudo kldload ndis". To load our fancy new driver, type "sudo kldload W70N51_SYS" (or the lower case equivalent if you changed case). We're now ready to configure IP addressing.

I'll take the simplest use case and assume you're using WPA authentication and getting an IP address via DHCP. Add the following lines to /etc/rc.conf

#Wireless
wlans_ndis0="wlan0"
ifconfig_wlan0="WPA DHCP"

The first line incorporates the new wireless interface in FreeBSD 8. It creates a "wlan0" pseudo-interface and maps it to the physical ndis interface. The second line simply tells the ifconfig command to use WPA authentication and to grab a dynamic IP. Next, add the following to your /boot/loader.conf to make these changes permanent:

#Wireless
if_ndis_load="YES"
W70N51_SYS_load="YES"

At this point, you can either reboot the laptop or restart networking using "/etc/rc.d/netif restart". If you choose to restart networking, you might have to manually create the pseudo-interface using the following command: "ifconfig wlan0 create wlandev ndis0". If you are upgrading your laptop, you may wish to remove all the ipw* entries from both configuration files as they are no longer needed.

Using this configuration, one odd bug I've run into is that my wireless interface comes up and associates with the WAP but I do not get an IP address. I suspect that this could possibly be due to the fact that the DHCP server is on a different box, but I'll have to run a few debugs to see where it's sticking.

Using ndis, while a little clunky initially, has proven to be a much better replacement for the built in ipw driver. While I was on FreeBSD 7.2 and even Linux, my wireless interface would frequently reload the driver firmware. I'm told that's due to a bursting configuration on the WAP but I don't have bursting enabled and no other wireless device on my network displays the same behavior. Along with the cool changes in FreeBSD 8, this makes BSD on my laptop that much more enjoyable!