Saturday, September 15, 2007

Install Fedora 6 and Build Kernel

I got one more PC and am going to install Fedora 6 on it. Some software like Intel VTune doesn't support Fedora 4, neither Debian.

There is a good tutorial about FC6 installation http://www.mjmwired.net/resources/mjm-fedora-fc6.html while Stanley has tutorial for FC5. Don't forget official FC6 release notes http://docs.fedoraproject.org/release-notes/fc6/en_US/. It contains lots of useful stuff. The bug report is also worthy to read http://fedoraproject.org/wiki/Bugs/FC6Common, especially because FC6 installation program can't decide the right processor in some cases.

release notes


There are a few performance enhancement in this release, like DT GNU HASH for dynamic linking applications, ext3 performance boost and cacheFS for NFS as part of cacheFS program.

There is no difference between UP and SMP version. It supports POSIX priority inheriting and protecting mutex.

installation

I use automatic partitioning and select all three package options, Office and Productivity, Development and Web server. Fedora extra and individual package are not selected. After one hour, FC6 is ready. The Helix spiral desktop looks pretty good.

The next step is to customize packages. I follow the suggestion of mjmwired. There is an automatic updater running after installation. It has to be stopped because it locks the database. Use sudo /etc/init.d/yun-updated stop and then reconfigure packages.

I need to be patient during that as it's very slow. If I select a package group and de-select, the computer stops to response. The system monitor shows that it's running at almost 100% load. The other thing is that it's better to login as root instead of maintenance user account if you want to reconfigure packages.

The next step is to check if installation program know the right processor type. There is detailed instructions in FC6 bug report. Basically I use rpm -qa 'kernel*' --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n"|sort and see if the kernel type is i686 in my case.

After all, use yum update to update all packages. The kernel is updated from 2.6.18-2798 to 2.6.22-5. However both kernel images are there. You can choose during boot up.

Kernel build

Kernel source has to be installed manually after installation because it's not included. For most of cases, like add-on modules, kernel header is enough. Just use yum install kernel-devel. However in my case, there is also kernel-header package for 2.6.22. I don't know where it comes from.

To install kernel source, first you need download a tool, yumdownloader. Then use rpm to install. Next to prepare source because the Fedora core is different to Vanilla core. The last step is build and install.

1. install the tool, yumdownloader. yum install yum-utils

2. yumdownloader --source kernel --enablerepo updates-source. A rpm file is downloaded to current dir.

3. rpm -Uvh kernel-2.6.18-1.2798.fc6.src.rpm. Ignore errors about non-existent user and group.

4. Prepare the source code to apply Fedora patch.
cd /usr/src/redhat/SPECS
rpmbuild -bp --target i686 kernel-2.6.spec

5. Move source code as Linux convention
cd /usr/src/redhat/BUILD/kernel-2.6.17
mv linux-2.6.17.i686 /usr/src/
cd /usr/src
ln -s ./linux-2.6.17.i686 linux
cd /usr/src/linux

6. Get the right config file. I use i686 one. There is no difference between UP and SMP for FC6.
cp config/kernel.i686.config .config

7. Build kernel.
make oldconfig
make menuconfig
make all
make modules_install
make install

8. reboot, use uname -a to see if new kernel works.

The EXTRAVERSION define in Makefile is used to differentiate the one just build and the one downloaded. It's set to 'prep' by default. The kernel build as prep as a suffix.

Saturday, March 31, 2007

Automatic backup script in Perl

An automatic backup script is a very handy tool so I can "forget" the backup task everyday. It's also an exercise after I read Perl tutorial. Now, it's scheduled and run everyday via crontab on my Linux server at home.

Basically it's a lightweight backup tool. First it archive files to backup. Then it compares to last backup archive. If it's different, the archive is ftped to a remote server. A brief log and a detailed log are generated meanwhile.

It works pretty well and stable. The source code is shown as following.

#!/usr/bin/perl

use strict;
use warnings;

my ($logdir, $log, $detailedlogdir, $detailedlog, $lastsuccessfilename);
my ($targetdir, $target, $targetprefix, $targetnameonly);
my $cbserver;
my @source;
my ($timeforfilename, $timestring);

sub get_timestring {
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdat);

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdat) = localtime;

$year+=1900;
$mon = sprintf("%02d", $mon+1);
$mday = sprintf("%02d", $mday);

$timeforfilename = $year.$mon.$mday;
return $year."/".$mon."/".$mday."-".$hour.":".$min.":".$sec;

}

sub print_usage {

print "usage: squarrel daily|weekly|monthly\n";

}

sub get_argv {

if ($#ARGV!=0) {
&print_usage;
exit;
}

if ($ARGV[0] eq "daily") {
@source="..."; # file or directories to backup on daily base.
} elsif ($ARGV[0] eq "weekly") {
@source="..."; # file or directories to backup on weekly base.
} elsif ($ARGV[0] eq "monthly") {
@source="..."; # file or directories to backup on monthly base.
} else {
&print_usage;
exit;
}

$targetprefix=$ARGV[0];

}

sub init {

$logdir = "/var/www/html"; # log is written in httpd directory so I can check it via browser
$log = "$logdir"."/emc.log";
$detailedlogdir = "/home/emc";
$detailedlog = "$detailedlogdir"."/emcdetailed.log";

if (-e $log) {
open LOGFILE, ">> $log" or die $!;
} else {
open LOGFILE, "> $log" or die $!;
}

if (-e $detailedlog) {
open DETAILEDLOG, ">> $detailedlog" or die $!;
} else {
open DETAILEDLOG, "> $detailedlog" or die $!;
}

print LOGFILE "----------------------------------------------------\n";
print DETAILEDLOG "----------------------------------------------------\n";

$timestring = &get_timestring;
print LOGFILE "$timestring backup($targetprefix) starts\n";
print DETAILEDLOG "$timestring backup($targetprefix) starts\n";

$targetdir = "/home/bt/crossbackup";
# $targetnameonly = "backup".$timeforfilename.".tar.bz2";
$targetnameonly=$targetprefix.$timeforfilename.".tar.bz2";
$target = "$targetdir/".$targetnameonly;

$lastsuccessfilename = "$detailedlogdir"."/lastsuccess_".$targetprefix;
$cbserver = "..."; # remote server address

}

sub archive {
my ($archivecmd, $result);

$archivecmd = "tar cvfj $target @source";

$timestring = &get_timestring;
print LOGFILE "$timestring $archivecmd\n";
print DETAILEDLOG "$timestring $archivecmd\n";

system("$archivecmd >>$detailedlog 2>> $detailedlog");
$result = $?;
$timestring = &get_timestring;

if ($result == 0) {
print LOGFILE "$timestring archiving finish successfully\n";
print DETAILEDLOG "$timestring archiving finish successfully\n";
} else {
print LOGFILE "$timestring archiving fail $result\n";
print DETAILEDLOG "$timestring archiving fail $result\n";
}

return $result;
}

sub check_identical {
my $lastsuccesstarget;
my $different;

if (-e $lastsuccessfilename) {
open LASTSUCCESS, "$lastsuccessfilename" or die "Write $lastsuccessfilename";
$lastsuccesstarget=;
chop($lastsuccesstarget);
close LASTSUCCESS;

$timestring = &get_timestring;
print LOGFILE "$timestring compare $target $lastsuccesstarget\n";
print DETAILEDLOG "$timestring compare $target $lastsuccesstarget\n";

system("diff -q $lastsuccesstarget $target >> $detailedlog 2>> $detailedlog");
if ($?) {
$timestring = &get_timestring;
print LOGFILE "$timestring $target is different to $lastsuccesstarget\n";
print DETAILEDLOG "$timestring $target is different $lastsuccesstarget\n";
return 1;
} else {
$timestring = &get_timestring;
print LOGFILE "$timestring $target is identical to $lastsuccesstarget\n";
print DETAILEDLOG "$timestring $target is identical to $lastsuccesstarget\n";
system("rm -f $lastsuccesstarget\n");
$timestring = &get_timestring;
print LOGFILE "$timestring remove $lastsuccesstarget\n";
print DETAILEDLOG "$timestring remove $lastsuccesstarget\n";
return 0;
}
} else {
return 1;
}

}

sub ftp_upload {
my $ftpcmd;
my $result;

$ftpcmd = '"user username password\nbinary\nput '.$target.' '.$targetnameonly.'\nquit\n"';

$timestring = &get_timestring;
print LOGFILE "$timestring ftp -v -d $cbserver <<$ftpcmd\n"; print DETAILEDLOG "$timestring ftp -v -d $cbserver <<$ftpcmd\n"; system("echo -e $ftpcmd | ftp -v -d $cbserver>> $log 2>> $log");
$result=$?;

$timestring = &get_timestring;
if ($result == 0) {
print LOGFILE "$timestring uploading finish successfully\n";
print DETAILEDLOG "$timestring uploading finish successfully\n";
} else {
print LOGFILE "$timestring uploading fail $result\n";
print DETAILEDLOG "$timestring uploading fail $result\n";
}
return $result;
}

sub done {
my ($result, $stage) = @_;

$timestring = &get_timestring;
if ($result == 0) {
open LASTSUCCESS, ">$lastsuccessfilename" or die "Write $lastsuccessfilename";
print LOGFILE "$timestring backup($targetnameonly) succeed\n";
print DETAILEDLOG "$timestring backup($targetnameonly) succeed\n";
print LASTSUCCESS "$target\n";
close LASTSUCCESS;
} else {
print LOGFILE "$timestring backup($targetnameonly) failed in stage $stage\n";
print DETAILEDLOG "$timestring backup($targetnameonly) failed in stage $stage\n";
}
close LOGFILE;
close DETAILEDLOG;

}

my $result;

&get_argv;
&init;

$result = &archive;
if ($result) {
&done(1, "archive");
exit (1);
}

$result = &check_identical;
if ($result==0) {
&done(0, "");
exit(0);
}

$result = &ftp_upload;
if ($result) {
&done(2, "upload");
exit (2);
}

&done(0, "");
exit(0);


Sunday, March 18, 2007

Try Emacs

Emacs is the favorite editor of my leader, as well as my leader before. It looks handy and extensible. From Google Code, there is an emacs backend to enable navigation between source files. That's a good example that Emacs can be extended and customized for my need. I would like to have a try.

I read emacs build-in tutorial. It's basic but enough to start. There is a comprehensive manual from GNU emacs official website.

For starting, it's just different commands to vi or other editors. Just remember it.

^g reset emacs commands in case of hanging

^a / ^e move to the beginning or end of the line
ESC-< / ESC-> move to the beginning or end of the file
^k kill from cursor position to end of line
^ [SPACEBAR] or ^@ mark block
^w cut
ESC w copy
^y yank it back or paste

^s search or search again
^r reverse search or reverse search again
ESC % replace (type 'y' to confirm replacement)
No [RET] after entering search string

^x ^f open a file
^x ^s save current buffer
^x ^c exit
^x ^b list all buffers

^x u or ^_ undo
^u 8 repeat command for 8 times
^x 1 / 2 / o get rid of all other windows / split current window into two /switch to another window

All these commands work for both windows and Linux.

Saturday, March 10, 2007

PickupPerl & Screen

I read through PickupPerl in a few days. It's a simple but good starting point. As I am familiar with C programming, I only list what is important to me. As an exercise to study, I started to write a script for my data backup. Meanwhile I found some other good tutorials with more details @www.perl.com, an official perl website.

I also found a pretty handy tool, screen, a terminal manager. Just remember a few often used commands. There is a good introduction @ http://jmcpherson.org/screen.html

Perl

1. The first example. Just remember it.

#!/usr/bin/perl

use strict;
use warnings;

print "What is your username? ";
my $username;
$username = ;
chomp($username);
print "Hello, $username.\n";

2. Scalar variable can be either a string or a number. And a scalar variable is not defined as a string or a number. Perl does automatic conversion between string and number.

3. Single-quoted string. no special character except ' and \. Note \' and \\ is replaced but backslash followed by something else keeps both. For instance \o means \o, two characters.

4. New line can be embedded into a single-quoted string.

5. Double-quoted string is similar to that in C except that $ and @ are special characters and need backslash.

6. For number, you can use underscore for readability. It's just for readability.

7. Scalar variable support interpolation.

8. Undefined variable is allowed and assigned a special value 'undef'.

9. 0, undef, "" means false and others means true.

10. <=> cmp, . string concatenation, x string duplication.

11. Names are case sensitive.

12. Array(@) can grow and shrink dynamically as needed by setting $#array. When an array is growing very large very quickly, it can be a bit inefficient. You can pre-build an array of certain size instead. $#array: subscript of the last element in the array.

13. Everything in the array must be a scalar. No 2-D array. Array in another array simply concatenate each other.

14. Array quoted by () or qw//. Use .. with slice.

16. Push, pop at the end of array, shift/enshift at the beginning of array.

17. blocks are quoted by {}. Variables declared in the block is valid only in the block.

18. if/elsif/else, foreach. foreach my $item (@collection) { print "$item\n"; }

20. hashes(%) are not subscripted by numbers but an arbitrary scalar value. A hash is a list of value pairs, key and value. keys/values %hash return array of key or value.

22. Regular expression(quoted by //). * zero or more of the previous character; . any; | or ; () grouping; ^ start of string; $ end of string; =~ for pattern matching. \d match [0-9]. check 'perlre' for more.

24. Subrouting. sub subname { xxx; }, return; parameter. special array variable @_.


Screen

C-A c create
C-A p/n page forward/backward
C-A 0/1/2.. select a window
C-A d/r detach/retach

Saturday, March 3, 2007

Write Perl Script

I did some Shell and Tcl script designing before but apparently it's not enough to write a good backup script. Before starting to play with scripts, I need to decide which script language to use, Tcl or Perl. I searched for 'comparison tcl perl' and got some interesting comments.

Tom Christiansen has a nice comparison. From his view, Perl is a good system programming language while Tcl is a metalanguage. (Metalanguage means that you can create your own language based on it.) Perl is also much more efficient because the intepreter first compile the code and run the intermediate code. Also because of compiling, it's more robust.

I would say that perl is a language designed for high-level, portable, systems programming on tasks of small to medium scope, but with support for enough underlying general-purpose programming constructs to make it suitable for many users who would not characterize themselves as systems programmers. This includes not just systems administrators but also people doing software installations, rapid prototyping, generic data munging, simple client/server programming, customer support, and test suite design and analysis. Another application area for which perl provides an elegant and convenient solution is one which is growing so fast that I suspect even its second-derivative is still positive: World Wide Web script support (a.k.a. CGI programming). I suspect than in a few years, perl may well be better known as a CGI language than it is as a sysadmin language.
(From http://www.perl.com/doc/FMTEYEWTK/versus/tcl-discussion.html)

For me there are two other advantages: similarity to C and that my colleagues know Perl. Richard Stallman is negative to Tcl either from experience of Emacs development. So conclusion is clear now. I choose Perl.

There are quite some free Perl readings on Internet. I downloaded a tutorial called PickupPerl. It's a good reading to start although it can be more compact. Start to read it and backup application is a good exercise.

Sunday, February 25, 2007

Build up home data center and backup policy

Last a few days I re-organized/cleanup my large hard disks to build up a center repository. All legacy data, reference information and current data are stored on the server which is the only data storage. The advantage is that there is no need to synchronize data and it simplify backup. And all data can be accessed anywhere as well.

A new backup policy is defined. It's in fact as important as the hard disk. :) Basically I want
1. robust data management
2. easy and flexible to use, accessible anywhere
3. easy to automate backup
4. searchable by desktop search engine

The general backup rule is:
1. all fixed data are stored on the external hard disk with read only permission.
2. all dynamic data are stored on another partition on external hard disk.
3. fixed data are backup to DVD with snapshots, dynamic data are weekly (monthly for media) archived and ftp to another computer.

Backup of dynamic data can be automated. I am going to write a script to do that automatically. All data is robust because they have at least one extra copy elsewhere.

All data on server are mapped to windows network drive. It's easy to use and new google desktop can index it! And it is really indexing now! :)

Resource now I have
/dev/hda1 system disk 10G
/dev/hdc5 temporary data disk 10G, used for Bittorrent as well
/dev/sda1 user data 15G
/dev/sda2 repository for fixed data and media 205G NTFS
/dev/sda3 shared data 15G

I bought an external Philips DVD writer last week. At first glance it looks not so good but now I like it very much. :) But I didn't try to burn DVD on Linux yet.

By the way, some often used commands for CVS under linux. Tortoise doesn't work with network drive.

CVSROOT=:ssh:sunwei@192.168.11.99:/home/cvs
(if on the same computer, simply set CVSROOT=/home/cvs)
cvs -q checkout [-r tag] -P ejpgl
cvs -q import ejpgl tcvs-vendor tcvs-release
cvs -q commit *.c
cvs -q tag -c TAGNAME

The last thing is that RealView can't open multiple MP3 files. I installed VideoLAN instead following instructions on VideoLAN site in yum approach. But in 'yum update' it's always error that it can't access some server. I use 'yum clean‘ and 'yum install video-lan' without update and it works.

Thursday, February 8, 2007

Upgrade to Fedora 4

Although RH7.2 works well, it doesn't support some new applications like VLC. I upgrade it into Fedora 4 in last a few days. Another reason I choose Fedora is that it suggests Pentium 500 and 256MB memory. That fits my DELL server well which is PIII 800 with 256MB RDRAM.

There is a great guide about how to set up Fedora 4, step by step, very detailed, http://stanton-finley.net/fedora_core_4_installation_notes.html. I downloaded the image from a mirror site http://ftp.uni-koeln.de/mirrors/fedora/linux/core/

The configuration is almost the same to RH7.2 while I use the whole disk for Fedora. It's because that I noticed some discussion about the problems to have Linux and Windows on the same disk. I also choose all graphical administration tools. After it starts, I disabled unused daemons according to Stanton.

CVS:
It's almost the same to that on RH7.2 while now the cvs is already exists in /etc/xinetd.d. You only need to enable it.

Samba:
You don't need to edit /etc/samba/smb.conf. Now it can be done via graphical tool. The other difference is that user access is not limited to his home directory. You can add any share directory and decide who can access it. After saving, restart smb by 'service smb restart'.

SSH and X-windows:
SSH is enabled by default. To set up remote X-windows, it's the same to that in RH7.2

FTP and web server:
Just enable vsftpd and httpd.

I also connect an external hard disk with NTFS to Fedora. It works well! To do that, we need to download the NTFS package from http://www.linux-ntfs.org/. Note we should download the package for Fedora not old Linux. Then rpm -ivh kernel-module-ntfs-2.6.11-1.1369_FC4-2.1.22-0.rr.6.0.i686.rpm. To be able to be accessed by users other than root, use 'mount -t ntfs -r -o umask=0222 /dev/sda2 /home/repository/'. Done!

Before I found the umask trick, all files are only accessible from root. I made a mistake to use 'chmod -R o+x o+r *' to add permission. I don't know if it would impact the NTFS system. I need to run filesystem check later.

I installed Xilinx EDK8.1 on it. The strange thing is that ISE8.1 always doesn't accept the registration ID which is correct. I try ISE webpack 8.1 later.

Anyway, my computing center is upgraded and now very convenient to use. :P