Showing posts with label RHCSA. Show all posts
Showing posts with label RHCSA. Show all posts

Monday, May 26, 2014

RHCSA Objectives ANSWERS

Understand and use essential tools
·         Access a shell prompt and issue commands with correct syntax.
A: Applications -> system tools -> terminal
·         Use input-output redirection (>, >>, |, 2>, etc.).
A: 1 > stdout 2> stnderr > filename < stdin (both stdoutAndstderr >filename 2>&1
·         Use grep and regular expressions to analyze text.
A: grep word filename, grep -v (do not). grep -v ^# filename
·         Access remote systems using ssh and VNC.
A: ssh root@iptaddress; yum install tigervnc-server(server) (client - tigervnc) 
·         Log in and switch users in multiuser runlevels.
·         A: su - username (su -)
·         Archive, compress, unpack, and uncompress files using tar, star, gzip, and bzip2.
A: tar –czvf newtar.tar.gz originfile (j – bz2), untar = tar –x(j)zvf newtar.tar.gz, star –c f=newname.star filename, sar –xattr f=backup.star sat.doc
·         Create and edit text files.
A: vim, touch, cat-read, ls –la, less
·         Create, delete, copy, and move files and directories.
A: touch, rm (-rf), cp (-rp), mv
·         Create hard and soft links.
A: ln –s /fullpath source/ fulpath ; ln sourcefile filename
·         List, set, and change standard ugo/rwx permissions.
A: ls –l, ll, chmod, r = 4, w=2, x=1
·         Locate, read, and use system documentation including man, info, and files in /usr/share/doc.
A: rpm –qd service, locate, find, grep less
Note: Red Hat may use applications during the exam that are not included in Red Hat Enterprise Linux for the purpose of evaluating candidate's abilities to meet this objective.
Operate running systems
·         Boot, reboot, and shut down a system normally.
A: init 0, init 6, shutdown –r now, shutdown –h now (+10), reboot
·         Boot systems into different runlevels manually.
A: init 1,2,3, telinit 1,2,3
·         Use single-user mode to gain access to a system.
A: space bar, grub menu edit, kernel append 1 (passwd)
·         Identify CPU/memory intensive processes, adjust process priority with renice, and kill processes.
A: top, ps, pstree, ps –ef, top –p pidnumber, sar –A, lsof –c; nice –n –p, renice, inside top (r option) to renice, kill -9(-15) pidnumber, killall name, pkill -9 (-15) or no number; ps –aux | grep –w Z (zombie process)
·         Locate and interpret system log files.
A: less, more, tail (-f),  dmesg, sealert –a /var/log/audit/audit.log
·         Access a virtual machine's console.
A: Applications->system tools->virt-manager, virt-view domain
·         Start and stop virtual machines.
A: virsh shutdown (destroy) domain, virsh start domain, virsh list –all,
·         Start, stop, and check the status of network services.
A: /etc/init.d/network status (stop, start, restart)
Configure local storage
·         List, create, delete, and set partition type for primary, extended, and logical partitions.
A: fdisk –l, n, d, p, e: pvs, vgs,lvs, lvdisplay, pvcreate(vg,lv) lvremove
·         Create and remove physical volumes, assign physical volumes to volume groups, and create and delete logical Volumes.
A: pvcreate, vgcreate, vgremove, pvremove
·         Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot.
A: crypsetup –y –v luksFormat /dev/mapper/balo1
·         Configure systems to mount file systems at boot by Universally Unique ID (UUID) or label.
# blkid
·         Add new partitions and logical volumes, and swap to a system non-destructively.
A: pvcreate,vgextend, lvresize –r, mkswap –L Labelname, swapon Labelname
Create and configure file systems
·         Create, mount, unmount, and use ext2, ext3, and ext4 file systems.
·         Mount, unmount, and use LUKS-encrypted file systems.
·         Mount and unmount CIFS and NFS network file systems.
A: mount –t cifs //serverip/shareolder /mnt
·         Configure systems to mount ext4, LUKS-encrypted, and network file systems automatically.
·         Extend existing unencrypted ext4-formatted logical volumes.
·         Create and configure set-GID directories for collaboration.
A: chmod 2070 /home/group
·         Create and manage Access Control Lists (ACLs).
A: add acl by defaults in /etc/fstab, setfacl –m u:user:rwx /file (-x remove, -b remove all the acl)
·         Diagnose and correct file permission problems.
A: ls –l, lsattr, chattr +
Deploy, configure, and maintain systems
·         Configure networking and hostname resolution statically or dynamically.
A: /etc/sysconfig/network-scripts/ifcfg-eth0
·         Schedule tasks using cron.
A: crontab –e, crontab –l
·         Configure systems to boot into a specific runlevel automatically.
A: /etc/inittab
·         Install Red Hat Enterprise Linux automatically using Kickstart.
A: system-config-kickstart; -x ks=, linux ks=http:file
·         Configure a physical machine to host virtual guests.
A: yum groupinstall “Virtualization”; yum groupinstall “Virtualization Platform”; yum groupinstall “Virtualization Client”
·         Install Red Hat Enterprise Linux systems as virtual guests.
A: virt-install, or Applications->System Tools-> Virt-manager->create new
·         Configure systems to launch virtual machines at boot.
A: virsh autostart domainname
·         Configure network services to start automatically at boot.
A: ifcfg-eth0 -> ONBOOT=yes
·         Configure a system to run a default configuration HTTP server.
A: yum groupinstall “Web Server” –y; service httpd start, chkconfig httpd on, open port80.
·         Configure a system to run a default configuration FTP server.
A: yum install vsftpd –y; service vsftpd start, chkconfig vsftpd on, open port 20 and 21
·         Configure a system to use time services.
A: yum install ntp –y, vim /etc/ntp.conf
·         Install and update software packages from Red Hat Network, a remote repository, or from the local file system.
A: vim /etc/yum.repos.d/file.repo, [name],name=, baseurl=http://server/model/os/$basearch; yum clean all, yum repolist all, yum install –disablerepo package
·         Update the kernel package appropriately to ensure a bootable system.
A: yum install kernel
·         Modify the system bootloader.
A: vim /boot/grub/grub.conf
Manage users and groups
·         Create, delete, and modify local user accounts.
A: useradd, userdel (-r), usermod, usermod –aG team user
·         Change passwords and adjust password aging for local user accounts.
A: passwd; chage –E mm/dd/yyyy user; chage –l user
·         Create, delete, and modify local groups and group memberships.
A: groupadd, groupmod, groupdel,
·         Configure a system to use an existing LDAP directory service for user and group information.
A: GUI mode -> Adminstration
Manage security
·         Configure firewall settings using system-config-firewall or iptables.
A: system-config-firewall
·         Set enforcing and permissive modes for SELinux.
A: setenforce 1 or 0 or /etc/selinux/config
·         List and identify SELinux file and process context.
A: ls –Z or for dir – ls –Zd, ps –eZ |grep processname
·         Restore default file contexts.
A: restorecon -R
·         Use boolean settings to modify system SELinux settings.
A: semanage boolean –l, setsebool –P boolean on/off
·         Diagnose and address routine SELinux policy violations
A: yum install policycoreutils-gui setroubleshoot, sealert –a /var/log/audit/audit.log


Wednesday, May 21, 2014

NTP Server / Client

NTP SERVER

# yum install ntp -y
# /etc/init.d/ntpd start
# chkconfig ntpd on
-Open the UDP 123 port in your firewal
# iptables -I INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
# service iptables save

Open the configuration file and uncomment where ip restrict is and modify the subnet according to your subnet.
# vim /etc/ntp.conf

{# Hosts on local network are less restricted.}
{#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap}
s/
# Hosts on local network are less restricted.
restrict 192.168.122.0 mask 255.255.255.0 nomodify notrap
:wq

# /etc/init.d/ntpd restart

To verify your server synced with the most accurate time server available after couple minutes. 
# ntpq -p

Output should show in *servername for the synced server

NTP CLIENT

# yum install ntp -y
# /etc/init.d/ntpd start
# chkconfig ntpd on

Comment out all 4 default servers from the OS System and enter your time server in the /etc/ntp.conf file.

# vim /etc/ntp.conf
server 192.168.122.50 iburst
:wq

Check if your NTP client is synced with the NTP server you have provided
# ntpq -p

AutoFS in Linux

AutoFS automounts desired nfs share and other mountpoints automatically, when it is needed.

# yum install autofs
# /etc/init.d/autofs start
# chkconfig autofs on

Open the /etc/auto.master file to make your new entries for the automount. You will have one example in the file as cdrom.

# vim /etc/auto.master

/remote    /etc/auto.remote
:wq

Now create auto.remote file in the /etc/ directory

# vim /etc/auto.remote
nfs        -fstype=nfs,intr         192.168.122.50:/home/share
:wq

# /etc/init.d/autofs restart

# cd /remote/nfs
or
# ls /remote/nfs/

Now you should be able to access to the nfs from automount, if it becomes inactive for about 10 minutes, it will be disconnected automatically until you again access it. 

Tuesday, May 13, 2014

NFS in Linux

Network File System - allows remote hosts to mount file systems over the network. We will be setting up a NFS server and client in this post.

NFS SERVER:
First you will have to install packages
# yum groupinstall "NFS file server"

Open Firewall Ports TCP 2049, TCP 111, UDP 111
# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
:wq

# service iptables restart

Start your services for NFS
# service rpcbind start
# service nfslock start
# service nfs start

Let us make our services persistent to reboot
# chkconfig rpcbind on
# chkconfig nfslock on
# chkconfig nfs on

Now we can create our share directories, if you have one that is even better
# mkdir -p /home/testshare

We will enter desired directory to share in the /etc/exports file
# vim /etc/exports
/home/testshare nfsclient(rw,no_root_squash)
:wq

Export the directory
# exportfs -avr

NFS CLIENT:

Install basic services for nfs client also, in my case I have again groupinstalled all the packages (just lazy)
$ Start the services
$ Make them persistent to reboot

# mount -t nfs 192.168.122.50:/home/testshare /nfsclientdir
# cd /nfsclientdir

Do not forget to enter mount information to the /etc/fstab file to make it persistent to reboot
# vim /etc/fstab
192.168.122.50:/home/testshare   /nfsclientdir      nfs          _netdev       0 0
:wq

* _netdev option is for system not to try to mount the filesystem until nfs service started after boot. (will prevent boot time hanging)

Now you have access to the folder that has been shared, and you will have read and write permissions.

Saturday, May 10, 2014

LVM in Linux - (Logical Volume Management)

Logical Volume Management is widely used technique for deploying logical storage rather than physical.

First check what device blocks do you have with fdisk utility 

In my VM I had /dev/sdb, /dev/sdc, and /dev/sdd empty new blocks to use

You can create partitions with fdisk and make sure to take extra step before -w (write) command to convert the partition to LVM (8e) type. Before writing changes select (t) option and change partition to LVM.

Example disks output of fdisk -l:

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  8e  Linux LVM

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1044     8385898+  8e  Linux LVM

Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1044     8385898+  8e  Linux LVM


1) Once, all the partitions are done we start creating physical  volumes.

# pvcreate /dev/sdb1
# pvcreate /dev/sdc1
# pvcreate /dev/sdd1

Check your newly created physical volumes with

# pvs
or
#pvdisplay

2) We now will create a volume group that will consist of physical volumes.

# vgcreate volume_group_new /dev/sdb1 /dev/sdc1 /dev/sdd1

Check your volume group with

#vgs
#vgdisplay

You can extend or remove physical volumes from the volume group

# vgextend volume_group_new /dev/sdb2

# vgreduce volume_group_new /dev/sdb2

To remove volume group itself

# vgremove Volume Group Name

3) After you have created volume group now you can create LVM blocks and allocate size to them

# lvcreate -L 10G -n logical_volume_new volume_group_new

Now you will have a 10 GB LVM block in the /dev/mapper/volume_group_new/logical_volume_new

# lvs
# lvdisplay

NOTE: You will need to format the LVM block after you have created

# mkfs.ext4 /dev/mapper/volume_group_new/logical_volume_new

Next step is create a directory to mount and mount the lvm

# mkdir /lvmextra
# mount /dev/mapper/volume_group_new/logical_volume_new /lvmextra

Please, make sure you enter the entries to the /etc/fstab file to make it persistent to reboot

# blkid - this will give you UUID of all the blocks so you can enter its UUID to /etc/fstab file

4) Here is some helpful and most important commands of LVM

To extend a space on lv disk (cool part of LVM)
# lvextend -L +1G /dev/mapper/volume_group_new/logical_volume_new
# resize2fs /dev/mapper/volume_group_new/logical_volume_new

To reduce the space on lvm (which you might not use it often)
Please, be sure you might loose some data here and do this if you know what you are doing.

First unmount the device
# umount /lvmextra
# fsck -f /dev/mapper/volume_group_new/logical_volume_new

Then do the opposite of the extending procedure. Let us say you want the total disk size be 7GB.
# resize2fs /dev/mapper/volume_group_new/logical_volume_new 7G
# lvresize -L 7G /dev/mapper/volume_group_new/logical_volume_new

Now, mount your device or just run the # lvs command to check the new resized disk space.

*** There is GUI form of LVM if you are interested to learn. Above material might have typos or mistakes please read about LVM at www.redhat.com documentation or learn some before using the commands.

Wednesday, May 7, 2014

User and Group Administration in Linux

User and Group management is essential skill of the System Administrator.

To add a new user

# useradd newuser
-c - "Comment" - you can comment user's name or anything
-G - Group user belongs to (by default user group will be same as its username)
-e - expiration date of the user's account
-d - custom home directory
-p - set a password
-s - custom shell for a user

You can modify user's account

#usermod user1

Above options will work with usermod and plus some extra commands
-L - lock user's account
-U - unlock user's account
-m - move home dir to another location

You can delete user with

#userdel username
#userdel -r username -> deletes users fully (recursively) from the system

You can modify user's account password with

#passwd user1 - change password for a user
#passwd -l username > to lock user's account
#passwd -u username > to unlock user's account
#chage - changes user password age
#chage -E year-month-date > sets an expiration date
#chage -W 2 > sets a warning for a password expiration
#chage -M 30 > sets a maximum (30) days for the user's account to expire
#chage -l $username > lists information about the user's account

You can create a groups in Linux

#groupadd Groupname - > Adds a group
#groupmod Groupname -> Modifies a group
#groupdel Groupname - > Deletes a group

#groupmod -n oldname newname
#groupmod -g 1001 groupname -> changes group's id

You can set up particular user as an Admin of the group
#gpasswd -A username groupname

Now user can add users to the group he or she is admin of
#gpasswd -a username groupname

User configuration file: /etc/passwd
User password configuration file: /etc/shadow

Group configuration file: /etc/group
Group password file: /etc/gshadow

If you want, you can use GUI too under SYSTEM > ADMINISTRATION > USERS&GROUPS.

Monday, May 5, 2014

Encrypting Filesystems in Linux

If you do not have cryptsetup command you can install the package with:

# yum install cryptsetup-luks

In my case I did not have to install, I already had it.

Warning: Your data in the partition will be lost, please backup your files, if you have any.

1) Command to format the partition with the encryption
# cryptsetup -y -v luksFormat /dev/sdb1 (or any logical volume /dev/mapper/vg1-lv1)

It will ask you to enter: YES option then you will have to enter a passphrase

2) Now you will map your encrypted device 
# cryptsetup luksOpen /dev/sdb1 safefs
it will ask you for the passphrase 

You can check the mapped device after it is done with
# ls -l /dev/mapper/safefs
# cryptsetup -v status safefs

3) You will need to format the mapped device with:
# mkfs.ext4 /dev/mapper/safefs

4) Create a directory to mount the mapped filesystem 
# mkdir /safefsmount 

5) Mount the filesystem to the folder you have just created
# mount -t ext4 /dev/mapper/safefs /safefsmount

6) Please check your SELinux configurations too

7) Open cryptsetup configuration file and enter following input
# vim /etc/crypttab
safefs                  /dev/sda1               none

Above our mapping name, encrypted filesystem and third one is do not decrypt the passphrase (prompt for the password)

8) To make our mountpoint persistent to reboot enter the information to /etc/fstab file
# vim /etc/fstab
/dev/mapper/safefs   /safefsmount   ext4    defaults   0 0

9) Finally, reboot your system
# reboot (init 6)

When the system is booted it will ask you to enter the passphrase.

To unmount and secure your data you can
# umount /safefsmount
#cryptsetup luksClose safefs

You can always access to your secure information with the same open command of cryptsetup.

Disk Quotas (managing quotas for user)

Add 'usrquota' option in /etc/fstab file for /home directory
 then remount home partition

# mount -o remount /home
# mount |grep home

# quotacheck -cum /home
c = creates quota table options
u = creates aquota.user file
m = tells do not remount /home dir in read only mode

To view user's quota table run
# edquota -u user 

Limiting the space for the user 
# setquota -u user 30000 35000 0 0 /home 


Turn on quotas for the home directory 
# quotaon /home

Fill the disk with bunch of zeros

# dd if=/dev/zero of=testfile bs=1024 count=25000

Check what is the status of the user for the quotas
# edquota -u user

Copy quota settings from user to user
# edquota -up user1 user2

We can see all the users quotas with
# repquota -a

Group quotas are also similar to user quotas

In the /etc/fstab file you should enter 'grpquota' on the mount point

Then remount the filesystem you have grpquota
# mount -o remount /mountpoint
# mount |grep mountpoint (should show grpquota option on the output)

Add quota file to the location
# quotacheck -cgp /mountpoint

Turn the quota on
# quotaon /mountpoint

Set quota for the group
# setquota -g groupname 99000(99MB) 12000 0 0 /mountpoint

You can check the quotas in the all groups with
# repquota -ga

Friday, May 2, 2014

Red Hat Package Manager

RPM - RedHat Package Manager

man rpm (for more information)

Installing rpm package
$ rpm -ivh packagename.rpm - to install a package
-i - installs
-v - verbose
-h - shows progress as hash

Updating package
$ rpm -Uvh packagename (never use this command for installing kernel)

Removing package
$ rpm -e packagename

Query the rpm database of rpm (which is in /var/lib/rpm)

To query all the rpm packages
$ rpm -qa

Or grep certain package you want
$ rpm -qa |grep httpd

To look for documentation of the rpm package
$ rpm -qd packagename

To look for configuration file of the rpm package
$ rpm -qc packagename

To look for information about package
$ rpm -qi packagename

RPM will not find dependencies of the package automatically as yum does. Yum can perform exact same commands that rpm uses and can find dependencies of the package automatically.

YUM - Yellow Dog Update is commonly used installer command in RedHat
Yum must be running as root. Here is some common commands 
1) # yum install package

2) # yum remove package

3) # yum update package

4) # yum search package

5) # yum info package

6) # yum list (lists all the packages)

7) # yum whatprovides /path/filename

8) # yum update

You can find more information in depth in redhat.com website. 

Sunday, April 27, 2014

How to mount and unmount - in Linux

Here are some simple commands that you can use for mounting a device in Linux.

To mount something to the filesystem - general mount syntax
# mount -t ext4 /dev/sda2 /home

Remount syntax is
# mount -o remount /home

To make all the mount options persistent to reboot edit the /etc/fstab file. Once you have edited the fstab file you can run the the following option, which will mount all the things /etc/fstab contains.
# mount -a

To unmount the filesystem
# umount /home
# umount -a

To add permissions to the filesystem
# mount -rw -o remount /

To list all the mountpoint options you run the following
# mount
or
# mount |grep home - for individual mount points

Following command also will show all the mounted systems
# df or df -h (-h for human readable)

Forcefully unmount the system
# umount -f /mnt

You can run the fuser command to see which process is holding the mount point
# fuser -cu /mnt
# ps -ajx | grep /mnt

Mounting a cd rom device
# mount  -t iso9660 -o ro /dev/cdrom /mnt 

Wednesday, April 23, 2014

Fdisk Utility

Fdisk is the best tool to manage disk partitions. Using fdisk you can create a new partition, delete one, and change existing partitions. There are other tools you can use I found the fdisk to be easy to use.

To list all the drives in the system
# fdisk -l
# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf6edf6ed

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1959    15735636    c  W95 FAT32 
/dev/sda2            1960        5283    26700030    f  W95 Ext'd 
/dev/sda3            5284        6528    10000462+   7  HPFS/NTFS
/dev/sda4            6529        9729    25712032+   c  W95 FAT32 
/dev/sda5   *        1960        2661     5638752   83  Linux
/dev/sda6            2662        2904     1951866   83  Linux
/dev/sda7            2905        3147     1951866   83  Linux
/dev/sda8            3148        3264      939771   82  Linux swap / Solaris
You can list particular disk drive with
# fdisk -l /dev/sdb

Warning: When you use fdisk command please be sure to backup all your data, because everything will be lost.

To create a partition to the newly added disk

1) # fdisk /dev/sdb (or whatever disk name you have)

Fdisk has simple navigation once you are inside it, as long as you know core functions in it.

Once you are inside the fdsik mode after running 1) fdisk would be offering m option for help if you need any.

m - print help menu
p - print the partition table
l - list known partitions
n - add a new partition
     When you have selected n option there are some extra steps to work on
     it will ask you to choose if it is -- extended or -- primary partition
     select whichever you like mostly (p) primary
     select partition number
     then it will prompt to minimum start size of the disk
     after selecting min size it will ask you max size of the disk

By default it will create a Linux partition 83 you can change it by option (t) and use 82 for swap so on

w - this command writes all the changes (please make sure and verify with (v) and (p) options. This would be your last chance to check before it writes all the changes you have made.

# fdisk  /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

After you have created the partition, now you have to format the partition
# mkfs.ext4 /dev/sdbX 

Wednesday, April 16, 2014

VIM Editor Commands

VIM Editor Commands
Vim is an editor to create or edit a text file.
There are two modes in vim. One is the command mode and another is the insert mode.
In the command mode, user can move around the file, delete text, etc.
In the insert mode, user can insert text.
Changing mode from one to another
From command mode to insert mode type a/A/i/I/o/O ( see details below)
From insert mode to command mode type Esc (escape key)
Some useful commands for VIM
Text Entry Commands (Used to start text entry)
a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there
The following commands are used only in the commands mode.
Cursor Movement Commands
h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
^F (CTRl F) Forward screenful
^B Backward screenful
^f One page forward
^b One page backward
^U Up half screenful
^D Down half screenful
$ Move cursor to the end of current line
0 (zero) Move cursor to the beginning of current line
w Forward one word
b Backward one word
Exit Commands
:wq Write file to disk and quit the editor
:q! Quit (no warning)
:q Quit (a warning is printed if a modified file has not been saved)
ZZ Save workspace and quit the editor (same as :wq)
: 10,25 w temp
write lines 10 through 25 into file named temp. Of course, other line
numbers can be used. (Use :f to find out the line numbers you want.

Text Deletion Commands
x Delete character
dw Delete word from cursor on
db Delete word backward
dd Delete line
d$ Delete to end of line
d^ (d caret, not CTRL d) Delete to beginning of line
Yank (has most of the options of delete)-- VI's copy commmand
yy yank current line
y$ yank to end of current line from cursor
yw yank from cursor to end of current word
5yy yank, for example, 5 lines
Paste (used after delete or yank to recover lines.)
p paste below cursor
P paste above cursor
"2p paste from buffer 2 (there are 9)
u Undo last change
U Restore line
J Join next line down to the end of the current line
File Manipulation Commands
:w Write workspace to original file
:w file Write workspace to named file
:e file Start editing a new file
:r file Read contents of a file to the workspace
To create a page break, while in the insert mode, press the CTRL key
And l. ^L will appear in your text and will cause the printer to start
A new page.


Other Useful Commands
Most commands can be repeated n times by typing a number, n, before
the command. For example 10dd means delete 10 lines.
. Repeat last command
cw Change current word to a new word
r Replace one character at the cursor position
R Begin overstrike or replace mode – use ESC key to exit
:/ pattern Search forward for the pattern
:? pattern Search backward for the pattern
n (used after either of the 2 search commands above to
continue to find next occurrence of the pattern.
:g/pat1/s//pat2/g replace every occurrence of pattern1 (pat1) with
pat2
Example :g/tIO/s//Ada.Text_IO/g
This will find and replace tIO by Ada.text_IO everywhere in the file.
:g/a/s// /g replace the letter a, by blank
:g/a/s///g replace a by nothing
note: Even this command be undone by u

Examples
Opening a New File
Step 1 type vim filename (create a file named filename)
Step 2 type i ( switch to insert mode)
Step 3 enter text (enter your Ada program)
Step 4 hit Esc key (switch back to command mode)
Step 5 type :wq (write file and exit vim)

Editing the Existing File
Step 1 type vim filename (edit the existing file named filename)
Step 2 move around the file using h/j/k/l key or any appropriate command
h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
Step 3 edit required text (replace or delete or insert)
Step 4 hit Esc key (exit from insert mode if you insert or replace text)

Step 5 type :wq

Tuesday, April 15, 2014

Network Basics in Linux

This website is very useful to learn Linux overall.

This URL is chapter about basic Networking: Please check: http://www.slackbook.org/html/basic-network-commands.html

http://www.slackbook.org/html/index.html

Monday, April 14, 2014

Linux Boot Process (6 stages)

Press the power button on your system, and after few moments you see the Linux login prompt.
Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?
The following are the 6 high level stages of a typical Linux boot process.

1. BIOS

  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
  • #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz
    hiddenmenu
    title CentOS (2.6.18-194.el5PAE)
              root (hd0,0)
              kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
              initrd /boot/initrd-2.6.18-194.el5PAE.img
  • As you notice from the above info, it contains kernel and initrd image.
  • So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.