Saturday, January 30, 2010

Unmounting & file system checking

Click Here For Free Windows Downloads
mywindowsdownloads.blogspot.com

Click here for all Free Linux Downloads



Blog address for Linux in Hindi

umount

Sometimes it is required to unmount a directory. For example, Linux doesn’t open the tray of CD drive unless you unmount it. For this, you can use one of the following commands:


# umount /mnt/cdrom
# umount /media/cdrecorder

# umount /dev/sda1

# umount /home/mydisk


Mount and Remount

One of many options in Linux rescue mode is to mount file system, as root ( / ), is read only mode. Or, you may like to mount a file system with programs as /usr in read only mode. For this, you will have to change /etc/fstab file and reboot the system. However, you can check for changes firstly by remounting the directory with required options. For example, if you like to remount /usr directory in read-write mode, you can use the following command:

# mount -o remount,rw /usr


Or if you like to remount / (root) directory in read only mode, you can use the following command:


# mount -o remount,ro /



The above changes remain applied until you reboot the Linux system. For making the changes permanent you will have to edit /etc/fstab file, using any of the text editor command, like vi.



Troubleshooting with fsck


The fsck command is one important tool, used by Linux to automatically check for the partitions on the system. If your Linux system has trouble in mounting any particular partition, file system integrity check fails in some way. In either case you will have to check for failed operation using fsck.

This command can check and repair the Linux file system. fsck command runs the desired dedicated commands for specific file system, like fsck.ext2, fsck.ext3 or fsck.reiserfs, in background.


Note:
We should not run fsck command on the mounted partition, as it may lead to file system damage.

Switches with fsck command

Switch Details

-A Checks for all the file systems listed in /etc/fstab
-a Automatically repairs the file system without prompting
-R With –A option it will skip checking the root ( / ) file system.
-y It sets the default answer of “yes”, for any suggested solution.

Friday, January 29, 2010

Disk space checking with df and du

Click Here For Free Windows Downloads
mywindowsdownloads.blogspot.com

Click here for all Free Linux Downloads



Blog address for Linux in Hindi


The du and df are two similar disk management commands. du, the directory usage, command shows the amount of space used by each file in and under the current directory. df, the disk free, command shows the amount of space available on each hard disk volume.
Type df without options, to see amount of space available on all the mounted file systems on Linux computer.

# df



To get output in more human readable form, use –h option as follows:

# df -h



du command, with no option shows all directories below the current directory, along with space consumed by each directory. du is also a good way to check the space being used by particular user or in a particular file system partition. Here also we can use –h option to get the output in more human readable format.

# du -h




Thursday, January 28, 2010

Creating ext3 partitions

Click Here For Free Windows Downloads
mywindowsdownloads.blogspot.com


Click here for all Free Linux Downloads



Blog address for Linux in Hindi



Many a times, after installation, it becomes necessary to create one or two more ext3 partitions. For example, if added a new hard disk within the system, then you will have to create a new partition. The following steps will be needed to create partitions:


1. Create partition using fdisk or parted utility
2. Format the newly created partition before using it, with the help of mkfs utility
3. Label the new partition using e2label utility, this is optional step
4. Mount this newly created partition within the existing file system
5. Make the mounting permanent by adding the entry in /etc/fstab file


Steps in creating a new partition:



1. Install a fresh hard disk in the system.

2. Boot the system from already installed Red Hat Linux.

3. As root user, type the following command to check whether new disk has been detected:


# dmesg | less



In the output of this command, check for the device name. If the hard disk added was second SATA, then we should see something like sdb:.
Or, you can run the command


# fdisk -l



Some where near the end of its output you should see a line like:
Disk /dev/sdb doesn’t contain a valid partition table

4. Now since you have come to the device name for this hard disk, you can run the following command to open up this hard disk:

# fdisk /dev/sdb



If it is a completely new hard disk, you will see a message telling that this hard disk does not contain a valid partition table, as we saw in the previous command. If it doesn’t show it, this will mean that it is old hard disk.

5. We can get help of all the commands which can be used here. For this just press m on the prompt like Command (m for help):

6. To create new partition type n, as follows:

Command (m for help): n

7. Here you will be asked to choose primary or extended partition. To choose for primary partition, type the following:

Command action

e extended
p primary partition (1-4)
p

8. Now you will be asked for the partition number. If you are creating first partition, type one:

Partition number (1-4): 1

9. Now you will have to tell the cylinder number. Here just press ENTER, to accept default, or specify the desired number:

First cylinder (1-4865, default 1): 1

10. Lastly, either define the last cylinder, if you know, else define the space in MB. Default is last cylinder to use entire hard disk:

Last cylinder or +size or +sizeM or +sizeK (1-4865, default 4865): +5000M

11. Repeat the previous five steps to create more partitions on the disk.

12. Save changes to the disk using w, this will send you back to the shell.

13. At this point of time, to make the changes effective, just restart the system. Instead of restarting the system, you can run the partprobe command as well.


# partprobe



14. Now we will have to make the file system on this partition, i.e. format the partition. To create an ext3 file system on the first partition of this disk, type the following:


# mkfs -t ext3 /dev/sdb1



Alternatively, if you are formatting a partition for Linux swap space, you can use mkswap command, e.g. if you want to setup /dev/sdb2 as swap partition, you can run the following command:


# mkswap /dev/sdb2



15. If you created other partitions also, repeat the above step one by one for all the partitions (like /dev/sdb2, /dev/sdb5 etc.)

16. To use the partition just created, make a directory to mount on it:


# mkdir /home/mydisk


17. Now mount it like this:


# mount /dev/sdb1 /home/mydisk



18. Above method of mounting is temporary, i.e. at next reboot you will again have to mount it before you can use. For mounting it permanently you will need to add an entry, like below, in /etc/fstab file:

# vi /etc/fstab

/dev/sdb1 /home/mydisk ext3 defaults 1 2


In this example, the partition /dev/sdb1 has been mounted on /home/mydisk directory as an ext3 file system. The defaults keyword causes the partition to get mounted at booting time itself. Numbers 1 2 cause the file system neither be dumped nor be checked by fsck.

That is all; you can start using the new partition. Now if you want the above file system to adjust as per your needs, then you can use tune2fs command. Using tune2fs command, you can change the file system error behavior, change volume label, how often the file system be checked or you even can change ext2 file system into ext3 file system so that journaling can be used.

# tune2fs -j /dev/sdb1


This example assumes that /dev/sdb1 was an older partition formatted with ext2. Running the above command will automatically convert this partition into ext3 file system. After you have used tune2fs, you will need to correct your /etc/fstab file to change the system type from ext2 to ext3.

Wednesday, January 27, 2010

The ext3 file system and its features:

Click Here For Free Windows Downloads
mywindowsdownloads.blogspot.com


Click here for all Free Linux Downloads



Blog address for Linux in Hindi


In Red Hat Linux the default file system is ext3, which an enhanced version of ext2 file system. Few of the ext3 features are as follows:


Consistency:

The ext3 file system provides the journaling, which means that e2fsck type of system checking is not necessary after improper system shut down. Actually e2fsck program used to check each mounted ext2 file system, which was a very time consuming process. And moreover, during this time any data on those volumes could not be accessed. Time taken in recovering an ext3 file system after improper shut down depends on the size of journal used to maintain consistency. It takes only one second to recover the default journal size.


Throughput:

Ext3 file system has higher speed than ext2, because the hard disk head motion is optimized now.

Integrity:

In ext3 file system you can select the level and type of protection, the data should receive. Its volumes are configured for high level of data protection

Partition types


We have three types of partitions, which can be configured on any hard disk. These are:

1. Primary partition- These are made up as the starting point for any O.S. to boot, as it stores the boot loader such as GRUB or LILO. We can make up to four primary partitions on a single hard disk, and only one out of these can be made active, to boot from.

2. Extended partition- This partition is made for increasing the number of partitions on the hard disk. We can make only one extended partition on the disk. We can neither use this partition directly nor make it active. We will have to make at least one partition within it, then only it can be used.

3. Logical partition- These are the partitions made within the extended partition. We can make maximum of 11 logical partitions on SCSI disk and maximum of 12 logical partitions on IDE disk.

Monday, January 25, 2010

Red Hat Linux file system:

Click Here For Free Windows Downloads
mywindowsdownloads.blogspot.com


Click here for all Free Linux Downloads



Blog address for Linux in Hindi

File system of any operating system used to be the structure, in which all the information on our system is stored. The file system is organized in hierarchy of directories, which may contain files or the subdirectories as well. A file system can be of different format which is called file system type. These file system types determine how the information can be stored as files or as directory. In Linux there are following types file system, which we generally use: ext3, swap, LVM and RAID.


Linux file system structure:


Red Hat Linux organizes file into directories. The standard directories are as follows:

/ This is top level root directory. The remaining directories are kept below this root ( / ) directory, i.e. these are subdirectories of root directory.


Note: / is different from root. Both are pronounced as root, but former is directory while later is a user with administrative privileges.


/root This is the home directory for root user (administrator).


/home This directory is place for keeping all the user’s home directories except root user.


/dev This directory will list all available device drivers.


/mnt It contains the mount points of removable media, like /mnt/cdrecorder


/etc It contains the basic Linux configuration files related to passwords, Xwindow and

daemons etc.


/boot It store the file and commands to boot Linux on our system.


/bin It has all the basic command line utilities.


/lib It lists program libraries, which may be needed by different applications or Linux kernel.


/proc It includes the kernel related processes which are running currently.


/initrd It configures one empty directory which is used by Initial RAM disk during boot. We should not delete this directory; else we will not be able to boot the Linux system.


/sbin It contains commands for system administration.


/var It contains log file and print spools etc.


/usr It contains programs and data which is available to all the users.

Saturday, January 23, 2010

Red Hat Linux file system:

लिनक्स संबंधी सभी डाउन लॉड् के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:

File system of any operating system used to be the structure, in which all the information on our system is stored. The file system is organized in hierarchy of directories, which may contain files or the subdirectories as well. These file system types determine how the information can be stored as files or as directory. In Linux there are following types file system, which we generally use: ext3, swap, LVM and RAID.


Linux file system structure:


Red Hat Linux organizes file into directories. The standard directories are as follows:


/ This is top level root directory. The remaining directories are kept below this root ( / ) directory, i.e. these are subdirectories of root directory.

Note: / is different from root. Both are pronounced as root, but former is directory while later is a user with administrative privileges.

/root: This is the home directory for root user (administrator).

/home: This directory is place for keeping all the user’s home directories except root user.

/dev: This directory will list all available device drivers.

/mnt: It contains the mount points of removable media, like /mnt/cdrecorder

/etc: It contains the basic Linux configuration files related to passwords, Xwindow and daemons etc.

/boot: It store the file and commands to boot Linux on our system.

/bin: It has all the basic command line utilities.

/lib: It lists program libraries, which may be needed by different applications or Linux kernel.

/proc: It includes the kernel related processes which are running currently.

/initrd: It configures one empty directory which is used by Initial RAM disk during boot. We should not delete this directory; else we will not be able to boot the Linux system.

/sbin: It contains commands for system administration.

/var: It contains log file and print spools etc.

/usr: It contains programs and data which is available to all the users.

Friday, January 22, 2010

ACL continued...

लिनक्स संबंधी सभी डाउन लॉड् के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:


Setting ACL

setfacl

This utility sets the ACL for files and directories. We should use –m option to add or change the ACL for a file or directory:

setfacl -m rules files

The rules must be used in the following formats. We can use multiple rules in the same command by separating them with commas.

o:perms
It sets the ACL for users other than those in group for the file.

u:uid:perms
It sets the ACL for user. We should specify the user name or UID in place of uid.

g:gid:perms
It sets the ACL for group. We should specify the group name or GID in place of gid.

m:perms
Its sets the effective rights mask. It is union of all the permissions of owning group and all the user and group entries.

Permissions should be a combination of r (read), w (write) and x(execute). The white spaces are ignored. If the file or directory already has ACL, and we use setfacl command for it, then additional rules are added to the existing ACL. For example, to give read and write permission to user anil, we will use the following command:

# setfacl -m u:anil:rw /home/project

To remove all permission of user, group or others, we can use -x option. Here we will not specify any permission:

setfacl -x rules files

For example:

# setfacl -x u:502 /home/project
Setting default ACL

To set default ACL, we will have to add d: before the rule and instead of file name we will have to specify a directory name. For example, to set the default ACL for /home/shared directory for others to read and execute, we can use the following command:

# setfacl -m d:o:rx /home/shared

Retrieving ACL

To find the existing ACL of a file or directory, we will use the following command syntax:
getfacl filename

It will return the output similar to this:

user::rw-
user:vijai:r- -
group:: r- -


Thursday, January 21, 2010

Access Control Lists (ACL)

लिनक्स संबंधी सभी डाउन लॉड्‍स के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:

All the files in Linux have some kind of permissions defined for owner, group members and others. These permissions, however, have some limitations, that is we can not set different permissions for different users. And that is why Linux has implementation for Access Control Lists. Red Hat Enterprise Linux 5.0 provides ACL support for NFS exported file system, ext3 file system and also for Samba.

For implementing ACL, we should have kernel support as well as acl package in Linux. The acl package provides utilities to add, remove, retrieve or modify the ACL information. The commands like mv and cp move and copy the ACL information linked with files and directories.
Here we will study the following topics associated with ACL:

1. Mounting the file system
2. Setting ACL
3. Retrieving ACL
4. Archiving file system with ACL

Mounting the file system

Before we can use ACL, we should make sure that the desired partition has been mounted with ACL support. For ext3 file system we can use following command:

# mount -t ext3 -o acl device_name partition

As:

# mount -t ext3 -o acl /dev/volgroup1/logvol1 /home/mylv1

Or, we can use /etc/fstab file and make an entry like this:

LABEL=mylv1 /home/mylv1 ext3 acl 1 2

If the above ext3 file system is accessed through Samba and ACL have been enabled for it, Then the ACLs are effected because Samba has been compiled with the acl support option.

Similarly, the ACLs are effected for NFS also. If we do not want ACL on NFS share, we can disable it by including no_acl option in /etc/exports file.

The ACLs are of two types:

1) Default ACL and 2) Access ACL.

The default ACL can be associated with the directory only. These are optional. Whereas, the access ACL can be associated with specific file as well as directory both.

We can configure ACL for:

1. Per user
2. Per group
3. For users not in user group for file
4. Through the effective rights mask

Wednesday, January 20, 2010

Text Editor: vi

लिनक्स संबंधी सभी डाउन लॉड्‍स के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:

vi


It is a text editor in Linux. We use vi, either to create a new file or to modify an old file. It should be used with a file name following it, which is as follows:


# vi /home/anil/file1

If it is a new file, we will see something as under:


~
~
~
~
~
“/home/anil/file1” [New File]


There are three modes of working in vi editor. These are:

Command mode, Text mode, and Execute mode.


Command mode:

It is the default mode. It is used to search text, delete characters, words or lines or scroll within the text. We can come back to the command mode from text mode by using escape (Esc) key. We can use this mode to enable line numbering also, which is as follows:

: set nu


Deleting text

To delete the text in vi, we have three commands associated with the current location of cursor:

dd To delete the whole line
dw To delete current word
x To delete current character


Searching text

Searching of text can be done easily with forward slash. For example if we want to search the word India, we can type the following:

/india

It will highlight the first place of the found word. To go to the next instance just press n.

Other commands used within command mode are:

Saving text :w
Quitting after saving :q
Saving and quitting :wq
Forcefully quitting without saving :q!


Text mode:

We use text mode to type in the text in the file. We have the following options to insert the text:

Command Action Details

i : insert What ever we type, will be inserted from the current position of cursor

a : append What ever we type, will be inserted from one position after the current
position of cursor

o : open What ever we type, will be inserted from one line below the current
position of cursor

O : open What ever we type, will be inserted from one above the current
position of cursor

cw : change word Replaces the word that comes after the current position of cursor

Execute mode:

We can run regular bash commands from here. For this just type :! followed by the command. For example:

:!ls /etc/cron.daily

This will list all files in /etc/cron.daily directory.

Tuesday, January 19, 2010

Permissions and Umask

लिनक्स संबंधी सभी डाउन लॉड्‍स के लिए निम्न लिंक क्लिक करें:


हिन्दी लिनक्स ब्लॉग का एड्रेस:

chmod


As shown in the output of ls -l command above, each and every file has the permissions associated with it. These permissions are defined for three types of persons namely- the owner of the file, the group members of the owner, and all other persons who are not the members of the group whom this owner belongs to. Let us have a look on following line:


-rwxrw-r-- 1 root root 468 Aug 8 07:15 file1


Permissions are defined within first ten characters of the above like output from ls -l. Normally, the first character can either be - or d, - represents that it is a file while d represents a directory. Remaining characters are grouped in set of three characters which are r (read), w (write), and x (execute).


In the above example first three characters are rwx which means owner of the file has all the permissions on file1. Next three characters are rw- which will mean the group members will have read and write permission on file1 but not execute permission on it. The last set is r—which will mean that others will only have read permission on file1 but they will not have write and execute permission on file1.


We can set the permissions by using chmod command. For example, for setting the permissions as above we can run the following command:


# chmod 764 file1


We can use the following example to find any type of permission, we want to set.



umask


When new files or directories are created, they get some default permissions. These permissions depend on value of umask. This command when used alone will show the current numeric masked value of the permissions. This is as under:


# umask

0022


Here we should remember that first number is not currently in use, therefore, the actual mask will be 022 in the above example. We should remember that, by default, execute permissions are off for regular files, i.e. we can not assign x permission by umask. Hence, umask value masks the permission value of 666 for a file and 777 for a directory.


1. For finding the desired umask value for files, we will see the following examples:


Desired permission r w - r - - r - -

Binary equivalent 4 2 0 4 0 0 4 0 0

i.e. 6 4 4


umask value 6 - 6 6 - 4 6 - 4 (for file umask always subtract from 6)

i.e. 0 2 2 (so the actual umask will be 022)


2. For finding the desired umask value for directory, we will see the following examples:


Desired permission r w x r - x r - x

Binary equivalent 4 2 1 4 0 1 4 0 1

i.e. 7 5 5


umask value 7 - 7 7 - 5 7 - 5 (for file umask always subtract from 6)

i.e. 0 2 2 (so the actual umask will be 022)


Hence, we saw that umask value 022 will result in default permissions of rw-r--r-- for file and of rwxr-xr-x for directory.