Feeds:
Posts
Comments

Archive for November, 2008

In this practice we studied a concept called Virtual Machine, here some information:

In computer science, a virtual machine (VM) is a software implementation of a machine (computer) that executes programs like a real machine.

The desire to run multiple operating systems was the original motivation for virtual machines, as it allowed time-sharing a single computer between several single-tasking OSes.

The guest OSes do not have to be all the same, making it possible to run different OSes on the same computer (e.g., Microsoft Windows and Linux)“.[1]

So as is possible to see, you can run different applications or even different OS’s inside of the currently installed one in your computer by using this tool.

I’ll describe how to install FreeBSD 7 in Fedora 8, and how to enable networking in the guest system. So from now and on, we will call the FreeBSD system running in the virtual machine like “Guest” and Fedora 8 (the current OS in the computer) like “Host“.

1. Better if the system is updated, in the command line type:
# yum update (enter)

2. Install the tool kit and the GUI for the Virtual Machine.
# yum install libvirt virt-manager

3. Start the libvirt daemon.
# service libvirt start

4. Go to: Applications / System Tools / Virtual Machine Manager.

5. LocalHost should be connected, if not, select it, right-button of the mouse and click in “Connect”.

connect

6. With the LocalHost selected click en “New” button (right-bottom part of the VM screen).

7. Go through the wizard as follow:

  • Set the name (I chose “MyFreeBSD”).
  • Fully Virtualized mode.
  • Select the location of the media that you want to install in your virtual system (I installed from a CD-ROM).
  • Assign storage space (I use the second hard drive).
  • Connect to host network.
  • Allocate memory and CPU (I left the default values).
  • Check the Settings Summary and if everything is okay, click on “Finish” button.

9. After this point, is possible to install FreeBSD in the VM, we did it choosing the standard way.

Now is possible work with the guest system as you want, in our case, we played with the Guest routing table and set the Host IP like gateway in the FreeBSD system so in that way the Guest was able to reach other networks…

Host and Guest Routing Tables

Host and Guest Routing Tables

Another thing that we were able to do, was have a SSH session from Host to Guest, as is shown in the next screenshots:

Adding a user in the Guest...

Adding a user in the Guest...

SSH session from Host to Guest

SSH session from Host to Guest

Actually we could see X-Windows features working, typing the “startx” command brought this to the screen…

startx

You can be creative and install different stuff in the VM, this is just a small help that might provides some good clues about this topic and it’s advantages.

I want to say thank you to my team partner and friend Varinder Singh for doing this with me and Prof. Chan for explain us some special things about Networking…

[1] Wikipedia.

Read Full Post »

If you are in a situation that require -for example- install a Linux System like a server or install it in a small device, you may need to modify the kernel and recompile it with the objective of take out some capabilities and reduce its size of it or give the priority of some services and avoid to install things that just would make use of resources unnecessarily.

For this practice Fedora 9 system was installed in a second hard drive and worked with it.

I will describe in the next lines the steps that I followed to build a new Kernel, this is a general view about the whole process.

After install Fedora 9 in the second drive, restart the computer (make the cd come out before the starting process begin)…

When the screen shows a descending counting, press the space bar and when a list be shown just type the letter “c”, doing that will let us go to the command line, specifically to the “grub” menu.

So, in the grub menu, select first the disc and partition and fill the next lines as follows:
grub> root (hd1,0)
grub> kernel /vmlinuz…
(tab for auto complete)
grub> initrd /initrd-2… (tab for auto complete)
grub> boot (enter)

After rebooting, go trough the wizard…

Next thing is download the latest version of the kernel (I did it from the Kernel.org site.)

Is coming in a compressed file, so, it should be unzipped (example: # tar xvjf linux-2.6.27.7.tar.bz2).

Install by the command line kernel-devel (source code, c programs), kernel-headers (kernel headers files, from c libraries) and Development Tools (Compilers, makefiles, interpreters):
# yum install kernel-devel
# yum install kernel-headers
# yum groupinstall ‘Development Tools’

Go inside to the directory which was previously unzipped, there is a makefile in there, but we need create a new one with a correct “.config” file (that file gathers the modules information).

Should be in /usr/src/kernels/2.6.27… (something like this), is a hidden file so, list the directory using the -a option to the ls command (ls -a).

Now in the command line type this command (we should do this like regular user):
# make oldconfig (enter)
in my case this error came up:
/bin/sh: gcc: command not found

that means I needed to install gcc (GNU C compiler), that is done by running this:
# yum install gcc

again run the command “make oldconfig”

Some information from man about make command:
“To prepare to use make, you must write a file called the makefile that
describes the relationships among files in your program, and the states
the commands for updating each file. In a program, typically the exe-
cutable file is updated from object files, which are in turn made by
compiling source files.

Once a suitable makefile exists, each time you change some source
files, this simple shell command:

make

suffices to perform all necessary recompilations. The make program
uses the makefile data base and the last-modification times of the
files to decide which of the files need to be updated. For each of
those files, it issues the commands recorded in the data base.”

As says in man, just run:
# make

After that, is necessary to find and copy the Kernel Image file (bzImage) and the System.map file in /boot (the bzImage should be in a path like this: /home/HomeUser/linux-2.6.27.7/arch/x86_64)

In the directory which the makefile is, run the command:
# make modules_install

It will install all the modules (or should be) in: /lib/modules/’kernel version’, in the screen you just will see something like this:make-modules_install-screen

To finalize we need to run this command:
# mkinitrd initrd-2.6.27.7 2.6.27.7 (you can choose another name I just used the number of release and version).

Reboot the machine and trough the Grub menu, try to boot with the new kernel (the one that has the name just 2.6.27.7).

Read Full Post »

     Finally Python is coming… hopefully in few time we will be a Python-geeks… so with that in mind, hands-on!.
This was the task:
…………………………………………………………………………………………………………………………………………………………………………………………………….

1. Save this script, set the permissions correctly, and run it.

#!/usr/bin/python

import random
secret=random.randrange(1,100)

guess=int(raw_input(“Enter a guess: “))
if guess<secret:

……….print “Too low!”
elif guess>secret:
……….print “
Too high!
else:
……….print “Correct!”

2. Modify the script so that the user is given playing instructions before the game starts.
3. Make the script loop to prompt for input until the the correct number is guessed.
4. Displays the number of guesses the user took to guess the secret (score).
5. Modify the script so that it does not stop when invalid data is entered (such as a word). Suggestion: use try/except.
6. Accept only input value from 1 to 100.
7. Write a blog entry giving your impressions of Python.

…………………………………………………………………………………………………………………………………………………………………………………………………….

So, after add the required stuff I got something like this:
…………………………………………………………………………………………………………………………………………………………………………………………………….
#!/usr/bin/python

print “This game is about a number that the system will generate for you to guess, “
print “so, enter a number in between 1 and 100 “
print “you will have until 10 chances… ready? GO!”

import random
secret=random.randrange(1,100)
PlayerScore=10
Counter=0

# Verify that the Input from user is correct accord to the game rules, otherwise “raise” a error message…
def ValidateInput(x, min=1, max=100):
……….try:
……….……….if not min <= x <= max:
……….……….……….raise ValueError(‘That number is not in between 1 and 100…’)
……….……….else:
……….……….……….return 1
……….except ValueError:
……….……….print “That number is not in between 1 and 100…”
……….……….return 0

while True:
……….try:
……….……….Counter+= 1
……….……….guess=int(raw_input(“Enter a guess: “))
……….……….ValAnswer=ValidateInput(guess)
……….……….if ValAnswer==0:
……….……….……….continue
……….……….else:
……….……….……….if guesssecret:
……….……….……….……….print “Nop… lower than that…”
……….……….……….……….PlayerScore-=1
……….……….else:
……….……….……….……….print “You have guess!!!!”
……….……….……….……….break
……….……….if Counter > 9:
……….……….……….……….print “Sorry but this is taking to much time!… GAME OVER!”
……….……….……….……….break
……….except ValueError:
……….……….print “This program just accept numbers…”

print
print
“Stats: “
if Counter <= 3:
……….print “You tried to guess “,Counter , “times. That was really good!!! CONGRATULATIONS!”
else:
……….print “You tried to guess “,Counter , “times.”
print “Your score: “,PlayerScore
…………………………………………………………………………………………………………………………………………………………………………………………………….
I’m marking the indentation in each line because in my opinion is one of the basic things that we should care.

I want to share some things that I learned trough this experience:

     In Python Indentation is very important, there is no way to close a loop with some instruction, but the correct indentation, it was a pain in.. the brain! so since I’m not get used to its syntax was kind of difficult, Python is strict on this; for example, I was forgetting add “:” after “try” or “while True”… which by the way can not be “true” should be “True”… (I guess the compiler was having fun letting me know that I had gotten some mistakes…)

     But still I want to get into this, the power of Python programming is amazing, because is Cross-platform… very important feature!

Read Full Post »

In Lab 9 in Networking course, we were requested to do a routing exercise, this is a very helpful practice to understand basics about the way that it works. We learned how different nets can “see” each other and how to set a basic router configuration for this purpose.

The instructions for this Lab were as follows:

Set up THREE networks:

  • Network A: 11.0.0.0/8,
  • Network B: 172.17.0.0/16, and
  • Network C: 192.168.2.0/24

Setup THREE Hosts, one in each network

  • Host A: 11.0.0.1
  • Host B: 172.17.0.1
  • Host C: 192.168.2.1

Setup TWO Linux routers: Router R-ab and R-bc

  • Router R-ab: eth0 11.0.0.254, eth1 172.17.0.254
  • Router R-bc: eth0 172.17.254.254, eth1 192.168.2.254

Use the ping command to verify that ALL 5 Linux systems (three hosts and two routers) can communicate with each other.

…………………………………………………………………………………………………………………………………………………………………………………………………………

Setting the network

For this we chose 5 machines from our laboratory where 2 of them would do the router roll.

In our Lab, every n minutes the dhcp service is updating/checking the IP Addresses in every host, so, in order to avoid changes in the configuration that we are about to make, is necessary to find the dhclient process and kill it.
# ps aux | grep dhclient | grep -v grep
# kill -9 processnumber

After that, the IP addresses can be set (ifconfig command):
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host A: #ifconfig eth1 11.0.0.1 netmask 255.0.0.0 broadcast 11.255.255.255
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host B: #ifconfig eth1 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host C: #ifconfig eth1 192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
In Router AB:
# ifconfig eth1 172.17.0.254 netmask 255.255.0.0 broadcast 172.17.255.255
# ifconfig eth0 11.0.0.254 netmask 255.0.0.0 broadcast 11.255.255.255
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
In Router BC:
#ifconfig eth1 172.17.254.254 netmask 255.255.0.0 broadcast 172.17.255.255
#ifconfig eth2 192.168.2.254 netmask 255.255.255.0 broadcast 192.168.2.255
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Now the next step is set the routing tables in each machine (route command):
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host A:
# route add -net 172.17.0.0 netmask 255.255.0.0 gw 11.0.0.254
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 11.0.0.254
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host B:
# route add -net 11.0.0.0 netmask 255.0.0.0 gw 172.17.0.254
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 172.17.254.254
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Host C:
# route add -net 11.0.0.0 netmask 255.0.0.0 gw 192.168.2.254
# route add -net 172.17.0.0 netmask 255.255.0.0 gw 192.168.2.254
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
In Router AB: # route add -net 192.168.2.0 netmask 255.255.255.0 gw 172.17.254.254
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
In Router BC: # route add -net 11.0.0.0 netmask 255.0.0.0 gw 172.17.0.254
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Also is necessary turn the IP packet forwarding on in each router, we can do this in the command line (the changes won’t be kept after rebooting):
# echo “1” > /proc/sys/net/ipv4/ip_forward

OR by editing the file: /etc/sysctl.conf (change the net.ipv4.ip_forward value from 0 to 1 in the correspondent line):
# Controls IP packet forwarding
net.ipv4.ip_forward = 1

After that is necessary run this command (in this way the changes will be permanent even after reboot):
#sysctl -p

Here some information about this:

When IP forwarding is enabled, the operating system kernel will act as a router. For the Linux kernel, the parameter net.ipv4.ip_forward can be set to 1 to enable this behaviour. In FreeBSD, NetBSD and OpenBSD the parameter is net.inet.ip.forwarding.
In most systems, the command sysctl -w parameter=1 will enable the desired behaviour. This will persist until the next reboot. If the behaviour should be enabled whenever the system boots, the line parameter=1 can be added to the file /etc/sysctl.conf.

(From Parameters Section…)
-p Load   in   sysctl   settings   from   the   file  specified  or /etc/sysctl.conf if none given.  Specifying – as filename  means reading data from standard input.” [1]

The result network is represented in this diagram:
nerworkdiagram
(click on the figure to enlarge)
…………………………………………………………………………………………………………………………………………………………………………………………………………
Command “route -n”
To see the routing table the command route -n is used (the parameter -n shows numerical addresses instead of trying to determine symbolic host names [2]), as an example, I want to show the routing table of host B in different stages.

It was looking like this just after add the net 11.0.0.0/8:
# route add -net 11.0.0.0 netmask 255.0.0.0 gw 172.17.0.254
# route -n

Kernel IP routing table
Destination    Gateway            Genmask           Flags       Metric    Ref    Use    Iface
172.17.0.0     0.0.0.0                255.255.0.0       U             0           0        0        eth1
11.0.0.0         172.17.0.254      255.0.0.0           UG           0           0        0        eth1

I can read it like this:
My net is 172.17.0.0 (no gateway)
I can reach the net 11.0.0.0 trough the gateway 172.17.0.254

Later on, after add the net 192.168.2.0 the routing table was showed like this:
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 172.17.254.254
# route -n

Kernel IP routing table
Destination     Gateway                Genmask              Flags        Metric     Ref    Use   Iface
192.168.2.0    172.17.254.254      255.255.255.0      UG            0            0        0      eth1
172.17.0.0      0.0.0.0                    255.255.0.0          U               0            0        0      eth1
11.0.0.0          172.17.0.254          255.0.0.0              UG            0            0        0       eth1

also readable like: now I can reach the net 192.168.2.0 trough the gateway 172.17.254.254 as well.

At the end we were able to send a successful ping signal to any host in the net.

…………………………………………………………………………………………………………………………………………………………………………………………………………
[1] Wikipedia.
[2] Man pages.

Read Full Post »

Many people believes that is not possible do a lost of things in Linux based OS’s, I discovered that is totally false, we will see two good examples now.

…………………………………………………………………………………………………………………………………………………

Removing Red Eyes in pictures using GIMP.

I have installed Fedora 9 in my computer and one of the applications included by default is the image editor GIMP (GNU Image Manipulation Program).

GIMP Logo

GIMP is a treasure, it has a lot of very useful functions and work very well,we will use it for remove red eyes in pictures, here the steps:

To open GIMP, go to the menu Applications -> Graphics -> GNU Image Manipulation Program and launch your picture in the same way that you open a file in any software (menu File -> Open…).

Once you have done that, click on rectangle select tool:

RectangleSelectTool

…(or go to the menu Tools -> Selection Tools -> Rectangle Select) and draw a rectangle around the eye area like this: selecting

then go to Filters –> Enhance –> Red Eye Removal. A small screen will appear, use the Threshold scroll bar to adjust the eyes colour… 3

… click Ok when you finish, save your file and it’s done, now you have a very nice picture with no red eyes.
noredeyes

…………………………………………………………………………………………………………………………………………………

Creating a photographic mosaic.

You can create photographic mosaics made of other pictures or images, using a command-line program called Metapixel, which is a “photomosaic generator”.  In my opinion this is very cool stuff (you can impress your friends with this work).

Here the steps…

Installing the program:
Open a windows shell (Applications -> System Tools -> Terminal) and login like root, as follow:
# su –
# (type root password)

then run this command:
# yum install metapixel.

Now for this, you must have a picture that you want to have in mosaics and also a directory with lots of images (if you don’t have any or not enough then you can do what I did, I googled flower images and I copied around 120), the most you have, the best.

After that, you need create one more directory and leave it empty. Let’s call this last directory as “Tiles”.

Now again in the shell terminal:
# metapixel-prepare Directory-with-the-images/ Tiles/
That will index the images and convert them to a .png format, that makes them ready for perform the next command:
# metapixel –metapixel -w 6 -h 6 –library Tiles/ YourPicture.jpg AnyName.png
(The values after the arguments -w and -h indicate the width and heigh of each tile, so you can change these to see what happens)

It will take a bit (time depends how many images you are using for compose your mosaic).

The next line is for display the created image, (if you prefer go by the File Browser, up to you)
# display AnyName.png

At the end you will have something like this:

Image Resulted
(Click in the image to enlarge)

If you have a bigger picture then you may be able to appreciate better every tile that compose the result, you can experiment as much as you want, be creative and have fun…

For more information, visit this link: http://www.complang.tuwien.ac.at/schani/metapixel/

Read Full Post »

Lab 07 – First part…
Torrent files and Magnet Links (advantages and disadvantages)

To share files over Internet is very common the use of “peer to peer” applications, Bit Torrent and Magnet Links are two of that kind.

Bit Torrent seems to be more popular or more used, and is always a advantage since generally whatever is frequented is also well-attended, and this let find more updated resources on BitTorrent than Magnet Links.

BitTorrent itself does not offer a search facility to find files by name. A user must find the initial torrent file by other means, such as a web search; with Magnet links you are able to perform a search trough the client application and maybe the main advantage of Magnet links is that it allows resources to be referenced without the need for a continuously available host, while Bit Torrent works with a Internet hosting service system, which provide better performance whereby is faster, but you need to have an available “tracker” which is a computer that has the function to help the peers to communicate, peers that want to download the file must first obtain a torrent file for it, and connect to the specified tracker, which tells them from which other peers to download the pieces of the file [1] [1 – Wikipedia]

In other respects Bit Torrent could be securer, it doesn’t let to share entire directories, is necessary mark the files that the user wants to have in common with others, Magnet links allows shared a entire folder and this can cause some vulnerability.

luxeed_keyboard_black1

Lab 07 – Second part…
Task: Create a BASH shell script called backup. This script will backup all files in user’s home directory that were created or changed within the current day as a single compressed tar file in a ~/.backup/ directory. Each backup file name will be the current date. If a backup file exists already it will be overwritten without prompting.

#!/bin/bash

USERHOMEPATH=/home/$(logname)
echo “Backing up the files of the day in $USERHOMEPATH…”

#make a directory for the backup files if is not created yet…
BACKUPDIR=~/.Backup_Daily

if [ ! -e $BACKUPDIR ]
then
mkdir $BACKUPDIR
chmod 744 $BACKUPDIR
fi

#find $USERHOMEPATH -name ‘.*’ -prune -o -mtime 0 -print
#find $USERHOMEPATH -name ‘.*’ -prune -o -mtime 0 -print0 -exec tar cvf CHECKTHISOUT.tar {} +;
#find $USERHOMEPATH -name ‘.*’ -prune -o -mtime 0 -fprint0 | xargs -0 tar cvf IHATETHIS.tar

find $USERHOMEPATH -name ‘.*’ -prune -o -mtime 0 -print | tar cvf $BACKUPDIR/$(date “+20%y-%m-%d”).tar –no-recursion -T –

#where:
# -name ‘.*’ prune <— if a name of directory is found that starts with dot, then is pruned (ignored)
# -o <— “or” (otherwise)

echo “Backup finished…”

Read Full Post »

For my project I’m doing a bash script (for now) which is downloading a SRPM package from the CVS repository, and then it makes a ISO image of that… so, part by part I will explain what the script is doing.

This part is getting the name of the package that the user want to get the source.
#!/bin/bash
CURRENTDIR=$PWD
RPM=”$1″
echo “Getting SRPM for: $RPM”

Since the name of the package has dots (in the number of version/release) is necessary to replace those dots for underlines from the string… this line is doing it:
TAG=$(echo $RPM| sed “s/\.[^.]*$//” | tr “.” “_”)
echo “$TAG”

It will be necessary to have the name of the package (no version, no release, but the name of the package) so this line extract just that part.
PACKAGE=$(echo $TAG|sed “s/-[^-]*-[^-]*$//”)
echo $PACKAGE

For download the SRPM it creates a directory in /tmp/, the name of this dir is made up with the name of the package plus the number of the current process… (so it will be unrepeatable)
DIRECTORY=/tmp/$PACKAGE-$$
mkdir $DIRECTORY

… and this line will put us inside of the just created directory…
cd $DIRECTORY
echo “the package will be downloaded temporally in: $DIRECTORY”

Now, this line is important, because this made the connection to the CVS repository and it will ask download an specific package:
cvs -d :pserver:anonymous@cvs.fedora.redhat.com:/cvs/pkgs co -r “$TAG” $PACKAGE
where:
-d = cvs root directory
co = for check out
-r = to specify a version of a specific package
$TAG = the value of this variable is a string with the name of the package to download.
$PACKAGE = the value of this variable is a string with just the name of the package (no version, no release) so, in that way, the package will be downloaded in a directory with this name.

After downloading the package, we need to be inside the corresponding directory and creating the srpm…
cd $PACKAGE/F-*

In this point we need to run the make command, that will created a source rpm package….
make srpm

… and take name of the SRPM in a variable and the directory which it is kept, for later use…
SRPM=$(ls *src.rpm)
mkdir DIRforISO
cp $SRPM $PWD/DIRforISO/
DIRECTORY_CONTAINING_RPMS=$PWD/DIRforISO

The next line will create the .iso image of the srpm package…
genisoimage -o $SRPM.iso -R $DIRECTORY_CONTAINING_RPMS

after that it will be copied to original work directory:
mv $PWD/$SRPM.iso $CURRENTDIR/

The last step is to erase the work temporal directory, for be able to do that we need to move out of it…
cd
rm -rf $DIRECTORY

At the end of this process we will have an Iso image in our current directory for the requested package …

This is the preliminary version that I have, it will change a lot more, It was very interesting and because of that I have learned a lot more about scripting.

If somebody want to download it: Click on here

Read Full Post »