Thursday, June 25, 2009

How to add Windows TrueType fonts easily in Linux desktop system

How do you use Windows True Type fonts in Linux or how do you install Windows TrueType fonts in Linux?

Fonts are very important. When you migrate from Windows XP to Linux you may miss Truetype font. TrueType is a font standard developed by Apple Computer. By 1991 Microsoft had built TrueType into the Windows 3.1 operating system. The FreeType project provides TrueType under Linux. So let us see how to backup your Windows TrueType fonts and install them in Linux.

It is quite easy to add Windows True Type fonts in Linux. First make sure you copy Windows fonts on USB pen (usually located in C:\Windows\Fonts directory) or just mount windows NTFS/FAT partition. You can copy selected or all fonts from C:\Windows\Fonts directory.
Linux Gnome desktop

=> Open your default file manger or double click Computer icon on Gnome desktop
=> Type url:
Alternatively, select Open Location? from file menu and type
=> Once window open, just drag and drop fonts into this new windows from USB pen or mounted partition. Don't forget to restart application or just logout and login again.

Display Microsoft fonts like in Windows in CentOS/Fedora

Staying in front of your computer for hours and hours with the default fonts can be a challenge on Linux/Unix. I, for one, can’t work properly without the Windows fonts comfort :)

Having the windows fonts working on Unix systems is fairly easy, but on Red Hat-based operating systems such as CentOS or Fedora, can be a real nightmare. The most critical aspect of having the Microsoft fonts to display properly on CentOS in compiling freetype with bytecode interpreter enabled. Let’s go through this procedure.

This tutorial assumes you have the 3 most popular community repositories enabled (Karanbir Singh, Dag Wieers and Dries).

1. Create the system source tree:

$ su
# mkdir -p /usr/src/redhat/SPECS

2. Download the latest version of the Freetype source code from a CentOS repository – For instance: freetype-2.*.el5.src.rpm – To your desktop (has to have a .src.rpm extension) and install the source:

# rpm -Uvh ./Desktop/freetype-2.1.9-1.0.rf.src.rpm

3. Open the spec (make) file in a text editor:

# gedit /usr/src/redhat/SPECS/freetype.spec

And enable the bytecode interpreter changing this line:

%define without_bytecode_interpreter 1


%define without_bytecode_interpreter 0

(And not the opposite!)

4. Install some essential compilation tools and a few upgrades:

# yum install gcc-c++ rpm-build xorg-x11-deprecated-libs-devel xorg-x11-devel automake autoconf libtool zlib-devel libX11-devel

5. Build Freetype:

# cd /usr/src/redhat/SPECS
# rpmbuild -ba freetype.spec

6. Now you should have your RPMs:

# cd /usr/src/redhat/RPMS/i386 && ls
freetype-2.1.9-1.2.rf.i386.rpm freetype-devel-2.1.9-1.2.rf.i386.rpm
freetype-demos-2.1.9-1.2.rf.i386.rpm freetype-utils-2.1.9-1.2.rf.i386.rpm

7. Install the new version of Freetype:

# rpm -Uvh --force *

8. Download the Microsoft fonts and extract them:

# mkdir /usr/share/fonts/TTF
# tar xvjpf msfonts.tbz -C /usr/share/fonts/TTF/

Download the fontconfig files and extract them into your fontconfig directory:

# tar xvjpf fontconfig.tbz -C /etc/fonts/

9. Make sure the fonts directory is listed in the fontconfig configuration file:

# gedit /etc/fonts/fonts.conf



10. Log out from Gnome/KDE and relog in. Now here’s how your fonts should look like:

Wednesday, June 24, 2009

Virtual IP addresses

You can add several virtual IP addresses to a physical network interface. A good starting point is to copy the interface definition file of the device you want to add a virtual IP address to.

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

You may have to modify ifcfg-eth0 to match your physical interface name.

Now you can edit the new file ifcfg-eth0:0 and specify the network settings of the virtual interface.

To make the changes take effect please restart the network services using:

service network restart

Tuesday, June 23, 2009

How to create a range of ip addresses on ethx.

Create a range file in /etc/sysconfig/network-scripts




CLONENUM_START -- interface clone number to start using for this range. # eg "1"

Which would start at eth0:1

Linux wireless device parameter for AD-HOC connection


Installing Broadcom BCM4312 802.11b/g on centos

Download wireless package from Broadcom
Untar the file hybrid-portsrc-x86_32_5_10_27_6.tar.gz (hybrid-portsrc-x86_64_5_10_27_6.tar.gz if you’re running on a 64-bit kernel) in its own folder:

# tar -xvzf hybrid-portsrc-x86_32_5_10_27_6.tar.gz

You should now see this in your directory listing:


Need to compile now
Before u compile...
Something missing in code:---

Without adding the following headers the compiling process exits with error
don't worry have solution here.
Add the following line to the file
Open file src/include/typedefs.h and add there the line below at header

# vim src/include/typedefs.h


      Don't exclude the hash before define. It has to be typed as such mentioned here

Now build the Loadable Kernel Module (LKM) like so:

# make -C /lib/modules/`uname -r`/build M=`pwd`

Of course, you need to make sure you have all the required kernel headers before building it. Once that’s done, your directory listing should look like this:


The magic file we need is wl.ko. Make sure you don’t have b43, b43legacy or b43xx loaded by running this:

# rmmod bcm43xx; rmmod b43; rmmod b43legacy

And for good measure remove ndiswrapper modules:

# rmmod ndiswrapper

Now load the module ieee80211_crypt_tkip:

# modprobe ieee80211_crypt_tkip

And finally load the wl.ko module:

# insmod wl.ko

Now if you do an ifconfig, you should see wlan0 right after your eth0 and lo devices.

Else try iwconfig 

Yippee-kay-yay! Test it out by scanning and connecting to a network. If it works, then you might want your module to load upon boot, which is something the Broadcom readme doesn’t touch on. Let me school you how.

Copy the wl.ko file to /lib/modules/2.6.26-1-686/kernel/net/wireless/

# cp wl.ko /lib/modules/2.6.26-1-686/kernel/net/wireless/

Create the module dependencies:

# depmod -a

Try loading your new module!:

# modprobe wl

If you get no error on modprobe, then it worked perfectly! Next you have to tell your system to load the module at startup. On my debian system, I do this by editing the file /etc/modprobe.conf to include the following:

# vim

# alias wlan0 wl

Now, reboot and you’ve got official Broadcom wifi goodness! Hooray! Ubuntu 8.10 (due out the end of this month) will have this driver bundled with it, here’s hoping that Debian will have it in its repositories soon! Of course, all the above was done on my GNU/Debian Lenny/Sid system, so let me know if you tried it out on yours and tell me how it worked for you. Cheers!

Need to setup Linux as router ?

Enable the ipforwarding and add the masquerade to eth0

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Monday, June 22, 2009

Debian / Ubuntu Linux Install and Configure Remote Filesystem Snapshot with rsnapshot Incremental Backup Utility

Q. I'd like to configure my Debian box to backup two remote servers using rsnapshot software. It should make incremental snapshots of local and remote filesystems for any number of machines on 2nd hard disk located at /disk1 ( /dev/sdb2).

A. rsnapshot is perfect open source solution for making backups on local system. It supports both remote and local systems. From the man page:
rsnapshot saves much more disk space than you might imagine. The amount of space required is roughly the size of one full backup, plus a copy of each additional file that is changed. rsnapshot makes extensive use of hard links, so if the file doesn’t change, the next snapshot is simply a hard link to the exact same file. The following instructions are compatible with both Debian and Ubuntu Linux.
Required software / setup on local backup system

1. rsnapshot
2. rsync
3. ssh client
4. 2nd hard disk ( RAID array is suggested) - you can also use primary hard disk
5. Password less login configured using ssh keys
6. /disk1/backup - Backup directory
7. /disk1/backup/server1 - Backup directory for remote server called server1
8. /disk1/backup/server2 - Backup directory for remote server called server2
9. /disk1/backup/localhost - Backup directory for local server

Required software on remote server

1. OpenSSH sshd server
2. Password less login configured using ssh keys

Step #1: Install rsync and rsnapshot software

Use apt-get command, enter:
$ sudo apt-get install rsync rsnapshot

Step #2: Configure passwordless login / public key based login

Type the following command
# ssh-keygen -t rsa
# scp .ssh/
# scp .ssh/
See how to configure RSA / DSA SSH public key based authentication.

Step #3: Configure rsnapshot utility

The configuration file is located at /etc/rsnapshot.conf. The configuration file requires tabs between elements and all drectories require a trailing slash. Just open config file using a text editor such as vi or gedit:
# vi /etc/rsnapshot.conf
$ sudo vi /etc/rsnapshot.conf
Set snapshots root directory:
snapshot_root /disk1/backup/
Note: you must separate snapshot_root and /disk1/ by a [tab] key i.e. type snapshot_root hit [tab] key once and type /disk1/backup/. All snapshots will be stored under this root directory (/disk1/backup/).
Configure backup policy

You can make hourly, daily, weekly or monthly snapshots of local and remote systems. To make a snapshot every four hours (six times a day) and keep a second set, which are taken once a day, and stored for a seven days, enter:
interval hourly 6
interval daily 7
Feel free to adapt configuration as per your backup needs.
Specify local and remote backup directories

Find out comments that read as follows:


You need to comment out / delete default backup directories. To make snapshots for /home/, /etc/, /webroot/ directories to /disk1/backup/localhost, enter:
backup /home/ localhost/
backup /etc/ localhost/
backup /webroot/ localhost/
To backup remote server1 /home/, /etc/, /var/spool/mail/, /webroot/ directories to /disk1/backup/server1, enter:
backup server1/
backup server1/
backup server1/
backup server1/
backup server2/
Save and close the file.
Test your config file for errors

Type the following to test your configuration file for errors
# rsnapshot configtest
Syntax OK
You can also run rsnapshot in a test mode to display its action:
# rsnapshot -t hourly

Step #4: Run rsnapshot for first time

To run first time, enter:
# rsnapshot hourly

Step #5: Configure cron job

Edit /etc/cron.d/rsnapshot file to setup backup snapshot job. This is a sample cron file for rsnapshot. The values used correspond to the examples in /etc/rsnapshot.conf. There you can also set the backup points and many other things. To activate this cron file you have to uncomment the lines below.
Feel free to adapt it to your needs.
0 */4 * * * root /usr/bin/rsnapshot hourly
30 3 * * * root /usr/bin/rsnapshot daily
0 3 * * 1 root /usr/bin/rsnapshot weekly
30 2 1 * * root /usr/bin/rsnapshot monthly
See crontab related faq for more information about cronjob under UNIX / Linux.

How do I exclude files from backup?

rsnapshot allows you to set the include and exclude parameters, if enabled, simply get passed directly to rsync. If you have multiple include/exclude patterns, put each one on a separate line. For example,
exclude_file /etc/rsnapshot.server1.conf
Append exclude file list to /etc/rsnapshot.server1.conf:
# vi /etc/rsnapshot.server1.conf
Exclude files matching pattern from backup:
Save and close the file.

How do I backup remote MySQL database?

You can backup default database directory /var/lib/mysql. However, you can backup remote or local MySQL database with the following script:
NOW=$(date +"%d-%m-%Y")
MUSER="MySQL-UserNAME" #root
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
FILE=mysql-$db.$NOW-$(date +"%T").gz
Now add following line to /etc/rsnapshot.conf file:
backup_script /root/scripts/ server1/mysql/

How do I restore backup?

You can simply copy back file using regular scp / cp command.