Why filesystem are hard
An interesting article on lwn.net : Why filesystem are hard.
Removing missing physical volumes from a Linux Volume Group
I saw these messages during boot up on one of the linux servers that I was working on:
Scanning for LVM volume groups...
Reading all physical volumes. This may take a while...
Couldn't find device with uuid 'flRhH7-5l8N
-LWGG-2mUB-DeDZ-w4y0-Q0a6ib'.
Couldn't find all physical volumes for volume group
VolGroup00.
Couldn't find device with uuid 'flRhH7-5l8N
-LWGG-2mUB-DeDZ-w4y0-Q0a6ib'.
Couldn't find all physical volumes for volume group
VolGroup00.
Volume group "VolGroup00" not found
Puzzled I checked out the "VolGroup00" volume group:
#vgdisplay
Couldn't find device with uuid 'flRhH7-5l8N
-LWGG-2mUB-DeDZ-w4y0-Q0a6ib'.
Couldn't find all physical volumes for volume group
VolGroup00.
Couldn't find device with uuid 'flRhH7-5l8N
-LWGG-2mUB-DeDZ-w4y0-Q0a6ib'.
Couldn't find all physical volumes for volume group
VolGroup00.
Volume group "VolGroup00" not found
Was the volume group corrupted? Then I figured it out. It wasn't. This volume group had a number of phyiscal volumes removed that was removed a few days ago but its metadata were still pointing to the removed PVs. This fixed the problem:
# vgreduce --removemissing VolGroup00
Using Huawei E180 modem in linux (RHEL5)
The idea
First you need to get udev to create a device node for the modem at /dev/ttyUSB0. At this point which turns the modem is just like an analog modem. Then you will then use a modem dialer program (such as wvdial) to use the modem dial to the Singtel network. If it works correctly, you'll see a ppp0 link when you do a ifconfig at the console:
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.111.22.151 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:658 (658.0 b) TX bytes:688 (688.0 b)
Setting up USB_Modeswitch
The Huawei E180 is one of those new style devices that comes with Windows device driver stored in them. When first plugged in, it will appear as a pseudo CD-ROM and then Windows will use it install the device drivers for it. This is convinent forWindows users but prevents it from being recongized as a modem when you use in a Linux system. So the first thong to do is to install the USB_ModeSwitch utility (http://www.draisberghof.de/usb_modeswitch/)
Get the code, compile and put the binary in your /sbin directory and the usb_modeswitch.conf at /etc/. Then you need to configure it. The utility reads the configuration from /etc/usb_modeswitch.conf. Take a look at the file and uncomment the section for your modem. There is a section for Huawei modems in there.
The important thing is to get the Vendor and Product id right, to check do a lsusb like this:
# lsusb
Bus 007 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 001 Device 009: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 006 Device 001: ID 0000:0000
Here the Vendor id for the Huawei E180 modem is 12d1 and the product ID is 1003.
########################################################
# Huawei E220 (aka "Vodafone EasyBox II", aka "T-Mobile wnw Box Micro")
# Huawei E270
# Huawei E870
#
# Two options: 1. removal of "usb-storage" 2. the special control
# message found by Miroslav Bobovsky
#
# Contributor: Hans Kurent, Denis Sutter
DefaultVendor= 0x12d1;
DefaultProduct= 0x1003
# choose one of these:
;DetachStorageOnly=1
HuaweiMode=1
For the Huawei modem, I uncommented the "HuaweiMode=1" line which should detach the CD-ROM mode and turn the modem into a modem. For other modems you may have to experiement a bit. The utility takes in command line arguments which should make it easier to test changes.
Creating the /dev/ttyUSB0 node
First create a script for udev as /sbin/usb_modeswitch.sh:
#!/bin/shThe exec is a hack for RHEL 5 and UDEV 0.95 which I am using (see http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=11). Then you need to tell the udev process to execute the script when it sense the modem is plugged and after this to load the usb_serial module:
# close these FDs to detach from udev
exec 1<&- 2<&- 5<&- 7<&-
sh -c "sleep 4; /usr/bin/usb_modeswitch" &
exit 0
# cat /etc/udev/rules.d/66-huawei.rules
SUBSYSTEM=="usb", SYSFS{idVendor}=="12d1", SYSFS{idProduct}=="1003", RUN+="/sbin/usb_modeswitch.sh"
SUBSYSTEM=="usb", SYSFS{idVendor}=="12d1", SYSFS{idProduct}=="1003", RUN+="/sbin/modprobe usbserial vendor=0x12d1 product=0x1003"
The important thing is to get the vendor and product id, the script and modprobe command correct.
Now if everything is ok, when you plug in the modem you should be a /dev/ttyUSB0 node created.
Dialing the ISP
You can use any modem dialler to do this. I like simpicity and so I prefer wvdial. To do I add the following entry to /etc/wvdial.conf
# http://ubuntuforums.org/showthread.php?t=426354&page=4
[Dialer singtel-wireless]
Phone = *99#
Username = 123
Password = 123
Stupid Mode = 1
Dial Command = ATDT
Modem = /dev/ttyUSB0
Baud = 115200
Init2 = ATZ
Init3 = ATQ0V1E1S0=0&C1&D2+FCLASS=0
INIT5 = AT+CGDCONT=1,"IP","internet"
ISDN = 0
Modem Type = Analog Modem
Then I execute "wvdial singtel-wireless" to starting dialling. If everything works, then a ppp0 link in created and you can start surfing.
3D Mandelbrot sets
Ever since Mandelbrot sets (http://en.wikipedia.org/wiki/Mandelbrot_set) were discovered, people have been fascinated by the fractal imageries that they give birth to. Well, now with the advent of newer and more powerful computers, someone has finally rendered 3D Mandelbrot sets:

You can see more here.
Monitor process with kill
Saw this interesting tech tip (from Rich Lundeen) in the September edition of Linux Journal:
You can test if a process ID is valid with kill -0:
# kill -0 517 ----- where PID 517 is the udevd process on my PC now
# echo $?
0
Signal 0 is special so kill -0 does not terminate the process. The return status can be used to determine
whether a process is running. If the process is still running, the status is 0.
This method is much easier than parsing the ps command.
Also many processes save their PID at /var/run in a file. So you can use those to test them:
# kill -0 $(cat /var/run/cupsd.pid)
On grub-install
Had a look at grub-install today. It's the script that installs GRUB (GRand Unified Bootloader) which
is used by just about every open source OS during boot up. Here's what I found:
- It's a 650+ line shell script
- Well written. Some useful gems in there.
- Essentially a wrapper around the GRUB shell program (/sbin/grub). Adds error checking and
gives a more user-friendly way to install GRUB.
- The main function is install_boot_block() which installs GRUB:
install_boot_block () {
# Before all invocations of the grub shell, call sync to make sure
# the raw device is in sync with any bufferring in filesystems.
sync
# Now perform the installation.
$grub_shell --batch $no_floppy --device-map=$device_map <>$log_file
root $1
setup $force_lba --stage2=$grubdir/stage2 --prefix=$grub_prefix $2
quit
EOF
}
- On my Fedora box, the images are actually stored at /usr/share/grub and grub-install will copy the images from
there to the /boot/grub directory
- These images are very likely the binary files that contain executable code for the bootloading functionalities.
I am quite certain the 512byte /boot/grub/stage1 is the part of the bootloader that lives in the Master Boot Record (MBR)
The main purpose of this stage1 bootloader is to load the the stage 2 bootloader (/boot/grub/stage2) which is the
GRUB bootloader proper.
The architecture of mailnator and talkinator
Came across this interesting blog post of about a high performance chat server implemented with Java:
http://mailinator.blogspot.com/2008/08/benchmarking-talkinator.html
Also interesting is this post:
http://mailinator.blogspot.com/2007/01/architecture-of-mailinator.html
How many POSIX ACLs can you set on a file in Linux?
"How many POSIX ACL can you set on a file in Linux?" a manager once asked me that at work. Someone wanted to implement Linux ACLs for their IT systems and he needed to know the limits of ACL. I had to admit I didn't know and apparently no one knew either. At time the time I could not give a good answer because I had no time and had no access to a test system. But the question intrigued me and so I am attempting to find a better answer here.
Actually there's no fixed answer. That's because the limit on the number of ACL entries is determined by the blocksize of your filesystem and the types of ACLs being stored. On the ext2/3 filesystem, ACLs are implemented using extended attributes. The kernel code for extended attributes is here. The leading comments gives hints on how ACLs are stored. But even knowing how ACLs are stored, it is still not possible to give an exact answer. It's probably possible to come up with a formula but a more practical way would be to estimate with a simple script like this one:
#!/usr/bin/python
import os
i=1
status=0
while status == 0:
username = "u" + str(i)
print username
os.system("useradd " + username);
status = os.system("setfacl -m user:"+ username + ":rw- testacl.txt");
i+=1
This script attempts to set as many user acl on the file called testacl.txt as possible. On my Fedora Core system
using a Ext3 filesystem with 4KB block size, I could set up to 496 individual ACLs. The same for group ACLs.
This is way more than would ever be needed. A rule of thumb is around 20 max. Beyond that things will get complicated.