Category Archives: Cent OS

The Linux File System basics

Each file in a Linux file system (eg, ext2, ext3) is described by an Inode, and every inode is identified by a unique number.
An Inode is a datastructure that describes the blocks of data the file occupies, as well as, metadata about the file like, the file’s owner and group owner, the file’s access permissions(eg rwx-r–r–), it’s size in bytes, timestamps telling when the file was last modified and last accessed and when the file’s status (like ownership etc) was last changed and a count telling how many hard links point to the inode.
It should be noted that the filename is not stored in the inode.

A File’s name along with it’s inode number are stored in special files called directories. In other words, a directory is just another file, which is treated specially by the linux, and it contains a list of filenames along with their inode numbers. All these list of files are assumed to be contained within that directory.

Use ls -i to see the inode numbers of files and directorys .

[tony@localhost ~]$ ls -ila
total 820
65538 drwx-----x 57 tony tony    4096 Feb 22 12:18 .
65537 drwxr-xr-x  4 root root    4096 Jul  6  2009 ..
65997 drwx------  3 tony tony    4096 Jul  1  2009  adobe
66027 -rw-rw-r--  1 tony tony     352 Feb 18 21:56 .aspell.en.prepl

All the inodes of a file system are created at the moment we format the disk (eg, when we use mkfs command). Thus, the maximum number of inodes (and so the maximum number of files) that the filesystem can have, is determined during the filesystem’s creation itself.
These inodes are all kept together in inode tables towards the beginning of the partition. The inode tables usually occupy about 1% of the partition’s space when using the default settings.
The decision as to how many inodes to create is made on Linux using an algorithm. The default setting creates an inode for every 2K bytes contained in the filesystem, but the number can be adjusted by the user when creating the filesystem. For example, it can be wise to create fewer inodes when setting up a filesystem that will contain just a few large files.

It should be noted that, there are two ways in which a filesystem can run out of space: it can consume all the space for adding new data (i.e., to existing files or to new files), or it can use up all the available inodes even when space is left for adding data. I tried to check this myself in a test filesystem, see here if you are intersted.
Use the command df -i to see the number of inodes available, used and free.

[tony@localhost ~]$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/mapper/CentOsVG-RootLV
4161536  155678 4005858    4% /
/dev/sda9              26104      40   26064    1% /boot

Whenever a file is created, the kernel assigns a free inode to that file. The inode is updated to reflect the details of the file. The file’s name, along with that free inode’s number, is written to the directory, the file is supposed to be in.

Hard links and Symbolic links

Hard links are different filenames that point to same inode number (in essence to the same file).
A soft link or symbolic link is a file whose data contains the ‘path’ (eg, /home/tony/resume.txt) of another file(its target).

Since inode numbers are unique only within a filesystem, hard links cannot span across partitions or different filesystems. Where as softlinks can be to anywhere as long as a valid path is there to its target.

[tony@localhost test]$ echo "this is just some contents" > mytestfile  //create a file
[tony@localhost test]$ ln mytestfile myhardlink              //create a hardlink
[tony@localhost test]$ ln -s mytestfile mysoftlink           //create a softlink
[tony@localhost test]$ ls -li
total 8
2687664 -rw-rw-r-- 2 tony tony 27 Feb 22 14:59 myhardlink
2687665 lrwxrwxrwx 1 tony tony 10 Feb 22 14:58 mysoftlink -> mytestfile
2687664 -rw-rw-r-- 2 tony tony 27 Feb 22 14:59 mytestfile

Note in the above shell dialogue that the hardlink and the original file has the same inode number, and the same size.
The soft link has different inode number and of different size, obviously as it is another file whose data has the path to ‘mytestfile

Virtual File System

On top of the underlying filesystem, the linux maintains a Virtual FileSystem (VFS). The VFS is an interface for the operating system, system services, and programs to the underlying filesystem.
VFS allows Linux to support many, often very different, file systems, each presenting a common software interface to the VFS. All of the details of the underlying file systems are translated by VFS so that all file systems appear identical to the rest of the Linux kernel and to programs running in the system.
Each filesystem type supported by your VFS will have an associated driver routines loaded in to the kernel.
Linux’s Virtual File system layer allows you to transparently mount the many different file systems at the same time.

The /proc File System

The /proc file system really shows the power of the Linux Virtual File System. It does not really exist; neither the /proc directory nor its subdirectories and its files actually exist.
The /proc file system, like a real file system, registers itself with the Virtual File System. However, when the VFS makes calls to it requesting inodes as its files and directories are opened, the /proc file system creates those files and directories from information within the kernel.
For example, the kernel’s /proc/devices file is generated from the kernel’s data structures describing its devices.
The /proc file system presents a user readable window into the kernel’s inner workings.

References
http://tldp.org/LDP/tlk/fs/filesystem.html
http://www.linfo.org/inode.html

rar archive support in Cent OS 5

.rar archive is not available in linux by default, but it can be installed by the command

[root@localhost ~]# yum install unrar

This allows you to extract rar files using the command

[tony@localhost ~]# unrar e myfile.rar

The e parameter tells the unrar to extract. More details can be found in man unrar

Now In Gnome, You could right click on the file and click Extract here.

Installing phpMyAdmin in my Cent OS 5.3

I did this by yum, which i think is the easiest way.

[root@localhost ~]# yum install phpmyadmin

This will install it in /usr/share/phpmyadmin

Now, configure it by editing config.inc.php

[root@localhost html]# gedit /usr/share/phpmyadmin/config.inc.php 

add the blowfish secret,
$cfg['blowfish_secret'] = 'a8b7dafdferHJHJ^&U^45776TIUuiYc6d';

and i also changed to mysqli in,
$cfg['Servers'][$i]['extension'] = 'mysqli';

Now you could access the phpMyAdmin by,
http://127.0.0.1/phpmyadmin/

This is possible because an alias is created for apache to the directory where phpMyAdmin in installed [ie /usr/share/phpmyadmin]. This is done in the file,

[tony@localhost ~]$ gedit /etc/httpd/conf.d/phpmyadmin.conf

You will see a lines like,
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

————-

You could also install phpMyAdmin manually by downloading phpMyAdmin.
Make sure you download the version 2.xx and not 3.xx[requires PHP 5.2] as Cent OS 5.3 has only PHP 5.1 by default

Extract the tar.gz file to your desktop.

Copy it to /var/www/html/phpmyadmin as root,

[root@localhost ~]# mv /home/tony/Desktop/phpMyAdmin-3.2.1-all-languages /var/www/html/phpmyadmin

Give the appropriate permission for apache,
Set owner as apache

[root@localhost html]# chown apache -R /var/www/html/phpmyadmin/

Set the group owner as your user, this is good as you can edit the files easily,

[root@localhost html]# chgrp tony -R /var/www/html/phpmyadmin/

Now give group user the write permission

[root@localhost html]# chmod g+w -R /var/www/html/phpmyadmin/

Now, add the blowfish secret and mysqli extension as above,

Thats all.

Mounting the windows fat32 drive on startup for a normal user

This can be done by adding the line similar to the one shown below, to the end of the /etc/fstab.

/dev/sda6     /home/tony/win     vfat     defaults,uid=500,gid=500     0     0

This will automatically mount the fat32 drive/dev/sd6 to the directory /home/tony/win for the user with uid=500 in read/wite mode. Modify the /dev/sdax and /home/tony/win appropriately to reflect your setup.

The uid and gid of the user can be found by the command

[tony@localhost ~]$ id
uid=500(tony) gid=500(tony) groups=500(tony)

Before doing this take a backup of fstab by

[tony@localhost ~]$ su -
Password:
[root@localhost ~]# cp /etc/fstab /etc/fstab.bak

Now you can use gEdit to add the line

[root@localhost ~]# gedit /etc/fstab

Once we add the line, we could check the result of it immediately [without rebooting] by,

[root@localhost ~]# mount -a

Check whether we have the required result, if not modify the lines appropriately and recheck.

If a drive is mounted, you can unmount it, for any reason [perhaps to try another set of options] by,

[root@localhost ~]# umount /home/tony/Data/

A bit of info on how things work.

When a system boots the kernel reads the /etc/fstab and mounts the filesystems specified in it according to the list of options specified.
Each filesystem is described on a separate line. Fields on each line are separated by tabs or spaces.  Lines starting with ’#’ are comments.

The general form of the line is

device     directory     partition-type     mount-options     fs_freq     fs_passno

Lets see the possible values of these fields,
device – the partition as seen by linux
eg: /dev/sda5
/dev/sdb6
/dev/hda7

directory – the directory that will be the mount point
eg: /home/john/windows
/mnt/win

partition-type
eg: vfat
ntfs

mount-options – They are comma separated list of words which determine how the filesystem will be mounted. Some useful options are,
rw – read/write
ro – read only
auto – mounts automatically
noauto – not mounted automatically
exec – allows execution of binary files
noexec – no execution of binary
user – allows mounting by any user
users – allows mounting by any user but any other user can unmount.
sync – data written synchronously
async – data written asynchronously
uid=x,gid=x – Set the owner and group owner of the files (available only for some partition types)

defaults -rw,auto,exec,nouser,async

For full list and and more details on each of the options, check man mount.

fs_freq – This is used by  the dump command  to determine which filesystems need to be dumped. This field is 0 usually. Dump will assume that the filesystem does not need to be dumped.

fs_passno - This is used by the fsck program to determine the order in which filesystem checks are done at reboot time. It can be left 0. fsck will assume that the filesystem does not  need  to be checked.

Source
man mount
man fstab

Prevent gEdit from creating files that end with a tilde (~)

My home directory is full of files ending with tilde (~) created by gEdit. These are backup files created by gEdit when it modifies a file. We can set gEdit not to create backup files by going to Edit > Preferences > Editor and unchecking “Create backup copy before saving

To remove the all those backup files in one step you can try the script described here
http://dambalah.com/?s=gedit