Tuesday, January 20, 2009

Making Cisco VPN Client work in Linux

The easiest way would be to install "vpnc" package which provides client for Cisco VPN concentrator (more information http://www.unix-ag.uni-kl.de/~massar/vpnc/).

On various OS, "yum" can be used to download and install the package.

#yum install vpnc

Once installed, you can use great script pcf2vpnc developed by Steven. This is useful only if you already have a .pcf file available with you.

#pcf2vpnc Input.pcf US-VPN.conf

NOTE: You can give any meaningful name to the output configuration file. Copy the output file to "/etc/vpnc" folder.

#cp US-VPN.conf /etc/vpnc

Cisco VPN server can be connected using below command

#vpnc US-VPN

If everything goes well, you are connected to the VPN server.


SquashFS, AUFS, Video4Linux, Cryptoloop and ext4 support in latest kernel 2.6.28

I always believe in "Need is the key to invention".

Though we are not going to do an invention here but will follow simple steps to customize the Linux kernel as per the need.


I had to do this for a variety of reasons -


1. I need to compress data stored on various partitions to save space and make them available in both read-only and read-write mode.
2. Integrated webcam (ALi Corp. camera) which comes with Lenovo Y300 13' laptop is not recognized by default by Fedora Core 10.
3. Accessing my new HTC Touch mobile phone inside Fedora.
4. To encrypt my important and personal data inside encrypted files and partitions.
5. To incre
ase the performance of writes and reads on hard disk.

Hence the journey began....

One of the most important thing to keep in mind while building kernel is to know what you want to achieve out of that unless somebody just want to know how it feel to compile and run customized kernel.

Searching Google for all above points gave me pointers as to how to go ahead and add support for all of
them.

First thing which one has to perform is to download latest kernel from www.kernel.org. I had chosen the latest version 2.6.28 which was available at that time.

Once downloaded, unfold its source inside a directory which having approx. 2.0 GB of space. Actually less also will do but to compile most of the modules and almost every feature provided within the kernel, one would need that much of space.

[Italic font shows commands to be executed on any shell inside Linux]
$su -
Password:

#cd /usr/src
#tar -jxvf /pawan/sources/linux-2.6.28.tar.bz2 -C kernels/

#ln -s /usr/src/kernels/linux-2.6.28 linux

#cd linux
#vim Makefile
(set the EXTRAVERSION to any meaningful value. I have used -xAUFS-SQFS-EXT4)

Please change the path of root d
irectory as per your settings. It is better to use UUID instead of partition identifier such as /dev/sda1. You can get the UUID value for all partitions using "blkid" command.

There are many file systems which does compression but squash file system (SQFS) seems to be the most promising one. So, I have chosen SQFS. Its tarball can be downloaded from squashfs.sourceforge.net website. SQUASHFS comes with a well written guide to add its patch inside kernel.


#patch -p1 < /pawan/sources/squashfs3.4/kernel-patches/linux-2.6.27-rc4-next/squashfs3.4-patch


I had to use patch for 2.6.27-rc4 and its upcoming versions since there was no patch specifically created for 2.6.28. But this worked for me and hopefully it will for you as well.

AUFS or Another Union File System is file system which will give user consolidated view of both read-only and read-write directories/partitions so that one can read/write to a directory without worrying about the internal details. What was the intension behind using this? I have made a compressed SQUASHFS file out of /usr/src directory to save space. It get automatically mounted using "/etc/rc.local" script but in read-only mode. After couple of days when I started installing Cisco VPN client to access our partner servers, I have started getting error while copying files to /usr/src. Then I came across AUFS after gooling a way to resolve this. It is again needs a patch to work with kernel 2.6.28 and many previous versions.


Below is how to download its source code and apply a patch to the kernel to be build.


# mkdir /pawan/sources/aufs.wcvs

# cd /pawan/sources/aufs.wcvs
# cvs -d:pserver:anonymous@aufs.cvs.sourceforge.net:/cvsroot/aufs login (Use EMPTY password)
# cvs -z3 -d:pserver:anonymous@aufs.cvs.sourceforge.net:/cvsroot/aufs co aufs
# make include/linux/version.h include/linux/utsrelease.h
# cd /pawan/sources/aufs.wcvs/aufs
# rm fs/aufs/Kconfig
# make -f local.mk kconfig
# patch -p1 < /pawan/sources/aufs.wcvs/aufs/patch/fsync_super-2.6.19.patch

# patch -p1 < /pawan/sources/aufs.wcvs/aufs/patch/sec_perm-2.6.24.patch
# patch -p0 < /pawan/sources/aufs.wcvs/aufs/patch/splice-2.6.23.patch

# patch -p0 < /pawan/sources/aufs.wcvs/aufs/patch/sysfs_get_dentry.patch

# patch -p0 < /pawan/sources/aufs.wcvs/aufs/patch/put_filp.patch
# patch -p0 < /pawan/sources/aufs.wcvs/aufs/patch/ksize.patch


#make xconfig

This command will open a Qt-GUI so that we can easily see all the functionality provided by our dear kernel in an easy way.
Go to File Systems panel to view all the supported file systems.
Choose compile within the kernel or as a module option for ext4, Another unionfs and FUSE from the right side of the File Systems link.

Click on the sub-menu called Miscellaneous filesystems to enable Squash FS 3.4 file system.


Go to Multimedia Devices to add support for webcam. Enable "Video For Linux" Also, choose V4L USB Devices and enable GSPCA for webcams. Choose ALi USB m5602 Camera Driver as a module.
If you have Sony Digital camera then also choose Sony MemoryStick Card support to access memory stick directly from the slot provided within the laptop for memory chips. Choose "MMC/SD/SDIO Card Supprt".

Save the settings to update ".config" file withing the source code folder.

Run below command to start compiling linux for all the desired features.


#make

Run modules_install to install modules and other kernel files inside /lib/modules/2.6.28-xAUFS-SQFS-EXT4/ directory.


#make modules_install


Now perform these step to load the compiled kernel from GRUB/LILO.

#cp arch/i383/boot/bzImage /boot/bzImage-2.6.28-xAUFS-SQFS-EXT4

#cp System.map /boot/System.map-2.6.28-xAUFS-SQFS-EXT4

#mkinitrd /boot/initrd-2.6.28-xAUFS-SQFS-EXT4.img 2.6.28-xAUFS-SQFS-EXT4


Add a new entry for the newly built kernel as shown below.


#vim /etc/grub.conf

default=1
timeout=5
splashimage=(hd0,7)/grub/splash.xpm.gz
#hiddenmenu
password --md5 $1$Oh/nmqE5$q5V.MJW4f0afWpljI30yI.
title Fedora (2.6.28)
root (hd0,7)
kernel /bzImage-2.6.28 ro root=UUID=ad3afe2e-46bf-4071-ab97-47ee050142be quiet vga=0x318
initrd /initrd-2.6.28.img
title Fedora (2.6.28-xAUFS-SQFS-EXT4)
root (hd0,7)
kernel /bzImage-2.6.28-xAUFS-SQFS-EXT4 ro root=UUID=ad3afe2e-46bf-4071-ab97-47ee050142be quiet vga=0x318
initrd /initrd-2.6.28-xAUFS-SQFS-EXT4.img
title Fedora (2.6.27.9-159.fc10.i686)
root (hd0,7)
kernel /vmlinuz-2.6.27.9-159.fc10.i686 ro root=UUID=ad3afe2e-46bf-4071-ab97-47ee050142be rhgb quiet vga=0x318
initrd /initrd-2.6.27.9-159.fc10.i686.img
title Fedora (2.6.27.5-117.fc10.i686)
root (hd0,7)
kernel /vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=ad3afe2e-46bf-4071-ab97-47ee050142be rhgb quiet
initrd /initrd-2.6.27.5-117.fc10.i686.img

#exit

Restart the OS to boot the new kernel and have your fingure crossed. You will see a nice penguin welcoming you inside the new kernel. If everything goes well you will be shown GDM manager or console as per your settings.

We will see creating and mounting various file systems which were added the
above kernel in next article.

Enjoy!!