Friday, October 3, 2008

Copying LInux MBR to boot from WIndows BootLoader

To save the current Linux MBR type
dd if=/dev/hdaX of=/bootsect.lnx bs=512 count=1

where hdaX is the device in which you installed the MBR and /bootsect.lnx is the file in which you whant to dump it.

Then, to use it from Windows Boot Manager, edit c:\boot.ini adding
c:\bootsect.lnx="Linux"

Monday, September 29, 2008

Windows Backup made easy with SystemRescueCD

Quick solution to add an 'open source' automatic recovery option from the windows boot manager.
Steps:

1- Download SystemRescueCD iso from http://www.sysresccd.org/Download
2 - Extract sysrcd.dat, rescuecd, initram.igz and place them on C:
3 - Download Grub4Dos from https://gna.org/projects/grub4dos/ (tested with version grub4dos-0.4.3-2007-08-27.zip) extract the file grldr to C:\
4 - Modify C:\boot.ini adding in the section [operating systems] the statement:
C:\grldr="SystemRescueCd"
5 - Add the following file to C:\


#======================menu.lst=======================
default 2
timeout 30

# This is a sample menu.lst file for SystemRescueCd
title Create Backup
root (hd0,0)
kernel /rescuecd ar_nowait autoruns=0 setkmap=it docache
initrd /initram.igz

# This is a sample menu.lst file for SystemRescueCd
title Restore Backup
root (hd0,0)
kernel /rescuecd ar_nowait autoruns=1 setkmap=it docache
initrd /initram.igz

# This is a sample menu.lst file for SystemRescueCd
title SystemRescueCd from the NTFS disk
root (hd0,0)
kernel /rescuecd ar_disable setkmap=it docache
initrd /initram.igz
#================================================



#===========================autorun0=============
#!/bin/sh
#Create Backup Script
ntfs-3g /dev/sda2 /mnt/windows
partimage --compress=2 --overwrite --nodesc --batch save /dev/sda1 /mnt/windows/win_backup.bz2
umount /mnt/windows
reboot
#================================================



#===========================autorun1=============
#!/bin/sh
#Restore Backup Script
ntfs-3g /dev/sda2 /mnt/windows
partimage --batch restore /dev/sda1 /mnt/windows/win_backup.bz2
umount /mnt/windows
reboot
#================================================

6 - Resize you C partition and create another one which will contain the backup.

Thursday, August 21, 2008

Automatic login in Windows XP

Taken from:

http://support.microsoft.com/kb/315231

Quick command:

Start->Execute-> control userpasswords2

Thursday, July 10, 2008

Character encoding in Apache

One of the last problem that i faced is related on how to setup character encoding on apache httpd for content served directly by the web server. What i was willing to do was to serve all the content with UTF-8 character encoding. Let see how to procede.

First we must edit the httpd.conf. Search for AddDefaultCharset and set it to utf-8:

AddDefaultCharset utf-8

Then we must be sure that the content that we are going to serve is stored on the file system in utf-8 as well. If this is not the case we will have wired behavior, with characters not displayed correctly. Unfortunately in linux is not possible to discover which is the encoding of a file, so the quickest way will be to verify directly the output on the browser. Linux in any case provide a quick way to convert from an encoding to another:

iconv -f ISO-8859-1 -t UTF-8 index.html > index.html.utf8

then we can simply:

mv -f index.html.utf8 index.html

Pay attention that iconv do NOT check the source file encoding. This means that if you apply this command to a file that is already stored with utf-8 encoding it will simply produce a wired file as output.

Last but not least, i would suggest you to avoid to put inside the page:

<meta equiv="Content-Type" content="text/html; charset=utf-8">

because in any case the parameters passed by apache through the http header will override it.

PS I've created a small script to modify a bunch of file in a row. It accept a search like parameter :

#!/usr/bin/ksh
USAGE="usage: "
if (( $# < 1 )) then
print $USAGE;
exit;
elif (( $# > 1 )) then
print $USAGE;
exit;
fi

for file in *$1*
do
if [[ $file = *html* ]]
then
iconv -f ISO-8859-1 -t UTF-8 $file > $file.utf8;
mv -f $file.utf8 $file;
echo $file;
fi
done


Wednesday, July 9, 2008

Compress / Decompress initrd files

To Decompress:

zcat initrd.gz > initrd
mount -t ext2 -o loop,rw initrd /tmp/

After the modification of the folder structure, to compress again:
gzip -c initrd > initrd.gz

Monday, May 12, 2008

Remove tabulation from an Excel file

Just a simple routine to remove "Tab characters" from an excel file:

Sub RemoveTab()
Dim MyCell As Range
For Each MyCell In Selection
Dim a As String
a = MyCell.Text
a = Replace(a, Chr(9), "")
MyCell.Value = a
Next MyCell
End Sub

Saturday, April 5, 2008

Create a manager accout

It is very usefull to create a manager account in your tomcat. In fact it will be used to access all the administration sections that you can see if you point to the root of your tomcat from a browser (e.g. http://localhost:8080/). But it is also usefull if you want to start, stop, redeploy... from the url with the tomcat manager (http://{host}:{port}/manager/{command}?{parameters}) or with ant. We have to open tomcat-users.xml (..apache-tomcat-5.5.26\conf\tomcat-users.xml). We will add the following lines:

<role rolename="manager">
...
<user username="user" password="pass" roles="manager">

So in the end we will have something like this:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="user" password="pass" roles="manager"/>
<user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

Use tomcat through a proxy

During last days I had the necessity to access from my development tomcat the external world (e.g. access remote web services). The problem is that, inside my network, access to the external world is achieved through a proxy with autentication. The solution is to add the following line to your catalina.properties (..\apache-tomcat-5.5.26\conf\catalina.properties):

http.proxyHost=my.proxy.com
http.proxyPort=8080
http.proxyUser=user
http.proxyPassword=password

VoilĂ !

Wednesday, March 19, 2008

Hex Edit using VI

Here are some few commands to edit an hexadecimal file using vi:

vi file.hex
#now editing in vi
[esc] :%!xxd
#now editing file.hex in hex
#find some innocuous string or rcsid
#change the values on the hex side
[esc] :%!xxd -r
[esc] :wq!
#Now have a look on the file just created
hexdump file.hex

Wednesday, February 13, 2008

Setup network interfaces file

I'll just analyze how to setup a network interface. In this case it's a wireless lan with hidden essid and static ip. Let's open the interfaces file:

root@ubuntu:~# gedit /etc/network/interfaces


We will found inside something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

Now let's add the following lines:

auto ath0
iface ath0 inet static
wireless-essid myEssid
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255

And last but not least let's restart the network:

root@ubuntu:~# /etc/init.d/networking restart



Setup network

I will just post a quick way to setup a network interface from command line. We will analyze the case of wireless lan with hidden essid and static ip address:

root@ubuntu:~# iwconfig ath0 essid "myEssid"
root@ubuntu:~# ifconfig ath0 192.168.3.3

root@ubuntu:~# route add default gw 192.168.3.1

Thursday, January 31, 2008

For cycle from shell

Let's see a small example of a for cycle directly inside the shell:

me@ubuntu:~/workspace/myFile$ for file in *
> do
> echo $file
> grep foo $file
> done
test.txt
hi, my name is foo

In this case we will cycle all the files in the current directory, print out their names and grep "foo" for each one. Of course you can simply make recursive grep with * as file input parameter... but this can be a startup point for more complex operations

Thursday, January 24, 2008

How to enable speed step on core 2 duo

Before starting we have to discover which governors are avaiable for our processor:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

The output should be something like this:

powersave ondemand conservative performance

Considering that in Ubuntu Gusty scaling is supported directly by the kernel we will to do nothing else than load the following modules:

cpufreq_conservative
cpufreq_ondemand
cpufreq_powersave
acpi-cpufreq

To do this we have to add the previous lines to the modules file:

$ sudo gedit /etc/modules

Now we can reboot the machine and enjoy the speed stepping. To set a specif governor we can type
cpufreq-selector -g {governor}, here there is an example:

$ cpufreq-selector -g ondemand

We can also add the CPU frequency scaling monitor. To do this right click on the top panel and select Add to panel. Now we can drag & drop the gnome applet. To be able to change the governor from the applet we have to type the following command:

$ sudo chmod +s /usr/bin/cpufreq-selector