Linux Tutorial PDF
Linux Tutorial PDF
Manual Pages
Keystrokes Action
dd
Delete 3 lines.
C Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.
dw
Delete 4 words
r Replace character
S Substitute entire line and begin to insert at the beginning of the line
Make sure you press the right command otherwise you will end up making undesirable changes to the
file. You can also enter the insert mode by pressing a, A, o, as required.
Keystroke Use
k Move cursor up
You should be in the command mode to exit the editor and save changes to the file.
Keystroke Use
The /etc/passwd file is a colon-separated file that contains the following information:
User name.
Encrypted password.
Login shell.
/etc/group file
and each line has the following format (all fields are separated by a colon (:)
group_name: It is the name of group. If you run ls -l command, you will see this name printed in the
group field.
Password: Generally password is not used, hence it is empty/blank. It can store encrypted password.
Group ID (GID): Each user must be assigned a group ID. You can see this number in your /etc/passwd
file.
Group List: It is a list of user names of users who are members of the group. The user names, must be
separated by commas.
Password : It is your encrypted password. The password should be minimum 8-12 characters long
including special characters, digits, lower case alphabetic and more. Usually password format is set to
$id$salt$hashed, The $id is the algorithm used On GNU/Linux as follows:
Last password change (lastchanged) : Days since Jan 1, 1970 that password was last changed
Minimum : The minimum number of days required between password changes i.e. the number of days
left before the user is allowed to change his/her password
Maximum : The maximum number of days the password is valid (after that user is forced to change
his/her password)
Warn : The number of days before password is to expire that user is warned that his/her password must
be changed
Inactive : The number of days after password expires that account is disabled
Expire : days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying when the login
may no longer be used.
Permissions
SUID ( setuid ) :-
If SUID bit is set on a file and a user executed it. The process will have the same rights as the owner of
the file being executed.
For example: passwd command have SUID bit enabled. When a normal user change his password this
script update few system files like /etc/passwd and /etc/shadow which can’t be update by non root
account. So that passwd command process always run with root user rights.
Mehtod 1:
# ls -l suresh.txt
Method 2:
# ls -l suresh.txt
SGID ( setgid) :-
Same as SUID, The process will have the same group rights of the file being executed. If SGID bit is set on
any directory, all sub directories and files created inside will get same group ownership as main
directory, it doesn’t matter who is creating.
Implementation of SGID on directory:
# ls -ld /test
# su - suresh
$ cd /test/
$ touch suresh.net.txt
$ ls -l suresh.net.txt
Sticky Bit :-
The sticky bit is used to indicate special permissions for files and directories.
If a directory with sticky bit enabled, will restricts deletion of file inside it.
It can be removed by root, owner of file or who have write permission on it.
Method 1:
# chmod +t suresh.txt
# ls -l suresh.txt
Mothod 2:
# ls -l suresh.txt
In above output it showing sticky bit is set with character t or T in permissions filed.
Small t represent that execute permission also enable and capital T represent that execute permission
are not enabled.
Sample Output
ii python2.7 2.7.3-0ubuntu3.4
Interactive high-level object-oriented language (version 2.7)
ii python2.7-minimal 2.7.3-0ubuntu3.4
Minimal subset of the Python language (version 2.7)
ii python-openssl 0.12-1ubuntu2.1
Python wrapper around the OpenSSL library
ii python-pam 0.4.2-12.2ubuntu4
A Python interface to the PAM library
First, we ran dpkg –l, which lists installed *.deb packages on your system. Second, we piped that output
to grep –i python, which simple states “go to grep and filter out and return everything with ‘python’ in it.”
The –i option is there to ignore-case, as grep is case-sensitive. Using the –i option is a good habit of
getting into, unless of course you are trying to nail down a more specific search.
2. Search and Filter Files
The grep can also be used to search and filter within individual files or multiple files. Lets take this
scenario:
You are having some trouble with your Apache Web Server, and you have reached out to one of the
many awesome forums on the net asking for some help. The kind soul who replies to you has asked you
to post the contents of your /etc/apache2/sites-available/default-ssl file. Wouldn’t it be easier for you,
the guy helping you, and everyone reading it, if you could remove all of the commented lines? Well you
can! Just run this:
# grep –v “#” /etc/apache2/sites-available/default-ssl
The –v option tells grep to invert its output, meaning that instead of printing matching lines, do the
opposite and print all of the lines that don’t match the expression, in this case, the # commented lines.
3. Find all .mp3 Files Only
The grep can be very useful for filtering from stdout. For example, let’s say that you have an entire
folder full of music files in a bunch of different formats. You want to find all of the *.mp3 files from the
artist JayZ, but you don’t want any of the remixed tracks. Using a find command with a couple of grep
pipes will do the trick:
# find . –name “*.mp3” | grep –i JayZ | grep –vi “remix”
In this example, we are using find to print all of the files with a *.mp3 extension, piping it to grep –i to
filter out and prints all files with the name “JayZ” and then another pipe to grep –vi which filters out and
does not print all filenames with the string (in any case) “remix”.
1. 35 Practical Examples of Linux Find Command
4. Display Number of Lines Before or After Search String
Another couple of options are the –A and –B switches, which displays the matched line and number of
lines either that come before or after the search string. While the man page gives a more detailed
explanation, I find it easiest to remember the options as –A = after, and –B = before:
# ifconfig | grep –A 4 eth0
# ifconfig | grep -B 2 UP
Will print out the line containing the pattern in quotes. On the other hand, if you try:
# ifconfig | grep –w “RUN”
Nothing will be returned as we are not searching for a pattern, but an entire word.
10. Search a string in Gzipped Files
Deserving some mention are grep’s derivatives. The first is zgrep, which, similar to zcat, is for use on
gzipped files. It takes the same options as grep and is used in the same way:
# zgrep –i error /var/log/syslog.2.gz
11. Match Regular Expression in Files
The egrep is another derivative that stands for “Extended Global Regular Expression”. It recognizes
additional expression meta-characters such at + ? | and (). egrep is very useful for searching source files,
and other pieces of code, should the need arise. It can be invoked from regular grep by specifying the –E
option.
# grep –E
This is just a starting point with grep, but as you are probably able to see, it is invaluable for a variety of
purposes. Aside from the simple one line commands we have implemented, grep can be used to write
powerful cron jobs, and robust shell scripts, for a start. Be creative, experiment with the options in the
man page, and come up with grep expressions that serve your own purposes!
FIND COMMAND
./suresh.txt
/home/suresh.txt
./suresh.txt
./Suresh.txt
4. Find Directories Using Name
Find all directories whose name is Suresh in / directory.
# find / -type d -name Suresh
/Suresh
./suresh.php
./suresh.php
./login.php
./index.php
OR
Disk Management
fdisk stands (for “fixed disk or format disk“) is an most commonly used command-line based
disk manipulation utility for a Linux/Unix systems. With the help of fdisk command you can view,
create, resize, delete, change, copy and move partitions on a hard drive using its own user
friendly text based menu driven interface.
This tool is very useful in terms of creating space for new partitions, organising space for new
drives, re-organising an old drives and copying or moving data to new disks. It allows you to
create a maximum of four new primary partition and number of logical (extended) partitions,
based on size of the hard disk you have in your system.
Caution – Don’t Create, Delete or Modify Partitions. Unless you know what you are doing!
The following basic command list all existing disk partition on your system. The ‘-l‘ argument
stand for (listing all partitions) is used with fdisk command to view all available partitions on
Linux. The partitions are displayed by their device’s names. For
example: /dev/sda, /dev/sdb or /dev/sdc.
To view all partitions of specific hard disk use the option ‘-l‘ with device name. For example, the
following command will display all disk partitions of device /dev/sda. If you’ve different device
names, simple write device name as /dev/sdb or /dev/sdc.
If you would like to view all commands which are available for fdisk. Simply use the following
command by mentioning the hard disk name such as /dev/sda as shown below. The following
command will give you output similar to below.
switch off the mode (command 'c') and change display units to
Type ‘m‘ to see the list of all available commands of fdisk which can be operated
on /dev/sda hard disk. After, I enter ‘m‘ on the screen, you will see the all available options for
fdisk that you can be used on the /dev/sda device.
switch off the mode (command 'c') and change display units to
To print all partition table of hard disk, you must be on command mode of specific hard disk
say /dev/sda.
From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print the
specific /dev/sda partition table.
If you would like to delete a specific partition (i.e /dev/sda9) from the specific hard disk such
as /dev/sda. You must be in fdisk command mode to do this.
Next, enter ‘d‘ to delete any given partition name from the system. As I enter ‘d‘, it will prompt
me to enter partition number that I want to delete from /dev/sda hard disk. Suppose I enter
number ‘4‘ here, then it will delete partition number ‘4‘ (i.e. /dev/sda4) disk and shows free
space in partition table. Enter ‘w‘ to write table to disk and exit after making new alterations to
partition table. The new changes would only take place after next reboot of system. This can be
easily understood from the below output.
switch off the mode (command 'c') and change display units to
If you’ve free space left on one of your device say /dev/sda and would like to create a new
partition under it. Then you must be in fdisk command mode of /dev/sda. Type the following
command to enter into command mode of specific hard disk.
After entering in command mode, now press “n” command to create a new partition
under /dev/sdawith specific size. This can be demonstrated with the help of following given
output.
switch off the mode (command 'c') and change display units to
After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘
command. Type the following command in the terminal to format a partition. Here /dev/sda4 is
my newly created partition.
After formatting new partition, check the size of that partition using flag ‘s‘ (displays size in
blocks) with fdisk command. This way you can check size of any specific device.
5194304
If you’ve deleted a logical partition and again recreated it, you might notice ‘partition out of
order‘ problem or error message like ‘Partition table entries are not in disk order‘.
For example, when three logical partitions such as (sda4, sda5 and sda6) are deleted, and new
partition created, you might expect the new partition name would be sda4. But, the system
would create it as sda5. This happens because of, after the partition are deleted, sda7 partition
had been moved as sda4and free space shift to the end.
To fix such partition order problems, and assign sda4 to the newly created partition, issue the ‘x‘
to enter an extra functionality section and then enter ‘f‘ expert command to fix the order of
partition table as shown below.
After, running ‘f‘ command, don’t forget to run ‘w‘ command to save and exit from fdisk
command mode. Once it fixed partition table order, you will no longer get error messages.
10. How to Disable Boot Flag (*) of a Partition
By default, fdisk command shows the boot flag (i.e. ‘*‘) symbol on each partition. If you want to
enable or disable boot flag on a specific partition, do the following steps.
Press ‘p‘ command to view the current partition table, you see there is a boot flag (asterisk (*)
symbol in orange color) on /dev/sda1 disk as shown below.
switch off the mode (command 'c') and change display units to
As shown above two physical volumes are created – /dev/sda6 and /dev/sda7.
If the physical volumes are already created, you can view them using the pvscan command as shown
below.
$ sudo pvscan
PV /dev/sda6 lvm2 [1.86 GB]
PV /dev/sda7 lvm2 [1.86 GB]
Total: 2 [3.72 GB] / in use: 0 [0 ] / in no VG: 2 [3.72 GB]
You can view the list of physical volumes with attributes like size, physical extent size, total physical
extent size, the free space, etc., using pvdisplay command as shown below.
$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda6
VG Name
PV Size 1.86 GB / not usable 2.12 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 476
Free PE 456
Allocated PE 20
PV UUID m67TXf-EY6w-6LuX-NNB6-kU4L-wnk8-NjjZfv
Note : PE – Physical Extents are nothing but equal-sized chunks. The default size of extent is 4MB.
Create the Volume Group – Use vgcreate, vgdisplay Commands
Volume groups are nothing but a pool of storage that consists of one or more physical volumes. Once you
create the physical volume, you can create the volume group (VG) from these physical volumes (PV).
In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.
$ sudo vgcreate vol_grp1 /dev/sda6 /dev/sda7
Volume group "vol_grp1" successfully created
LVM processes the storage in terms of extents. We can also change the extent size (from the default size
4MB) using -s flag.
vgdisplay command lists the created volume groups.
$ sudo vgdisplay
--- Volume group ---
VG Name vol_grp1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.72 GB
PE Size 4.00 MB
Total PE 952
Alloc PE / Size 0 / 0
Free PE / Size 952 / 3.72 GB
VG UUID Kk1ufB-rT15-bSWe-5270-KDfZ-shUX-FUYBvR
$ sudo lvdisplay
--- Logical volume ---
LV Name /dev/vol_grp1/logical_vol1
VG Name vol_grp1
LV UUID ap8sZ2-WqE1-6401-Kupm-DbnO-2P7g-x1HwtQ
LV Write Access read/write
LV Status available
# open 0
LV Size 80.00 MB
Current LE 20
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage
purpose.
$ sudo mkfs.ext4 /dev/vol_grp1/logical_vol1
LVM resize: Change the size of the logical volumes – Use lvextend Command
We can extend the size of the logical volumes after creating it by using lvextend utility as shown below.
The changes the size of the logical volume from 80MB to 100MB.
$ sudo lvextend -L100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 100.00 MB
Logical volume logical_vol1 successfully resized
We can also add additional size to a specific logical volume as shown below.
$ sudo lvextend -L+100 /dev/vol_grp1/logical_vol1
Extending logical volume logical_vol1 to 200.00 MB
Logical volume logical_vol1 successfully resized
RPM package is a powerful utility to manage the software in all major Linux distributions. RPMs
can be used to,
Install packages
Remove packages
Upgrade packages
Verify packages
7. To check what has changed in the files on the system since the HTTPD rpm originally
installed,
rpm -V httpd
8. Checking package to ensure its integrity and origin: (NOTE: gpg or pgp software must be
installed on your system before you use this command)
rpm -K /mnt/iso/suse/i586/wget-1.10.2-78.i586.rpm
rpm -e wget
YUM
# yum grouplist
# yum repolist
Symbolic links are created with the “ln” command in linux. The syntax of the command is:
$ln -s
-s = This flag tells to create a symlink (if you don’t use this it will create a hard link, which we will talk
about soon).
For Example,
$ ln -s /usr/bin/suresh ~/Desktop/suresh
So, in hard link, you are referencing the inode directly on the disk, which means that there should be
a way to know how many hard links exist to a file. For the same, in the inode information, you have an
option for “links”, which will tell how many links exists to a file. You can find the same information by
using this command:
$ stat 01
Size: 923383 Blocks: 1816 IO Block: 4096 regular file
Device: 803h/2051d Inode: 12684895 Links: 3
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-09-07 01:46:54.000000000 -0500
Modify: 2012-04-27 06:22:02.000000000 -0500
Change: 2012-04-27 06:22:02.000000000 -0500
In this example, it means that the specific file have 2 hard links, which makes the count to 3.
A. A softlink will have a different Inode number than the source file, which will be having a pointer to
the source file but hardlink will be using the same Inode number as the source file.
Q. How can I find all the Soft Links in my system ?
A. Use this command for the same “find /etc -type l -exec ls -li {} \;”
Q. How can I find all the files having Hard Links in my system ?
A. Use this command for the same “find / -links +2 -type f -exec ls -li {} \;”
Q. How to find whether a file is a softlink ?
A. Simply using this command “ls -l” will tell you whether a file is pointing to some other file or not.
Linux Cron utility is an effective way to schedule a routine background job at a specific time
and/or day on an on-going basis.
Linux Crontab Format
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/Suresh/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
2. Schedule a Job For More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.
This example executes the specified incremental backup shell script (incremental-backup) at
11:00 and 16:00 on every day. The comma separated value in a field specifies that the command
needs to be executed in all the mentioned time.
00 11,16 * * * /home/Suresh/bin/incremental-backup
00 09-18 * * * /home/Suresh/bin/check-db-status
Suresh@dev-db$ crontab -l
@yearly /home/Suresh/annual-maintenance
*/10 * * * * /home/Suresh/check-disk-space
[Note: This displays crontab of the current logged in user]
root@dev-db# crontab -l
Suresh@dev-db$ crontab -e
@yearly /home/Suresh/centos/bin/annual-maintenance
*/10 * * * * /home/Suresh/debian/bin/check-disk-space
~
"/tmp/crontab.XXXXyjWkHw" 2L, 83C
[Note: This will open the crontab file in Vim editor for editing.
Please note cron created a temporary /tmp/crontab.XX... ]
When you save the above temporary file with :wq, it will save the crontab and display the
following message indicating the crontab is successfully modified.
root@dev-db# crontab -e
* * * * * CMD
The * means all the possible unit — i.e every minute of every hour through out the year. More
than using this * directly, you will find it very useful in the following cases.
*/10 * * * * /home/Suresh/check-disk-space
It executes the specified command check-disk-space every 10 minutes through out the year. But
you may have a requirement of executing the command only during office hours or vice versa.
The above examples shows how to do those things.
Instead of specifying values in the 5 fields, we can specify it using a single keyword as mentioned
below.
There are special cases in which instead of the above 5 fields you can use @ followed by a
keyword — such as reboot, midnight, yearly, hourly.
Table: Cron special
keywords and its meaning
Keyword Equivalent
@yearly 0011*
@daily 00***
@hourly 0****
@reboot Run at startup.
This will execute the system annual maintenance using annual-maintenance shell script at
00:00 on Jan 1st for every year.
@yearly /home/Suresh/red-hat/bin/annual-maintenance
This will execute the shell script tape-backup at 00:00 on 1st of every month.
@monthly /home/Suresh/suse/bin/tape-backup
11. How to Execute a Linux Command After Every Reboot using @reboot?
Using the @reboot cron keyword, this will execute the specified command once after the
machine got booted every time.
@reboot CMD
12. How to Disable/Redirect the Crontab Mail Output using MAIL keyword?
By default crontab sends the job output to the user who scheduled the job. If you want to
redirect the output to a specific user, add or update the MAIL variable in the crontab as shown
below.
Suresh@dev-db$ crontab -l
MAIL="Suresh"
@yearly /home/Suresh/annual-maintenance
*/10 * * * * /home/Suresh/check-disk-space
If you wanted the mail not to be sent to anywhere, i.e to stop the crontab output to be emailed,
add or update the MAIL variable in the crontab as shown below.
MAIL=""
13. How to Execute a Linux Cron Jobs Every Second Using Crontab.
You cannot schedule a every-second cronjob. Because in cron the minimum unit you can specify
is minute. In a typical scenario, there is no reason for most of us to run any job every second in
the system.
For example, instead of specifying /home/Suresh/tape-backup, if you want to just specify tape-
backup, then add the path /home/Suresh to the PATH variable in the crontab as shown below.
Suresh@dev-db$ crontab -l
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/Suresh
@yearly annual-maintenance
*/10 * * * * check-disk-space
Suresh@dev-db$ crontab -l
$ cat cron-file.txt
@yearly /home/Suresh/annual-maintenance
*/10 * * * * /home/Suresh/check-disk-space
Suresh@dev-db$ crontab -l
@yearly /home/Suresh/annual-maintenance
*/10 * * * * /home/Suresh/check-disk-space
Note: This will install the cron-file.txt to your crontab, which will also remove your old cron
entries. So, please be careful while uploading cron entries from a cron-file.txt.
To use cron tab there are two important commands:
Here is an example of a very easy to reference header for your crontab. You have
the descriptions for every time slot and what every slot will accept. This example
also specifies the shell and the path making sure the binaries you run can be found.
The last line is an example of running "newsyslog" Sunday at midnight. You are
welcome to cut/paste this block to the top of your cron tab.
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute (0-59)
#| hour (0-23)
#| | day of the month (1-31)
#| | | month of the year (1-12 or Jan-Dec)
#| | | | day of the week (0-6 with 0=Sun or Sun-Sat)
#| | | | | commands
#| | | | | |
#### rotate logs weekly (Sunday at midnight)
00 0 * * 0 /usr/bin/newsyslog
Lets take a look at some examples in order of simple to alittle more complex.
Notice all of the binaries are using their absolute paths. Cron uses its own PATH
variable and it is a safe practice to always use absolute paths in your crontab. This
is to avoid confusion.
00 0 * * 0 /usr/bin/newsyslog
Rotate logs weekly at 12midnight. (instead of 0 for the day of the week we can use
Sun for Sunday)
00 0 * * Sun /usr/bin/newsyslog
59 23 * * * /usr/local/bin/pflogsumm -d today
/var/log/maillog | mail -s "mail report" root
Run the backup scripts at 5am on the 3rd (Wed) and 5th (Fri) day of the week.
Send any errors to /dev/null
Compress backup files at 6am on the 1st and 15th of the month.
00 6 1,15 * * /tools/BACKUP_compress.sh
05 0 * * */3 /tools/ad_servers_newlist.sh
Clear the blocked hosts list at 3:23pm (15:23) every Monday only on even
numbered months.
23 15 * */2 1 /tools/clear_blocked_hosts.sh
Run a script at 8:45pm (20:45) on 2nd and the 16th only in the months of January
and April.
Run a script every day at 8:45pm (20:45) and add a random sleep time between 0
and 300 seconds.
Run the script at 23:59 (11:59pm) on the last day of the month.
To use "at" you need to know the structure and how to complete the command.
To run jobs only once it is easier to use "at" than to setup and cron job and then go
back and remove it once the job has ran. Remember you need to have the "atd"
daemon running on Linux systems to run "at" jobs. On OpenBSD or FreeBSD
system the "crond" daemon will handle "cron" and "at" jobs.
To run an "at" job you need to fist tell "at" what time to run the job. Remember to
use absolute paths to avoid confusion. Once to execute att with the time and date
you will be put into an "at" shell. This is where you will enter the commands you
want to execute, one command per line to make it simple.
Once you have completed entering your commands and type Ctrl-d "at" will
respond with the job number and a verification printout of when the job is going to
run. If you made a mistake and ran the job at the wrong time you can usr "atrm" to
remove the job and re-enter your job with the current time.
NETWORKING
1. ifconfig
ifconfig (interface configurator) command is use to initialize an interface, assign IP Address to
interface and enable or disable interface on demand.
With this command you can view IP Address and Hardware / MAC address assign to interface
and also MTU (Maximum transmission unit) size.
# ifconfig
# ifconfig eth0
Assigning an IP Address and Gateway to interface on the fly. The setting will be removed in
case of system reboot.
Enable eth0
# ifup eth0
Disable eth0
# ifdown eth0
Setting MTU Size
By default MTU size is 1500. We can set required MTU size with below command. Replace
XXXX with size.
# ping 4.2.2.2
OR
# ping www.suresh.com
PING suresh.com (50.116.66.136) 56(84) bytes of data.
64 bytes from 50.116.66.136: icmp_seq=1 ttl=47 time=284 ms
64 bytes from 50.116.66.136: icmp_seq=2 ttl=47 time=287 ms
64 bytes from 50.116.66.136: icmp_seq=3 ttl=47 time=285 ms
In Linux ping command keep executing until you interrupt. Ping with -c option exit after N
number of request (success or error respond).
# ping -c 5 www.suresh.com
# traceroute 4.2.2.2
# netstat -r
5. DIG Command
Dig (domain information groper) query DNS related information like A Record, CNAME, MX
Record etc. This command mainly use to troubleshoot DNS related query.
6. NSLOOKUP Command
nslookup command also use to find out DNS related query. The following examples shows A
Record (IP Address) of suresh.com.
# nslookup www.suresh.com
Server: 4.2.2.2
Address: 4.2.2.2#53
Non-authoritative answer:
www.suresh.com canonical name = suresh.com.
Name: suresh.com
Address: 50.116.66.136
For more NSLOOKUP Command, read the article on 8 Linux Nslookup Command Examples.
7. ROUTE Command
route command also shows and manipulate ip routing table. To see default routing table in
Linux, type the following command.
# route
Route Adding
# host www.google.com
# arp -e
# iwconfig [interface]
12. HOSTNAME Command
hostname is to identify in a network. Execute hostname command to see the hostname of your
box.
You can set hostname permanently in /etc/sysconfig/network. Need to reboot box once set a
proper hostname.
# hostname
suresh.com
13. GUI tool system-config-network
Type system-config-network in command prompt to configure network setting and
you will get nice Graphical User Interface (GUI) which may also use to configure IP Address,
Gateway, DNS etc. as shown below image.
# system-config-network
Linux GUI Network Configuration
Linux GUI Network Configuration Tool
This article can be useful for day to day use of Linux Network administrator in Linux / Unix-like
operating system.
Booting Procedure
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
2. MBR
3. GRUB
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
root (hd0,0)
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
5. Init
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.
LogRotate
1St Method:
vi /etc/logrotate.conf
/usr/local/tomcat/logs/*.log{
daily
dateext
maxage 90
missingok
2nd Method:
vi /etc/logrotate.conf
/usr/local/tomcat/logs/*.log {
missingok
nomail
postrotate
endscript
RAID 0
RAID is Redundant Array of Inexpensive disks, used for high availability and
reliability in large scale environments, where data need to be protected than
normal use. Raid is just a collection of disks in a pool to become a logical
volume and contains an array. A combine drivers makes an array or called as
set of (group).
RAID can be created, if there are minimum 2 number of disk connected to a
raid controller and make a logical volume or more drives can be added in an
array according to defined RAID Levels. Software Raid are available without
using Physical hardware those are called as software raid. Software Raid will
be named as Poor man raid.
Main concept of using RAID is to save data from Single point of failure, means
if we using a single disk to store the data and if it’s failed, then there is no
chance of getting our data back, to stop the data loss we need a fault
tolerance method. So, that we can use some collection of disk to form a RAID
set.
What is Stripe in RAID 0?
Stripe is striping data across multiple disk at the same time by dividing the
contents. Assume we have two disks and if we save content to logical volume
it will be saved under both two physical disks by dividing the content. For
better performance RAID 0 will be used, but we can’t get the data if one of the
drive fails. So, it isn’t a good practice to use RAID 0. The only solution is to
install operating system with RAID0 applied logical volumes to safe your
important files.
RAID 0 has High Performance.
Zero Capacity Loss in RAID 0. No Space will be wasted.
Zero Fault Tolerance ( Can’t get back the data if any one of disk fails).
Write and Reading will be Excellent.
Requirements
Minimum number of disks are allowed to create RAID 0 is 2, but you can add
more disk but the order should be twice as 2, 4, 6, 8. If you have a Physical
RAID card with enough ports, you can add more disks.
Here we are not using a Hardware raid, this setup depends only on Software
RAID. If we have a physical hardware raid card we can access it from it’s
utility UI. Some motherboard by default in-build with RAID feature,
there UI can be accessed using Ctrl+I keys.
If you’re new to RAID setups, please read our earlier article, where we’ve
covered some basic introduction of about RAID.
IP Address : 192.168.0.225
Two Disks : 20 GB each
This article is Part 2 of a 9-tutorial RAID series, here in this part, we are going
to see how we can create and setup Software RAID0 or striping in Linux
systems or servers using two 20GB disks named sdb and sdc.
Step 1: Updating System and Installing mdadm
for Managing RAID
1. Before setting up RAID0 in Linux, let’s do a system update and then install
‘mdadm‘ package. The mdadm is a small program, which will allow us to
configure and manage RAID devices in Linux.
3. Once the new hard drives detected, it’s time to check whether the attached
drives are already using any existing raid with the help of following ‘mdadm’
command.
In the above output, we come to know that none of the RAID have been
applied to these two sdb and sdc drives.
Step 3: Creating Partitions for RAID
4. Now create sdb and sdc partitions for raid, with the help of following fdisk
command. Here, I will show how to create partition on sdb drive.
# fdisk /dev/sdb
Create Partitions
Note: Please follow same above instructions to create partition on sdc drive
now.
5. After creating partitions, verify both the drivers are correctly defined for
RAID using following command.
-C – create
-l – level
-n – No of raid-devices
7. Once md device has been created, now verify the status of RAID
Level, Devices and Array used, with the help of following series of commands
as shown.
# cat /proc/mdstat
Verify RAID Level
# mdadm -E /dev/sd[b-c]1
Verify RAID Device
# mkfs.ext4 /dev/md0
Create ext4 Filesystem
9. Once ext4 filesystem has been created for Raid device, now create a mount
point directory (i.e. /mnt/raid0) and mount the device /dev/md0 under it.
# mkdir /mnt/raid0
# df -h
11. Next, create a file called ‘suresh.txt‘ under the mount point /mnt/raid0,
add some content to the created file and view the content of a file and
directory.
# touch /mnt/raid0/suresh.txt
# cat /mnt/raid0/suresh.txt
# ls -l /mnt/raid0/
# vim /etc/fstab
Add the following entry as described. May vary according to your mount
location and filesystem you using.
13. Run mount ‘-a‘ to check if there is any error in fstab entry.
# mount -av
Check Errors in Fstab
# cat /etc/mdadm.conf
That’s it, we have seen here, how to configure RAID0 striping with raid levels
by using two hard disks. In next article, we will see how to setup RAID5.
RAID 1
RAID Mirroring means an exact clone (or mirror) of the same data writing to
two drives. A minimum two number of disks are more required in an array to
create RAID1 and it’s useful only, when read performance or reliability is more
precise than the data storage capacity.
Mirrors are created to protect against data loss due to disk failure. Each disk
in a mirror involves an exact copy of the data. When one disk fails, the same
data can be retrieved from other functioning disk. However, the failed drive
can be replaced from the running computer without any user interruption.
Features of RAID 1
Mirror has Good Performance.
50% of space will be lost. Means if we have two disk with 500GB size total, it
will be 1TB but in Mirroring it will only show us 500GB.
No data loss in Mirroring if one disk fails, because we have the same content
in both disks.
Reading will be good than writing data to drive.
Requirements
Minimum Two number of disks are allowed to create RAID 1, but you can add
more disks by using twice as 2, 4, 6, 8. To add more disks, your system must
have a RAID physical adapter (hardware card).
Here we’re using software raid not a Hardware raid, if your system has an
inbuilt physical hardware raid card you can access it from it’s utility UI or
using Ctrl+I key.
Read Also: Basic Concepts of RAID in Linux
My Server Setup
IP Address : 192.168.0.226
Hostname : rd1.sureshlocal.com
This article will guide you through a step-by-step instructions on how to setup
a software RAID 1 or Mirror usingmdadm (creates and manages raid) on
Linux Platform. Although the same instructions also works on other Linux
distributions such as RedHat, CentOS, Fedora, etc.
Step 1: Installing Prerequisites and Examine
Drives
1. As I said above, we’re using mdadm utility for creating and managing RAID
in Linux. So, let’s install themdadm software package on Linux using yum or
apt-get package manager tool.
2. Once ‘mdadm‘ package has been installed, we need to examine our disk
drives whether there is already any raid configured using the following
command.
# mdadm -E /dev/sd[b-c]
As you see from the above screen, that there is no any super-block detected
yet, means no RAID defined.
Step 2: Drive Partitioning for RAID
3. As I mentioned above, that we’re using minimum two
partitions /dev/sdb and /dev/sdc for creating RAID1. Let’s create partitions on
these two drives using ‘fdisk‘ command and change the type to raid during
partition creation.
# fdisk /dev/sdb
After ‘/dev/sdb‘ partition has been created, next follow the same instructions
to create new partition on/dev/sdc drive.
# fdisk /dev/sdc
Create Second Partitions
4. Once both the partitions are created successfully, verify the changes on
both sdb & sdc drive using the same ‘mdadm‘ command and also confirm the
RAID type as shown in the following screen grabs.
# mdadm -E /dev/sd[b-c]
Verify Partitions Changes
Note: As you see in the above picture, there is no any defined RAID on
the sdb1 and sdc1 drives so far, that’s the reason we are getting as no super-
blocks detected.
Step 3: Creating RAID1 Devices
5. Next create RAID1 Device called ‘/dev/md0‘ using the following command
and verity it.
# cat /proc/mdstat
Create RAID Device
6. Next check the raid devices type and raid array using following commands.
# mdadm -E /dev/sd[b-c]1
From the above pictures, one can easily understand that raid1 have been
created and using /dev/sdb1 and/dev/sdc1 partitions and also you can see
the status as resyncing.
Step 4: Creating File System on RAID Device
7. Create file system using ext4 for md0 and mount under /mnt/raid1.
# mkfs.ext4 /dev/md0
Create RAID Device Filesystem
8. Next, mount the newly created filesystem under ‘/mnt/raid1‘ and create
some files and verify the contents under mount point.
# mkdir /mnt/raid1
# touch /mnt/raid1/suresh.txt
10. Run ‘mount -a‘ to check whether there are any errors in fstab entry.
# mount -av
11. Next, save the raid configuration manually to ‘mdadm.conf‘ file using the
below command.
The above configuration file is read by the system at the reboots and load the
RAID devices.
In the above image, we can see there are 2 devices available in our RAID and
Active Devices are 2. Now let us see what will happen when a disk plugged
out (removed sdc disk) or fails.
# ls -l /dev | grep sd
Now in the above image, you can see that one of our drive is lost. I unplugged
one of the drive from my Virtual machine. Now let us check our precious data.
# cd /mnt/raid1/
# cat suresh.txt
Verify RAID Data
Did you see our data is still available. From this we come to know the
advantage of RAID 1 (mirror). In next article, we will see how to setup a RAID
5 striping with distributed Parity. Hope this helps you to understand how the
RAID 1 (Mirror) Works.
RAID 5
In RAID 5, data strips across multiple drives with distributed parity. The
striping with distributed parity means it will split the parity information and
stripe data over the multiple disks, which will have good data redundancy.
Setup Raid 5 in Linux
For RAID Level it should have at least three hard drives or more. RAID 5 are
being used in the large scale production environment where it’s cost effective
and provide performance as well as redundancy.
What is Parity?
Parity is a simplest common method of detecting errors in data storage. Parity
stores information in each disks, Let’s say we have 4 disks, in 4 disks one disk
space will be split to all disks to store the parity information’s. If any one of the
disks fails still we can get the data by rebuilding from parity information after
replacing the failed disk.
Pros and Cons of RAID 5
Gives better performance
Support Redundancy and Fault tolerance.
Support hot spare options.
Will loose a single disk capacity for using parity information.
No data loss if a single disk fails. We can rebuilt from parity after replacing
the failed disk.
Suits for transaction oriented environment as the reading will be faster.
Due to parity overhead, writing will be slow.
Rebuild takes long time.
Requirements
Minimum 3 hard drives are required to create Raid 5, but you can add more
disks, only if you’ve a dedicated hardware raid controller with multi ports.
Here, we are using software RAID and ‘mdadm‘ package to create raid.
mdadm is a package which allow us to configure and manage RAID devices in
Linux. By default there is no configuration file is available for RAID, we must
save the configuration file after creating and configuring RAID setup in
separate file called mdadm.conf.
Before moving further, I suggest you to go through the following articles for
understanding the basics of RAID in Linux.
IP Address : 192.168.0.227
Hostname : rd5.sureshlocal.com
This article is a Part 4 of a 9-tutorial RAID series, here we are going to setup a
software RAID 5 with distributed parity in Linux systems or servers using three
20GB disks named /dev/sdb, /dev/sdc and /dev/sdd.
Step 1: Installing mdadm and Verify Drives
1. As we said earlier, that we’re using CentOS 6.5 Final release for this raid
setup, but same steps can be followed for RAID setup in any Linux based
distributions.
# lsb_release -a
3. After the ‘mdadm‘ package installation, let’s list the three 20GB disks which
we have added in our system using ‘fdisk‘ command.
# fdisk -l | grep sd
4. Now it’s time to examine the attached three drives for any existing RAID
blocks on these drives using following command.
# mdadm -E /dev/sd[b-d]
Note: From the above image illustrated that there is no any super-block
detected yet. So, there is no RAID defined in all three drives. Let us start to
create one now.
Step 2: Partitioning the Disks for RAID
5. First and foremost, we have to partition the disks (/dev/sdb, /dev/sdc
and /dev/sdd) before adding to a RAID, So let us define the partition using
‘fdisk’ command, before forwarding to the next steps.
# fdisk /dev/sdb
# fdisk /dev/sdc
# fdisk /dev/sdd
Now partition the sdc and sdd drives by following the steps given in the
screenshot or you can follow above steps.
# fdisk /dev/sdc
6. After creating partitions, check for changes in all three drives sdb, sdc, &
sdd.
or
# mdadm -E /dev/sd[b-c]
Note: In the above pic. depict the type is fd i.e. for RAID.
7. Now Check for the RAID blocks in newly created partitions. If no super-
blocks detected, than we can move forward to create a new RAID 5 setup on
these drives.
9. After creating raid device, check and verify the RAID, devices included and
RAID Level from the mdstat output.
# cat /proc/mdstat
If you want to monitor the current building process, you can use ‘watch‘
command, just pass through the ‘cat /proc/mdstat‘ with watch command
which will refresh screen every 1 second.
10. After creation of raid, Verify the raid devices using the following command.
# mdadm -E /dev/sd[b-d]1
Verify Raid Level
Note: The Output of the above command will be little long as it prints the
information of all three drives.
11. Next, verify the RAID array to assume that the devices which we’ve
included in the RAID level are running and started to re-sync.
# mkfs.ext4 /dev/md0
Create md0 Filesystem
13. Now create a directory under ‘/mnt‘ then mount the created filesystem
under /mnt/raid5 and check the files under mount point, you will
see lost+found directory.
# mkdir /mnt/raid5
# ls -l /mnt/raid5/
14. Create few files under mount point /mnt/raid5 and append some text in
any one of the file to verify the content.
# touch /mnt/raid5/raid5_suresh_{1..5}
# ls -l /mnt/raid5/
# cat /mnt/raid5/raid5_suresh_1
# cat /proc/mdstat
15. We need to add entry in fstab, else will not display our mount point after
system reboot. To add an entry, we should edit the fstab file and append the
following line as shown below. The mount point will differ according to your
environment.
# vim /etc/fstab
Raid 5 Automount
16. Next, run ‘mount -av‘ command to check whether any errors in fstab entry.
# mount -av
Check Fstab Errors
Note: Saving the configuration will keep the RAID level stable in md0 device.
Step 6: Adding Spare Drives
18. What the use of adding a spare drive? its very useful if we have a spare
drive, if any one of the disk fails in our array, this spare drive will get active
and rebuild the process and sync the data from other disk, so we can see a
redundancy here.
For more instructions on how to add spare drive and check Raid 5 fault
tolerance, read #Step 6 and #Step 7 in the following article.
Add Spare Drive to Raid 5 Setup
So let's begin this tutorial by creating partitions (Which will be acting as a physical disk in
software raid level 5)
?
13
Command (m for help): n
14
First cylinder (18947-19457, default 18947):
15
Using default value 18947
16
Last cylinder or +size or +sizeM or +sizeK (18947-19457, default 19457): +100M
17
18
Command (m for help): n
19 First cylinder (18960-19457, default 18960):
20 Using default value 18960
22
Command (m for help): w
23
The partition table has been altered!
24
25
Calling ioctl() to re-read partition table.
26
27
WARNING: Re-reading the partition table failed with error 16: Device or resource
28 busy.
33
34
Next thing that we need to do after creating the partitions is to inform the linux system that
these partitions will be used for raid. This is acheived by changing the partition types to
RAID.
CHANGE THE TYPE OF PARTITION TO RAID TYPE:
?
9
10 Command (m for help): t
14
Command (m for help): t
15
Partition number (1-13): 12
16
Hex code (type L to list codes): fd
17 Changed system type of partition 12 to fd (Linux raid autodetect)
18
23
Command (m for help): w
24
The partition table has been altered!
25
26
Calling ioctl() to re-read partition table.
27
28
WARNING: Re-reading the partition table failed with error 16: Device or resource
29 busy.
34
CREATE RAID 5 DEVICE:
1
[root@localhost ~]# mdadm --detail /dev/md5
2
/dev/md5:
3 Version : 0.90
4 Creation Time : Tue Apr 9 17:22:18 2013
Raid Devices : 3
8
Total Devices : 3
9
Preferred Minor : 5
10
Persistence : Superblock is persistent
11
12
Update Time : Tue Apr 9 17:22:31 2013
13 State : clean
14 Active Devices : 3
15 Working Devices : 3
16 Failed Devices : 0
17 Spare Devices : 0
18
Layout : left-symmetric
19
Chunk Size : 64K
20
21
22 UUID : d4e4533d:3b19751a:82304262:55747e53
23 Events : 0.2
24
29
1
[root@localhost ~]# cat /proc/mdstat
2 Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
3 md5 : active raid5 sda13[2] sda12[1] sda11[0]
4 208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
8
md0 : active raid0 sda7[1] sda6[0]
9
208640 blocks 64k chunks
10
PERMANENT MOUNTING:
To make the mounting exist even after reboot make entry in /etc/fstab file.
?
/dev/md5:
2
Version : 0.90
3
Creation Time : Tue Apr 9 17:22:18 2013
4
Raid Level : raid5
5
Array Size : 208640 (203.78 MiB 213.65 MB)
6 Used Dev Size : 104320 (101.89 MiB 106.82 MB)
7 Raid Devices : 3
8 Total Devices : 3
9 Preferred Minor : 5
11
Update Time : Wed Apr 10 08:53:03 2013
12
State : clean, degraded
13
Active Devices : 2
14
Working Devices : 2
15
Failed Devices : 1
16 Spare Devices : 0
17
18 Layout : left-symmetric
19 Chunk Size : 64K
20
21 UUID : d4e4533d:3b19751a:82304262:55747e53
Events : 0.4
22
23
Number Major Minor RaidDevice State
24
0 8 11 0 active sync /dev/sda11
25
1 8 12 1 active sync /dev/sda12
26
2 0 0 2 removed
27
28
3 8 13 - faulty spare /dev/sda13
29
30
31
Now you can clearly see that /dev/sda14 is successfully added to raid5 its showing active.
To see what happens with your raid devices in details you can use this command.
?
1
[root@localhost ~]# dmesg | grep -w md
2
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
3 md: bitmap version 4.39
4 md: Autodetecting RAID arrays.
To get the information about a particular raid device you can use this command.
?
1
[root@localhost ~]# dmesg | grep -w md5
2 md: created md5
3 md5: WARNING: sda12 appears to be on the same physical disk as sda11. True
4 md5: WARNING: sda13 appears to be on the same physical disk as sda12. True
5 md5: WARNING: sda14 appears to be on the same physical disk as sda13. True
raid5: raid level 5 set md5 active with 2 out of 3 devices, algorithm 2
7
EXT4 FS on md5, internal journal
8
If you have configured more than one raid in your machine and you want to know detail
about all of them you can use below command.
?
The above command showa you the all the raid configured in your machine along with the
number disk devices each raid is using,It also shows the UUID of the parition
Read: What is UUID of a partition
Conclusion
Here, in this article, we have seen how to setup a RAID 5 using three number
of disks. Later in my upcoming articles, we will see how to troubleshoot when
a disk fails in RAID 5 and how to replace for recovery.
SWAP MEMORY
crptdb-ch2-a1p.sys.suresh.net
==============================
#free -m
Create the LVM with size 8gb(already 8gb is there requirement -16gb)
#mkswap /dev/RootVolGroup00/lv_swap2
#vi /etc/fstab
swapon -v /dev/RootVolGroup00/lv_swap2
==============================
crptdb-wc-a1p.sys.suresh.net
==============================
We have 20gb of enough space is there in RootVolGroup00 vg
#free -m
Create the LVM with size 8gb(already 8gb is there requirement -16gb)
#mkswap /dev/RootVolGroup00/lv_swap2
#vi /etc/fstab
swapon -v /dev/RootVolGroup00/lv_swap2
RollBack Plan
=============
#lvremove /dev/RootVolGroup00/lv_swap2
Remove the entry in /etc/fstab that what you have added
#free -m
TIME ZONE
For this example, assume that your current timezone is UTC as shown below. You would like to
change this to ET.
# date
Edit the file “/etc/sysconfig/clock” and set the required zone in first line
of the file(Sometimes there may be an additional entry “UTC=true”, if yes
leave this entry as it is – This is for supporting day light changes in some
OS versions
Example
cp /etc/sysconfig/clock /etc/sysconfig/clock_bkp
#vi /etc/sysconfig/clock
ZONE=”EST5EDT”
(or)
#/usr/sbin/tzdata-update
verify the changes by executing “date” command
# date
For this example, assume that your current timezone is UTC as shown below. You would like to
change this to ET.
# date
TCP COMMANDS
This article may help you to explore tcpdump command in depth and also to
capture and analysis packets in future.
tcpdump command will work on most flavors of unix operating system. tcpdump allows
us to save the packets that are captured, so that we can use it for future analysis. The
saved file can be viewed by the same tcpdump command. We can also use open source
software like wireshark to read the tcpdump pcap files.
In this tcpdump tutorial, let us discuss some practical examples on how to use the
tcpdump command.
$ tcpdump -i eth1
Note: Editcap utility is used to select or remove specific packets from dump file and
translate them into a given format.
$ tcpdump -c 2 -i eth0
2 packets captured
The above tcpdump command captured only 2 packets from interface eth0.
Note: Mergecap and TShark: Mergecap is a packet dump combining tool, which will
combine multiple dumps into a single dump file. Tshark is a powerful tool to capture
network packets, which can be used to analyze the network traffic. It comes with
wireshark network analyzer distribution.
$ tcpdump -A -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
E.....@.@..]..i...9...*.V...]...P....h....E...>{..U=...g.
......G..7\+KA....A...L.
E.....@.@..\..i...9...*.V..*]...P....h....7......X..!....Im.S.g.u:*..O&....^#Ba...
E..(R.@.|.....9...i.*...]...V..*P..OWp........
0x0000: 0050 569c 35a3 0019 bb1c 0c00 0800 4500 .PV.5.........E.
0x0010: 0028 042a 4000 7906 c89c 10b5 aaf6 0f9a .(.*@.y.........
0x0020: 69c4 f999 0016 57db 6e08 c712 ea2e 5010 i.....W.n.....P.
18:52:54.877713 IP 10.0.0.0 > all-systems.mcast.net: igmp query v3 [max resp time 1s]
0x0000: 0050 569c 35a3 0000 0000 0000 0800 4600 .PV.5.........F.
0x0010: 0024 0000 0000 0102 3ad3 0a00 0000 e000 .$......:.......
0x0020: 0001 9404 0000 1101 ebfe 0000 0000 0300 ................
32 packets captured
-w option writes the packets into a given file. The file extension should be .pcap, which
can be read by any network protocol
analyzer.
0x0000: 0200 000a ffff 0000 ffff 0c00 3c00 0000 ............<...
0x0010: 0000 0000 0100 0080 3e9e 2900 0000 0000 ........>.).....
0x0020: 0000 0000 ffff ffff ad00 996b 0600 0050 ...........k...P
$ tcpdump -n -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
You can open the file comm.pcap using any network protocol analyzer tool to debug any
potential issues.
15. tcpdump Filter Packets – Capture all the packets other
than arp and rarp
In tcpdump command, you can give “and”, “or” and “not” condition to filter the packets
accordingly.
SUPER BLOCK
by VIVEK GITE on AUGUST 15, 2008 last updated AUGUST 15, 2008
in CENTOS, DEBIAN / UBUNTU, FILE SYSTEM, HARDWARE, LINUX, REDHAT AND FRIENDS,
TROUBLESHOOTING, UBUNTU LINUX
Q. How can I Recover a bad superblock from a corrupted ext3 partition to get back my data? I’m getting
following error:
/dev/sda2: Input/output error
A. Linux ext2/3 filesystem stores superblock at different backup location so it is possible to get back data
from corrupted partition.
Warning examples may crash your computerWARNING! Make sure file system is UNMOUNTED.
If your system will give you a terminal type the following command, else boot Linux system from rescue
disk (boot from 1st CD/DVD. At boot: prompt type command linux rescue).
Sample output:
Now check and repair a Linux file system using alternate superblock # 32768:
Sample output:
Fix? yes
Fix? yes
..........
You can also use superblock stored at 32768 to mount partition, enter:
# cd /mnt
# mkdir test
# ls -l
# cp file /path/to/safe/location
TSM
1. Introduction
This section will first provide an introduction to the TSM Command Line Interface (CLI) and then
describe how to manually back up and restore files on the local machine. The screen shots and
descriptions that follow may refer to older TSM clients, but with the exception of the file specifications
the syntax is generic to all platforms.
2.2. Mac
Open [Terminal] from [Applications] | [Utilities] and type sudo dsmc. You will be
prompted for your Mac password then should see a prompt of the form:
IBM Tivoli Storage Manager
tsm>
2.3. Unix/Linux
Run dsmc as root from the shell prompt (e.g., in Ubuntu, run sudo dsmc). You should see a prompt of
the form:
IBM Tivoli Storage Manager
(c) Copyright by IBM Corporation and other(s) 1990, 2014. All Rights
Reserved.
2.4. Netware
Type load dsmc at the console.
3. Accessing Help
Online help for TSM commands, options and error messages is available by typing help at
the tsm> prompt. The result will be similar to below:
1.0 New for IBM Tivoli Storage Manager Version 6.4
2.2.2 Options
2.2.3 Parameters
2.5 Archive
Note that commands and options may be abbreviated to a short form as indicated by capitalisation of
words in the syntax entry for a command. Thus, for example, query filespace can be abbreviated
to q fi. Options and commands can also be included on the original command line so, using the above
example, on a Netware machine you can run load dsmc q fi to just run a query of the current
partitions backed up. Obviously, more complex queries and commands can be similarly run in the same
manner.
Action: Incremental
Options:
Objects:
Priority: 5
Duration: 15 Minutes
Period: 1 Week
Day of Week: Wednesday
Month:
Day of Month:
Week of Month:
Expire: Never
Note that the include/exclude directives are listed at the partition level first, then the directory/folder
level and finally at the file level. The order they are displayed above is the order in which these
directives are applied by TSM. You will note that the order of the directives at any one level is the
opposite of the order in which they appear in the options file. That is, TSM reads the directives listed in
options file from the bottom up.
4.3. Querying what partitions have been backed up
At the tsm> prompt enter q fi to list which partitions have been backed up:
Windows:
Mac:
tsm> q fi
Linux:
tsm> q fi
Solaris:
tsm> q fi
Netware:
If you give just a path to a directory/folder you will only get the folder returned as the output:
Windows:
tsm> q ba c:\Downloads
Size Backup Date Mgmt Class A/I File
Mac:
tsm> q ba /Users
Linux:
tsm> q ba /home/ians/projects
Netware:
tsm> q ba USR:/ians
Note that the Windows client lists the directory in UNC format. This format can also be used for the file
specification in the query.
If you just add a trailing * (star) as a wildcard in the above query, TSM will only return those files and
directories backed up immediately belowthe directory path given in the query
tsm>q ba /home/ians/projects/*
If you want to query all the current files and directories backed up under a directory and all its
subdirectories you need to add the -subdir=yesoption as below:
tsm> q ba /home/ians/projects/* -subdir=yes
Note that file specifications with spaces in them will need to be quoted. Thus to query all the files backed
up under C:\My Documents and any sub-directories below it, the following input would be required:
tsm> q ba "C:\My Documents\*" -subdir=yes
By default only the current versions of files are listed. In order to query both current active and
previous inactive versions of files, add the -inactive option to the query:
tsm> q ba /home/ians/projects/* -subdir=yes -inactive
Note how the previous versions of files are marked by an I (for Inactive) in the A/I column.
Unix and Linux users should be aware of potential confusion of how TSM stores files in nested file
spaces. This can arise in the following situation: A user backs-up a file myconf.txt on
the /usr partition in the /usr/local/etc directory. Subsequently, a new disk partition is mounted
at /usr/local, or it is defined as a virtualmountpoint. Running the command:
tsm> q ba /usr/local/etc/*
will not list the myconf.txt file. This is because TSM always looks for a file in the filespace (partition)
with the longest name that matches the file specification you include in the command. In the above
example, the file was not backed up under the /usr/local filespace but under the/usr filespace. To
tell TSM to look for a file in latter filespace you must specify the filespace explicitly using braces, as
below:
tsm> q ba {/usr}/local/etc/*
To run an incremental by date backup of the above, add the -incrbydate option, as in:
tsm> incr C: D: F: -incrbydate
To back up entire disk volumes irrespective of whether files have changed since the last backup, use
the selective command with a wildcard and -subdir=yes as below:
tsm> sel C:\* D:\* F:\* -su=yes ** Windows
You can, however, enter several file specifications on the command line, as below:
** Windows **
** Linux/Unix **
** Netware **
** Mac **
tsm> rest /Users/ians/myfile.txt /Users/ians/restore/
** Linux/Unix **
** Netware **
Note from the first example of each restore above that in order to specify a directory as a destination,
you need a trailing / (slash) at the end of the destination-filespec. Otherwise TSM may overwrite a file of
the same name. The second example demonstrates a filename in the destination-filespec.
Restores of single files cannot be restarted if interrupted. In this case you will need to restore the file
afresh.
** Linux/Unix **
** Netware **
Note that in order to restore a full directory and the contents of all its sub-directories you need the -
su=yes option. It is always good practice to terminate the destination-filespec with a trailing / (slash) if
the element in the destination-filespec is a directory.
As this restore is wild-carded, it can be restarted if interrupted due to user input (Ctrl-C), server error or
communications error. Restartable restores can be queried via q rest and will restart at the point of
interruption.
6.3. Restoring entire partitions
Essentially, the syntax is the same as in 'Restoring multiple files and directories' above. However, the
obvious caveats are to ensure enough space in the destination partition and to allow enough time.
** Windows **
** Linux/Unix **
** Netware **
As with 'Restoring multiple files and directories' above, this restore is wild-carded and thus can be
restarted if interrupted.
--------------------------------------------------------------------------
------------------------
170. | 12-09-2011 19:57:09 650 B A
/home/ians/projects/hsm41test/inclexcl.test
0---------10--------20--------30--------40--------50--------60-------
-70--------80--------90--
pick>
You are now in the pick interface and can select individual files to restore via the number to the left,
scroll up or down via U and D as described at the bottom of each listing of files.
Remember to issue the destination-filespec with the original restore command if you want to prevent
overwriting current versions of files with older versions.
7. Restoring your data to another machine
In certain circumstances, it may be necessary to restore some, or all, of your data onto a machine other
than the original from which it was backed up. Ideally the machine platform should be identical to that
of the original machine. Where this is not possible or practical please note that restores are only possible
for partition types that the operating system supports. Thus a restore of an NTFS partition to a Windows
9x machine with just FAT support may succeed but the file permissions will be lost. Please do not
attempt cross-platform restores, e.g. by trying to restore files onto a Windows machine that have
previously been backed up with a non-Windows one: using TSM for Windows to try to access backups
sent by other OS platforms can cause those backups to become inaccessible from the host system.
To restore your data to another machine you will need the TSM software installed on the target
machine. Entries in dsm.sys and/or dsm.optwill need to be edited if the node that you are restoring
from does not reside on the same HFS server as the one that you are restoring to. Please see our help
page section on TSM configuration files for their locations for your operating system. To check which
HFS server is required, please go to View TSM Client Details, where the listed HFS Server will be the
one needed for the Servername field in both dsm.sys(Mac/Unix/Linux only) and dsm.opt (all
operating systems). If you do need to edit these files, it is recommended that you first of all make copies
so that you can get your old settings back later. The other two values which need to be changed
are TCPServer and TCPPort, in dsm.sys(Mac/Unix/Linux) or dsm.opt (Windows/Netware): these
can be got from our page on connecting to the HFS through a firewall, where the relevant fields are in
the 'DNS Name' and 'Port' columns respectively.
To access files from another machine you should then start the TSM client as below:
where DEAD.MACHINE should be substituted for the nodename of the machine to be restored. You will
then be prompted for the TSM password for this machine.
Querying and restoring the filestore is then as in the previous section, 6. Restoring your data. You will
probably want to restore to a different destination to the original files to prevent overwriting files on the
local machine, as below:
tsm> rest D:\* D:\RESTORE\ -su=yes ** Windows
PASSWORDACCESS Generate
set in your options file, it is recommended you manually re-set your TSM password. To do this at
the tsm> prompt enter:
tsm> set password oldpassword newpassword
TSM (Tivoli Storage Manager) is a centralized, policy-based, enterprise class, data backup and
recovery package from IBM Corporation.The software enables the user to insert objects not only via
backup, but also through space management and archive tools. It also allows retrieval of the same data via
similar restore, recall, and retrieve methods.
As Unix Admins we used to get lot of requests from the application teams for tsm backup restores.I would
like to discuss about the the best 14 best use-full TSM client commands.
In this article we are going to discuss about the following contents with practice examples.
2) Backing Up data
A. Backing your local filesystems
B. Backing up selected files
3) Restore Data
A. Restore a file to its original directory
B. Restore the most recent backup version of a file
C. Display a list of active and inactive backup versions of files from which you can select versions
to restore
D. Restore with a directory including subdirectories
E. Restore the file under a new name and directory
F. Restore all files in a directory as of their current state
G. Restore all files from a directory that end with .xyz to the another directory
H. Restore files specified in the text file to a different location
#dsmc q fi
# Last Incr Date Type File Space Name
--- -------------- ---- ---------------
1 02-05-2013 02:13:13 UFS /
2 25-07-2012 12:26:09 UFS /export/home
3 02-05-2013 02:13:26 UFS /home
4 16-01-2013 11:26:37 UFS /scratch
5 02-05-2013 02:13:54 UFS /usr/local
6 12-02-2013 02:52:41 UFS /var
** Netware **
If you just add a trailing * (star) as a wildcard in the above query, TSM will only return those files and
directories backed up immediately below the directory path given in the query
#dsmc q ba /home/oraadm/*
Size Backup Date Mgmt Class A/I File
---- ----------- ---------- --- ----
512 12-09-2012 19:57:09 STANDARD A /home/oraadm/data1.dtf
1,024 08-12-2012 02:46:53 STANDARD A /home/oraadm/data2.dtf
512 12-09-2012 19:57:09 STANDARD A /home/oraadm/data3.dtf
512 24-04-2002 00:22:56 STANDARD A /home/oraadm/data4.dtf
If you want to query all the current files and directories backed up under a directory and all its sub-directories
you need to add the -subdir=yes option as below:
2. Backing Up data
A. Backing your local filesystems
The syntax for this is "dsmc backup-type filesystem" , where backup-type is one of incremental or
selective.
Incremental Backup : It is one that backs up only the data that changed since the last backup — be it a
full or incremental backup
Selective Backup : A type of backup where only the user specified files and directories are backed up. A
selective backup is commonly used for backing up files which change frequently or in situations where the
space available to store backups is limited. Also called a partial backup.
I would always suggest you always go with incremental. The command is "dsmc incremental" or "dsmc
incr" Where "incr" is an abbreviation for incremental.
Make this will omit the filesystems which were mention in the exclude file.
To incrementally back up specific file-systems enter:
#dsmc incr / /usr /usr/local /home
To back up entire filesystem irrespective of whether files have changed since the last backup, use the
selective command with a wild-card and -subdir=yes as below:
#dsmc sel /* /usr/* /home/* -su=yes
You can, however, enter several file specifications on the command line, as below:
#dsmc incr /home/surya/* /usr/bin/* -su=yes
3) Restore Data
We use the "restore" command to restore files
If you do not specify a destination, the files are restored to their original location.
If the file you are restoring no longer resides on your client machine, and you have run an incremental
backup since deleting the file, there is no active backup of the file on the server. In this case, use the
latest option to restore the most recent backup version. Tivoli Storage Manager restores the latest backup
version, whether it is active or inactive.
When restoring a specific path and file, Tivoli Storage Manager recursively restores all sub-directories
under that path, and any instances of the specified file that exist under any of those sub-directories.
Use the pitdate option with the pittime option to establish a point in time for which you want to display or
restore the latest version of your backups. Files that were backed up on or before the date and time you
specified, and which were not deleted before the date and time you specified, are processed. Backup
versions that you create after this date and time are ignored.
G. Restore all files from a directory that end with .xyz to the another
directory
Restore all files from the /usr/oradata/docs/ directory that end with .bak to the /usr/oradata/projects/
directory.
If the destination is a directory, specify the delimiter (/) as the last character of the destination. If you omit
the delimiter and your specified source is a directory or a file spec with a wildcard, you will receive an
error. If the projects directory does not exist, it is created.
The files (entries) listed in the filelist must adhere to the following rules:
Each entry must be a fully or partially qualified path to a file or directory or a relative path.
Each entry must be on a new line.
Do not use wildcard characters.
Each entry results in the processing of only one object (file or directory).
If the file name contains any spaces, enclose the file name with quotes.
The filelist can be an MBCS file or a Unicode file with all Unicode entries.
Tivoli Storage Manager ignores any entry that is not valid.
IP TABLES
Above output indicates that the firewall is not active. The following sample shows an active
firewall:
# iptables -L -n -v
Sample outputs:
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source
destination
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
state INVALID
394 43586 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0
state RELATED,ESTABLISHED
93 17292 ACCEPT all -- br0 * 0.0.0.0/0 0.0.0.0/0
1 142 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source
destination
0 0 ACCEPT all -- br0 br0 0.0.0.0/0 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
state INVALID
0 0 TCPMSS tcp -- * * 0.0.0.0/0 0.0.0.0/0
tcp flags:0x06/0x02 TCPMSS clamp to PMTU
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0
state RELATED,ESTABLISHED
0 0 wanin all -- vlan2 * 0.0.0.0/0 0.0.0.0/0
0 0 wanout all -- * vlan2 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT all -- br0 * 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 425 packets, 113K bytes)
pkts bytes target prot opt in out source
destination
Chain wanin (1 references)
pkts bytes target prot opt in out source
destination
Chain wanout (1 references)
pkts bytes target prot opt in out source
destination
Where,
• -L : List rules.
• -v : Display detailed information. This option makes the list command show the interface
name, the rule options, and the TOS masks. The packet and byte counters are also listed,
with the suffix 'K', 'M' or 'G' for 1000, 1,000,000 and 1,000,000,000 multipliers
respectively.
• -n : Display IP address and port in numeric format. Do not use DNS to resolve names.
This will speed up listing.
#1.1: To inspect firewall with line numbers, enter:
# iptables -n -L -v --line-numbers
Sample outputs:
Chain INPUT (policy DROP)
num target prot opt source destination
1 DROP all -- 0.0.0.0/0 0.0.0.0/0 state
INVALID
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state
RELATED,ESTABLISHED
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy DROP)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 DROP all -- 0.0.0.0/0 0.0.0.0/0 state
INVALID
3 TCPMSS tcp -- 0.0.0.0/0 0.0.0.0/0 tcp
flags:0x06/0x02 TCPMSS clamp to PMTU
4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state
RELATED,ESTABLISHED
5 wanin all -- 0.0.0.0/0 0.0.0.0/0
6 wanout all -- 0.0.0.0/0 0.0.0.0/0
7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Chain wanin (1 references)
num target prot opt source destination
Chain wanout (1 references)
num target prot opt source destination
You can use line numbers to delete or insert new rules into the firewall.
#1.2: To display INPUT or OUTPUT chain rules, enter:
# iptables -L INPUT -n -v
# iptables -L OUTPUT -n -v --line-numbers
#2: Stop / Start / Restart the Firewall
If you are using CentOS / RHEL / Fedora Linux, enter:
# service iptables stop
# service iptables start
# service iptables restart
You can use the iptables command itself to stop the firewall and delete all rules:
# iptables -F
# iptables -X
# iptables -t nat -F
# iptables -t nat -X
# iptables -t mangle -F
# iptables -t mangle -X
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT ACCEPT
# iptables -P FORWARD ACCEPT
Where,
• -F : Deleting (flushing) all the rules.
• -X : Delete chain.
• -t table_name : Select table (called nat or mangle) and delete/flush rules.
• -P : Set the default policy (such as DROP, REJECT, or ACCEPT).
#3: Delete Firewall Rules
To display line number along with other information for existing rules, enter:
# iptables -L INPUT -n --line-numbers
# iptables -L OUTPUT -n --line-numbers
# iptables -L OUTPUT -n --line-numbers | less
# iptables -L OUTPUT -n --line-numbers | grep 202.54.1.1
You will get the list of IP. Look at the number on the left, then use number to delete it. For
example delete line number 4, enter:
# iptables -D INPUT 4
OR find source IP 202.54.1.1 and delete from rule:
# iptables -D INPUT -s 202.54.1.1 -j DROP
Where,
• -D : Delete one or more rules from the selected chain
#4: Insert Firewall Rules
To insert one or more rules in the selected chain as the given rule number use the following
syntax. First find out line numbers, enter:
# iptables -L INPUT -n --line-numbers
Sample outputs:
Chain INPUT (policy DROP)
num target prot opt source destination
1 DROP all -- 202.54.1.1 0.0.0.0/0
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state
NEW,ESTABLISHED
To insert rule between 1 and 2, enter:
# iptables -I INPUT 2 -s 202.54.1.2 -j DROP
To view updated rules, enter:
# iptables -L INPUT -n --line-numbers
Sample outputs:
Chain INPUT (policy DROP)
num target prot opt source destination
1 DROP all -- 202.54.1.1 0.0.0.0/0
2 DROP all -- 202.54.1.2 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state
NEW,ESTABLISHED
Note down its ip address and type the following to block all outgoing traffic to 75.126.153.206:
# iptables -A OUTPUT -d 75.126.153.206 -j DROP
You can use a subnet as follows:
# iptables -A OUTPUT -d 192.168.1.0/24 -j DROP
# iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP
#11.1: Example - Block Facebook.com Domain
First, find out all ip address of facebook.com, enter:
# host -t a www.facebook.com
Sample outputs:
www.facebook.com has address 69.171.228.40
## open cups (printing service) udp/tcp port 631 for LAN users ##
iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT
## allow time sync via NTP for lan users (open udp port 123) ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -
j ACCEPT
KICK START
Go to the url https://cbm.sys.suresh.net/
Time: 08:57:52 AM
avg-cpu: %user %nice %system %iowait %steal %idle
5.68 0.00 0.52 2.03 0.00 91.76
To display extended information for a specific partition (For example, /dev/sda1), do the
following.
$ iostat -x sda1
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
To display the version of iostat, use -V. This will really display the version information of sysstat,
as iostat is part of sysstat package.
$ iostat -V
sysstat version 7.0.2
(C) Sebastien Godard
VMSTAT EXAMPLES
11. vmstat – Basic example
vmstat by default will display the memory usage (including swap) as shown below.
$ vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu--
----
r b swpd free buff cache si so bi bo in cs us sy id wa
st
0 0 305416 260688 29160 2356920 2 2 4 1 0 0 6 1 92
2 0
$ vmstat -a
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu--
----
r b swpd free inact active si so bi bo in cs us sy id wa
st
0 0 305416 253820 1052680 2688928 2 2 4 1 0 0 6 1 92
2 0
To execute every 2 seconds for 10 times, do the following. You don’t need to press Ctrl-C in this
case. After executing 10 times, it will stop automatically.
$ vmstat 2 10
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu--
---
r b swpd free buff cache si so bi bo in cs us sy id wa
st
1
0 0 537144 182736 6789320 0 0 0 0 1 1 0 0 100
0 0
0 0 0 537004 182736 6789320 0 0 0 0 50 32 0 0 100
0 0
..
Note: If you use a older version of vmstat, option -t might not be available. In that case, use the
method we suggested earlier to display timestamp in vmstat output.
16. vmstat – Display slab info
Use option -m, to display the slab info as shown below.
$ vmstat -m
Cache Num Total Size Pages
fib6_nodes 5 113 32 113
ip6_dst_cache 4 15 256 15
ndisc_cache 1 15 256 15
RAWv6 7 10 768 5
UDPv6 0 0 640 6
tw_sock_TCPv6 0 0 128 30
...
Use option -w to increase the width of the output columns as shown below. This give better
readability.
$ vmstat -w 1 3
procs -------------------memory------------------ ---swap-- -----io---- --
system-- -----cpu-------
r b swpd free buff cache si so bi bo in
cs us sy id wa st
0 0 0 3608712 148368 3898204 0 0 0 0 1
1 0 0 100 0 0
0 0 0 3608712 148368 3898204 0 0 0 0 93
23 0 0 100 0 0
0 0 0 3608696 148368 3898204 0 0 0 0 35
34 0 0 100 0 0
MPSTAT EXAMPLES
22. mpstat – Display basic info
By default mpstat displays CPU statistics as shown below.
$ mpstat
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011
10:25:32 PM
CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
10:25:32 PM all 5.68 0.00 0.49 2.03 0.01 0.02 0.00
91.77 146.55
10:26:34 PM
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:26:34 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 99.99
10:26:34 PM 0 0.01 0.00 0.01 0.01 0.00 0.00 0.00
0.00 99.98
10:26:34 PM 1 0.00 0.00 0.01 0.00 0.00 0.00 0.00
0.00 99.98
10:26:34 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 100.00
10:26:34 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 100.00
10:28:04 PM
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:28:04 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 99.99
10:28:04 PM 0 0.01 0.00 0.01 0.01 0.00 0.00 0.00
0.00 99.98
10:28:04 PM 1 0.00 0.00 0.01 0.00 0.00 0.00 0.00
0.00 99.98
10:28:04 PM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 100.00
10:28:04 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 100.00
To display statistics information of a particular CPU (or core), use option -P as shown below.
$ mpstat -P 0
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011 _x86_64_
(8 CPU)
10:28:53 PM
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:28:53 PM 0 0.01 0.00 0.01 0.01 0.00 0.00 0.00
0.00 99.98
$ mpstat -P 1
Linux 2.6.32-100.28.5.el6.x86_64 (dev-db) 07/09/2011 _x86_64_
(8 CPU)
10:28:55 PM
CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
10:28:55 PM 1 0.00 0.00 0.01 0.00 0.00 0.00 0.00
0.00 99.98
Finally, as we mentioned earlier mpstat is part of the sysstat package. When you do mpstat -V, it
will really display the version number of the systat package as shown below.
$ mpstat -V
sysstat version 9.0.4
(C) Sebastien Godard (sysstat orange.fr)
Contents
1 Overview
2 Boot the Manjaro Installation Media
3 Chroot into your existing Manjaro Installation
o 3.1 Use mhwd-chroot
o 3.2 Manually Identify and Prepare the Installed Partition(s)
4 Restore GRUB
o 4.1 For BIOS Systems
o 4.2 For UEFI Systems
4.2.1 Note
4.2.2 Alternative method
5 Troubleshooting
o 5.1 Arch Linux is not recognized
6 More
Overview
As with any Linux operating system, the GRUB (GRand Unified Bootloader) is responsible for
booting up Manjaro. If for any reason your GRUB is not working --perhaps due to being
corrupted, mis-configured, or even deleted-- then it may not be necessary to reinstall Manjaro.
The GRUB can instead be fully repaired and restored, retaining your installed Manjaro
system. To undertake this task, you will need to use your Manjaro installation media, such as, a
CD/DVD or USB Flashdrive.
Tip: Setting the language and keyboard layout are undertaken by pressing the Function (F) keys.
As many computers have multiple functions assigned to each function key, it may be necessary
to hold down another key first to use them. For example, on a HP G62 laptop, to use the function
keys, the 'fn' key must first be pressed and held.
3. Boot Manjaro Linux. It does not matter which boot option you choose, as the installation
media is being used solely to repair/reinstate the GRUB, and not to install a fresh system.
4. Open the terminal or access the command line of the live CD.
From the desktop environment: open a terminal from your desktop menu, and enter
sudo su in the terminal.
or
From the command line of the NET-Edition or having used the Boot in Text mode
option: enter the default login username root and then the password "manjaro" to log in.
Use mhwd-chroot
1. First, use an application called gparted, which should be in Menu > System > GPartEd. This
will provide a simple visual illustration of the partitions on your hard drive(s).
lsblk -f
2. mhwd-chroot is a tool to easily chroot into an installed Linux installation from a live boot of a
Manjaro Installation Media. Install it with
yaourt -S mhwd-chroot
Start mhwd-chroot from your Start Menu or in your terminal one of the following commands:
sudo mhwd-chroot
sudo mhwd-chroot-shell
sudo su
2. List your partitions. This is necessary in order to identify the partition your Manjaro system is
installed on. If you have used a separate boot partition, it will be necessary to identify this as
well. For a list of your paritions, enter the command:
lsblk -f
or
sudo blkid -o list -c /dev/nul
In this particular instance, having used the assisted preparation method to install Manjaro
earlier, the partitions for the author's Manjaro system are as follows:
If you are still unsure, then you can also use an application called gparted, which should be in
Menu > System > GPartEd. This will provide a simple visual illustration of the partitions on your
hard drive(s). If a separate partition for the GRUB exists, it will be marked as 'bootable', and
should only be about 100MB in size.
3. Mount your Manjaro system partition. The syntax to mount the Manjaro system partition is:
In this instance, as the Manjaro system partition is /dev/sda3, this will be mounted using the
following command:
IF you have used a separate partition for your GRUB bootloader, then this must also be
mounted. The syntax to mount a separate partition used to boot is:
In this instance, a separate partition --/dev/sda1-- has been used for the GRUB, and will be
mounted using the following command:
cd /mnt
This is undertaken so that you are working from --and with-- your installed system, rather than
the installation media. To do so, it will be necessary to enter a series of commands in the
following order:
Restore GRUB
First, install the software applications mtools and os-prober. mtools is a collection of tools to
access MS-DOS disks from GNU/Linux and Unix without mounting them. os-prober is a utility
that detects if there are any other operating systems present. Install them both with the following
command:
grub-install /dev/sda
note: sda is the disk device where you want to install GRUB. You can check it using lsblk -f or
using GParted as explained before.
2. Recheck to ensure the that installation has completed without any errors:
update-grub
All done! Now close the terminal and reboot your system to use your freshly re-installed GRUB.
For UEFI Systems
Warning: You need to be chrooted for this procedure as mentioned in the previous step.
1.) First of all check the partition for the ESP (EFI System Partition). An ESP is a fat32 partition
and contains .efi files for booting.
(Note: If you do not have a EFI partition, you will need to create it. Use Gparted for that.
Type- fat32
X = Alphabet of the drive = a,b,c ... Y = Partition number of the EFI partition = 1,2,3,4...
Example - /dev/sda4
sudo update-grub
Note
Then install the efibootmgr, dosfstools and grub packages and try steps 4 and 5 again.
If it still doesn't work, then try exiting the chroot environnment by typing exit, then loading the
efivarfs module:
See also
Arch Wiki:GRUB#UEFI_systems_2
Alternative method
After the above you could chroot and try the update-grub command as earlier.
SCP COMMAND
1. Verbose output
With verbose output, the scp program would output lots of information about what it does in the
background. This is often useful when the program fails or is unable to complete the request.
The verbose output would then indicate the exact point where the program ran into issues.
The output would be big and contain detailed information about how the connection is made,
what configuration and identity files are being used and so on.
$ scp username@remotehost:/path/directory/\{foo.txt,bar.txt\} .
$ scp [email protected]:~/\{abc.log,cde.txt\} .
3. Copy entire directory (recursively)
To copy an entire directory from one host to another use the r switch and specify the directory
$ scp user1@remotehost1:/some/remote/dir/foobar.txt
user2@remotehost2:/some/remote/dir/
In the above example we moved the entire directory with compression enabled. The speed gain
would depend on how much the files could be compressed.
NIC BONDING
1 Procedure for NIC bonding
1.1 Procedure
vi /etc/sysconfig/network-scripts/ifcfg-bond0
vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
vi /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
iv. Make sure bonding module is loaded when the channel-bonding interface (bond0) is
brought up. You need to modify kernel modules configuration file.
vi /etc/modprobe.conf
modprobe bonding
vi. Restart the networking service in order to bring up bond0 interface by using below
command.
cat /proc/net/bonding/bond0
ifconfig
FTP SERVER
Configure FTP Server on RHEL6
vsftpd package is required for FTP Server. Check whether package is installed or not. If package
is missing install it first.
Current status of vsftpd service must be running. Start if it is stopped. Restart vsftpd service
whenever you made any change in configuration file.
FTP Server is by default configured to listen on port 21. Port 21 must be opened if you have
configured firewall. The configuration of a firewall for an FTP server is a relatively simple
process.
From RHEL version 6 you will not be able to run ftp command. By default you will get
following error
LAB Exercises
vsftpd.conf is the main configuration file of FTP server and it contains lot of directives.
Configuration of an anonymous-only download is relatively simple. Default configuration of
vsftpd.conf already supports anonymous-only download. But it also supports access from local
users. All you need to do is disable the directive which allows locally configured users to login
with their accounts.
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
With these setting users are not allowed to login as the user named ftp. So they need to use
anonymous as user name. So whenever an anonymous user logged in, he is taken to ftp user’s
home directory /var/ftp. So if you want to change the default directory associated with
anonymous logins, change the home directory associated with the local user named ftp. Create a
file on the root of the ftp directory /var/ftp/pub. This file will be downloaded by anonymous
user.
If you are running Linux without SELinux that’s all setting which we need for this exercise.
SELinux is listed in RHCE6 exam objective. So if you have configured SELinux, also configure
following boolean option.
Go on linuxclient system and login to the FTP server as anonymous user and download test_file
Most commonly commands used on ftp prompt are
put To upload files on server
get To download files from server
mput To upload all files
mget To download all files
? To see all available command on ftp prompts
cd To change remote directory
lcd To change local directory.
In this exercise we will configure FTP server that allow local users logins to their home
directories. Download/upload must be allowed for these users. Go on server system and open
/etc/vsftpd/vsftpd.conf file
upload/download file
Login again from normal user and try to change parent directory
Come back on linux client system and login form sanjay and try again to change directory to /
Now normal user will not be able to navigate outside the home directory.
local_enable=YES
Enable local users login with their regular password
chroot_local_user=YES
write_enable=YES
local_umask=022
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
# setsebool allow_ftpd_full_access 1
# setsebool allow_ftpd_anon_write 1
Supports the writing of files to directories configured with the public_content_rw_t SELinux
setting
# setsebool allow_ftpd_use_cifs 1
# setsebool allow_ftpd_use_nfs 1
# setsebool ftp_home_directory 1
Any directory that is going to be used on read FTP operations it must be labelled as
public_content_rw_t
Any directory that is going to be used on read-write FTP operations it must be labelled as
public_content_rw_t
SAMBA SERVER
Samba runs on most Unix and Unix-like systems, such as Linux, Solaris, AIX and the BSD
variants, including Apple’s Mac OS X Server and Mac OS X client (version 10.2 and greater).
Samba is standard on nearly all distributions of Linux and is commonly included as a basic system
service on other Unix-based operating systems as well. Samba is released under the terms of the
GNU General Public License. The name Samba comes from SMB (Server Message Block), the
name of the standard protocol used by the Microsoft Windows network file system.
Configure samba server
In this example we will configure a samba server and will transfer files from client side.For this
example we are using two systems one linux server one window clients.
samba rpm is required to configure samba server. check them if not found then install
By default name of workgroup is MYGROUP in smb.conf file. you can change it with desire
name
our task is to share data folder for vinita user so go in the end of file and do editing as shown
here in this image
we have made necessary change now on smb service and check it status
if you already have on this service then restart it with service smb restart commands.
Go on windows system and ping samba server, change computer name to client2 and workgroup
name to MYGROUP
After reboot open my network place here you can see samba server [ if not see then click on
view workgroup computer in right pane, if still not see then use search button from tool bar and
search computer samba server form ip ]
First try to login from user nikita she will not successes as nikita have not permission to login
Now login from user vinita [ give the password which you set with smbpasswd command ]
As you can see in image user vinita gets the /data folder which we share from samba server
Copy some window files in data folder
on samba server you can check runtime status of samba server to check it run smbstatus
command
in output you see that one samba shared directory is used on window system
NFS SERVER
Configure nfs server
In this example we will configure a nfs server and will mount shared directory from client side.
For this example we are using two systems one linux server one linux clients . To complete these per quest of
nfs server Follow this link
Network configuration in Linux
A linux server with ip address 192.168.0.254 and hostname Server
A linux client with ip address 192.168.0.1 and hostname Client1
Updated /etc/hosts file on both linux system
Running portmap and xinetd services
Firewall should be off on server
We suggest you to review that article before start configuration of nfs server. Once you have completed the
necessary steps follow this guide.
Three rpm are required to configure nfs server. nfs, portmap, xinetd check them if not found then install
share data folder for the network of 192.168.0.254/24 with read and write access
verify with showmount command that you have successfully shared data folder
now mount this share folder on mnt mount point. To test this share folder change directory to mnt and create
a test file
After use you should always unmount from mnt mount point
In this way you can use shared folder. But this share folder will be available till system is up. It will not be
available after reboot. To keep it available after reboot make its entry in fstab
create a mount point, by making a directory
now open /etc/fstab file
make entry for nfs shared directory and define /temp to mount point
save the with :wq and exit reboot the system with reboot -f command
#reboot -f
after reboot check /temp directory it should show all the shared data
NFS (Network File System) is another way of sharing files across a network. It is used primarily in
Linux and UNIX systems, although there are NFS clients for Windows.
Installing NFS
Configuration of NFS is pretty simple. You add the directories you wish to export to the
file/etc/exports.
mkdir /public
vi /etc/exports
/public *(ro,sync)
*--The clients allowed to access the share. You can restrict it by IP address. For example, you could,
instead of the asterisk, put
sync--Reply to requests only after any changes have been committed to stable storage. This is a
slower, but more stable option than alternatives.
In the following screen capture, you can see how I configured /etc/exports to share /public:
Figure 7: Configuring an NFS shared directory in /etc/exports.
6. NFS requires the rpcbind service to be running. Start it with the following command:
/etc/init.d/nfs start
9. Enable the export immediately with the command exportfs -v. You can view the export with the
command showmount -e.
If you are using a firewall, you must explicitly allow traffic from your local subnet to access the
server.
You must install the nfs package on the client with this command:
You can also create a new directory on your client and mount the NFS export to the directory, thus
giving you access to the files in the directory:
Figure 9: Creating and viewing a mount point for the NFS share.
In the above example, I mounted the export from LinuxServer01 (/public) to a directory on my local
client machine, called ubuntuServer02. As you can see, after it was mounted, I was able to view the
contents of the exported directory locally.
DNS SERVER
DNS
domain name system is the crucial glue that keeps computer networks in harmony by
converting human friendly hostnames to the numerical ip addresses computers require to communicate
with each other.
Script : /etc/init.d/named
Port : 53
Daemon : named
Resolving Dependencies
Dependencies Resolved
=====================================================================================
========================================
Package Arch Version Repository Size
=====================================================================================
========================================
Installing:
Transaction Summary
=====================================================================================
========================================
Install 4 Package(s)
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------------------------------
Running rpm_check_debug
Running Transaction
Installed:
Dependency Installed:
portreserve.x86_64 0:0.0.4-9.el6
Complete!
Step2: update /etc/sysconfig/network, /etc/hosts file with the server’s ip address ad change the
hostname with fully qualified domain name
#ifconfig –a
collisions:0 txqueuelen:1000
collisions:0 txqueuelen:0
#netstat -rn
#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
IPADDR = “192.168.190.166”
NETMASK = “255.255.255.0”
DNS1 = “192.168.190.166”
GATWAY =”192.168.190.2”
HWADDR="00:0C:29:61:7A:AC"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="9dab5157-aba7-42ec-869b-2f92e45315fe"
#Vi /etc/hosts
#vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=suresh.tcs.com
#vi /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
nameserver 192.168.190.2
Connection activated [ OK ]
#vi /etc/named.conf
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
//
//
options {
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
# vi /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
//
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
//
zone "tcs.com" IN {
type master;
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "190.168.192.in-addr.arpa" IN {
type master;
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
Step5: navigate to /var/named directory and create a forward and reverse zone files
#cd /var/named
#ls
#vi forward.zone
$TTL 1D
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS suresh.tcs.com
Suresh IN A 192.168.190.166
AAAA ::1
Copy again named.localhost, this time as reverse.zone and edit it as shown below
#vi reverse.zone
$TTL 1D
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS suresh.tcs.com.
Step 6: change the group named to the forward.zone and reverse.zone file
Stopping named: [ ok ]
Starting named : [ ok ]
Now we are done with DNS server configuration ,check whether it is resolving IP to hostname and
hostname to IP using various commands
#dig suresh.tcs.com
;; Got answer:
;; QUESTION SECTION:
;suresh.tcs.com. IN A
;; AUTHORITY SECTION:
;; SERVER: 192.168.190.2#53(192.168.190.2)
#dig -x 192.168.190.166
;; Got answer:
;; QUESTION SECTION:
;166.190.168.192.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
168.192.IN-ADDR.ARPA. 5 IN SOA 168.192.IN-ADDR.ARPA. . 0 28800 7200 604800
86400
;; SERVER: 192.168.190.2#53(192.168.190.2)
#host 192.168.190.166
#nslookup suresh
Server: 192.168.190.2
Address: 192.168.190.2#53