Thursday, January 31, 2008

Installing Asterisk PBX on Redhat Centos 5

This was easy and fast:
# mkdir asterisk
# cd asterisk
# wget http://redhat.theplanet.com/asterisk/asterisk-1.4.10.1.tar.gz
# tar xzvf asterisk-1.4.10.1.tar.gz
# cd asterisk-1.4.10.1/
#./configure
# make
# make install
# make samples

How to reinstall a package with Yum (Redhat/Fedora)

Yum does not has a feature to reinstall a package, though, there is a little walk arround:

[root@mutant build]# rpm -e --justdb --nodeps [package name]
[root@mutant build]# yum install [package name]

Sunday, January 06, 2008

Resizing a partition in linux with parted

To resize an ext3 partition comes handy LVM, but i will explain how i did it without. I did this in a Fedora 6, booting with a Fedora 7 or Knoppix disk and entering into rescue mode, sorry but i can not take any resposibility if something goes wrong while following this procedures>

After getting the prompt in Fedora 7 or any other distro in rescue mode, unmount all the partitions of the filesystem you want to resize, in my case it is the disk /dev/sda, but it could be /dev/hda

Fedora 7 rescue disk has parted installed and i get , so we are going to use it.
#umount /dev/{sda1,sda2,sda3}
Check the Filesystem to resize, i am going to shrink sda2 first
#e2fsck -f /dev/sda2
Resizing the partition:
#resize2fs -p /dev/sda2 2600M
The size parameter may be suffixed by one of the following the units designators: 's', 'K', 'M', or 'G', for 512 byte sectors, kilobytes, megabytes, or gigabytes, respectively. The -p argument is to display a nice status bar.
The message on screen is:
Resizing the filesystem on /dev/sda2 to 665600 (4k) blocks
So i do the calculation of how many bytes this is to use it later in fdisk:
665600 blocks * 4k = 2662400 Bytes.
My partition had 4 G before, now, after resizing, the partition will still have 4G, but "resize2fs" has prepared for a technical surgical procedure ;-) we are going to delete the partition and recreate it

I entered fdisk and deleted the /dev/sda2 partition, then i recreated it with the same starting cylinder and +2662400K as size (this is imperative and may loose all your information if you do not do this right, again, i take no responsability, the results may depend on filesystems). Then i wrote the partition with "w" and went back to the shell.

Now i execute again:
#resize2fs -p /dev/sda2 2600M
And this command to recreate some information of the partition table.
#e2fsck -f /dev/sda2
Time to reboot and see if all is ok, yes it is all fine and the partition has now 2662400 K.

Now it is time to resize the next partition, /dev/sda3, to take the space left by /dev/sda2, another surgical procedure is required.

Enter the rescue mode again, umount the partitions that are going to be resized and lets delete /dev/sda4 to begin at the end of /dev/sda2, this is done with "fdisk".
From the resize2fs man page:
If you wish to shrink an ext2 partition, first use resize2fs to shrink the size of filesystem. Then you may use fdisk(8) to shrink the size of the partition. When shrinking the size of the partition, make sure you do not make it smaller than the new size of the ext2 filesystem!

My partition distribution looks like this now:
start end
/dev/sda1 1 13
/dev/sda2 14 345
/dev/sda3 1012 1043
/dev/sda4 744 1011

Start - End
1 - 32,3 kb - 107 MB
2 - 107 MB - 2838 MB
4 - 6111 MB - 8316 MB
3 - 8316 MB - 8579 MB

The beginning of /dev/sda4 should be 346, so i used parted to move the partition. Be careful, it is not possible to delete the partition and recreate it with fdisk (well, it is possible but it would corrupt the partition because the partition table would be in the middle of the disk).

#parted
(parted) move
Start? 3000MB
End? 5204MB
Something curious happened here, i had to specify "MB" at the end of the numbers, else it gave me an error about "Can't have overlapping partitions"

Friday, January 04, 2008

First notes about Minix Source code.

I hope not to loose the path with this post, it is about Minix Source code which i am studying for curiosity, but would also be applicable to Linux kernel source code. It is about some conventions used while coding header files in C.

In some headers i find this:
PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)];
PRIVATE int mini_send() {...};
EXTERN struct proc proc[NR_TASKS + NR_PROCS];


These words are not from C, they are macros declared in a header src/include/minix/const.h file, like this:
#define EXTERN extern /* used in *.h files */
#define PRIVATE static /* PRIVATE x limits the scope of x */
#define PUBLIC /* PUBLIC is the opposite of PRIVATE */


The extern keyword
C permits to link together various modules already compiled, for better management possibilities and time reduction in big projects. The global variables have to be declared just one time. So, a solution is to declare all the global variables in one of the files, and in the other files where this variable is required, use the "extern" declaration. The "extern" work gives the compiler the information to know the types and names of the global variables, without creating a new storage.

The static keyword
The static variables have different effects when they are local or global.
Static local variables:
When the static modifier is applied to a local variable, the compiler creates a permanent storage for it. The difference between a local static variable and a global one, is that the local static variable is only known in the block in which it is declared. It is a variable that whoes value remains between the function calls.
Example:
adding (void ) {
static int age;
age = age + 1;
return age;
}

The variable age keeps existing between calls to the function, which returns always a new number.
Static global variables
This variables are only known in the file where they where declared, this means that though the variable is global, the other files are not going to see it, nor modify its content directly.

Tuesday, January 01, 2008

What is and how to setup SUDO in Linux

First of all, happy 2008 to everybody. To begin 2008 a post about SUDO and security configuration.
The program sudo (SuperUser DO) is an utility from the unix operating systems like Linux, BSD or MAC OS X, that gives the normal users the possibility to execute programs with security privileges of the admin user (root).

How to set it up ?
Write "visudo" as the administrator
# Host alias specification
# Here you set up the hosts from where should the rule be applied, in this it is for local users
Host_Alias LOCALHOST=127.0.0.1
# User alias specification
# SYS is just a group name, it can be any string, you will use it later in this same file.
User_Alias SYS=user1, walter, user2
# Here we define the binaries that can be executed.
Cmnd_Alias SQA=/root/sudoers/program1.sh,\
/root/sudoers/program2.sh,\
/root/sudoers/program3.sh
# User privilege specification
root ALL=(ALL) ALL
# This specifies that no password has to be asked when executing the command.
SYS LOCALHOST=NOPASSWD: SYS