phaqphaq

“a geeks daily life”

Archive for July, 2006

Setting e1000 Interface Settings Permanently On Debian

Monday, July 31st, 2006

Well, sometimes obvious things aren’t quiet as obvious as supposed.

After plugging in a dual Intel Pro 1000 into my Debian box and hooking it up to my ancient Cisco 1924 switch, I noticed this in the kernel logs:

Jul 31 09:10:35 localhost kernel: e1000: eth0: e1000_watchdog: NIC Link is Up 100 Mbps Half Duplex

I though it should be fairly easy set the interface speeds properly so the devices would actually talk to each other.

While doing so on the Cisco was actually easy, the Linux box would refrain from doing so at a first glance.

#ethtool -s eth0 speed 100 duplex full

Running the command given above resulted in an error preventing me to set the parameters. It took me a while to find out that I had to actually turn off auto negotiation to make it work, too.

#ethtool -s eth0 speed 100 duplex full autoneg off

Now I had to make this change permanent as it would reset to defaults after the next reboot. I did so by adding the post-up line to my /etc/network/interfaces file:

auto eth0
iface eth0 inet static
post-up /usr/sbin/ethtool -s eth0 speed 100 duplex full autoneg off
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1

It should be noted, that the module documention at Intel’s website does not actually state that auto-negotiation must be turned off when setting interface speed and duplex modes. The question remains if this was only the case on my particular setup or if it is an absolute requirement after all.

FreeBSD patch: enable fsck in mdmfs

Wednesday, July 26th, 2006

This patch is actually a follow-up development to my article on implementing filesystem allocation limits on FreeBSD jails.

My previous article basically lined out how to place jails inside a vnode-backed memory device to enforce filesystem allocation limits. This became possible through a new flag introduced to mdmfs in FreeBSD-CURRENT which allowed to skip ‘newfs’ (which requires mdmfs actually to be called mount_md to work properly).

This solution is quiet handy as it will automagically mount the container volumes as required. But since we do not live in a perfect world – and computers ain’t perfect either – crashes do happen. File system corruption on volumes will prevent jails to startup as their (virtual) root device will fail to mount.
This is where this patch comes in. It will enable mdmfs to optionally run an fsck on given volumes.

To apply the patch, create a new temporary build directory first:

#mkdir /root/mount_md
#cd /root/mount_md

Then get the original source code from CVS. Maybe it’s easiest to get this particular release through WebCSV at http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/sbin/mdmfs/mdmfs.c?rev=1.27.

Save this file to your previously created build directory.

If you have wget at hands you can also download it directly.

#wget -user-agent=’Mozilla/5.0′ ‘http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/sbin/mdmfs/mdmfs.c?rev=1.27′ -output-document=/root/mount_md/mount_md.c

Download and apply the patch: mount_md.c.diff

#wget -user-agent=’Mozilla/5.0′ ‘http://www.phunsites.net/wp/wp-content/uploads/2006/07/mount_md.c.diff.txt’ -output-document=/root/mount_md/mount_md.c.diff

#patch < /root/mount_md/mount_md.c.diff

Compile the source:

#gcc /root/mount_md/mount_md.c -o /root/mount_md/mount_md

Then copy the file to some location you like, eg. /usr/sbin.

#cp /root/mount_md/mount_md /usr/sbin/mount_md
Make sure you call the file as given in the example. It won’t work otherwise.

Special care must be taken that you DO NOT replace your existing mdmfs binary file by this new version. DO NOT overwrite it. Do not rename this patch to mdmfs. Use the names provided in this example instead.

Setup Jail’s fstab

Now check out your jail’s fstab and look for this line:

md /var/jails/192.168.0.1 md rw,-P,-F/mnt/r5_vol1/jails/192.168.0.1/rootfs.volume

Change it as follows:

md /var/jails/192.168.0.1 md rw,-P,-F/mnt/r5_vol1/jails/192.168.0.1/rootfs.volume,-Tufs

or

md /var/jails/192.168.0.1 md rw,-P,-F/mnt/r5_vol1/jails/192.168.0.1/rootfs.volume,-tufs

The difference in the two lies in the ‘-T’ or ‘-t’ argument. Both enable fsck before mounting the volume, hence ‘-T’ runs ‘fsck -y’ while ‘-t’ does not.

You need also to provide the filesystem type with either option for fsck to work properly.

Removing CRLF Using Vi

Tuesday, July 25th, 2006

Sometimes DOS files end up on unix systems without being converted. Files will then have those nasty ^M character at the line ending, which prevents some applications to work properly.

The reason for is is DOS to use CRLF (carriage return + line feed) for line endings while unix uses LF (line feed) only.

If only few files need to be changed, vi/vim is the tool of choice.

After opening up the file, enter command mode to run this macro:

:%s/^M$//g

To get the ^M do not actually enter it as is. Insert it by typing the CTRL-V CTRL-M sequence instead.