Documente Academic
Documente Profesional
Documente Cultură
• Basic Commands
• Disk Management
• User Management
• Basic Utilities to monitor and Troubleshoot
• Installing Applications
• Gui
• CPU, RAM, HDD, I/O Devices
• Command Line
• root, su, su user, su – user
• changing passwords
• /etc/passwd, /etc/shadow
1
o The shell - The shell is primarily a command interpreter. The
shell accepts commands you enter, interprets these commands,
and then passes them to the kernel for execution.
The 3 most common primary shells are :
Bourne Again (Bash) shell
C shell
Korn shell
2
These days, the distinction has rather blurred as users run powerful
multi-user multi-tasking OS’s on their PC. I would therefore define
the
CONSOLE as the display used to boot the system, and any other
display as a
terminal. This would be especially true of an X system: in the X GUI
all
the windows are effective terminals; the system console is the text
based
access available via CTRL-ALT-F1.
3
sections for passwd man page), man –s 4 passwd (to check section 4
of man page).
Exercise :
To use the output of the ps command as input for the tail command
and
4
list the word count, enter the following:
$ ps -ef | tail +2 | wc -l
74
To set history
ls /etc
5
To view a recursive list of the contents of the dir1
directory, enter
ls -R dir1.
$ ls -R dir1
$ cd
$ cd dir1
$ pwd
/export/home/user1/dir1
$ cd ../dir2
$ pwd
/export/home/user1/dir2
$ cd
$ cd dir1/coffees
$ cd /export/home/user1/dir1/coffees
6
There are two ways to display file types. You can use the ls
-F command or you can use the file command.
#file filename
Will display detailed information of the file
#file
$ ls -F
7
d Directories - Directories store information that associates
file names with inode numbers. Unlike regular files, which
can hold many different types of data, directories only hold
file name-to-inode associations. A directory contains entries
for files of all types that are logically found within that
directory.
# ln -s file1 link1
# cd /dev
# ls -l
9
Information in each inode keeps count of the number of file
names associated with it. This is called a link count. In the
output from the ls -l command, the link count appears
between the column of file permissions and the column
identifying the owner. In the following example, the file
called file1 uses one hard link.
# cd dir1
# touch file1
# ls -l
total 0
-rw-r--r-- 1 root other 0 Apr 7 15:26 file1
A new hard link for a file name increments the link count in
the associated inode. In the following example, inode 1282
now has two hard links, one for file1 and the other for
file2. The ls -li command lists the inode number in the
left-most column. The find -inum command locates files
and directories that have the same inode numbers.
# ln file1 file2
# ls -l
total 0
-rw-r--r-- 2 root other 0 Apr 7 15:26 file1
-rw-r--r-- 2 root other 0 Apr 7 15:26 file2
# ls -li
total 0
1282 -rw-r--r-- 2 root other 0 Apr 7 15:26 file1
1282 -rw-r--r-- 2 root other 0 Apr 7 15:26 file2
# find . -inum 1282
./file1
./file2
10
Removing Hard Links
Deleting one of the files has no effect on the other file. The
link count decrements accordingly.
# rm file1
# ls -li
11
User Management
Adding Users
/etc/skel
Note : By default Redhat linux UID’s start from 500 by default and are
incremented by 1, everytime a new user is added. In Suse Linux UID’s start
from 1000.
Set the password for the user you created by using the passwd command
# passwd user1
Note: If you want to change a password of a account you are logged into, just
execute the passwd command and press enter and you will be prompted to
enter a new password and confirm it.
12
Passwords are encrypted in the /etc/shadow file using the MD5.
You can find out all shells installed on the OS by using the cat /etc/shells
command and it will display all the shells that are supported by the
distribution.
When you create a account the entries are made into /etc/passwd file and
when you create a password for that user using the passwd user command,
entries are updated in /etc/shadow file.
You can use the stat passwd command to display information of the file, the
date it was modified etc.
13
Modifying a User Account
Use the usermod command to modify a user’s login account on the system.
Option Definition
-o Allows a UID to be duplicated.
-m Moves the user’s home directory to the new location
specified with the -d option.
-l newlogname Changes a user’s login name for the
specified user account.
-f inactive Sets the number of inactive days that are
allowed on a user account. If the account is not logged in to
for the specified number of days, it is locked.
-e expire Sets an expiration date on the user account.
Specifies the date (mm/dd/yy) on which a user can no longer
log in and access the account. After that
date, the account is locked.
loginname Identifies the user’s login name for the current
user account.
Deleting a user
14
userdel -r login
15
Basic File permissions
16
HL UID GID Size
17
Symbolic mode uses combinations of letters and symbols to
add or remove permissions for each type of user.
Octal mode uses octal numbers to represent each
permission. Octal mode is also referred to as absolute mode.
$ ls -l dante
-rw-r--r-- 1 user1 staff 1319 Mar 22 14:51 dante
$ chmod o-r dante
$ ls -l dante
-rw-r----- 1 user1 staff 1319 Mar 22 14:51 dante
+ add permissions
- remove permissions
= absolute permission
18
Octal Digits for Permission Sets
$ ls -l dante
-rw-rw-rw- 1 user1 staff 1319 Mar 22 14:51 dante
$ chmod 555 dante
$ ls -l dante
-r-xr-xr-x 1 user1 staff 1319 Mar 22 14:51 dante
19
To change group permission to read and execute only, enter
the following:
$ chmod 755 dante
$ ls -l dante
-rwxr-xr-x 1 user1 staff 1319 Mar 22 14:51 dante
umask
The umask utility affects the initial permissions for files and
directories when the files and directories are created. The
umask utility is a three-digit octal value that is associated
with the read, write, and execute permissions. The first digit
determines the default permissions for the owner, the second
digit determines the default permissions for the group, and
the third digit determines the default permissions for other.
21
You can apply this same process to determine the default
permissions when you create new directories.
Use the default umask value of 022 to remove (or deny) write
permission for group and other. The result in octal mode is:
4214-14-1 or 755
22
The new umask value affects only those files and directories
that are created from this point forward. However, if the user
logs out of the system, the new value (027) is replaced by
the old value (022) on subsequent logins because the umask
value was changed using the command line.
System Wide Umask set in /etc/bashrc for the bourne again shell
and /etc/csh.cshrc for the c shell.
User specific umask to be set in their respective profile
/home/abc/.bash_profile
23
#umask
Will display the default umask
#stat /tmp
Will display the directory information, including the default
umask the system took while creating the directory.
#which useradd
Will display the location of the useradd command
24
Vi Editor
#which vi
#cd /etc
#vi fstab
You can use the arrow keys to move up, down, left & right or
You can use the j key to move down, k key to move up, l key
to move right and h key to move left.
To use help in vi, press ESC key, then type :help and press
the Enter key.
To quit from help mode press ESC key, and type :q and
press Enter.
25
To continue searching for another instance of same
keyword, simply press the n key.
Press CTRL+g to view how many lines are there in the file
and in what position of line the cursor is in..
To delete more than one line, take your cursor to the first line
from where you wish to delete and press 4dd and it will
delete the 4 lines from the specified location.
26
To delete the rest of the line from a specific point, take your
cursor to the desired location and press d$.
Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)
Useful Commands
27
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME
%%.*}:${PWD/#$HOME/~}\007"'
PWD=/root
28
GRUB – Grand Unified Boot Loader
Its always a good idea to maintain multiple boot entries in the GRUB menu
so that you can boot into the various kernels incase of difficulty.
When the system is powered on the bios detects the necessary hardware
including the RAM. Once the hardware detection process is complete, the
next step is to hand over the boot process to the default hard disk on the
system and to the first sector of that particular hard disk, i.e. the first 512
bytes, the magical area on the hard disk, referred to as the MBR (Master
Boot Record) and it fits perfectly in the boot sector.
Immediately after the grub stage 1 process calls stage 1.5 and entrance stage.
Stage 1.5 provides support for various file systems. We will see that
information later on when the system is up, where that information is stored.
Stage 1.5 has knowledge, the know how and support for various file systems
including ext3, ext2, iso9660 i.e. CDROM etc. Stage 1.5 then invokes stage 2
and stage 2 will eventually hand over the boot process to the actual Linux
kernel vmlinuz residing in /boot.
Press p at the grub screen and we enter into the grub configuration mode.
Pressing e will take us to a next screen showing the 2 kernels which were to
be loaded, if it was to be selected.
Note: Pressing ESC will take you back to the main menu.
29
30
Notice the hd0,0. The hd0 is the first hard disk in the system. This parameter
is passed from the bios of the system to grub. Whatever the bios believes to
be the bootable hard disk will be displayed as hd0. But this does not mean
that grub is restricted to booting from the first hard disk only. Grub is
capable of booting from other hard drives. But the menu item root would be
needed to modified to reflect the altered configuration. Note that the root in
the first entry doesn’t mean its looking into the / root file system of Linux.
Instead it looks for the /boot file system where the kernel is located.
The 2nd zero following the hd0, is the first partition. Recall while installing
RHEL, the /boot filesystem was added to the first partition. The next
directive in the grub list is the kernel. This instructs grub where to find the
kernel.
The kernel version shown in the grub is 2.6.9-5.EL and its mounted in read
only(ro) mode and root label is the forward slash / indicating that this is the
root file system.
Grub hands over or attempts to boot the system and loads the kernel in read
only mode as well as the initial ram disk. The initial ram disk really provides
access to memory (RAM). It functions initially in read only mode for the
loading of drivers that are needed for accessing the real /(root) file system.
The idea here for modularity, so that kernel can be of small size and consult
modules during boot time or at run time for providing support for hardware
that are attached to the system such as network card etc.
Once the file system is mounted in rw mode the kernel gets rid of the initial
ram disk that was loading during the boot process.
31
To edit parameters move the cursor using the arrow keys to the entry and
press e. The screen below shows editing of the boot device from hd0,0 to
hd1,0, which means that grub should look into the 2nd hard disk
Note: Grub at this stage has access to the file system. It has the driver to load
ext2 filesystem. The entry for booting another linux kernel can be added or
the current entry modified to load another kernel which exists on the
filesystem.
To modify the kernel, such as the smp kernel to run in single user mode
move the cursor to the entry in grub and press the a key.
The above screen shows adding single to the booting option which passes the
parameter single to grub, which starts the system in a single user mode.
Another way to start linux in single user mode is to type init=1 instead of
single and the system will come up in single user mode, which is init 1.
To work in the command line mode of grub, at the main screen type c, the
grub command line interface will come up. Type help and press enter to see
help related to all commands in the command line mode.
32
In the command line mode tab completion of commands is support. Type re
and press tab and grub will display the information about the available
commands. Type reb and press tab key and grub will complete the command
to reboot.
1. Reboot the system if the system is running using the reboot command.
The reboot command really runs init with the 6th run level.
2. Boot the system with the RHEL CD1 which is used to install. On the
installation screen press F5 key to enter into rescue mode.
3. Once you see the rescue screen, simply type linux rescue.
4. Once the system runs in rescue mode a linux kernel is booted from the
CD-ROM
5. The kernel will load device drivers, network interface etc and will
prompt to mount the hard disk to /mnt/sysimage, this is the location of
the root file system of the hard drive which needs to be repaired or
modified, etc incase a administrator needs to.
6. Finally the system will display a shell prompt(bourne shell) and the
root file system will now be mounted into /mnt/sysimage for repairing.
33
File System Management Tools
Ext3 is a modern day file system which includes journaling. Ext 3 is the
successor to the Ext2 file system. Because ext3 provides journaling which
provides fast recovery of the operating system in the advent of an unexpected
or unanticipated power failure.
/boot – This partition should be about 100 Mbytes.
To alter the disk partitions in Linux use the fdisk or the parted utility.
Another tool an administrator can use is the system-config-lvm tool to
configure logical volumes.
Note: Do not make changes to a mounted partition. Start the system in single
user mode, backup the data if any and then make changes to active partitions
if necessary.
The default tool which gives you a quick snapshot of various partitions/slices
on your system is called df.
When you run df without options it returns the amount of 1k blocks that are
available, the amount used, the amount available, which reflects the
difference between total blocks used.
[root@server grub]# df
Filesystem 1K-blocks Used Available
Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
4483148 2525068 1730344 60% /
/dev/sda1 101086 9132 86735
10% /boot
34
none 128020 0 128020 0%
/dev/shm
df –h option will return the outpout in human readable format i.e. KB, MB,
GB etc.
The /etc/fstab file is the location of mappings between mount point and the
device location.
The first column in the /etc/fstab file indicates the device location, the second
column generally locates the mount locations.
35
Fdisk utility
Running the fdisk utility with the –l option lists the currently attached and
mounted disks/partitions
Executing fdisk /dev/sda will allow you to create, edit, delete, print partition
table of the SCSI disk 1, represented as /dev/sda.
Press l to see the list of supported file systems supported by the Linux
system. A p will print the current partition table.
37
[root@server ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition
table, nor Sun, SGI or OSF disklabel Building a new
DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of
course, the previous
content won't be recoverable.
38
In the above example a Scsi disk 2 was loaded in fdisk and a new extended
partition was created. Inside a extended partition logical partitions can be
created. The example below shows created logical partitions in extended
partition
Deleting a partition
40
/dev/sdb5 1 62 497983
83 Linux
/dev/sdb6 63 130 546178+
83 Linux
Note: We deleted partition 5, but partition 5 is still listed. What fdisk does is
once it deletes a lower numbered partition; the higher numbered partition is
decremented, in the above case partition 6 automatically decremented to 5
once partition 5 was deleted.
41
Device Boot Start End Blocks
Id System
/dev/sdb1 1 130 1044224+
5 Extended
/dev/sdb5 1 62 497983
83 Linux
/dev/sdb6 63 130 546178+
83 Linux
[root@server ~]#
42
The file /proc/filesystems houses the filesystem that are supported by the
kernel.
43
The mke2fs utility is used to format and create filesystems to be mounted
and used.
45
To create the ext2 filesystem, execute the following command
Note: When executing mke2fs without any options, the default set of options
are applied. The above command created ext2 filesystem which is the
default.
46
47
Finally once the filesystem is ready to be used, a mount point needs to be
created. To check which slices on hard disks are available on your system
exectute
[root@server /]# df -h
Filesystem Size Used Avail Use% Mounted
on
/dev/mapper/VolGroup00-LogVol00
4.3G 2.5G 1.7G 60% /
/dev/sda1 99M 9.0M 85M 10% /boot
48
none 126M 0 126M 0%
/dev/shm
/dev/sdb5 471M 2.3M 445M 1% /backup
49
[root@server /]# mount -t ext3 /dev/sdb6
/backupext3
[root@server /]# mount | grep sdb
/dev/sdb5 on /backup type ext2 (rw)
/dev/sdb6 on /backupext3 type ext3 (rw)
Note: Our first partition is ext2 and the second is ext3 journal based
filesystem.
Note: While creating a filesystem with the mke2fs, we can execute –t ext3
option to create a ext3 filesystem which supports journaling.
50
Note: Converting a mounted ext2 filesystem to an ext3 journal filesystem
will convert the filesystem, but the mount command will yet display the
status of the filesystem as ext2 filesystem, until the filesystem is remounted.
The above example shows 2 newly created ext2 and ext3 filesystem,
where /backup is ext2 and /backupext3 is ext3 journaling filesystem. Both
the partitions were created to 500 MB and then were formatted with mke2fs
and mounted. The ext3 filesystem shows a 3% usage which is actually being
used for journaling, which means a little overhead using ext3.
The backupext3 directory is the mount point for /dev/sdb6, which was
created with the –j option, creating a journal based ext3 file system. Below
tune2fs –j is used to modify a ext2 filesystem to a journal based ext3
51
filesystem. Once the conversion process is complete a .journal file is added
to the directory which is the mount point for /dev/sdb5.
Note: Modifying size of filesystems and remounting it, might make mount
command to report size which was mounted earlier. To make change reflect,
reboot the system and recheck with mount command.
52
[root@server ~]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man
fstab-sync' for details
s file is edited by fstab-sync - see 'man fstab-
sync' for details
/dev/VolGroup00/LogVol00 /
ext3 defaults 1 1
LABEL=/boot /boot
ext3 defaults 1 2
none /dev/pts
devpts gid=5,mode=620 0 0
none /dev/shm
tmpfs defaults 0 0
none /proc
proc defaults 0 0
none /sys
sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap
swap defaults 0 0
/dev/hdc /media/cdrecorder
auto
pamconsole,fscontext=system_u:object_r:removable_t,
exec,noauto,managed 0 0
/dev/fd0 /media/floppy
auto
pamconsole,fscontext=system_u:object_r:removable_t,
exec,noauto,managed 0 0
53
the kernel recognizes the LABEL=/boot as such, it is an alias to
wherever the /boot filesystem is.
3. The 2nd field in the file specifies the mount point of the filesystem.
4. The 3rd field contains the type of filesystem.
5. The 4th field refers to the permissions on the filesystem. Incase of
defaults it defaults to read writable mount, it allows all users to interact
with the filesystem. But generally it is read write permission.
6. The 5th field specified whether the filesystem should be dumped.
7. The 6th field specifies.
The first and second columns should be pretty straightforward. They tell the
mount command exactly the same things that you tell mount when you
mount stuff manually: what is the device or partition, and what is the mount
point. The mount point specified for a device in /etc/fstab is its default
mount point. That is the directory where the device will be mounted if you
don't specify any other mount point when mounting the device.
Most Linux distribution create special directories for mount points. Most
distribution create them under /mnt, but some (RHEL)) under /media. As
you probably noticed when looking at the example fstab, I have used
RHEL AS 4’s mount points as an example.
You can freely change the default mount points listed in /etc/fstab if
you're not satisfied with the defaults your Linux distribution has given you.
Just make sure the mount point is a directory that already exists on your
system. If it doesn't, simply create it.
54
Some partitions and devices are also automatically mounted when your
Linux system boots up. For example, have a look at the example below.
There are lines that look like this many a times:
/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2
ext2 and ext3 Very likely your Linux partitions are Ext3. Ext2 used to be the
standard filesystem for Linux, but these days, Ext3 and ReiserFS are usually
the default filesystems for almost every new Linux distribution. Ext3 is a
newer filesystem type that differs from Ext2 in that it's journaled, meaning
that if you turn the computer off without properly shutting down, you
shouldn't lose any data and your system shouldn't spend ages doing
filesystem checks the next time you boot up.
reiserfs Your Linux partitions may very well be formatted as ReiserFS. Like
Ext3, ReiserFS is a journaled filesystem, but it's much more advanced than
Ext3. Many Linux distributions (including SuSE) have started using
ReiserFS as their default filesystem for Linux partitions.
55
vfat and ntfs Your Windows partitions are probably either Vfat or NTFS.
The 9x series (95, 98, ME) all use Vfat (more widely known as FAT32), and
the NT series (NT, 2000, XP) use NTFS. In 2000 and XP you can choose the
filesystem type, so 2000 and XP partitions may be formatted as Vfat, too. If
you want to be able to write to your Windows partitions from Linux, I
suggest formatting them as Vfat, because Linux's support for writing to
NTFS partitions is a bit shabby at this moment, though it does and might
work.
auto No, this isn't a filesystem type :-) The option "auto" simply means that
the filesystem type is detected automatically. If you take a look at the
example fstab above, you'll see that the floppy and CD-ROM both have
"auto" as their filesystem type. Why? Their filesystem type may vary. One
floppy might be formatted for Windows and the other for Linux's Ext2.
That's why it's wise to let the system automatically detect the filesystem type
of media such as floppies and cdroms.
The fourth column in fstab lists all the mount options for the device or
partition. This is also the most confusing column in the fstab file, but
knowing what some of the most common options mean, saves you from a big
headache. Yes, there are many options available, but I'll take a look at the
most widely used ones only. For more information, check out the man page
of mount.
auto and noauto With the auto option, the device will be mounted
automatically (at bootup, just like I told you a bit earlier, or when you issue
the mount -a command). auto is the default option. If you don't want the
device to be mounted automatically, use the noauto option in
/etc/fstab. With noauto, the device can be mounted only explicitly.
user and nouser These are very useful options. The user option allows
normal users to mount the device, whereas nouser lets only the root to
mount the device. nouser is the default, which is a major cause of
headache for new Linux users. If you're not able to mount your cdrom,
56
floppy, Windows partition, or something else as a normal user, add the user
option into /etc/fstab.
exec and noexec exec lets you execute binaries that are on that partition,
whereas noexec doesn't let you do that. noexec might be useful for a
partition that contains binaries you don't want to execute on your system, or
that can't even be executed on your system. This might be the case of a
Windows partition.
exec is the default option, which is a good thing. Imagine what would
happen if you accidentally used the noexec option with your Linux root
partition...
rw Mount the filesystem read-write. Again, using this option might cure the
headache of many new Linux users who are tearing their hair off because
they can't write to their floppies, Windows partitions, or something else.
sync and async How the input and output to the filesystem should be done.
sync means it's done synchronously. If you look at the example fstab,
you'll notice that this is the option used with the floppy. In plain English, this
means that when you, for example, copy a file to the floppy, the changes are
physically written to the floppy at the same time you issue the copy
command.
However, if you have the async option in /etc/fstab, input and output
is done asynchronously. Now when you copy a file to the floppy, the changes
may be physically written to it long time after issuing the command. This
isn't bad, and may sometimes be favorable, but can cause some nasty
accidents: if you just remove the floppy without unmounting it first, the
copied file may not physically exist on the floppy yet!
async is the default. However, it may be wise to use sync with the floppy,
especially if you're used to the way it's done in Windows and have a
tendency to remove floppies before unmounting them first.
57
defaults Uses the default options that are rw, suid, dev, exec, auto, nouser,
and async.
Dump? Well, dump is a backup utility and fsck is a filesystem check utility. I
won't discuss them in great length here, but I'll mention them, because
otherwise you'd spend the rest of the day wondering what on God's green
Earth do these things mean.
The 5th column in /etc/fstab is the dump option. Dump checks it and
uses the number to decide if a filesystem should be backed up. If it's zero,
dump will ignore that filesystem. If you take a look at the example fstab,
you'll notice that the 5th column is zero in most cases.
The 6th column is a fsck option. fsck looks at the number in the 6th column
to determine in which order the filesystems should be checked. If it's zero,
fsck won't check the filesystem.
As an example, we'll take a look at a couple of fstab entries that have been
a source of endless frustration for new Linux users: floppy and CD-ROM
(although these days floppies aren't that important anymore).
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
58
Note, again, the user option that enables you to mount the CD as a normal
user. The CD-ROM has the ro option because it's no use mounting a CD-
ROM read-write because you wouldn't be able to write to it anyway. Also
note the exec option. It's especially useful if you'd like to be able to execute
something from your CD.
Also note that the noauto option is used with the floppy and CD-ROM. This
means that they won't be automatically mounted when your Linux system
boots up. This is useful for removable media, because sometimes there won't
be any floppy or CD-ROM when you boot up your system, so there isn't any
reason to try to mount something that doesn't even exist.
If you type mount command you will see /dev/shm as a tempfs file system.
Therefore, it is a file system, which keeps all files in virtual memory.
Everything in tmpfs is temporary in the sense that no files will be created on
your hard drive. If you unmount a tmpfs instance, everything stored therein is
lost. By default almost all distribution configured to use /dev/shm.
For example, if you have 8GB RAM then remount /dev/shm as follows:
# mount -o remount,size=8G /dev/shm
To be frank if you have more than 2GB RAM and if you running multiple
Virtual machines this hack always improves performance.
59
To add our backup filesystem to vfstab add the following lines:
To read floppy disks and other removable media, you need to mount the
device. If RHEL detects your hardware, it adds the proper settings to
/etc/fstab and default mount points to the /mnt directory. The default mount
points are straightforward; for example, floppy disks are mounted on
/mnt/floppy, CDs are mounted on /mnt/cdrom. If you're mounting an MS-
DOS-formatted floppy, you can do so with the following command:
# mount -t vfat /dev/fd0 /mnt/floppy
The -t switch specifies the type of filesystem (vfat). The device file /dev/fd0
represents the first floppy drive; /mnt/floppy is the directory through which
you can access the files on the floppy after mounting.
But the command that you actually need may be simpler. Take a look at your
/etc/fstab configuration file. You'll probably see something like the following
line:
/dev/fd0 /mnt/floppy auto
noauto,owner,kudzu 0 0
This /etc/fstab line sets the default configuration for the first floppy drive
(/dev/fd0). Normally, it's mounted on the /mnt/floppy directory. The format
is auto, which means that the mount command searches through the
/etc/filesystems configuration file. As long as vfat is part of this file, you do
not need to specify the filesystem type. The mount command reads the
filesystem on the floppy and mounts it with the correct filesystem
automatically. So all you really need to mount the floppy is the following
command:
# mount /dev/fd0 /mnt/floppy
60
But wait-if you know something about /etc/fstab, you know that the device
and mount points are effectively linked. If you specify either, mount looks
through /etc/fstab for the appropriate device, label, or mount point.
Therefore, all you actually need to mount the floppy is either one of the
following two commands:
# mount /dev/fd0
# mount /mnt/floppy
But as with a floppy disk, the actual command that you need is simpler. Take
a look at the relevant default line from /etc/fstab:
/dev/cdrom /mnt/cdrom udf,iso9660
noauto,owner,kudzu,ro 0 0
The following commands unmount both our floppy and our CD-ROM:
61
# umount /mnt/floppy
# umount /mnt/cdrom
The Automounter
Once you run the mount command on a partition, it stays mounted until you
unmount it or shut down or reboot your computer. This can cause problems.
For example, if you've mounted a floppy and then physically removed the
disk, Linux may not have had a chance to write the file to the disk. This
situation also applies to Zip or other 'hot-swap' removable drives.
This is where the Automounter can help. It relies on the autofs daemon to
mount configured directories as needed, on a temporary basis. In RHEL, the
relevant configuration files are /etc/auto.master and /etc/auto.misc. If you use
the Automounter, keep the /misc directory free. Red Hat configures
automounts on this directory by default, and they won't work if there are
local files or directories stored there.
/etc/auto.master
You can activate the Automounter by activating this command (or adding a
similar command). As you should already know as a Linux expert, the pound
sign (#) is a comment character. When you delete the #, the command is
activated. This command:
You can set up the Automounter on other directories. One popular option is
to set up the Automounter on the /home directory. In this way, you can
configure user home directories on remote servers, mounted on demand.
Users are given access to their home directories upon login, and with the
following command in /etc/auto.master, the home directory is automatically
unmounted 60 seconds after that user logs off the system:
# /home /etc/auto.home --timeout=60
This works only if you don't have a /home directory on your computer.
/etc/auto.misc
63
The next command assumes that the /boot directory is stored on the
/dev/hda1 partition. With this command, you don't need to mount /boot when
you start Linux. Instead, this command allows you to automount it with the
mount /misc/boot command.
#boot -fstype=ext2 :/dev/hda1
The next command points to the first partition on the third SCSI drive. The
'jaz' at the beginning suggests this is suitable for an Iomega type 'Jazz' drive.
#jaz -fstype=ext2 :/dev/sdc1
Finally, the last command assumes that you want to apply the Automounter
to the IDE drive connected as the slave on the secondary controller. The
'removable' at the beginning suggests this is suitable for removable hard
drives.
#removable -fstype=ext2 :/dev/hdd
With the possible exception of the floppy commands, you'll probably need to
modify these lines before activating them for your own hardware.
64
With the default command in the /etc/auto.misc file, you should now be able
to mount a CD on the /misc/cd directory, automatically, just by accessing the
configured directory. Once you have a CD in the drive, the following
command should work:
# ls /misc/cd
If you were to make /misc/cd your current directory, the Automounter would
ignore any timeouts. Otherwise, /misc/cd is automatically unmounted
according to the timeout, which according to the command in
/etc/auto.master, is 60 seconds.
65
Swap File System
Linux uses the swap space configured on one or more hard drive partitions to
store infrequently used programs and data. Swap space can extend the
amount of effective RAM on your system. However, if you don't have
enough actual RAM, Linux may use the swap space on your hard drive as
virtual memory for currently running programs. Because hard drive access
can be 1/100,000th the speed of RAM, this can cause significant
performance problems.
But you can't just buy extra RAM and eliminate swap space. Linux moves
infrequently used programs and data to swap space even if you have
gigabytes of RAM.
Normally, Linux (on a 32-bit Intel-style computer) can use a maximum 4GB
of swap space, in partitions no larger than 2GB. This 4GB can be spread over
a maximum of eight partitions. The typical rule of thumb suggests that swap
space should be two to three times the amount of RAM. However, at larger
amounts of RAM, the amount of swap space that you need is debatable.
The way Red Hat assigns default swap space is based on the amount of RAM
on your system and the space available in your hard drive. Red Hat requires
at least 256MB of RAM on RHEL 4. If there's room available on your hard
drives, Anaconda configures a swap partition of at least 512MB. For Intel
32-bit systems, Red Hat requires a swap partition at least equal to the amount
of RAM on your system.
Red Hat RAM and swap space requirements vary if you're installing RHEL 4
on computers with non-Intel 32-bit CPUs.
In any case, you want to make the swap space you create as efficient as
possible. Swap partitions near the front of a hard disk, thus on a primary
partition, have faster access times. Swap partitions on different hard drives
attached to separate disk controllers gives Linux flexibility on where to send
swap data. Linux can start a program through one hard drive controller, and
66
move files to and from swap space on a separate hard drive controller
simultaneously.
To check your current swap space and its usage run the free command.
67
To create a swap filesystem, create a new partition for swap.
The command swapon is used to enable the swap filesystem. However with
the –s option it can list the current swap filesystems being used by the
system. Swapon –a will enable all swap filesystems listed in the /etc/fstab
file.
69
/dev/sdb5 partition
506004 0 -2
70
RAID Configuration and Data Recovery
Linux RAID has come a long way. A substantial number of hardware RAID
products support Linux, especially from name brand PC manufacturers.
Dedicated RAID hardware can ensure the integrity of your data even if there
is a catastrophic physical failure on one of the disks.
Depending on your definitions, RAID has nine or ten different levels, which
can accommodate different levels of data redundancy. Only three levels of
RAID are supported directly by RHEL: levels 0, 1, and 5. Hardware RAID
uses a RAID controller connected to an array of several hard disks. A driver
must be installed to be able to use the controller. Most RAID is hardware
based; when properly configured, the failure of one drive in a RAID 1 or
RAID 5 array does not destroy the data in the array. Linux, meanwhile,
offers a software solution to RAID. Once RAID is configured on a sufficient
number of partitions, Linux can use those partitions just as it would any other
block device. However, to ensure redundancy, it's up to you in real life to
make sure that each partition in a Linux software RAID array is configured
on a different physical hard disk.
The following sections describe the basic RAID levels supported on Red Hat
Enterprise Linux.
71
RAID 0 (Stripping without parity, Zero Fault Tolerance)
This level of RAID makes it faster to read and write to the hard drives.
However, RAID 0 provides no data redundancy. It requires at least two hard
disks.
Reads and writes to the hard disks are done in parallel, in other words, to two
or more hard disks simultaneously. All hard drives in a RAID 0 array are
filled equally. But since RAID 0 does not provide data redundancy, a failure
of any one of the drives will result in total data loss. RAID 0 is also known as
'striping without parity.'
This level of RAID mirrors information to two or more other disks. In other
words, the same set of information is written to two different hard disks. If
one disk is damaged or removed, you still have all of the data on the other
hard disk. The disadvantage of RAID 1 is that data has to be written twice,
which can reduce performance. You can come close to maintaining the same
level of performance if you also use separate hard disk controllers. That
prevents the hard disk controller from becoming a bottleneck.
And it is expensive. To support RAID 1, you need an additional hard disk for
every hard disk worth of data. RAID 1 is also known as disk mirroring.
72
RAID 5 (Disk Stripping with Parity across the disks)
Like RAID 4, RAID 5 requires three or more disks. Unlike RAID 4, RAID 5
distributes, or 'stripes,' parity information evenly across all the disks. If one
disk fails, the data can be reconstructed from the parity data on the remaining
disks. RAID does not stop; all data is still available even after a single disk
failure. RAID level 5 is the preferred choice in most cases: the performance
is good, data integrity is ensured, and only one disk's worth of space is lost to
parity data. RAID 5 is also known as disk striping with parity.
http://www.pcguide.com/ref/hdd/perf/raid/levels/singleLevel0-c.html
RAID in Practice
During the Red Hat Installation and Configuration, it's generally easier to do
as much as possible during the installation process. If you're asked to create a
RAID array, it's easiest to do so with Disk Druid, which only works during
installation. You can create RAID arrays once RHEL is installed, but as
you'll see in the following instructions, it is more time consuming, and
involves a process that is more difficult to remember.
73
However, if you're required to create a RAID array during your exam and
forget to create it during the installation process, not all is lost. You can still
use the tools describe here to create and configure RAID arrays. And the
skills you learn here can serve you well through your career.
All four drives (hda, hdb, hdc, hdd) should be approximately the same size.
This first example shows how to mirror both the /home and the /var
directories (RAID 1) on Drive 2 and Drive 3, leaving Drive 4 as a spare.
nr-raid-disks 2
nr-spare-disks 1
persistent-superblock 1
chunk-size 4
device /dev/hdb3
raid-disk 0
device /dev/hdc3
raid-disk 1
device /dev/hdd3
spare-disk 0
raiddev /dev/md1
raid-level 1
nr-raid-disks 3
nr-spare-disks 1
persistent-superblock 1
chunk-size 4
device /dev/hdb4
raid-disk 0
device /dev/hdc4
raid-disk 1
device /dev/hdd4
75
spare-disk 0
The table below shows what some of the commands are, along with a brief
description of what they do. If you haven't already done so, it's time to
format these partitions and convert them to the default ext3 filesystem.
Commands in raidtab
Command Description
nr-raid-disks Number of RAID disks to use
nr-spare-disks Number of spare disks to use
persistent-superblock Required for autodetection
chunk-size Amount of data to read/write
parity-algorithm How RAID 5 should use parity
Note: Take special note that raid-disks and spare-disks start counting at 0;
nr-raid-disks and nr-spare-disks are the correct number of drives. For
example, if nr-raid-disks = 3, then the raid-disks are 0, 1, and 2.
The Linux format command is mkfs; with the right switch, you can
automatically set it up to ext3 with a journal. For example, the following
command formats the /dev/hda4 partition:
# mkfs -j /dev/hda4
If the partitions in /etc/raidtab are new, repeat this command for all of those
other partitions.
76
Note: There are advantages to the ext3 journaling filesystem. If your system
suffers a sudden power failure, it does not have to check every inode for file
data; the information is already available in the journal.
If it works, you'll see the result in the dynamic /proc/mdstat file. You can
now mount the device and format it with the appropriate mkfs command,
and finally mount it on the Linux directory of your choice. You can even set
it up to be automatically mounted through /etc/fstab.
Note: Yes, when you configure a RAID device, you're formatting the same
space twice. First, you format the partitions that make up the array. Once
you've made RAID devices such as /dev/md0, you can then format those
devices as if they were new partitions.
For a RAID 5 array on the /var partition (in order to preserve mail, print
spools, and log files), the /etc/raidtab file should be modified as follows:
raiddev /dev/md0
raid-level 5
nr-raid-disks 3
nr-spare-disks 1
persistent-superblock 1
chunksize 32
parity-algorithm right-symmetric
device /dev/hda4
raid-disk 0
device /dev/hdb4
raid-disk 1
device /dev/hdc4
raid-disk 2
77
device /dev/hdd4
spare-disk 0
Now you can run mkraid /dev/md0 to initialize this RAID 5 device. You
can then format and mount this RAID array on the Linux directory of your
choice.
Now you can run the mkfs command to format each RAID array. It's fairly
simple; now that you've created arrays such as /dev/md0 and /dev/md1, you
can work with them as if they were any other hard drive partition. For
example, you can format these arrays to the ext3 filesystems with the
following commands:
# mkfs -j /dev/md0
# mkfs -j /dev/md1
But that's not the last step. You may not get full credit for your work on the
exam unless the directory gets mounted on the RAID array when you reboot
your Linux computer. Based on a standard RHEL 3 /etc/fstab configuration
file, you might add the following line to that file:
78
LABEL=/home/mj /home/mj ext3 defaults 1
2
Before this line can work, you'll need to set the label for this directory with
the following command:
# e2label /dev/md0 /home/mj
Drive 2:
hdb1 1200 /usr
hdb2 64 swap
hdb3 100 /tmp
hdb4 500 (not allocated)
Now with the following steps, you can create a mirror of hda3, which stores
the /home directory, to the hdb4 partition. (The partition sizes do not have to
be identical.)
79
1. Mark the two partition IDs as type FD using the Linux fdisk utility.
# fdisk /dev/hda
Command (m for help) : t
Partition number (1-4) 3
Partition ID (L to list options): FD
Command (m for help) : w
# fdisk /dev/hdb
Command (m for help) : t
Partition number (1-4) 4
Partition ID (L to list options): FD
Command (m for help) : w
nr-raid-disks 2
nr-spare-disks 0
persistent-superblock 1
chunk-size 4
device /dev/hda3
raid-disk 0
device /dev/hdb4
raid-disk 1
3. Now make the RAID device file md0 and format it this way:
# mkraid -R /dev/md0
# mkfs -j /dev/md0
4. All that's left is to restore the files to the device and mount it.
5. However, you may not get full credit for your work unless your Linux
system mounts the directory on the RAID device. Make sure to do so in
the /etc/fstab configuration file. Run the e2label command as required
80
to make sure that the LABEL that you add to /etc/fstab is read properly
the next time you boot Linux.
81
Process Management
[root@server ~]# ps
PID TTY TIME CMD
2980 pts/1 00:00:00 bash
2997 pts/1 00:00:00 ps
[root@server ~]# which ps
/bin/ps
As per existing standards required binaries are to exist in /bin directory and
ps is one such binary.
The ps with the –e option will list all the processing running on the system
82
[root@server ~]# ps -e
PID TTY TIME CMD
1 ? 00:00:00 init
2 ? 00:00:00 ksoftirqd/0
3 ? 00:00:00 events/0
4 ? 00:00:00 khelper
5 ? 00:00:00 kacpid
18 ? 00:00:00 kblockd/0
28 ? 00:00:00 pdflush
29 ? 00:00:00 pdflush
31 ? 00:00:00 aio/0
19 ? 00:00:00 khubd
30 ? 00:00:00 kswapd0
105 ? 00:00:00 kseriod
176 ? 00:00:00 scsi_eh_0
188 ? 00:00:00 kmirrord/0
197 ? 00:00:00 kjournald
1042 ? 00:00:00 udevd
The command ps –aux or ps aux (BSD Style) will list all process and their
ids and will provide detailed information about the processes running on the
system.
83
root 5 0.0 0.0 0 0 ? S<
07:36 0:00 [kacpid]
root 18 0.0 0.0 0 0 ? S<
07:36 0:00 [kblockd/0]
root 28 0.0 0.0 0 0 ? S
07:36 0:00 [pdflush]
root 29 0.0 0.0 0 0 ? S
07:36 0:00 [pdflush]
root 31 0.0 0.0 0 0 ? S<
07:36 0:00 [aio/0]
root 19 0.0 0.0 0 0 ? S
07:36 0:00 [khubd]
root 30 0.0 0.0 0 0 ? S
07:36 0:00 [kswapd0]
root 105 0.0 0.0 0 0 ? S
07:36 0:00 [kseriod]
root 176 0.0 0.0 0 0 ? S
07:36 0:00 [scsi_eh_0]
root 188 0.0 0.0 0 0 ? S<
07:36 0:00 [kmirrord/0]
root 197 0.0 0.0 0 0 ? S
07:36 0:00 [kjournald]
root 1042 0.0 0.1 2452 448 ? S<s
07:37 0:00 udevd
root 3022 0.8 1.1 5484 3040 pts/2 S
07:53 0:07 /usr/lib/vmware-tools/bin32/vmware
root 3087 0.0 0.3 2808 772 pts/1 R+
08:07 0:00 ps -aux
Here are the different values that the s, stat and state output specifiers (header
"STAT" or "S") will display to describe the state of a process.
84
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.
For BSD formats and when the stat keyword is used, additional characters
may be displayed:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group
Note: Use ps –aux | less command to display output one page at a time.
The above command filters the ps –aux and lists only the sshd process.
85
root 2202 0.0 0.1 2192 408 tty3 Ss+
07:37 0:00 /sbin/mingetty tty3
root 2203 0.0 0.1 2476 408 tty4 Ss+
07:37 0:00 /sbin/mingetty tty4
root 2452 0.0 0.1 1476 408 tty5 Ss+
07:37 0:00 /sbin/mingetty tty5
root 2525 0.0 0.1 2464 408 tty6 Ss+
07:37 0:00 /sbin/mingetty tty6
root 3154 0.0 0.2 5028 672 pts/1 S+
08:19 0:00 grep tty
The above command filters all processes and lists only tty (Tele Type
Terminals) processes.
Process Selections
The free command lists the amount of total memory, used, free, shared,
buffers, cached and the swap usage.
Use the free command with the –m and –s (seconds) to update the memory
usage every 3 seconds.
Use the top command to display information about the processes running on
the system. The top command updates the information displayed every 3
seconds.
89
top - 09:02:30 up 1:25, 3 users, load average:
0.05, 0.11, 0.15
Tasks: 76 total, 1 running, 73 sleeping, 2
stopped, 0 zombie
Cpu(s): 6.0% us, 5.6% sy, 0.0% ni, 88.4% id,
0.0% wa, 0.0% hi, 0.0% si
Mem: 256044k total, 247976k used, 8068k
free, 15540k buffers
Swap: 524280k total, 0k used, 524280k
free, 140992k cached
Pressing SHIFT+f will bring up a menu to select more options in the top
command.
The top command with the –u username option will display usage of a
particular user.
91
Mem: 256044k total, 248564k used, 7480k
free, 15648k buffers
Swap: 524280k total, 0k used, 524280k
free, 141020k cached
Killing a Process
Press k in the top menu to kill a process and type in the PID of the process
you want to kill (shut).
93
The kill command is used to kill a process by sending signal to the process
using the Process ID(PID).
kill –l
kill processid
Killall command
The killall command kills all the processes of the given process name.
#killall seq
Will kill all seq processes running in other shells (in background &).
Note: The information listed by ps, top etc is pulled from a filesystem /proc
which is mounted in memory. Below is a example of cpuinfo kept in the
/proc filesystem.
The uptime command displays information about the time since the system
has been up and running.
The jobs command is used to display the jobs running in the background.
The fg (Foreground) commands is used to display foreground processes
running in the shell. Both are inbuilt inside the shell and are not separate
binary files.
95
Adding and Removing RPM Packages
The rpm command makes it easy to add and remove software packages to
your system. It maintains a database regarding the proper way to add,
upgrade, and remove packages. This makes it relatively simple to add and
remove software with a single command.
Install Mode
The install mode, as its name suggests, is used to install RPM packages on
your system. You can install an RPM package with the -i option. For
example, the following command installs the hypothetical penguin RPM:
# rpm -i penguin-3.4.5-26.i386.rpm
Before installing the package, RPM performs several checks. First, it makes
sure the package you're trying to install isn't already installed-normally, RPM
won't let you install a package on top of itself. It also checks to make sure
you aren't installing an older version of the package. Next, RPM does a
dependency check. Some programs won't work unless others are already
installed. In this example, you've just downloaded the latest RPM version of
the Penguin utilities, and you now want to install it.
# rpm -i penguin-3.4.5-26.i386.rpm
failed dependencies:
iceberg >>= 7.1 is needed by penguin-3.26.i386.rpm
This error tells you that rpm did not install the Penguin package because it
requires the iceberg RPM package, version 7.1 or later. You'll have to find
and install the iceberg package, and any packages iceberg may require.
96
Finally, RPM checks to see if it would overwrite any configuration files
when it installs a package. RPM tries to make intelligent decisions about
what to do in this situation. If RPM chooses to replace an existing
configuration file, it gives you a warning like:
# rpm -i penguin-3.26.i386.rpm
warning: /etc/someconfig saved as
/etc/someconfig.rpmsave
It's up to you to look at both files and determine what, if any, modifications
need to be made.
Upgrade Mode
upgrades the old version of the package with the new one. In fact, if you've
never installed this package before, the -U switch works just like -i. The
package is simply installed for the first time.
Remove Mode
The rpm -e command removes a package from your system. But before
removing a package, RPM checks a few things first. It does a dependency
check to make sure no other packages need what you're trying to remove. If
it finds dependent packages, rpm -e fails with an error message identifying
these packages.
97
If you have modified any of the configuration files, RPM makes a copy of
the file, adds an .rpmsave extension to the end of the filename, and then
erases the original. Finally, after removing all files from your system and the
RPM database, it removes the package name from the database.
Note: Be very careful about which packages you remove from your system.
Like many other Linux utilities, RPM may silently let you shoot yourself in
the foot. For example, if you were to remove the packages for /etc/passwd or
the kernel, that would devastate your system.
Without RPM, you'd need to search around your filesystems to figure out
whether a particular software package is installed. RPM makes it easy for
you to figure out what RPM packages are installed and get information about
those packages.
The -q switch is used to query packages. When you use RPM's query mode,
you can learn if a specific package is installed or identify the files associated
with that package. The rpm -q packagename command will return the
installed version of a specified package. For example, to find the version
number of an installed mutt text e-mail reader, run the following command:
# rpm -q mutt
lynx-1.4.1-3
If you want to see which installed package owns a file, use the -f modifier.
Here we want to identify the package that owns /etc/passwd:
# rpm -qf /etc/passwd
setup-2.5.27-1
One of the most common modifiers to -q is -a, a query for all installed
packages on your system. As configured, my RHEL 3 system includes 700
packages. Here's a truncated output:
# rpm -qa
ghostscript-fonts-5.50-9
libmng-1.0.4-3
libtiff-3.5.7-13
ncurses-5.3-9.3
arts-1.1.3-2.2
...
commons-modeler-1.0-5
sendmail-cf-8.12.10-1
99
Note: It's common to use the rpm -qa command as a searchable database.
All you need to do is pipe the output with a search term through grep. For
example, the rpm -qa | grep kde command makes it easy to identify all
installed packages related to the K Desktop Environment.
For even more information about a specific package, use the -i (information)
modifier. The table below lists some of the most important entries from the
package output. Run the rpm -qi packagename command on the RPM of
your choice and see the result for yourself.
100
The Red Hat Package Management Utility
You can update packages with a graphical tool. The Red Hat Package
Management utility includes several advantages. It includes an interface
similar to the Anaconda Custom Installation screen. It allows you to install
more than one package at a time. It automatically installs any other
dependent packages that may be needed.
There are two ways to start the Package Management utility. In the GNOME
or KDE desktop, click Main Menu | System Settings | Add/Remove
Applications. Alternatively, in a GUI text command window, run the
system-config-packages command. Either action opens the Package
Management utility shown in below.
You can use it to add the package groups of your choice. The list shown is
the same as what you saw during the installation process. Once you've
101
selected a package group, you're allowed to customize the installation by
clicking the associated Details link.
102