Configuring VLAN interfaces on CentOS Linux hosts

I recently needed to configure a CentOS Linux host to use 802.1Q tagged queuing. This turned out to be super easy, and allowed me place the physical server on multiple layer-2 networks. To configure an 802.1Q interface, I first checked the ifcfg-eth0 script for the interface that was planning to participate in 802.1Q:

$ cd /etc/sysconfig/network-scripts

$ cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:1B:24:5C:2C:DD
ONBOOT=yes
TYPE=Ethernet

Once I had the interface information, I created a ifcfg-vlan301 interface file with the VLAN number as well as the VLAN options:

$ cat ifcfg-vlan301
VLAN=yes
VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
DEVICE=vlan301
PHYSDEV=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet

After the files were created, I used service to restart networking and everything came up smoothly. There are much better references on the Internet for Linux 802.1Q configuration, but I’m posting this here so I have a handy reference (and one I know works!).

Monitoring file activity on Linux hosts

While reviewing one of my Linux hosts, I noticed that a bunch of write activity was occurring to one specific file system. I was curious to see what this write activity was, so I started reading up on the Linux inotify framework. Inotify allows you to monitor file system events, and the super useful iwatch utility provides a command line interface to the inotify framework. When iwatch is executed and passed the name of a directory on the command line, it will print all of the events that are applicable to that directory:

$ iwatch -v /tmp

[21/Feb/2009 11:21:18] IN_CREATE /tmp/services
[21/Feb/2009 11:21:18] IN_CLOSE_WRITE /tmp/services
[21/Feb/2009 11:21:18] * /tmp/services is closed
[21/Feb/2009 11:21:25] IN_DELETE /tmp/services
[21/Feb/2009 11:21:25] * /tmp/services is deleted
[21/Feb/2009 11:21:35] IN_CREATE /tmp/foo
[21/Feb/2009 11:21:35] IN_CLOSE_WRITE /tmp/foo
[21/Feb/2009 11:21:35] * /tmp/foo is closed
[21/Feb/2009 11:21:46] IN_DELETE /tmp/foo
[21/Feb/2009 11:21:46] * /tmp/foo is deleted



This command line will cause a line to be printed to STDOUT each time an event is triggered due to operations taking place in /tmp. If you would prefer to get an e-mail when events occur, you can add the “-m” option to the command line:

$ iwatch -v -m matty@prefetch.net /tmp

This utility rocks, and I hope Solaris will provide a similar utility to take advantage of their notification framework.

How to undelete any open, deleted file on linux / solaris

Chris Dew wrote up a neat trick on how to recover files if deleted on Linux, yet still open by a process.

This works on Solaris as well.  =)

$:~:uname -a
SunOS somehost.com 5.10 Generic_127112-11 i86pc i386 i86pc

$:~:echo “sup prefetch.net folks?” > testfile
$:~:tail -f testfile &
[1] 17134

$:~:rm testfile
$:~:ls /proc/17134/fd/
0  1  2
$:~:cat /proc/17134/fd/0
sup prefetch.net folks?
$:~:cp !$ ./testfile
cp /proc/17134/fd/0 ./testfile
$:~:cat testfile
sup prefetch.net folks?

ZFS in the trenches

Ben Rockwood is awesome.  If you haven’t had a chance to check out his blog, its a must read for any Solaris Admin.

He gave a presentation at the Open Storage Summit about ZFS.  (Video Here) Its worth the read / view   for some indepth ZFS concepts.

Joerg assisted in turning some of this into plain English so the rest of us can understand.

Kudos to Ben for giving props to Matty in the pdf!

Monitoring interrupt activity on Linux hosts

While transferring a slew of data to one of my Linux boxes a few weeks back, I was curious how many interrupts were being generated each second. To answer my question, I installed the itop utility. Itop displays the number of interrupts per second that occur per device, and provides output similar to top. Here is a sample run:

$ itop -a

INT                NAME          RATE             MAX
  0 [             timer]     0 Ints/s     (max:     0)
  1 [             i8042]     0 Ints/s     (max:     0)
  6 [            floppy]     0 Ints/s     (max:     0)
  7 [          parport0]     0 Ints/s     (max:     0)
  8 [              rtc0]     0 Ints/s     (max:     0)
  9 [              acpi]     0 Ints/s     (max:     0)
 12 [             i8042]     0 Ints/s     (max:     0)
 15 [              ide0]     0 Ints/s     (max:     0)
 16 [     ehci_hcd:usb2]     0 Ints/s     (max:     0)
 17 [              ioc0]     0 Ints/s     (max:    24)
 18 [              eth0]  1400 Ints/s     (max:  1959)
 19 [   uhci_hcd:usb1, ]     0 Ints/s     (max:     0)



This is a useful tool, and one I want to remember for the future!