Tuesday, November 2, 2010

Installing Linux kernel 2.6.32 guide

Problem:
Compiling and installing kernel 2.6.32 gives the following error on boot.
insmod: error inserting '/lib/dm-region-hash.ko': -1 File exists
mount: could not find filesystem '/dev/root'

Solution:



# mkdir ~/kernel
# cd ~/kernel
# wget "http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.9.tar.bz2"
# tar jxf linux-2.6.32.9.tar.bz2
# cd linux-2.6.32.9
# cp /boot/config-2.6.18-164.11.1.el5.img .config
# make menuconfig

I don't make any changes except CPU type and set Preemption Mode to (none) No Forced Preemption (Server)).
Save changes.

# make && make modules_install headers_install install

Now let's look inside new kernel image, it's interesting:

# cd ..
# mkdir newinitrd
# cp /boot/initrd-2.6.32.9.img .
# cd newinitrd
# zcat ../initrd-2.6.32.9.img | cpio -i
# ls
bin  dev  etc  init  lib  proc  sbin  sys  sysroot
# ls bin
dmraid  insmod  kpartx  lvm  modprobe  nash

If you see lvm then just reboot and dance. Else:

# cp /sbin/lvm.static bin/lvm

Now look at init script, it should look like this:

# cat init
#!/bin/nash

mount -t proc /proc /proc
setquiet
echo Mounting proc filesystem
echo Mounting sysfs filesystem
mount -t sysfs /sys /sys
echo Creating /dev
mount -o mode=0755 -t tmpfs /dev /dev
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
mkdir /dev/shm
mkdir /dev/mapper
echo Creating initial device nodes
mknod /dev/null c 1 3
mknod /dev/zero c 1 5
mknod /dev/urandom c 1 9
mknod /dev/systty c 4 0
mknod /dev/tty c 5 0
mknod /dev/console c 5 1
mknod /dev/ptmx c 5 2
mknod /dev/rtc c 10 135
mknod /dev/tty0 c 4 0
mknod /dev/tty1 c 4 1
mknod /dev/tty2 c 4 2
mknod /dev/tty3 c 4 3
mknod /dev/tty4 c 4 4
mknod /dev/tty5 c 4 5
mknod /dev/tty6 c 4 6
mknod /dev/tty7 c 4 7
mknod /dev/tty8 c 4 8
mknod /dev/tty9 c 4 9
mknod /dev/tty10 c 4 10
mknod /dev/tty11 c 4 11
mknod /dev/tty12 c 4 12
mknod /dev/ttyS0 c 4 64
mknod /dev/ttyS1 c 4 65
mknod /dev/ttyS2 c 4 66
mknod /dev/ttyS3 c 4 67
echo Setting up hotplug.
hotplug
echo Creating block device nodes.
mkblkdevs
echo "Loading ehci-hcd.ko module"
insmod /lib/ehci-hcd.ko
echo "Loading ohci-hcd.ko module"
insmod /lib/ohci-hcd.ko
echo "Loading uhci-hcd.ko module"
insmod /lib/uhci-hcd.ko
mount -t usbfs /proc/bus/usb /proc/bus/usb
echo "Loading jbd.ko module"
insmod /lib/jbd.ko
echo "Loading ext3.ko module"
insmod /lib/ext3.ko
echo "Loading libata.ko module"
insmod /lib/libata.ko
echo "Loading ata_piix.ko module"
insmod /lib/ata_piix.ko
echo "Loading dm-mod.ko module"
insmod /lib/dm-mod.ko
echo "Loading dm-log.ko module"
insmod /lib/dm-log.ko
echo "Loading dm-region-hash.ko module"
insmod /lib/dm-region-hash.ko
echo "Loading dm-mirror.ko module"
insmod /lib/dm-mirror.ko
echo "Loading dm-zero.ko module"
insmod /lib/dm-zero.ko
echo "Loading dm-snapshot.ko module"
insmod /lib/dm-snapshot.ko
echo "Loading dm-region-hash.ko module"
insmod /lib/dm-region-hash.ko
mkblkdevs
echo Scanning and configuring dmraid supported devices
echo Scanning logical volumes
lvm vgscan --ignorelockingfailure
echo Activating logical volumes
lvm vgchange -ay --ignorelockingfailure  VolGroup00
resume /dev/VolGroup00/LogVol01
echo Creating root device.
mkrootdev -t ext3 -o defaults,ro /dev/VolGroup00/LogVol00
echo Mounting root filesystem.
mount /sysroot
echo Setting up other filesystems.
setuproot
echo Switching to new root and running init.
switchroot

First two bolded rows are  duplicates, remove them, it will fix first error (see above), second bolded commands usual missed, so just add them exactly before first /dev/VolGroup name occured (i.e before resume /dev/VolGroup00/LogVol01 as I did), it will fix second error. Now pack fixed kernel image back:

# find . | cpio -c -o > ../initrd
# cd ..

Now compress kernel image (I prefer -2 -- it loads faster):

# gzip -2 < initrd > initrd-2.6.32.9.img

Now install it:

# cp -f initrd-2.6.32.9.img /boot
# reboot
...
# uname -sr
Linux 2.6.32.9
Cheers!

UPD: you might need to set CONFIG_SYSFS_DEPRECATED_V2=y in kernel config
Reference: http://funky-dennis.livejournal.com/3290.html

Thursday, October 14, 2010

Mount NTFS partition in Linux with read-write mode

1. Install ntfs-3g (RPM) package (if not aready present)
2. mount -t ntfs-3g /dev/partition_name /mount/path/

Thursday, October 7, 2010

Disk Quota for Linux Users

Configuration:
1. Add "usrquota" qualifier to the home partition in /etc/fstab
    LABEL=/home             /home                   ext3    defaults,usrquota        1 2
2. Create an empty file /home/aquota.user with root as owner and permission 600
    touch /home/aquota.user
    chmod 600 /home/aquota.user
3. Remount the /home partition
    mount -o remount /home
4. Check /etc/mtab
    /dev/sda5 /home ext3 rw,usrquota 0 0
5. Run quotacheck to scan the filesystem for disk usage and update the aquota.user file
    quotacheck -vum /home
6. Run quotaon -av
    /dev/sda5 [/home]: user quotas turned on
7. Edit quota for user and set the soft and hard limit for the blocks (in KB)
    edquota -u senthilkumar.v
    Disk quotas for user senthilkumar.v (uid 500):
    Filesystem                   blocks       soft       hard     inodes     soft     hard
    /dev/sda5                    409928     900000    1000000       1789        0        0

A script to add new user with quota
#!/bin/bash
real_useradd=/usr/sbin/useradd
SLIMIT=2600000
HLIMIT=3000000
if [ $# -eq 0 ] ; then
        $real_useradd
        exit
fi
a=`echo $* | grep "\-D"`
if [ $? -eq 0 ] ; then
        $real_useradd $*
        exit
fi
a=`echo $* | grep "\-g"`
if [ $? -ne 0 ] ; then
        GRP="-g devgroup"
fi
login_name=${!#}
$real_useradd $GRP $*
passwd $login_name
setquota -u $login_name $SLIMIT $HLIMIT 0 0 -a

Quota Reports:
1. List quota
    quota -u user_id
2. List users who hit the quota limit
    quota -q
3. Quota summary report
    repquota -a

Quota Check:
Add a cron entry to check the disk usage regularly
1. Add the following in /etc/cron.weekly/quotacheck
    #!/bin/bash
    /sbin/quotacheck -vum /home
2. chmod +x  /etc/cron.weekly/quotacheck