• Home
  • About
  • Archives
  • Book
  • Contact me
  • Photos
  • Projects
  • Talks
Subscribe: Posts | Comments | E-mail
  • ArticlesArticles which I authored
  • GSOCGoogle Summer of code archives
  • HacksExperiments
  • LifeIn and around life
  • Open SourceFree and Open Source Software
  • PardusContributions with Pardus Project

Sarath Lakshman

Archive for the ‘Pardus’ Category


Posted on August 12, 2010 - by Sarath

Exit from chroot environment – python

chroot() is a useful system call available in most UNIX like operating systems. I have been using chroot to do several hacks for the past few years. Mostly people use chroot for fixing boot loader / GRUB. To fix GRUB, a live cd can be used to boot into a GNU/Linux system, then run

# chroot /mnt/root_partition

~# echo chrooted environment

Then, execute grub-install or any command to update GRUB configs.

Basically chroot makes the environment believe provided path is the root “/” of the filesystem.

We can exit from chrooted environment by pressing Ctrl-D.

chroot can be used to build chroot jail to protect server services for preventing attacker to gain complete access to the server by creating chroot jails.

Last day, I was working on my GSOC project Live Installer for Pardus. It was the first time, I was using chroot() in python. It had to execute a few statements in chroot environment and come back to prevous environment. But exiting from chroot environment found to be difficult and there were no direct methods to exit from it. So I had to do a little hack. I would like to share the hack so that you can reuse it without going for long search on how to do it.

import os
real_root = os.open("/", os.O_RDONLY)
os.chroot("/mnt/new_root")
# Chrooted environment
# Put statements to be executed as chroot here
os.fchdir(real_root)
os.chroot(".")

# Back to old root
os.close(real_root)

chroot() is provided by os module
The major player of this hack is fchdir() which can take file descriptor has argument and change to that directory as current working directory. We open our real root using real_root = os.open(“/”, os.O_RDONLY) and its file descriptor is stored in real_root. Now chroot to new file system. Execute all the required statements. After that execute fchdir() to change current directory to old_root using real_root descriptor. Then chroot to current directory to switch back to real root.

Happy Hacking :)


Posted on June 14, 2010 - by Sarath

diffdir : A utility to diff between directories

Hey,

I have been working on GSOC project on Pardus Live installer. I work on a separate svn branch for GSOC. When working across many files, we many need to generate diff between numerous files recursively working directory and some other branch directory. svn diff command helps only if the directories are fork of same svn repo and with change in revisions or so.

I needed a generic tool to make diff out of two directories. But googling a few minutes didn’t give me pleasing results and hence I am here with my own script.

Try out and comment.

#!/bin/bash
#Filename: diffdir.sh
#Description: A utility to take diff of files recursively between two directories
#Author: Sarath Lakshman
#e-mail: sarathlakshman@slynux.com
#Homepage: http://www.sarathlakshman.com


olddir=$1
newdir=$2

if [ $# -ne 2 ];
then
    echo -e "\nUsage: $0 [DIR OLD] [DIR NEW] > data.diff\n\n"
    exit 0
fi


(cd $olddir; find . -type f ! -regex ".*\.svn.*" ) > /tmp/files.$$
(cd $newdir; find . -type f ! -regex ".*\.svn.*" ) >> /tmp/files.$$

sort /tmp/files.$$ -u -o /tmp/reqfiles.$$

cut -c3- /tmp/reqfiles.$$ > /tmp/uniqfiles.$$

for file in `cat /tmp/uniqfiles.$$`;
do



    [ -e "$olddir/$file" ] && [ -e "$newdir/$file" ]

    if [ $? -ne 0 ];
    then

        echo [NEW] $file\:
        echo ===================================================================
        [ -e "$olddir/$file" ] && cat "$olddir/$file"
        [ -e "$newdir/$file" ] && cat "$newdir/$file"
       
    else


        diffed_data=`diff -u "$olddir/$file" "$newdir/$file"`

        if [[ -n $diffed_data ]];
        then

            echo $file\:
            echo ===================================================================    
            echo "$diffed_data"
            echo
        fi
    fi
done

Download the script : diffdir.sh

UPDATE : diff -Naur olddir newdir will do the stuff :)


Posted on May 16, 2010 - by Sarath

Pardus YALI – a case study on GSoc Project

Being a python and? code enthusiast, The most exciting feature about Pardus project is about their designs. All the of the applications pardus teams has ever written are awesome with their beauty in their code design. When ever you look at any project’s code, they are very transparent, readable and highly modular designs.

I am hacking with YALI ( Yet Another Linux Installer) Project for developing a Live OS installer. I went through the basic code and came up with an over view of YALI architecture. Hope this would be helpful for future YALI contributors and developers also.

Working of Yali4:
Yali starts with xdm service, which runs start-yali4 shell script. It runs /usr/bin/yali4-bin using /usr/bin/xinit and runs in fullscreen mode without KDE WM environment.
It invokes the method yali4.default_runner() which is yali4.gui.runner.Runner()

Pardus has its own service scripting and management technology COMAR. xdm is a comar script to serve as service for loading X.

runner.py:
Runner class servers as the major class which runs the Yali. It imports the main widget from gui/YaliWindow.py (Widget class). Widget class is Setup_ui using Ui_YaliMain (main.ui)
Resolution and screen size is set to maximum by reading QApplication.desktop()

Yali has a configuration system to behave as per different install_type.

YALI_INSTALL,YALI_DVDINSTALL, YALI_FIRSTBOOT, YALI_OEMINSTALL, YALI_PLUGIN, YALI_PARTITIONER, YALI_RESCUE = range(7) is defined in gui/installdata.py

In Runner class, it checks which sets install_type variable according to the configuration.

gui/context.py defines many constants and context variables (yali4/constants.py) . yali4.sysutils.

checkYaliParams() is used to identify the install_type configuration,
which can be passed as argument to kernel parameter.

In Runner, it creates an installer object by passing install_type and install_option to yali4.installer.Yali(). install_option is identified by yali4.sysutils.checkYaliOptions()

installer.py:

Yali class in installer.py is the main class which handles the Yali screens. Yali4 operates with the concept of screens.? mainStack Widget in the main.ui is called screen.
We dynamically load and remove different screen widgets required for the instalallation wizard. The base fullscreen UI is setup by runner and the screen is loaded from installer.py
Yali class in installer.py defines screen list for each install_type defined. Eg: self._screens[YALI_DVDINSTALL]

All different screens as defined as seperate .py files with name prefixed with Scr in yali4/gui. Each of these screen py files consist of a QWidget class Widget.
Widget class gui/YaliWindow.py has createWidgets() method which loads the required screens for given install_type. stackMove() method is used to show each screen
at appropriate time according to user interaction.

Changes/Work for Live installer
Most of the components required for the live installer can be reuse of existing screens from Yali4 and APIs.

To make Yali work as window mode and change the window size to a required size, yali4/Ui/main.ui require some changes as well as runner.py require some changes to prevent it from
resizing to available full screen width and height.

We need to add a new a new install_type YALI_LIVEINSTALL in gui/installdata.py

Instead of yali4/gui/ScrInstall.py, which handles installation for real pardus install medias. we have to write a new screen, ScrLiveinstall.py which can handle
installation from Live media.

yali4/installer.py will require an entry for YALI_LIVEINSTALL,

self._screens[YALI_LIVEINSTALL] = [                              # Numbers can be used with -s paramter
                                       yali4.gui.ScrKahyaCheck,        # 00
                                       yali4.gui.ScrWelcome,             # 01
                                       yali4.gui.ScrCheckCD,             # 02
                                       yali4.gui.ScrKeyboard,            # 03
                                       yali4.gui.ScrDateTime,            # 04
                                       yali4.gui.ScrUsers,               # 05
                                       yali4.gui.ScrAdmin,               # 06
                                       yali4.gui.ScrPartitionAuto,       # 07
                                       yali4.gui.ScrPartitionManual,     # 08
                                       yali4.gui.ScrBootloader,          # 09
                                       yali4.gui.ScrSummary,             # 10
                                       yali4.gui.ScrLiveinstall,         # 11
                                       yali4.gui.ScrGoodbye              # 12
                                      ]

Above changes are required to bring a minimal Live installer.

I have written a basic command line minimal Pardus Live installer,? http://web.sarathlakshman.com/gsoc/pardus/installer.py. Most of the required logic appears in its code.

Posted on April 27, 2010 - by Sarath

Google Summer of Code 2010

Finally this year’s Google Summer of Code 2010 students are announced. Glad to announce, I am one of them :)

This is my third year of participation with Google Summer of Code programs. It was fun working with different project and mentors along the recent years. This year’s selection procedures gave me a lot of input and support while talking to some of new mentors from different organisations Gentoo and Meego. I am with the Pardus due to my Pardus love. I enjoy it. But I missed other projects since I can work only on one project. I am thinking of working on the project I had proposed (not in gsoc context.) for fun.

This time I will be developing Live OS installer for Pardus. Also I will be developing Live CD creator from a Pardus installation. Optionally I have some more ideas out of gsoc context with Pardus, being a pardus developer. I will be writing a pisi-offline tool which is similar to Apt-On-CD on Ubuntu. But the one I am developing will be much better than Apt-On-CD which works based on package cache. But pisi-offline will not rely on cache. But the real installed applications.

My assigned mentor for the project is Mete Alpaslan, who is the author of Yali4 installer for Pardus :)

Project link: http://socghop.appspot.com/gsoc/student_project/show/google/gsoc2010/pardus/t127230768169

There is more glad news from my College, there is one more student from my College. Narayanan K, who would be working with OAR suite. His project url :http://socghop.appspot.com/gsoc/student_project/show/google/gsoc2010/oar/t127230761183

Congrats to all students :)


Posted on March 14, 2010 - by Sarath

Wireless LTSP

It is miniproject time for every Sixth semester B Tech students. I would like to update about my miniproject.
I am implementing a Wireless Linux Terminal Server project, Which is an extension to LTSP project.

From life.blog

Client Builder tool :)

Basically LTSP as quoted from wikipedia “Linux Terminal Server Project (LTSP) is a free and open source add-on package for Linux that allows many people to simultaneously use the same computer. Applications run on the server with a terminal known as a thin client (also known as an X terminal) handling input and output. Generally, terminals are low-powered, lack a hard disk and are quieter than desktop computers because they do not have any moving parts.”

LTSP facilities to use a powerful machine shared by many users from different terminals or thin clients. Thin client machines actually don’t do any processing rather than setting up a minimal system to run an X server. Basic principle of an LTSP system are as follows.

There will be a server machine which is having considerable ram, processing power and attached to a network. The client machines are low end machine with few megabytes of ram, low processing power and attached to the same network over LAN through ethernet card. Ethernet cards come with a special chip socket. We can actually flash a chip / ROM containing a minimal OS. We flash a minimal OS in it and call it PXE ( Preboot Execution Environment).
This ROM will setup a Linux kernel and an initial ramdisk atmost of (more…)


« Older Entries

  • About

    Sarath Lakshman is a Hactivist of Free and Open Source Software from Kerala.
    Read more about him.
  • My Book

    Solve real-world shell scripting problems with over 110 simple but incredibly effective recipes.



  • Follow

  • Random Photos

    InCTF Ceremony@Verisign http://picasaweb.google.com/avinashtjoshi/InCTF10PrizeDistribution
  • Tweets

    • Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/30 23:31
    • is down. Having some issues with hosting account. I will update when it is back.
      http://t.co/Hj3u1qm1
      2011/11/29 11:59
    • Blog post: Preparing for your first-job interviews:
      http://t.co/SBdRl4At
      2011/11/29 09:47
    • Packt Publishers interviewed me.
      http://t.co/CMrvOPh
      2011/09/08 00:21
  • Calendar

    May 2012
    M T W T F S S
    « Nov    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • Archives

  • Blogroll

    • FOSS.IN
    • GNU Vision Blog
    • Hiran Effects
    • J5′s blog
    • Pardus planet
    • Praveen Arimbrathodiyil’s blog
    • Santhosh Thottingal
    • SLYNUX GNU Operating System
    • St Josephs HSS, Thalassery – Alumni
    • Swaroop CH
    • TT’s Jottings-Blog of VU2SWX
  • Tags

    algorithm automation bangalore bash bash scripting bug code college contribution define development facebook fedora foss fossmeet freedom free sms freesoftware Friends fun gnome gnu google google summer of code hack hacking hacks internet interview joy kde 4.1.2 kochi Life linux mec microsoft new year night nitc pardus pitivi python script summer of code video editor
Copyright © 2005 - 2010 Sarath Lakshman
Powered by Wordpress 3.04