Pardus project


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 :)

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.info

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 :p

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.info/gsoc/pardus/installer.py. Most of the required logic appears in its code.

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 :)

Next Page »