Avoiding Device Confusion in FreeBSD with ZFS
In tutorial after tutorial, I find people creating zpools using a method that looks like:
% zpool create tank /dev/da2 /dev/da3 /dev/da4 /dev/da5
But, what happens when you reboot without /dev/da2 plugged in? /dev/da3 becomes /dev/da2 and your pool is confused and weird and all that junk.
A simple tip is to create a GPT on each disk you plan to add to a pool and rather than using the device node of /dev/da#p#, use the GPT partition ID device node that’s automatically created under /dev/gptid.
First, wipe the partition table on each of your disks, using:
% dd if=/dev/zero of=/dev/da2 bs=512 count=1
% dd if=/dev/zero of=/dev/da3 bs=512 count=1
% dd if=/dev/zero of=/dev/da4 bs=512 count=1
% dd if=/dev/zero of=/dev/da5 bs=512 count=1
Now create a new GPT on each disk, using:
% gpart create -s gpt da2
% gpart create -s gpt da3
% gpart create -s gpt da4
% gpart create -s gpt da5
Now create a FreeBSD ZFS partition on each disk. This is easy because we’re only making one partition per disk.
% gpart add -t freebsd-zfs da2
% gpart add -t freebsd-zfs da3
% gpart add -t freebsd-zfs da4
% gpart add -t freebsd-zfs da5
You should now see the gptids listed in /dev/gptid/
# ls -l /dev/gptid
total 0
crw-r----- 1 root operator 0, 126 Jan 23 15:44 1bcdc07f-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 135 Jan 23 15:44 1cf8bda4-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 143 Jan 23 15:44 1da00324-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 151 Jan 23 15:45 1e83229b-4603-11e1-bd02-003048bb1b96
Now simply create your zpool however you like, using the gptid device node instead of the device ID.
# zpool create external \
/dev/gptid/1bcdc07f-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1cf8bda4-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1da00324-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1e83229b-4603-11e1-bd02-003048bb1b96
And check on it…
# zpool status external
pool: external
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
external ONLINE 0 0 0
gptid/1bcdc07f-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1cf8bda4-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1da00324-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1e83229b-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
errors: No known data errors
You can use the gpart utility to see all kinds of data about your partitions as well. This is useful to figure out which gptid belongs to which disk.
ZFS Deduplication on Existing Pool
Similarly to enabling compression on a ZFS partition that already has data, enabling deduplication does not deduplicate the data that already exists. This was a problem for me. To add to the problem, this pool had many partitions and the partitions each had many snapshots, all of which I wanted to preserve.
The only solution seems to be moving all the data away and back. I bought 4 external hard drives, made a storagebomb and away I went. This page has a good description of how to move an entire pool to a different device, preserving all the snapshots and whatnot.
Duplicity & S3
It works really well and it’s cheap. Try it. Also read: http://andyleonard.com/2009…-of-others/
I’ll post my script here later.
Headless FreeBSD Install
Ever wanted to install without a keyboard and mouse on the system? Do it over serial console! Here’s how to make a CD that can do it.
Extract the ISO
Get your install ISO from somewhere and extract it to some directory.
mkdir ./iso tar -C ./iso -pxf 8.0-RELEASE-i386-disc1.iso cd ./iso
loader.conf
Next thing to do is to tell the boot loader to start using the serial port. This can be done by putting:
console="comconsole"
somewhere inside boot/loader.conf (obviously inside the iso directory)
Make the ISO!
Now wrap it all up into an iso using:
mkisofs -J -r -b boot/cdboot -no-emul-boot -o 8.0-RELEASE-i386-disc1-serial.iso ./iso
or something of the sort.
You’re done!
Go burn the ISO file and boot a system off the CD. Set your terminal’s baud rate to 9600 and you’ll eventually see things booting up!
Using portdowngrade
Recently, I needed to roll a port back to a much older revision. While I usually dislike this type of thing, I found it to be necessary this time. Somebody recommended that I use portdowngrade to revert the ports tree to the older version, so I could install it.
Here’s my process:
Verify Anonymous CVS Connectivity
First, you must verify that you can connect to the anoncvs server. You can find instructions in the FreeBSD Handbook for this process.
One thing you should probably be aware of is that there are a very limited number of anoncvs mirrors, which is why I chose the .tw one.
Prepare Your Ports Tree
You need to be sure that you have an updated portsdb installed so portdowngrade is able to find the matching ports with a search.
portsdb -u
Installing & Using portdowngrade
cd /usr/ports/*/portdowngrade make DEFAULT_CVS_SERVER=\":pserver:anoncvs@anoncvs.tw.freebsd.org:/home/ncvs\" install clean
Note that you may replace the server name with whichever mirror you chose in the earlier step.
Once installed, you may now downgrade the port using:
portdowngrade devel/bugzilla
for instance. From here the documentation will be more than enough to show you how to get the downgraded port checked out and installed.
The Missing Step: Making portupgrade Ignore the Port!
This is easy as pie, but there are two ways to do it. I chose to do both.
Option 1: Edit the pkgtools.conf file
Usually located in /usr/local/etc/, pkgtools.conf will allow you to specify an additional port in the HOLD_PKGS array like such:
HOLD_PKGS = [
'bsdpan-*',
'devel/bugzilla*'
]
Option 2: +IGNOREME
Creating a +IGNOREME file in the package directory will stop both portaudit and portmaster from upgrading the port.
touch /var/db/pkg/bugzilla/+IGNOREME