Prakash Sawarkar: Kernel 3.8 Released, how to Compile in Redhat, CenOS and Fedora..

Kernel 3.8 Released, how to Compile in Redhat, CentOS and Fedora.

Tuesday, 26 January 2010

Recover deleted files using Foremost

Foremost is a console program to recover files based on their headers, footers, and internal data structures. This process is commonly referred to as data carving. Foremost can work on image files, such as those generated by dd, Safeback, Encase, etc, or directly on a drive. The headers and footers can be specified by a configuration file or you can use command line switches to specify built-in file types. These built-in types look at the data structures of a given file format allowing for a more reliable and faster recovery.
Originally developed by the United States Air Force Office of Special Investigations and The Center for Information Systems Security Studies and Research and now foremost has been opened to the general public.
Files types supported by foremost:
jpg, gif, png, bmp
avi, mpg, wav, wmv, mov
pdf, doc, zip, exe, rff, rar, html, cpp
You can tweak /etc/foremost.conf to add support for more file types.
Please note that there's no guarantee that foremost will succeed in recovering your files, but at least there's a chance.
Foremost Installation:
Open the terminal and type following command to install foremost:
               # yum  install  foremost
Foremost isn’t the greatest solution; it recovers every file it sees and doesn’t support very many file types. It is possible to add types to the /etc/foremost.conf file, but it doesn’t look an easy task. However, if you’ve lost a bunch of photos or documents, Foremost could be just what you need.
Using Foremost:
Suppose you want to recover png file, from command line type following commad:
foremost -t png -i /dev/sda1
After completion, you will find a folder called output in the directory from where you executed the foremost, where within you can see the folder 'png' and inside png you can find your lost png file.
There are many more tools that you can use to recover your files:
Recover deleted files from NTFS filesystem from Centos Linux - Ntfsundelete
Recover your deleted jpeg pictures from filesystem or camera memory card - recoverjpeg
Utility to recover deleted files from an ext3 or  ext4 Linux partition - Extundelete

Friday, 20 November 2009

LVM (Logical Volume Manager) Concept on Linux RHEL / CentOS

 LVM is a method of allocating harddrive space into logical  volumes that can be easily resized instead of partitions.
 With LVM the harddrive (or) set of harddrives are allocated to  one or more physical volumes.
 The physical volumes are combined into volume  groups
 Each volume group is divided into logical volumes which are  assigned mountpoints such as /home and filesystem types such  as   ext3.
To configure LVM

1)Create three LVM partitions
2)Convert them as physical volumes
3)Create volume groups from physical volumes
4)Create logical volumes from volume groups and assign mountpoints

IMPLEMENTATION:
# fdisk /dev/sda
n
+500M
t
<partition number>
8e
w
partprobe
To convert LVM partitions as physical volumes
# pvcreate /dev/sda<partition numbers>
ex: pvcreate /dev/sda{9,10,11}

To view physical volumes
# pvdisplay

To create volume group
# vgcreate <vg name> <partitions>
ex: vgcreate maaza /dev/sda{9,10,11}

To view volume groups
# vgdisplay

To create a logical volume
# lvcreate -L <+size> <vg name> -n <LV name>
ex: lvcreate -L +500M /dev/maaza -n fanta

To view logical volumes
# lvdisplay

To format logical volumes
# mke2fs -j /dev/maaza/fanta

Create a mountpoint and mount logical volume on it
# mkdir /cyber
# mount /dev/maaza/fanta /cyber
# cd /cyber

To extend size of logical volume
# umount <mountpoint>
# lvcreate -L <size> <lv name>
ex:lvcreate -L +500M /dev/maaza/fanta

To make filesystem for extended size
# resize2fs <logical volume>
ex: resize2fs /dev/maaza/fanta
# mount /dev/maaza/fanta /cyber

To resize a logical volume
note:whenever we are reducing an LVM we have to take backup
# mkdir /a
# cp -rf /cyber/* /a

# lvreduce -L <-size> <LVM>
ex: lvreduce -L -100M /dev/maaza/fanta

To format LVM
# mkfs.ext3 <logical volume>
ex:mkfs.ext3 /dev/maaza/fanta

# mount /dev/maaza/fanta /cyber
# cp -rf /a/* /cyber

To remove an LVM
# umount <mountpoint>
# lvremove <logical volume>
ex:lvremove /dev/maaza/fanta

To extend volume group
1)create another LVM partition
2)convert into physical volume

# vgextend <vg name> <partition name>
ex:vgextend /dev/maaza /dev/sda12

To reduce volume group
# vgreduce <vgname> <partition name>
ex:vgreduce /dev/maaza /dev/sda12

To remove volume group
# vgremove <vg name>
ex:vgremove /dev/maaza

To delete physical volumes
# pvremove <partitions>

ex:pvremove /dev/sda{9,10,11,12}

Monday, 28 September 2009

DNS Configuration in CentOS /Redhat

DNS is a service which is used to resolve host to IP address and zone records & configuration files.

MASTER DNS

There are two types of zonerecords
1) Forwad lookup zone
2) Reverse lookup zone

 By defaults, computer connects to another computer with the help of IP address


Forward lookup zone :  It converts names into IP addresses

Reverse lookup zone: It converts IP addresses to names
Steps:
# yum install bind-* caching-nameserver*-y
# service named start
# chkconfig named on
# cd /var/named/chroot/etc
# ls
# cp named-caching-nameserver named.conf
# vi named.conf
  delete ipv6 lines (line nos. 16 &22)

(line no15) Listen on port 53 {127.0.0.1; 192.168.0.254;}
(here 192.168.0.254 is server ip
(line no 21) allow-query  192.168.0.0/24 (clients range)
(line no 30) match-clients {local host; 192.168.0.0/24; } (here 192.168.0.0/24 is clients ip range & subnet mask)
(line no 31) match-destinations    {localhost; 192.168.0.0/24;}
save&quit

#  vi /etc/rfc1912.zones
 copy ten lines from 21 to 31 and paste under 31
 change as follows
 zone "redhat.com" IN { 
  type master;
  file "redhat.for"
   allow-update { none; };
};
zone "0.168.192.IN-addr-arpa IN {
   type master;
   file "redhat.rev"
    allow-update { none; };
};

(here redhat.com is domain name and 0.168.192. is redhat.coms network range redhat.for is forward look up zone & redhat.rev is reverse lookup zone)
save & quit
#  chgrp named named.conf
# chgrp named named.rfc1912.zones
# cd /var/named/chroot/var/named
# cp localhost.zone redhat.for
# cp named.local redhat.rev
#  vi redhat.for

change as follows
$TTL    86400
@               IN SOA  redhat.com.       root.redhat.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum

                IN NS           server1.redhat.com.
server1.redhat.com.             IN A            192.168.0.254
www254.redhat.com.           IN CNAME        server1.redhat.com.
station1.redhat.com.           IN A            192.168.0.1
www1.redhat.com.              IN CNAME        station1.redhat.com.
station2.redhat.com.          IN A            192.168.0.2
www2.redhat.com.             IN CNAME        station2.redhat.com.
xxx2.redhat.com.              IN CNAME        station2.redhat.com.
yyy2.redhat.com.              IN CNAME        station2.redhat.com.
station3.redhat.com.        IN A            192.168.0.3
www3.redhat.com.           IN CNAME        station3.redhat.com.
station4.redhat.com.        IN A            192.168.0.4
www4.redhat.com.           IN CNAME        station4.redhat.com.
station5.redhat.com.        IN A            192.168.0.5
www5.redhat.com.           IN CNAME        station5.redhat.com.
station6.redhat.com.            IN A            192.168.0.6
www6.redhat.com.                IN CNAME        station6.redhat.com.



(zone: zone is a storage database which contains all zone records

forward lookup zone: used for resolving hostname to ipaddress & it maintains host to ip mapping information
reverse lookup zone: used for resolving ip address to hostname & it maintains ip to hostname mapping information

Types of records: 
SOA : sort of authority the first record in any zone  it indicates who is authority for this domain
NS :nameserver it identifies the dns server for each zone
A record : resolves hostname to ip address
CNAME record : resolves an alias name to a hostname
PTR record : resolves an ipaddress to a hostname
MX record : resolves mail server ip (used by mail server)
TTL :time to live)

save & quit

# vi redhat.rev
(change as follows)
$TTL    86400
@       IN      SOA redhat.com.    root.redhat.com.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                     86400 )    ; Minimum
            IN        NS      server1.redhat.com.
254      IN       PTR     server1.redhat.com.
1         IN       PTR     station1.redhat.com.
2        IN       PTR      station2.redhat.com.
3         IN      PTR     station3.redhat.com.
4         IN      PTR     station4.redhat.com.
5         IN      PTR     station5.redhat.com.
6         IN      PTR   station6.redhat.com.

save & quit

#  chgrp named redhat.for
#  chgrp named redhat.rev
#  service named restart

 to check:
# dig server1.redhat.com
# dig -x 192.168.0.1
 (if answer is 1 server is ready if answer is 0 server has some error)

to check error in configuration file
# named-checkconf redhat.com /var/named/chroot/etc/named.conf

to check errors in zone record 
# named-checkzone redhat.com /var/named/chroot/var/named/redhat.for
# named-checkzone redhat.com /var/named/chroot/var/named/redhat.rev

 SLAVE DNS

 Master DNS Server
It is the Master Copy of all the Zone Information.
It is Read/Write copy.

Slave DNS Server
It is Slave Backup of Master zone. It is Read Only

        if any error may occur to your dns server at the time the entir network will stop.sometimes it may cause huge damage.for that one we are createing slave dns for faulttolerance and load balancing.

we need another system which contains server o/s

Steps:

# yum install bind-* caching-nameserver -y
# service named start
# chkconfig named on
# cd /var/named/chroot/etc/named-rfc1912.zone

(change as follows)
copy 10 lines from 21 to 31 paste under 31
zone "redhat.com"
  type slave;
  file "redhat.for"
  masters {192.168.0.254:};

zone "0.168.192. IN-ADDR-arpa" IN {
  type slave ;
  file " redhat.rev"
  masters {192.168.0.254;};

save& quit

#service named restart
go to client 
# vi /etc/resolv.conf

nameserver 192.168.0.254
nameserver 192.168.0.1 (slave dns ip)  

FORWARDERS

If you have trusted relationship with another company  those comapny users can enter into our network & our company users can enter into their network by using this forwarders
Steps:
in master dns server 
#  vi /var/named/chroot/etc/named.conf

add aline 
 forwarders {192.168.10.254:};
 forward only ;
};
(here 192.168.10.254 is trusted companies dns)
save & quit

# service named restart

Sunday, 5 July 2009

Reinstall GRUB Bootloader on md0

After a power outage, an RHEL 4 server was stuck with nothing on the screen but "GRUB" at the top left. Rebooting had the same result. My bootloader was toast.

I put in the RHEL 4 install disc, and at the boot prompt selected the rescue option.

boot: linux rescue

Once the rescue image booted, scanned the system and mounted read/write, I attempted to reinstall grub:

# chroot /mnt/sysimage/
# grub-install /dev/sda
/dev/md0 does not have any corresponding BIOS drive
# grub-install --recheck /dev/sda
/dev/md0 does not have any corresponding BIOS drive
#
An error. The md0 mirror, which is composed of sda and sdb, was complicating things. I though maybe I could fudge the device map by adding an entry to /boot/grub/device.map:

(fd0)   /dev/fd0
(hd0)   /dev/sda
(hd1)   /dev/sdb
(hd2)   /dev/md0

# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.
Fixed. I then also installed the bootloader on sdb (hd1), just in case.
That was no good either. Finally, I had to run grub manually.
# grub
grub> root (hd0,0)        
root (hd0,0)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
# reboot

Fixed. I then also installed the bootloader on sdb (hd1), just in case.

Monday, 29 June 2009

Setting up a new LAN CARD (Ethernet) network device

If you added a new network device, but upon reboot, CentOS did not represent the card in the /etc/sysconfig/network-scripts/ifcfg-eth*, you may have to manually make aware the device to the OS. 

Step 1: Make sure that the OS has detected the new card. From the example below, it detected my 2nd card. If you are unable to detect, you may want to reinstall or check the driver.

#  lspci |grep -i ethernet
   0b:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
   14:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)

Step 2: Launch the system-config-network and fill up the necessary information.
# system-config-network
You will see that the system-config-network create an entry at /etc/sysconfig/network-scripts/ifcfg-eth1.
Restart the network
# service network restart