Wednesday, January 2, 2008

My Linux trainning

Exiting vi tutor

Press esc then enter

:q -Quit VI. If there have been changes made, the editor will issue a warning message.
:q! -Quit VI without saving changes.
:w -Write out the current file.
:w filename -Write the buffer to the filename specified.
:w >> filename -Append the contents of the buffer to the filename.
:wq -Write the buffer and quit.

Reset root password


  • Reboot the machine
  • Press e to edit the commands before booting, at Red Hat Enterprise Linux ES (2.6.9-22.EL)
  • The entered to the GNU GRUB,where I got three options.
1.root(hd0,0)
2.kernel
3.intitrd
  • Choose kernel and select e to edit.In the grub edit place 1 in the end and enter.
kernel /vmlinuz-2.6.9-22.EL ro root=LABEL=/ rhgb quiet 1
  • then press b for boot from there.
  • I entered to the shell mode,enter passwd there
sh-3.00# passwd
changing password for user root.
New UNIX password:

Auto Mount

Auto mount is useful for nfs, samba, and boot mounts/partitions. Think of having file exist on a central nfs capable server and all of your client machines are then able to automatically mount that file whenever you access them.If the filesystem is unmounted, and a user attempts to access it, it will be automatically (re)mounted. This is especially useful in large networked environments and for crossmounting filesystems between a few machines.
Autofs master configuration file lists one or more directories to take control over. This directory (mount point) will be controlled by the autofs daemon.Each line in the master configuration file gives autofs a mount point,can add any number of mount points, but we will only need one.

#ls /etc/auto* :main file is /etc/auto.master
#vi /etc/auto.master
auto.today --timeout=1s
#vi /etc/auto.today
autodir -fstype=etc3 :/dev/hda14
#service autofs restart


#cd /fsat
#ls
#mount :to check mounting
#ls autodir :auto mount happens
#ls :files can be seen .but after 1s seconds,if no activity happens it will get auto unmounted.Check with date command


#vi /etc/exports
#service nfs restart

use of auto mount

Allow non root people to mount files (specially CD roms)

eg: Host 192.168.10.224 has linux rpm package available in /var/ftp/pub (nfs enabled)
arrange auto mount the above directory as /fsat/pkgs

pkgs -fsat=nfs 192.168.10.224:/var/ftp/pub

How to add a disk file to swap

create a file with a required size.
#dd if=/dev/zero(input file) of=/tmp/myswap(output file) bs=1024k(block size) count=10(10 blocks)
#od -c /tmp/myswap | less
#mkswap /tmp/myswap
#swapon /tmp/myswap
#swapon -s


#useradd :create a new user
#id hnd
#tail /etc/passwd

#newgp :create a new group
#chown hnd /newdir :change the ownership of the new directory to the new user.Inlinux to change the ownership we should be a super user

#groupadd sand :to add a group with out a user
#usermod -g sands hnd :to see how arguments are given just type usermod and enter

#chgrp sands newdir

Allocating user disk quotas

To use quota, file system must be mounted with quota option
#mount -o userquota /dev/hda11 /home/mynewdir
#qutacheck -c /home/mynewdir
#qutaon /home/mynewdir
#usemod -d /home/mynewdir/hnd -m hnd :just changing the home directory
#edquota hnd
#repquota /home/mynewdir :to see
#dv :disk usage


MIrroring

Write the same thiing to both disks,both have same image.
create 2 50 MB partitions hda12 and hda13
:fd linux raid autodetect

#mdadm -C(create) /dev/md0 -l | -n 2(no of devices) /dev/hda12 /dev/hda13
#ls -l /dev/md0 : created
#mdadm --details /dev/md0
#mkfs.ext3 /dev/md0
#mount /dev/md0 /mnt
#mdadm --manage /dev/md0 -f /dev/hda13 :creating a faulty disk
#mdadm -D /dev/md0 :to display
#mdadm -S /dev/md0 :to stop
#mdadm -r /dev/md0 :to remove
the mirror divice is /dev/md0
#mdadm --manage /dev/md0 -a /dev/hda13 :adding another partion hda13


Logical volumes

iF disk 1 has 500MB free available and disk 2 has 300 MB available,in LVM by combining two we can have 800 MB space.

creating a logical volume
:t
:8e
:w

#pvcreate /dev/hda14 /dev/hda15 :physical volume create
#vgcreate vg0 /dev/hda14 /dev/hda15 :volume group creation
#vgdisplay
#lvcreate -L(length) 56m(size) -n(name) lv1 vg0(from)
this created logical volumegoes to /dev/mapper/vg0 -lv1 created from /dev/vg0/lv1

#lvdisplay
#mkfs.ext3 /dev/vg0/lv1
#mount /dev/vg0/lg1 /mnt
#df -h

#lvexpand -L +16m /dev/vg0/lv1 :expanding lv1
#df -h
#ext2online /dev/vg0/lv1 :start using expanded area

Removing

#lvremove /dev/vg0/lv1
#vgremove vg0
#pvremove /dev/hda14
#pvremove /dev/hda15

No comments: