blog'o thnet

To content | To menu | To search

BSD Unix

Entries feed

Wednesday 16 May 2007

Not the NanoBlogger Port Maintainer Anymore

Well, since I didn't use nanoblogger anymore, I decided to resign as its FreeBSD port maintainer.

And because a bad news doesn't come alone, it seems that nanoblogger will not get much interest in the future. I really enjoy used it for two years now, but because of recent changes with the thnet project, I can't provide help with it anymore.

Sunday 28 January 2007

About Kernel Debugging on FreeBSD

After posting about some very interesting entries on how to debug kernel problems in Solaris 10, here are some keywords which may be needed while looking for help on FreeBSD mailing lists. This is just a quick memo, so please read the excellent Kernel Debugging chapter of the FreeBSD Developers's Handbook.

At the debugger prompt, using DDB at the system console:

db> where
db> show pcpu
db> show alllocks
db> ps
db> show lockedvnods
db> show lockedbufs

Good luck!

Tuesday 24 October 2006

devfs.conf, or... devfs.rules

If you are using a USB thumbdrive, it may be interesting to be able to mount it as a normal user, i.e. without the need for a privileged account. The question is how to set these rights for devices not available at boot time?... Just use devfs.rules(5), it serves the same purpose than /etc/devfs.conf, but is specifically well suited for removable devices.

Here is an example of setting the mode and group (in which must resides the desired user(s)) for a USB removable key, seen as an SCSI device of the direct access class:

$ cat /etc/devfs.rules
[devfsrules_allow_usb=10]
add path 'da*' mode 0660 group usb

# Devices usually not available at boot time.
[devfsrules_allow=100]
add include $devfsrules_allow_usb

Many thanks to Roland Smith for its particular interesting notes on that subject and for contributing the devfs.conf(5) and devfs.rules(5) manual pages to the FreeBSD project.

Sunday 9 July 2006

Configuring an APC Back-UPS RS 800VA

I recently installed and configured an APC Back-UPS RS 800VA, which is an UPS aimed to be a high performance battery backup and protection for business computers. As i run some machines at home (servers and workstations), this kind of protection became more than necessary.

The main point is to properly install and configure apcupsd. Using the FreeBSD's ports collection and a recent FreeBSD RELENG_6 system, all will works out of box.

So, after plug in the USB cable for the very first time, you can see this in your /var/log/messages file:

ugen0: American Power Conversion Back-UPS BR  800 FW:9.o2 .I USB FW:o2, rev 1.10/1.06, addr 2

Good. Just configure apcupsd to learn it about UPSCABLE and UPSTYPE value:

# diff -u /usr/local/etc/apcupsd/apcupsd.conf.sample /usr/local/etc/apcupsd/apcupsd.conf
--- /usr/local/etc/apcupsd/apcupsd.conf.sample  Thu Jun 29 20:42:09 2006
+++ /usr/local/etc/apcupsd/apcupsd.conf Tue Jul  4 21:58:32 2006
@@ -26,7 +26,8 @@
 #     940-1524C, 940-0024G, 940-0095A, 940-0095B,
 #     940-0095C, M-04-02-2000
 #
-UPSCABLE smart
+#UPSCABLE smart
+UPSCABLE usb

 # To get apcupsd to work, in addition to defining the cable
 # above, you must also define a UPSTYPE, which corresponds to
@@ -63,8 +64,9 @@
 # dumb      /dev/tty**       Old serial character device for use
 #                            with simple-signaling UPSes.
 #
-UPSTYPE apcsmart
-DEVICE /dev/usv
+#UPSTYPE apcsmart
+UPSTYPE usb
+#DEVICE /dev/usv


 # LOCKFILE <path to lockfile>

Then, launch the daemon and get status information on the current UPS system state:

# grep apcupsd /etc/rc.conf
apcupsd_enable="YES"
# /usr/local/etc/rc.d/apcupsd start
# apcaccess status
APC      : 001,040,1003
DATE     : Fri Jul 07 20:48:14 CEST 2006
HOSTNAME : bento.thilelli.net
RELEASE  : 3.12.3
VERSION  : 3.12.3 (26 April 2006) freebsd
UPSNAME  : bento.thilelli.net
CABLE    : USB Cable
MODEL    : Back-UPS BR  800
UPSMODE  : Stand Alone
STARTTIME: Wed Jul 05 07:19:04 CEST 2006
STATUS   : ONLINE
LINEV    : 228.0 Volts
LOADPCT  :  39.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  20.6 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
OUTPUTV  : 230.0 Volts
DWAKE    : 000 Seconds
DSHUTD   : 000 Seconds
LOTRANS  : 194.0 Volts
HITRANS  : 264.0 Volts
RETPCT   : 000.0 Percent
ITEMP    : 29.2 C Internal
ALARMDEL : Always
BATTV    : 27.4 Volts
LINEFREQ : 50.0 Hz
LASTXFER : Low line voltage
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x07000008 Status Flag
SERIALNO : JB0604031535
BATTDATE : 2001-09-25
NOMBATTV :  24.0
FIRMWARE : .o2 .I USB FW:o2
APCMODEL : Back-UPS BR  800
END APC  : Fri Jul 07 20:48:15 CEST 2006

It is always a good thing to test the behavior of your UPS equipment and the correct interaction with your server, so follow carefully the well documentation provided on that subject by the apcupsd team, particularly the Simulated Power Fail Test, System Shutdown Test and Full Power Down Test suggestions.

Here are some logs obtained after encountering some real power problems:

# cat /var/log/apcupsd.events
[...]   /* During a complete managed reboot after loosing power supply. */
Tue Jul 04 21:37:44 CEST 2006  Power failure.
Tue Jul 04 21:37:50 CEST 2006  Running on UPS batteries.
Tue Jul 04 21:38:21 CEST 2006  Reached run time limit on batteries.
Tue Jul 04 21:38:21 CEST 2006  Initiating system shutdown!
Tue Jul 04 21:38:21 CEST 2006  User logins prohibited
Tue Jul 04 21:38:21 CEST 2006  Attempting to kill the UPS power!
Tue Jul 04 21:38:31 CEST 2006  apcupsd exiting, signal 15
Tue Jul 04 21:38:31 CEST 2006  apcupsd shutdown succeeded
[...]   /* The next day... what a bad night for power supply, but a very
           good luck for all the servers! */
Tue Jul 04 23:57:58 CEST 2006  Power failure.
Tue Jul 04 23:58:01 CEST 2006  Power is back. UPS running on mains.
Wed Jul 05 00:16:07 CEST 2006  Power failure.
Wed Jul 05 00:16:09 CEST 2006  Power is back. UPS running on mains.
Wed Jul 05 00:18:58 CEST 2006  Power failure.
Wed Jul 05 00:19:01 CEST 2006  Power is back. UPS running on mains.
Wed Jul 05 00:27:10 CEST 2006  Power failure.
Wed Jul 05 00:27:13 CEST 2006  Power is back. UPS running on mains.
Wed Jul 05 02:45:08 CEST 2006  Power failure.
Wed Jul 05 02:45:11 CEST 2006  Power is back. UPS running on mains.
Wed Jul 05 03:29:29 CEST 2006  Power failure.
Wed Jul 05 03:29:32 CEST 2006  Power is back. UPS running on mains.

It may be worth mentioning that when the daemon encounter an event, an email is sent to the root account. The subject says what it appended (such as Power has returned or Power Failure !!!) and the body is simply the ouput of the apcaccess program.

As a side note, the apctest sef-test program seems to fail with my APC. Curiously, reading the result separately says... the opposite. Which one to trust here, anyone?

# /usr/local/etc/rc.d/apcupsd stop
# apctest
2006-07-09 13:43:31 apctest 3.12.3 (26 April 2006) freebsd
Checking configuration ...
Attached to driver: usb
sharenet.type = DISABLE
cable.type = USB_CABLE

You are using a USB cable type, so I'm entering USB test mode
mode.type = USB_UPS
Setting up the port ...
Hello, this is the apcupsd Cable Test program.
This part of apctest is for testing USB UPSes.

Getting UPS capabilities...SUCCESS

Please select the function you want to perform.

1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) Change battery date
5) View battery date
6) View manufacturing date
7) Set alarm behavior
8) Quit

Select function number: 2

This test instructs the UPS to perform a self-test
operation and reports the result when the test completes.

Clearing previous self test result...CLEARED
Initiating self test...INITIATED
Waiting for test to complete...TEST DID NOT COMPLETE

1) Test kill UPS power
2) Perform self-test
3) Read last self-test result
4) Change battery date
5) View battery date
6) View manufacturing date
7) Set alarm behavior
8) Quit

Select function number: 3

Result of last self test: PASSED
[...]
# /usr/local/etc/rc.d/apcupsd start

So, not too bad after all... at least, it seems.

For more information on that subject, go to the excellent Dan Langille's FreeBSD Diary which has a very well documented entry on his settings.

Thursday 6 July 2006

FreeBSD Port Patch Preview for the Last NanoBlogger's 3.3 RC5

Here is the preview patch for the www/nanoblogger port.

You can apply and install it using the following steps:

# cd /usr/ports/www/nanoblogger && make deinstall
# cd /usr/ports && patch < /tmp/nanoblogger.3.3-rc5.patch
# cd /usr/ports/www/nanoblogger && make install clean clean-depends

Be aware that there are a lot of changes in NanoBlogger itself, so read carefully the NanoBlogger User Manual online documentation and the pkg-message post installation output. After the installation, you can (re)read it using:

# pkg_info -D /var/db/pkg/nanoblogger

Download: nanoblogger.3.3-rc5.patch

Wednesday 7 June 2006

The getent(1) Utility on FreeBSD!

Yes, you got it by now: the getent(1) utility finally reached the current tree some weeks ago and has just been MFC'ed! What a good news to have this very nice tool.

I was happy to be mentioned in the commit log as one of the original demander, since getent(1) can already be found on other OSes such as Sun Solaris/OpenSolaris, NetBSD or GNU/Linux and is generally useful.

Tuesday 9 May 2006

First PR Against the NanoBlogger's Port

Here is the first Problem Report against the NanoBlogger FreeBSD's port. In fact, this was not really a bug nor a big issue, just a misread at the installation time it seems. Read the bug's follow-up for more information... really nothing more to say here.

Saturday 22 April 2006

Setting Up a Soft Mirroring System Using gmirror(8)

Because of the nature of services provided by the ThNET Project, i already want to keep the I/O very reliable and used some old hardware RAID technology to do the job. Since there is no full hardware support due to some provider legal binary restrictions, the solution wasn't perfect and i always take a lot of time rebuilding the RAID array because of some obscure problem when problems on disks occurred.

I didn't want to do the same thing with the new infrastructure server, and decided to build the RAID-1 solution on top of the gmirror(8) software, a GEOM framework based tool provided under recent FreeBSD releases.

So, based on the work of others (see the end of this entry for references), here are the steps i follow to switch from classical to mirror solution for the main server of the project.

First, make sure that the second disk is treated as a new, fresh one:

# dd if=/dev/zero of=/dev/ad10 bs=512 count=79

Put a GEOM label onto it and force load the gmirror.ko kernel module:

# gmirror label -v -n -b round-robin gm0 /dev/ad10
# gmirror load

Then write a PC (BIOS) MBR, place a new BSD label, initialize it and create custom partitions:

# fdisk -v -B -I /dev/mirror/gm0
# bsdlabel -w -B /dev/mirror/gm0s1
# bsdlabel -e /dev/mirror/gm0s1
# cat << EOF > /etc/bsdlabel.gm0s1
# /dev/mirror/gm0s1:
8 partitions:
#         size   offset   fstype   [fsize bsize bps/cpg]
# a: Will be mounted as `/'.
# d: Will be mounted as `/var'.
# e: Will be mounted as `/tmp'.
# f: Will be mounted as `/usr'.
# g: Will be mounted as `/home'.
a:      512M       16   4.2BSD     2048 16384       8
b:     2048M        *     swap
c: 586099332        0   unused        0     0         # "raw" part, don't edit
d:     2048M        *   4.2BSD     2048 16384   28528
e:     4096M        *   4.2BSD     2048 16384   28528
f:    12288M        *   4.2BSD     2048 16384   28528
g:         *        *   4.2BSD     2048 16384   28528
EOF
# bsdlabel -R /dev/mirror/gm0s1 /etc/bsdlabel.gm0s1

Make new file systems on the corresponding partitions (note: generally speaking, it seems better not to put soft-updates on the root partition):

# newfs /dev/mirror/gm0s1a
# newfs -U /dev/mirror/gm0s1d
# newfs -U /dev/mirror/gm0s1e
# newfs -U /dev/mirror/gm0s1f
# newfs -U /dev/mirror/gm0s1g

Populate the content the of the second disk using dump(8) and restore(8) for example, or use some backup if this may be applicable for you:

# mkdir /tmp/gm0s1 && mount /mnt/da0
# 
# mount /dev/mirror/gm0s1a /tmp/gm0s1
# gzip -dc /mnt/da0/dump/2006-04-10.*/bento.thilelli.net.root.dump.gz | \
(cd /tmp/gm0s1 && restore -rf -)
# 
# mount /dev/mirror/gm0s1d /tmp/gm0s1/var
# gzip -dc /mnt/da0/dump/2006-04-10.*/bento.thilelli.net.var.dump.gz | \
(cd /tmp/gm0s1/var && restore -rf -)
# 
# mount /dev/mirror/gm0s1f /tmp/gm0s1/usr
# gzip -dc /mnt/da0/dump/2006-04-10.*/bento.thilelli.net.usr.dump.gz | \
(cd /tmp/gm0s1/usr && restore -rf -)
# 
# mount /dev/mirror/gm0s1g /tmp/gm0s1/home
# gzip -dc /mnt/da0/dump/2006-04-10.*/bento.thilelli.net.home.dump.gz | \
(cd /tmp/gm0s1/home && restore -rf -)
# 
# mount /dev/mirror/gm0s1e /tmp/gm0s1/tmp
# chmod 1777 /tmp/gm0s1/tmp

Prepare the new file system table, force the load of the GEOM mirror at boot time (necessary for the root mount) and be sure to boot on the second disk at the next reboot:

# cp -p /tmp/gm0s1/etc/fstab /tmp/gm0s1/etc/fstab.orig
/*
 * sed -e 's/dev\/ad8/dev\/mirror\/gm0/g' < /tmp/gm0s1/etc/fstab.orig \
 *  > /tmp/gm0s1/etc/fstab
 */
# cat << EOF > /tmp/gm0s1/etc/fstab
# Device                Mountpoint      FStype  Options                         Dump    Pass#
/dev/mirror/gm0s1b      none            swap    sw                              0       0
/dev/mirror/gm0s1a      /               ufs     rw                              1       1
/dev/mirror/gm0s1e      /tmp            ufs     rw,noatime,nosuid,nodev         2       2
/dev/mirror/gm0s1f      /usr            ufs     rw                              2       2
/dev/mirror/gm0s1d      /var            ufs     rw,noexec                       2       2
/dev/mirror/gm0s1g      /home           ufs     rw,userquota,nosuid,nodev       2       2
/dev/acd0               /cdrom          cd9660  ro,noauto                       0       0
/dev/da0s1              /mnt/da0        ufs     rw,noauto,nosuid,nodev          0       0
/dev/da1s1              /mnt/da1        msdosfs rw,noauto                       0       0
EOF
# echo geom_mirror_load=\"YES\" >> /tmp/gm0s1/boot/loader.conf
# echo "1:ad(1,a)/boot/loader" > /boot.config

Unmount the second side of the mirror and reboot:

# umount /tmp/gm0s1/tmp
# umount /tmp/gm0s1/home
# umount /tmp/gm0s1/usr
# umount /tmp/gm0s1/var
# umount /tmp/gm0s1
# 
# sync && shutdown -r now

After rebooting on the second disk (the GEOMified one), switch the mirror to auto-synchronization and add the first disk, which is now immediately synchronized with the second disk's content:

# gmirror configure -a gm0
# gmirror insert gm0 /dev/ad8
# 
# gmirror list
Geom name: gm0
State: DEGRADED
Components: 2
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 1
ID: 770137303
Providers:
1. Name: mirror/gm0
Mediasize: 300090727936 (279G)
Sectorsize: 512
Mode: r7w6e7
Consumers:
1. Name: ad10
Mediasize: 300090728448 (279G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 1
ID: 2706535066
2. Name: ad8
Mediasize: 300090728448 (279G)
Sectorsize: 512
Mode: r1w1e1
State: SYNCHRONIZING
Priority: 0
Flags: DIRTY, SYNCHRONIZING
GenID: 0
SyncID: 1
Synchronized: 71%
ID: 2682952005
# 
# gmirror status
Name    Status  Components
mirror/gm0  DEGRADED  ad10
              ad8 (71%)

During all of these steps, some kernel messages may be seen on the console or in the /var/log/messages system logs file, as shown below:

# tail -f /var/log/messages
GEOM_MIRROR: Device gm0: provider ad8 detected.
GEOM_MIRROR: Device gm0: rebuilding provider ad8.
GEOM_MIRROR: Device gm0: rebuilding provider ad8 finished.
GEOM_MIRROR: Device gm0: provider ad8 activated.

Last, please find some invaluable documentation on the subject, with a special note for the BSD DevCenter one since, although less secure for the data than the others, bypassed the need for duplicating the data from one disk to the other, much less as found when using SVM on Solaris from Sun Microsystems.

Monday 27 March 2006

FreeBSD Documentation Update: serialcomms

Although it was a long time ago, i think it may be worth to be noted here, just in case someone is interested. I work hard (at least, i hope ;)) to update the Serial Communications chapter of the FreeBSD Handbook in the past months, in particular the Introduction section. The work was heavily done with Gary W. Swearingen which take the PR for himself, helped by his mentor Giorgos Keramidas (not less), and the participation of Yar Tikhiy.

This work was done under the FreeBSD problem report docs/85355.

For reference only, here are most links to the different steps which drive us to the current committed code, as found in the documentation project source tree:

  1. chapter.sgml.orig
  2. chapter.sgml.diff.0
  3. chapter.sgml.diff.1
  4. chapter.sgml.diff.2
  5. chapter.sgml.diff.3
  6. chapter.sgml.diff.4

So, here it is: Serial Communications chapter.

Friday 3 February 2006

FreeBSD Port Patch Preview for the Last NanoBlogger's 3.3 RC4

Because i will be far from a computer for more than a week (as of today!), i post the preview patch for the www/nanoblogger port.

You can apply and install it using the following steps:

# cd /usr/ports/www/nanoblogger && make deinstall
# cd /usr/ports && patch < /tmp/nanoblogger.patch
# cd /usr/ports/www/nanoblogger && make install clean clean-depends

Be aware that there are a lot of changes in NanoBlogger itself, so read carefully the NanoBlogger User Manual online documentation and the pkg-message post installation output. After the installation, you can (re)read it using:

# pkg_info -D /var/db/pkg/nanoblogger

Download: nanoblogger.patch

- page 1 of 2