System/Network Administrator's Blog for Linux
This blog can be helpful who are interested in Linux,having basic knowledge of Linux Operating System & want to follow different Linux Based Services It contains direct justified hand's on exercise without making more concentration on Theory. Suggestions are welcomed.
About Me
Monday, January 23, 2012
LVM In Linux
Wednesday, June 29, 2011
Backup an entire hard disk using "dd" command
The "dd" command is one of the original Unix utilities and should be in everyone's tool box. It can strip headers, extract parts of binary files and write into the middle of floppy disks; it is used by the Linux kernel Makefiles to make boot images. It can be used to copy and convert magnetic tape formats, convert between ASCII and EBCDIC, swap bytes, and force to upper and lower case.
For blocked I/O, the dd command has no competition in the standard tool set. One could write a custom utility to do specific I/O or formatting but, as dd is already available almost everywhere, it makes sense to use it.
Like most well-behaved commands, dd reads from its standard input and writes to its standard output, unless a command line specification has been given. This allows dd to be used in pipes, and remotely with the rsh remote shell command.
Unlike most commands, dd uses a keyword=value format for its parameters. This was reputedly modeled after IBM System/360 JCL, which had an elaborate DD 'Dataset Definition' specification for I/O devices.
Using "dd" you can create backups of an entire harddisk or just a parts of it. This is also useful to quickly copy installations to similar machines. It will only work on disks that are exactly the same in disk geometry, meaning they have to the same model from the same brand.
Full Hard Disk copy
dd if=/dev/hdx of=/dev/hdy
dd if=/dev/hdx of=/path/to/image
dd if=/dev/hdx | gzip > /path/to/image.gz
Hdx could be hda, hdb etc. In the second example gzip is used to compress the image if it is really just a backup.
Restore Backup of hard disk copy
dd if=/path/to/image of=/dev/hdx
gzip -dc /path/to/image.gz | dd of=/dev/hdx
MBR backup
In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.
dd if=/dev/hdx of=/path/to/image count=1 bs=512
MBR restore
dd if=/path/to/image of=/dev/hdx
Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.
Another popular tools are: "Clonezilla, Mondo Rescue"
Regards,
Nishith N.Vyas
Monday, May 23, 2011
Zombie Process Understanding.
When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes.
However, the process's entry in the process table remains. The parent is sent a SIGCHLD signal indicating that a child has died; the handler for this signal will typically execute the wait system call, which reads the exit status and removes the zombie.
The zombie's process ID and entry in the process table can then be reused. However, if a parent ignores the SIGCHLD, the zombie will be left in the process table.
In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same process ID.
If you have zombie processes it means those zombies have not been waited for by their parent.
To remove zombies from a system, the SIGCHLD signal can be sent to the parent manually, using the kill command. If the parent process still refuses to reap the zombie, the next step would be to remove the parent process. When a process loses its parent, init becomes its new parent. Init periodically executes the wait system call to reap any zombies with init as parent.
How to find "zombie" process in Linux ?
Execute "top" command & read top left corner to check zombie process. If you are unable to identify the process, press "z" & you will get "red" colored identification for easy understanding.
How to kill "zombie" process in Linux ?
Run this command.
ps aux | awk '{ print $8 " " $2 }' | grep -w ZOutput would be,
Z 3456Use "Kill command" for all three processes as given below.
Z 2107
Z 1708
kill -9 3456
kill -9 2107
kill -9 1708
That's it. Enjoy Linux.
Tuesday, May 3, 2011
Commands to check "Disk Usage" in Linux
du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.
du /home/nishith
The above command would give you the directory size of the directory /home/nishith
du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.
du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.
du -c
This gives you a grand total as the last line of the output. So if your directory occupies 100MB the last 2 lines of the output would be
100M .
100M total
The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.
du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.
du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.
du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.
du --exclude=mp3
The above command would display the size of the current directory along with all its subdirectories, but it would exclude all the files having the given pattern present in their file names. Thus in the above case if there happens to be any mp3 files within the current directory or any of its subdirectories, their size would not be included while calculating the total directory size.
'df' = Finding the "disk free" space
df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.
df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.
Example :
I have my Linux installed on /dev/hda1 and I have mounted my Windows partitions as well (by default every time Linux boots). So 'df' by default shows me the disk usage of my Linux as well as Windows partitions. And I am only interested in the disk usage of the Linux partitions. This is what I use :
$ df -h | grep /dev/sda1 | cut -c 41-43
This command displays the following on my machine
78%
Please Note: You can find your drive letter by typing "fdisk -l / df -kh" command line.
Thanks,
Nishith N.Vyas
Friday, April 29, 2011
Kickstart installation guide for CentOS 5.5
The instructions should work the same on RedHat and Fedora.
Requirement:
* CentOS 5.5 DVD
* Static IP address for the Kickstart/DHCP server
* /data partition or any other
Installation Steps:
1. Login to the CentOS server using Root account.
2. Mount the CentOS DVD. Command would be : mount /dev/cdrom /media
3. Move to the CentOS RPM folder inside the DVD: cd /media/CentOS
4. Run the command bellow to install the TFTP-Server:
rpm -ivh xinetd-2.3.14-10.el5.i386.rpm
rpm -ivh tftp-server-0.49-2.el5.centos.i386.rpm
(If you get dependency error, download all necessary packages using "yum")
5. Run the command bellow to install the DHCP server:
rpm -ivh dhcp-3.0.5-23.el5.i386.rpm
6. Create new folder for the Kickstart server:
mkdir -p /data/kickstart
7. Edit using "vi", the file /etc/xinetd.d/tftp and change the following settings:
From:
disable = yes To: disable = no
From:
server_args = -s /tftpboot To: server_args = -s /data/kickstart
8. Run the command bellow to start the TFTP server:
/sbin/service xinetd start
9. Run the command bellow to start the TFTP server run at startup:
chkconfig xinetd on
10. Edit using "vi", the file /etc/dhcpd.conf and add the following lines:
ddns-update-style none;
allow bootp;
allow booting;
subnet 10.1.1.0 netmask 255.255.255.0 {
option routers 10.1.1.254;
option domain-name-servers 10.1.1.2;
next-server 10.1.1.1;
filename "pxelinux.0";
range dynamic-bootp 10.1.1.200 10.1.1.210;
}Note 1: Replace 10.1.1.0 with the correct network ID.
Note 2: Replace 255.255.255.0 with the correct subnet mask.
Note 3: Replace 10.1.1.254 with the correct default gateway.
Note 4: Replace 10.1.1.1 with the Kickstart server IP address.
Note 5: Replace 10.1.1.200 with the first IP of the DHCP pool.
Note 6: Replace 10.1.1.210 with the last IP of the DHCP pool.
Note 7: Replace 10.1.1.2 with the correct DNS server.
11. Start the DHCP server
service dhcpd start or /etc/init.d/dhcpd start
12. Run the command bellow to start the DHCP server run at startup:
chkconfig dhcpd on
13. Copy Boot Files
cp /usr/lib/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /data/kickstart
14. Create a folder for the PXE menu files:
mkdir -p /data/kickstart/pxelinux.cfg
15. Move to the CentOS DVD root folder:
cd /media
16. Copy vmlinuz and initrd.img from the DVD to the images directory:
cp /media/images/pxeboot/{vmlinuz,initrd.img} /data/kickstart/images
17. Create the CentOS DVD structure:
cp -r CentOS /data/kickstart/
cp -r isolinux /data/kickstart/
cp -r repodata /data/kickstart/
cp -r images /data/kickstart/
18. Create using "vi", the file /data/kickstart/pxelinux.cfg/default with the following content:
default menu.c32
prompt 0
MENU TITLE PXE Menu
LABEL CentOS
MENU LABEL CentOS
KERNEL images/vmlinuz
append initrd=images/initrd.img vga=normal network ks=nfs:10.1.1.1:/data/kickstart/ks.cfg textNote: Replace 10.1.1.1 with the Kickstart server IP address.
19. Create an unattended installation script /data/kickstart/ks.cfg
Note: Make sure the file starts with the following lines:
install
nfs --server=10.1.1.1 --dir=/data/kickstartNote 1: Replace 10.1.1.1 with the Kickstart server IP address.
Note: Make sure the lines beginning with “cdrom” and “url” does not exist on the file.
Note: To review ks.cfg file options, see the link:
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.4/html/Installation_Guide/s1-kickstart2-options.html
20. Edit using "vi", the file /etc/exports and add the following line:
/data/kickstart *(ro,no_root_squash)
21. Start the NFS service:
service portmap start
service nfs start
chkconfig nfs on
That' it.
Wednesday, April 20, 2011
Alert "Disk Usage" on your email id
Below shell script shows "Hard Disk Usage" on your email address on regular basis.
Step:1
Monday, September 27, 2010
Faster Internet Browsing Thru. Local DNS Cache
To see how fast your current domain name servers (DNS) are, open a terminal execute below command.
1. Install DNSMasq:]# dig yahoo.com
You Should get something like this.*************************************************************************
; <<>> DiG 9.6.1-P1 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42045 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION: ;yahoo.com. IN A
;; ANSWER SECTION: yahoo.com. 20142 IN A 69.147.114.224 yahoo.com. 20142 IN A 209.131.36.159 yahoo.com. 20142 IN A 209.191.93.53
;; Query time: 50 msec
;; SERVER: 208.67.220.220#53(208.67.220.220)
;; WHEN: Wed Dec 9 13:21:48 2009
;; MSG SIZE rcvd: 75*************************************************************************
Notice the "Query time" in bold. It's usually somewhere near 50 msec. (it depends on your domain name servers).
Run this one more time. If the query time decreases to less than 5
msec, it means your internet service provider DNS already uses some
caching method and you do not need to follow this how-to. If the
response time is almost the same and you are using a cable (broadband)
internet connection, you can use this guide to cache the DNS for faster
internet browsing.
Now, Let's Start The Practical.
Manually configuring the local DNS cache
yum install dnsmasq
2. Edit "Dnsmasq" configuration file.
vim /etc/dnsmasq.conf
3. Now search for "listen-address" (it's on line 90 on my Ubuntu Karmic installation), remove the "#" character in front of "listen-address" and add "127.0.0.1" after the "=" (all without the quotes). Basically, this is how the "listen-address" line should look like after editing it :
listen-address=127.0.0.14. You can also edit the cache size if you want. Search for this in the same file: "#cache-size=150" (it's on line 432 on my Ubuntu Karmic installation), remove the "#" character in front of the line (this uncomments it) and change "150" with the size you want for you DNS cache. This is how the line should look after editing it :
cache-size=500Note :- "500" can be any number you want.
5. Edit "/etc/resolv.conf" file & modify First Line.
nameserver 127.0.0.1
nameserver ISP_DNS1
nameserver ISP_DNS2
6. Finally "service network restart" & "service dnsmasq restart"
7. Testing
To see the performance improvement, open a terminal and type:
dig yahoo.com
************************************************************
; <<>> DiG 9.6.1-P2 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57501
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.com. IN A
;; ANSWER SECTION:
yahoo.com. 20982 IN A 209.131.36.159
yahoo.com. 20982 IN A 69.147.114.224
yahoo.com. 20982 IN A 209.191.93.53
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Dec 9 14:43:41 2009
;; MSG SIZE rcvd: 75************************************************************
0 msec. query time, because the domains are now cached.
That's it.