Archives

Device eth0 does not seem to be present

After cloning a Centos machine from Oracle Virtualbox or from VMware template, I got following error message when networking service was restarted
device eth0 does not seem to be present
Initially, I thought the issue might be with the network adapter but was not sure exactly which network adapter settings should be kept..
On further investigation, I came with a solution with following solution.
Basically, the problem occurs due to old NIC record does not getting erased even though new NIC record is assigned.
1) Open following file which holds record of the NIC templates
vi /etc/udev/rules.d/70-persistent-net.rules
The above file should contain similar records as below:
# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”,
ATTR{address}==”00:27:3e:ae:00:1a”,
ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”,
ATTR{address}==”00:27:3e:ae:00:1b”,
ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″
2) Remove previous eth entries and change the last entry NAME to eth0
# PCI device 0x15ad:0x07b0 (e1000)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”,
ATTR{address}==”00:27:3e:ae:00:1b”,
ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″
3) Save the file.
4) Open following file and modify the mac address

vi /etc/sysconfig/network-scripts/ifcfg-eth0
5) Save the file.
6) Reload udev configuration for the changes we made to reflect
start_udev
7) Restart network service
service network restart
or
/etc/init.d/network restart
8) Check the available ip using ifconfig command and update /etc/resolv.conf file with correct nameservers.

 

TROUBLESHOOTING

Difference between /bin vs /sbin vs /usr/bin vs /usr/sbin

/bin This directory contains executable programs which are needed in
single user mode and to bring the system up or repair it.

/sbin Like /bin, this directory holds commands needed to boot the sys-
tem, but which are usually not executed by normal users.

/usr/bin
This is the primary directory for executable programs. Most
programs executed by normal users which are not needed for boot-
ing or for repairing the system and which are not installed
locally should be placed in this directory.

/usr/sbin
This directory contains program binaries for system administra-
tion which are not essential for the boot process, for mounting
/usr, or for system repair.

Install D-Link DWA 525 N 150 Wireless Over Linux or Fedora 14
After a long time spending over google I find some useful NOTES over how to install D-Link DWA 525 N 150 Wireless Drivers, which are here:

Run command “lspci |grep -i network”
Output will be like :
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 03)
06:02.0 Network controller: RaLink Device 3060

Go to http://www.ralinktech.com/support.php?s=2 and download RT3062PCI/mPCI/CB/PCIe(RT3060/RT3062/RT3562/RT3592)

This will ask for your Name and Mail ID, enter and when you click on Accept this will ask you for save or open. Save file to anywhere on your machine, lets say in /opt/

Go to /opt/ and run following command:
cd /opt
tar zxvf DPO_RT3562_3592_3062_LinuxSTA_V2.4.1.1_20101217.tgz
cd DPO_RT3562_3592_3062_LinuxSTA_V2.4.1.1_20101217

Change following in os/linux/config.mk file
vim os/linux/config.mk
HAS_WPA_SUPPLICANT = n -> HAS_WPA_SUPPLICANT = y
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT = n -> HAS_NATIVE_WPA_SUPPLICANT_SUPPORT = y

After making above changes run following:
make
make install

After successfully completion of above command, run following:
insmod os/linux/rt3562sta.ko

Upgrade Fedora 7 to Fedora 8

Before upgrading your OS version we must take the backup of our system firstly. For upgrading to Fedora 8 from Fedora 7 follow the given below commands:

Update your packages:

yum update

Run following command to clear the yum cache:

yum clean all
Then run following command to install fedora 8 release packages:

rpm -Uvh ftp://ftp.uni-bayreuth.de/pub/redhat.com/fedora-archive/linux/releases/8/Everything/ppc64/os/Packages/fedora-release-8-3.noarch.rpm

rpm -Uvh ftp://ftp.uni-bayreuth.de/pub/redhat.com/fedora-archive/linux/releases/8/Everything/ppc64/os/Packages/fedora-release-notes-8.0.0-3.noarch.rpm

Now this is the time to run upgrade over the machine:

yum upgrade

If it stops with an error like this one:

—> Package orca.i386 0:2.20.0.1-1.fc8 set to be updated
–> Finished Dependency Resolution
Error: Missing Dependency: gecko-libs = 1.8.1.8 is needed by package yelp

simply uninstall the package that is causing the problem (in this case yelp) (I only had to do this with the yelp package which doesn’t seem to be overly important)…

yum remove yelp

Ref. : http://www.howtoforge.com/upgrading-fedora7-desktop-to-fedora8

For upgrade from Fedora8 to Fedora 9, use below given release RPMs and other are same as above

rpm -Uhv http://mirror.liberty.edu/pub/fedora/linux/releases/9/Fedora/i386/os/Packages/fedora-release-9-2.noarch.rpm http://mirror.liberty.edu/pub/fedora/linux/releases/9/Fedora/i386/os/Packages/fedora-release-notes-9.0.0-1.noarch.rpm

Upgrading from Fedora 9 to Fedora 10, follow below given URL:

Linux Security

—–>   Enable Authentication for Single-User Mode

Single-User Mode is used for a system recovery. However, by default, no authentication is used if single-user mode is selected. This can be used to bypassing security on the server and gaining root access. To enable authentication for single-user mode, open the /etc/inittab, file:

# vi /etc/inittab

Add the following line to the file:

~~:S:wait:/sbin/sulogin

 

—–> Disable Interactive Hotkey Startup at Boot

A few Linux distribution like Fedora, CentOS or RHEL allows the console user to perform an interactive system startup by pressing [I] key. Using interactive boot, attacker can disable the firewall and other system services. Open /etc/sysconfig/init file:

# vi /etc/sysconfig/init

Modify the setting as follows:

PROMPT=no

—–> Setup Time-out for Login Shells

 Go into the user’s home director:

# vi .bash_profile

TMOUT=300
readonly TMOUT
export TMOUT

In case of dealing with SSH, we need to define/enter the following:

To set an idle timeout interval, after this interval has passed, the idle user will be automatically logged out. Open /etc/ssh/sshd_config file, enter:

vi /etc/ssh/sshd_config

Find ClientAliveInterval and set to 300 (5 minutes) as follows:

ClientAliveInterval 300
ClientAliveCountMax 0

Save and close the file. Restart sshd:
# service sshd restart

Redhat Linux : Rollback RPMs

RPM Rollback for Redhat 5.x versions

1) Create a file /etc/rpm/macros and put following

cat >> /etc/rpm/macros
%_repackage_all_erasures 1

2) Add following at the end of /etc/yum.conf

echo “tsflags=repackage” >> /etc/yum.conf

After above entries, we can rollback rpms installed using yum

3) Now update system with single rpm or complete using

yum update

4) Lets say we had update rpms 1 hour, 2 month and 1 day ago and wants to remove all those then use following commands:

rpm –rollback “1 day ago”
rpm –rollback “1hour ago”
rpm –rollback “2 month ago”

Will be posting for Redhat 6.x version soon…….

Linux login issue – Can not login: Resource temporarily not available

Sometime we get following error while user login:

$su – username
Coud not login: Resource temporarily not available

Most of the times this is because of processes or number of files available to user is already used. So, could not arrange more files/processes to login, in this case we required to increase the limits for user in /etc/security/limits.conf (PAM module)

username        soft    nproc           3000
username        hard    nproc          4096
username        soft     nofile           6000
username        hard    nofile          8192

Set these values as per requirement else setting up these values higher may result in server inaccessible in case that particular uses all file descriptors, process and higher memory of server.

Linux Resize LUN Without Reboot

Try running following commands

Check OS using what devices for attached LUNs:

multipath -l

mpath5 (360060…………………..) dm-15

[size=100G][features=1 queue_if_no_path][hwhandler=1 emc][rw]

\_ round-robin 0 [prio=0][active]

\_ 1:0:0:14 sdb 66:192 [active][undef]

\_ 0:0:0:14 sdc  8:224  [active][undef]

\_ round-robin 0 [prio=0][enabled]

\_ 0:0:1:14 sdd 66:112 [active][undef]

\_ 1:0:1:14 sde 67:176 [active][undef]

Rescan all paths:

echo 1 > /sys/block/sdb/device/rescan

echo 1 > /sys/block/sdc/device/rescan

echo 1 > /sys/block/sdd/device/rescan

echo 1 > /sys/block/sde/device/rescan

Then run:
partprobe

multipathd -k
resize map mpath5

If LVM is used, also required following:

#pvscan

Check Disk Changes detected under LVM:

#pvs

#vgscan

Check VG Size is Increased:

#vgs

Now Extend the LV:

#lvextend -L +G

Finally Extend the File System

#resize2fs

Redhat Device Mapper Multipathing

REDHAT DEVICE MAPPER MULTIPATH

1) DM Software Installation

yum install device-mapper-multipath

2) Initialize /etc/multipath.conf file

mpathconf –enable

3) Start multipath service

service multipathd start

4) If you do not want to use user friendly name

mpathconf –enable –user_friendly_names n

5) Ignoring Local Disks when generating Multipath devices

multipath -v2 (shows local disk, /dev/sda, in the multipath map)

create: SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1 undef WINSYS,SF2372 size=33 GB features=”0″ hwhandler=”0″ wp=undef `-+- policy=’round-robin 0′ prio=1 status=undef
– 0:0:0:0 sda 8:0 [———

device-mapper ioctl cmd 9 failed: Invalid argument device-mapper ioctl cmd 14 failed: No such device or address

create: 3600a0b80001327d80000006d43621677 undef WINSYS,SF2372 size=12G features=’0′ hwhandler=’0′ wp=undef `-+- policy=’round-robin 0′ prio=1 status=undef
– 2:0:0:0 sdb 8:16 undef ready running `- 3:0:0:0 sdf 8:80 undef ready running

create: 3600a0b80001327510000009a436215ec undef WINSYS,SF2372 size=12G features=’0′ hwhandler=’0′ wp=undef `-+- policy=’round-robin 0′ prio=1 status=undef
– 2:0:0:1 sdc 8:32 undef ready running `- 3:0:0:1 sdg 8:96 undef ready running

In order to prevent the device mapper from mapping /dev/sda in its multipath maps, edit blacklist section in /etc/multipath.conf

blacklist {

wwid SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1


}

6) After updating file reload the changes

service multipathd reload

7) Run following command to remove multipath device

multipath -f SIBM-ESXSST336732LC____F3ET0EP0Q000072428BX1

8) Now check if device removed from multipath

multipath

create: 3600a0b80001327d80000006d43621677 undef WINSYS,SF2372 size=12G features=’0′ hwhandler=’0′ wp=undef `-+- policy=’round-robin 0′ prio=1 status=undef
– 2:0:0:0 sdb 8:16 undef ready running `- 3:0:0:0 sdf 8:80 undef ready running

create: 3600a0b80001327510000009a436215ec undef WINSYS,SF2372 size=12G features=’0′ hwhandler=’0′ wp=undef `-+- policy=’round-robin 0′ prio=1 status=undef
– 2:0:0:1 sdc 8:32 undef ready running `- 3:0:0:1 sdg 8:96 undef ready running

….

9) Add storage that is not supported by default as a know multipath device lets say “Vendor is HP, Product Open-V”

To add information about the HP Open-V series the entry looks like this, where %n is the device name. Add following in /etc/multipath.conf file

devices {


device {


vendor “HP”


product “OPEN-V.”


getuid_callout “/lib/udev/scsi_id –whitelisted –device=/dev/%n”

GRUB Image Files

GRUB consists of several images: a variety of bootstrap images for starting GRUB in various ways, a kernel image, and a set of modules which are combined with the kernel image to form a core image. Here is a short overview of them:

boot.img

On PC BIOS systems, this image is the first part of GRUB to start. It is written to a master boot record (MBR) or to the boot sector of a partition. Because a PC boot sector is 512 bytes, the size of this image is exactly 512 bytes.

The sole function of boot.img is to read the first sector of the core image from a local disk and jump to it. Because of the size restriction, boot.img cannot understand any file system structure, so grub-setuphardcodes the location of the first sector of the core image into boot.img when installing GRUB.

diskboot.img

This image is used as the first sector of the core image when booting from a hard disk. It reads the rest of the core image into memory and starts the kernel. Since file system handling is not yet available, it encodes the location of the core image using a block list format.

cdboot.img

This image is used as the first sector of the core image when booting from a CD-ROM drive. It performs a similar function to diskboot.img.

pxeboot.img

This image is used as the start of the core image when booting from the network using PXE. See Network.

lnxboot.img

This image may be placed at the start of the core image in order to make GRUB look enough like a Linux kernel that it can be booted by LILO using an ‘image=’ section.

kernel.img

This image contains GRUB’s basic run-time facilities: frameworks for device and file handling, environment variables, the rescue mode command-line parser, and so on. It is rarely used directly, but is built into all core images.

core.img

This is the core image of GRUB. It is built dynamically from the kernel image and an arbitrary list of modules by the grub-mkimage program. Usually, it contains enough modules to access /boot/grub, and loads everything else (including menu handling, the ability to load target operating systems, and so on) from the file system at run-time. The modular design allows the core image to be kept small, since the areas of disk where it must be installed are often as small as 32KB.

Initrd.img

initrd (initial ramdisk) is a scheme for loading a temporary file system into memory in the boot process of the Linux kernel. initrd and initramfs refer to slightly different methods of achieving this. Both are commonly used to make preparations before the real root file system can be mounted.

How to password protect GRUB?

There are only 3 steps to password protect users to edit grub properties while system booting:

1) Run following command to generate MD5 encrypted password:

root@localhost# grub-md5-crypt
Password:
Retype password:
$1$yAr5c0$ZYlcLULaS2rwOvry1B4gX/

2) Copy MD5 encrypted password of above command

3) Paste copied MD5 encrypted password in menu.list/grub.conf file :

default = 0
timeout=5
password –md5 $1$yAr5c0$ZYlcLULaS2rwOvry1B4gX/

Thats it!!!

Now whenever user’s try to run GRUB commands or try to change booting parameters at the time of BOOT, above entered text password will be required!!

Linux : How To Recover From Bad SuperBlock Corrupted Ext3 File System??

I was getting following error:
/dev/cciss/c0d0p1: Input/output error

mount: /dev/cciss/c0d0p1: can’t read superblock

In case you are also facing the same error with superblocks, you can follow below given steps to recover superblock:

#### dumpe2fs  /dev/cciss/c0d0p1|grep -i superblock

dumpe2fs 1.39 (29-May-2006)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super
Primary superblock at 1, Group descriptors at 2-2
Backup superblock at 8193, Group descriptors at 8194-8194
Backup superblock at 24577, Group descriptors at 24578-24578
Backup superblock at 40961, Group descriptors at 40962-40962
Backup superblock at 57345, Group descriptors at 57346-57346
Backup superblock at 73729, Group descriptors at 73730-73730

Above command output showing back’d up superblock. Now we need to restore from these superblocks

#### fsck -b 8193 /dev/cciss/c0d0p1

If still showing any error continue to restore with next Backup superblock i.e;  24577, 40961 etc….

After successful completion of above command i.e; output will be like this

Free blocks count wrong for group #362 (32254, counted=32248).

Fix? yes

Free blocks count wrong for group #368 (32254, counted=27774).

Fix? yes

……….

/dev/cciss/c0d0p1: ***** FILE SYSTEM WAS MODIFIED *****

/dev/cciss/c0d0p1: 59586/30539776 files (0.6% non-contiguous), 3604682/61059048 blocks

Now mount your file system

##### mount  /dev/cciss/c0d0p1 /mnt

How To Access GNU Screen Session Over SSH??

We can attach a GNU SCREEN session remotely over SSH; in this example we’ll open a GNU screen session on host1, and connect to it from host2.

First open and then detach a screen session on host1, named testscreen:

host1 ~ $ screen -S testscreen

Then detach from your screen session with the keyboard combination Ctrl+a+d:

[detached from 3829.testscreen]

Do not “exit” from shell only use Ctrl+a+d to detach from that session. One of the main feature I like about screen is that we can trace whatever user was doing last time (in case of script command a typescript file is created which show the complete working of user)

You can verify that it’s still there with this command:

host1 ~ $ screen -ls

There is a screen on:
        3941.testscreen (03/18/2012 12:43:42 PM) (Detached)
1 Socket in /var/run/screen/S-host1.

Then re-attach to your screen session from host2 (because we just detached our session last time not exited, so this will start from the last point were we were detached from session):

host2 ~ $ ssh -t user@host1 screen -r testscreen

You don’t have to name the screen session if there is only one 🙂

Ref: http://www.itworld.com/it-managementstrategy/261500/16-ultimate-openssh-hacks

Redhat/CentOS/Fedora Linux: How to Setup Chroot SSH/SFTP

Find below given steps to setup chrooted SSH:

1) Create a group : groupadd sftpgroup

2) Create a user : useradd -g sftpgroup -d /home/mysftpuser -s /sbin/nologin mysftpuser

3) Open /etc/ssh/sshd_config file and comment following line

#Subsystem      sftp    /usr/libexec/openssh/sftp-server

4) Add following lines to /etc/ssh/sshd_config

Subsystem      sftp    internal-sftp
ChrootDirectory /home/%u

5) Save and exit from /etc/ssh/sshd_config file

6) Restart sshd service

7) Try to login from server/client machine

[nginx_test:main.LINUX5 ~]# sftp mysftp@127.0.0.1
Connecting to 127.0.0.1…
mysftp@127.0.0.1’s password:
sftp>

sftp> pwd
Remote working directory: /

What Are Unix/Linux Processes And Their Types…….

A process is a running instance of a program. In this article we used two terms ‘program’ and ‘running instance’. Suppose we run a program simultaneously 5 times, then corresponding to each instance there will be a process running in the system. So we say that a process is a “running instance” of a program.

As you already know, you can use ps command to view the processes running on your system. For effective use of the ps command, refer to 7 Practical PS Command Examples for Process Monitoring.

1. Peeping Inside a Process

Now, since we are clear with what exactly a process is, lets dig a bit deeper to see what a process consists of. A Unix process can be thought of as a container which contains:

Program Instructions

Program instructions are kept in text segments which are executed by CPU. Usually for programs like text editors which are executed frequently the text segment is shared. This segment has read only privileges which means that a program cannot modify its text segment.

Data

Mostly the data is kept in data segment. Data segment can be classified into initialized data segment and uninitialized data segment. As the name suggest, initialized data segment contains those global variables which are initialized before hand while uninitialized data segment (also known as ‘BSS’ segment) contains uninitialized global variables. Also, static variables are stored in data segment.

Local variables which are local to functions are stored on stack. Stack is particular to a function and besides containing the information about local variables it also contains information about the address where the flow will return once the execution of function is done. Stack also contains information about the callers environment, like some of the machine registers are also stored on stack. A function which is called allocates memory for its local variables and temporary variables on stack itself. In case of recursive function an independent stack for each function call exists.

Then there is data which is stored on heap. This memory for this data is allocated on runtime on heap segment. Heap segment is not local to a process but shared across processes. This is the reason why C programmers worry a lot about memory leaks which are caused on heap segment and may affect other processes on the system.

Command line arguments and environment variables

A process also contains room for storing environment variables and the command line arguments that we pass to the program. Usually the vector containing the command line information is stored here and then the address of this vector of information and number of elements in vector is copied to ‘argv’ and ‘argc’ (the two arguments to ‘main()’ function).

Besides the above information, a process also contains information like

  • State of its I/O
  • Its priority and other control information

One of the most important control information for a process is the privileges. A process directly inherits all the privileges of the user who has triggered this process. For example a process triggered by user who does not have superuser privileges cannot do stuff that require root privileges while a process triggered by root can do any thing that it is programmed to do. An exception to the above rule is where a process can acquire greater privileges than the user who triggered it if the setuid or setgid bit is set for that particular process. But we will not go into much detail about it here(refer to the man pages of setuid and setgid for more information on this).

2. Background and foreground processes

As we already discussed that we can start a process by its name in Unix. Like some standard programs ‘ls’, ‘ps’ etc can be started by just typing their name on the shell prompt. There are two ways in which we can start a process

  • Starting in foreground
  • Starting in background

Suppose there is a utility that consumes some time and does a count. Lets say the the name of the utility is ‘count’ Now to trigger and run the program in foreground, I run the following command (where ‘count’ is the name of the binary from the code above) :

$ ./count
Counting done

So we see that, after running the binary ‘./count’, it took almost 10 seconds before the output was displayed on stdout and until then the shell was occupied by this process only. ie You could not perform any other operation on the same shell. Now, to trigger a process in background, add ‘&’ at the end of the command:

$ ./count &
[1] 4120

$ # Do some work on shell while the above program is working in the background

$ Counting done

The ampersand ‘&’ sign indicates that this process needs to be run as a background process. By running a background process, we can have access to the shell for doing any further operations. Like, in the output above, after running the binary ‘count’ in background, I used a couple of more commands on the same shell and when the binary ‘count’ was done with its processing, the output was thrown back on the same shell(the last line). So we can conclude that by default every process runs in foreground, receives input(if any) from keyboard and returns output to the user. While a background process is one which gets disconnected from the keyboard and user can use the same shell to do more operations.

For more information on foreground and background processes refer to: How to Manage UNIX Background Jobs

3. Types of process

So we see that process is a concept that is fundamental to an operating system. Almost every activity on an OS takes form of a process to do some stuff. There are different types of processes running on a system, some of them are :

Child processes

A process that is created by some other process during run-time. Usually child processes are created to execute some binary from within an existing process. Child processes are created using fork() system call. Normally process are made to run through shell/terminal. In that case the shell becomes the parent and the executed process becomes the child process. On Unix/Linux each process has a parent except the init process(we will learn about this later).

Daemon Processes

These are special processes that run in background. They are system related process that have no associated terminal. These processes run will root permissions and usually provide services to processes. As we already know that a daemon process does not have an attached terminal, well to achieve this the process has to be detached from the terminal. The ideal way on Linux/Unix to do this is to run a process through terminal and from within this process create another process and then terminate the parent process. Since the parent is terminated so now the child will become independent of the terminal and would be taken over by init process and hence would become a daemon process. A typical example would be a mail daemon that waits for the arrival of e-mails and notify when a mail is received.

Orphan processes

Usually a process creates a child process (as described above) and when the child process terminates, a signal is issued to the parent so that parent can do all the stuff that it is required to do when one of the child gets terminated. But there are situations when parent gets killed. In that case the child processes become orphan and then taken under by the init process. Though the init process takes the ownership of the orphan process but still these process are called as orphan as their original parents no longer exists.

Zombie process

When a child process gets terminated or completes its execution, then its entry in the process table remains until the parent process fetches the status information of the terminated child. So, until then the terminated process enters zombie state and is known as zombie process.  When a process is terminated then all the memory and resources associated with the process are released but the entry of the process in process table exists. A signal SIGCHILD is send to the parent of the process (that just terminated). Typically, the handler of this signal in the parent executes a ‘wait’ call that fetches the exit status of the terminated process and then the entry of this zombie process from the process table is also removed.

4. The init process

As we discussed earlier, init process is the 5th stage in the 6 Stage of Linux Boot Process.

You would be cognizant of the famous ‘chicken and egg’ theory regarding who came first. In terms of processes, as each process has a parent process, the same question can be asked about parent or child process. Well, fortunately there is an answer here. The answer is the init process that is started as a first process during boot sequence. That means there is no parent of init process. Lets verify it, since PID of init is ’1′, we use the ps command :

So we see from the output that PPID is 0, which means that there is no parent for this process.

$ ps -l 1
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY        TIME CMD
4 S     0     1     0  0  80   0 -  5952 poll_s ?          0:00 /sbin/init

Shell Script To Add User, Password And Add User To Sudo

Here’s the Shell Script which required 2 parameters 1) UserName 2) Password…..

After setting up user name and password, script will ask you if you want to add user to Super User / Sudo or not….

#!/bin/bash

UCOM=”/usr/sbin/useradd”

PCOM=”/usr/bin/passwd”

DCOM=”/usr/sbin/userdel”

GCOM=”/bin/grep”

if [ “$#” != “2” ]

then

echo -e “33[33m Required 2 Parameters : User Name and Password…”

exit;

else

$UCOM $1

( echo $2; echo $2 ) | $PCOM $1

if [ “$?” != “0” ]

then

$DCOM -r $1

else

echo -e “33[35m User $1 Successfully Added To System”

echo -e “33[0m”

fi

fi

echo -e “33[33m Do You Want To Add User to Sudoers/Super User List (y/n)”

read choice

echo -e “33[0m”

if [ “$choice” == “y” -o “$choice” == “Y” ]

then

$GCOM $1 /etc/sudoers

if [ “$?” == “0” ]

then

echo -e “33[31m User $1 Already Added To Sudoers File”

echo -e “33[0m”

else

echo “$1   ALL=(ALL)       ALL” | cat >> /etc/sudoers

echo -e “33[35m User $1 Successfully Added To Sudoers!!!”

echo -e “33[0m”

fi

elif [ “$choice” == “n” -o “$choice” == “N” ]

then

echo -e “33[35m $1 User Not Added To Sudoers!!!”

echo -e “33[0m”

else

echo -e “33[37m Invalid Choice….User Not Added To Sudoers :-(”

echo -e “33[0m”

fi

Linux recover boot loader or filesystem corruption using Rescue Mode

Here are the steps to recover corrupted linux filesystem (with or without LVM) or boot loader:

1) Boot system using Linux OS (should be the same version which is installed or needs to recover) CD/USB

2) When prompted, type ”linux rescue”

3) This will ask You for some questions like need to enable network or not and mount system or not

In case of installation/repair or grub boot loader

4) Try to mount file system and use following command to install grub
grub-install /dev/sda (should be a first partition where MBR resides)
run exit to reboot into new installed and recovered grub boot loader

In case of filesystem repair (skip step 4)

5) Do not mount partition

6) run following command over shell
e2fsck -p /dev/sda{1,2,3….} Partition which required to recover
fsck -p /dev/sda{1,2,3} Partition which required to recover

If all goes well reboot your system 🙂

In case of LVM filesystem repair (skip step 4 & 6)

7) In case of rescue mode, LVMs are not in active state we require to activate them manually

8) To check and activate LVMs run following commands:

lvm pvscan (Scan for PVs available and show them)
lvm vgscan (Scan for VGs available and show them)
lvm vgchange VGName -a y (This will activate all VGs LVM volumes)
lvm lvscan (Scan LVMs available)

9) Now use Step 6 (change partition with LVMs partition number which is shown by ”lvm lvscan”)

Thats it!!! Plz correct if wrong somewhere 🙂

Difference between /bin vs /sbin vs /usr/bin vs /usr/sbin

/bin This directory contains executable programs which are needed in
single user mode and to bring the system up or repair it.

/sbin Like /bin, this directory holds commands needed to boot the sys-
tem, but which are usually not executed by normal users.

/usr/bin
This is the primary directory for executable programs. Most
programs executed by normal users which are not needed for boot-
ing or for repairing the system and which are not installed
locally should be placed in this directory.

/usr/sbin
This directory contains program binaries for system administra-
tion which are not essential for the boot process, for mounting
/usr, or for system repair.

Install D-Link DWA 525 N 150 Wireless Over Linux or Fedora 14

After a long time spending over google I find some useful NOTES over how to install D-Link DWA 525 N 150 Wireless Drivers, which are here:

Run command “lspci |grep -i network”
Output will be like :
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 03)
06:02.0 Network controller: RaLink Device 3060

Go to http://www.ralinktech.com/support.php?s=2 and download RT3062PCI/mPCI/CB/PCIe(RT3060/RT3062/RT3562/RT3592)

This will ask for your Name and Mail ID, enter and when you click on Accept this will ask you for save or open. Save file to anywhere on your machine, lets say in /opt/

Go to /opt/ and run following command:
cd /opt
tar zxvf DPO_RT3562_3592_3062_LinuxSTA_V2.4.1.1_20101217.tgz
cd DPO_RT3562_3592_3062_LinuxSTA_V2.4.1.1_20101217

Change following in os/linux/config.mk file
vim os/linux/config.mk
HAS_WPA_SUPPLICANT = n -> HAS_WPA_SUPPLICANT = y
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT = n -> HAS_NATIVE_WPA_SUPPLICANT_SUPPORT = y

After making above changes run following:
make
make install

After successfully completion of above command, run following:
insmod os/linux/rt3562sta.ko

Thats it!!! Setup a wireless connection through Network Connection and Enjoy your wi-fi network 🙂

Implement System protection against DOS/DDOS

bash# vi /etc/sysctl.conf

add the below code:

# Enable IP spoofing protection, turn on Source Address Verification

net.ipv4.conf.all.rp_filter = 1

# Enable TCP SYN Cookie Protection

net.ipv4.tcp_syncookies = 1

Add the below code in /etc/rc.local and restart network
for f in /proc/sys/net/ipv4/conf/*/rp_filter;

do echo 1 > done

echo 1 > /proc/sys/net/ipv4/tcp_syncookies

Clean reboot of hung Linux server : Quick HOWTO

In day to day system administration job, you may come across the situation that your Linux server is hung or freeze and your system is not responding even  for Ctrl+Alt+Del in console itself and you must need to do a hard reboot by pressing reset button. As everyone know, the hard reboots is not good and can crash the File systems. so what to do now?

There is a way in Linux,
Hold down the Right Alt and SysRq keys and press this sequence:

  R E I S U B

This will cleanly unmount the drives, terminate the processes and nicely reboot your machine.

of course, To get this worked, you need to “enable” this feature on the running kernel first !
On 2.6 kernel

echo 1 > /proc/sys/kernel/sysrq

This will do the trick.
In Some distributions, you may have a way to enable this feature at boot time.

On Fedora and RHEL, edit the file /etc/sysctl.conf, and change the line kernel.sysrq = 0 to kernel.sysrq = 1

Automatic reboot after Kernel Panic in Linux

In Linux, By default after kernel panic, Linux waits for a system admin to restart or power cycle server.. We can change this behavior and set to reboot automatically when a kernel panic occurs.. For that, we have to change the value set on “kernel.panic” kernel parameter.

Now we have to check the current value on this kernel parameter in Linux server:

[root@myserver ~]# cat /proc/sys/kernel/panic
0
[root@myserver ~]# sysctl -a | grep kernel.panic
kernel.panic = 0

To make the Linux server automatically reboot after a kernel panic, we have to set a value greater than 0. The value should be the number of seconds to wait before automatic reboot of the server.

For example , if you set value 60 , then the server will wait for 60 seconds before automatic reboot after the kernel panic. To make this change permanent, edit /etc/sysctl.conf and set it there.

[root@myserver ~]# echo “10” > /proc/sys/kernel/panic
[root@myserver ~]# cat /etc/sysctl.conf |  grep kernel.panic 

kernel.panic = 10

Solution for UNIX Error: Terminal too wide

When you are working in an UNIX shell using Putty tool, you may get this error.

Problem:

When you are trying to open vi editor, you may get error message “Terminal too wide

How to Fix this??

Enter the below command in the shell and try to open vi editor again. It will work.

stty columns 120
Hope this will help on someone.

Solution: Error – “passwd: Sorry: less than 7 days since the last change.”

Problem:

When you trying to change password in solaris, you may get the below error:

ORACLE user1$ passwd oracle
Enter existing login password:
passwd: Sorry: less than 7 days since the last change.
Permission denied
Solution:

As root do the following:

# passwd -n 0 oracle
Now, Ask the oracle user to try again.

ORACLE user1$  passwd oracle
Now the Oracle user able to change their password.

Permenant fix:

Take a look at /etc/default/passwd file and check the MINWEEKS Parameter.

You can change it to NULL if you don’t want a minimum time between password changes.

Unmount filesystem when device is busy

When you unmount a filesystem, you may get “device is busy error” sometimes.  Using the following steps, you can unmount safely.

# umount  /testsrv1/rman
umount: /testsrv1/rman: device is busy
umount: /testsrv1/rman: device is busy

# fuser -m /testsrv1/rman
/testsrv1/rman:         31477c

# ps -eaf | grep 31477
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh

# df -h /testsrv1/rman
Filesystem            Size  Used Avail Use% Mounted on
testsrv1:/miszpool/mis
2.5T  1.9T  560G  78% /testsrv1/rman

# ps -eaf | grep 31477
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh

# ps -eaf | grep 31448
dbauser1 31448 31447  0 09:51 pts/0    00:00:00 -ksh
oracle  31477 31448  0 09:52 pts/0    00:00:00 /bin/ksh

# kill -9 31477
# ps -eaf | grep 31448
dbauser1 31448 31447  0 09:51 pts/0    00:00:00 -ksh

# umount -f /testsrv1/rman

# mount /testsrv1/rman

# df -h /testsrv1/rman
Filesystem            Size  Used Avail Use% Mounted on
testsrv1:/miszpool/mis
2.5T  1.9T  560G  78% /testsrv1/rman

Recover Bad Superblock in Linux Filesystem

If  you get a ¨Damaged Superblock¨ error message at filesystem (fsck) check in Linux Server, Usually fsck will not be able to repair the file system due to bad super block. In these situations, we can recover the damaged super block from the backup.

Solution:

There are backups of the Superblock located on several positions and we can restore them with a simple command in a Linux server

By default in Linux, the file system creates the backup of  super block in the following locations:

8193, 32768, 98304, 163840, 229376 and 294912.

Note: 8193 is only on older systems  in many cases. 32768 is the most current position for the first backup

When you get this “damaged superblock or bad superblock error” and if  you get a root-prompt in a recovery console, then issue the following command:

# e2fsck -b 32768 /dev/hda5

Now the System will check the filesystem with the information stored in that backup superblock and if the check was successful it will restore the backup to position 0.

If this is not successful, then try using the other copy of Superblock backup (Refer the backup location of superblock above)

Solution : Permission denied error while changing password in NIS

If you are getting a Error “Permission Denied” While changing the Passwords in NIS even if you are doing as root. the following steps solves this issue.

1. check whether the yppasswdd daemon is running. Type ps -ef|grep yp  to check this

2. if it is not running start the yppasswdd daemon with NIS Maps directory as parameter..

#  /usr/lib/netsvc/yp/rpc.yppasswdd -D /var/yp/src/

/var/yp/src/ directory contains the NIS Maps in Solaris

3. This will fix the  issue. Also check the permission and ownership of the passwd file on the NIS
Maps directory. it should be owned by root. This has been tested in Solaris and might work in
Linux as well

EXT2 to EXT3 and EXT3 to EXT4 Converting without data erase

Ext2 to ext3 file conversation

[root@server1 ~]# tune2fs -j /dev/sda5

Ext3 to ext4 file system conversation

[root@server1 ~]# tune2fs -O dir_index,uninit_bg,extents /dev/sda5

Ext2 to ext4 file system conversation

[root@server1 ~]# tune2fs -O dir_index,uninit_bg,has_journal /dev/sda5

Ext3 to ext2 file system back conversation

 # tune2fs -O ^has_journal /dev/sda5

Solving the “Control D” error…Linux:

Q:- What is the Meaning of Control D error?

A:- When the root user try to make any Permanent entry in fstab file & by mistake changes the path location of mounted file systems, it gives error while rebooting the system.

Control D Error:-

Steps to Rectify it:-….

1) Enter the bootable Cd/DvD of Rhel.
(The version you are using)

2) Read the control D error carefully.

3) Give the root password.

4) You will go to single usermod.

5) Try to access /etc/fstab file.

6) Will not allow you as will be in read only mode.

7) Enter this command:-
mount -o remount,rw /
(Will give read/write permission to /)

8) Will give u read/write permission to all
the files in /

9)Then again enter into /etc/fstab & rectify ur error.(vim /etc/fstab)

10)Give command reboot or init 5(As per ur wish)

Rectify it & Enjoy the Control D Error…..