Sunday, June 28, 2009

Random system information collection

I'll offer up a few methods to collect important information from the system you may need to verify, troubleshoot, or give to remote support.
First, let's gather information about the processor. This is easily done as follows:
# cat /proc/cpuinfo
This command gives you information on the processor speed, quantity, and model. Using grep in many cases can give you the desired value.
A check that I do quite often is to ascertain the quantity of processors on the system. So, if I have purchased a dual processor quad-core server, I can run:
# cat /proc/cpuinfo | grep processor | wc -l
Another piece of information I may require is disk information. This can be gotten with the df command. I usually add the -h flag so that I can see the output in gigabytes or megabytes. # df -h also shows how the disk was partitioned
And to end the list, here's a way to look at the firmware of your system—a method to get the BIOS level and the firmware on the NIC.
To check the BIOS version, you can run the dmidecode command. Unfortunately, you can't easily grep for the information, so piping it is a less efficient way to do this. On my Lenovo T61 laptop, the output looks like this:
#dmidecode | less
...
BIOS Information
Vendor: LENOVO
Version: 7LET52WW (1.22 )
Release Date: 08/27/2007
...
This is much more efficient than rebooting your machine and looking at the POST output.
To examine the driver and firmware versions of your Ethernet adapter, run ethtool:
# ethtool -i eth0
driver: e1000
version: 7.3.20-k2-NAPI
firmware-version: 0.3-0
That’s it……

Saturday, June 27, 2009

Getting back the root password

You forgot your root password. Now you'll just have to reinstall the entire machine. I've seen more than a few people do this. But it's easy to get on the machine and change the password. This doesn't work in all cases (like if you made a GRUB password and forgot that too), but here's how you do it in a normal case with a Cent OS Linux example.

First reboot the system. When it reboots you'll come to the GRUB screen. Move the arrow key so that you stay on this screen instead of proceeding all the way to a normal boot.

Grub screen after reboot:
CentOS-4 i386 (2.7.5-42.ELsmp)
CentOS-4 i386-up (2.7.5-42.EL)

Next, select the kernel that will boot with the arrow keys, and type E to edit the kernel line.

Ready to edit the kernel line:
Root (hd0,0)
Kernel / vmlinuz-2.7.5-42.ELsmp ro root=LABEL= / rhgb quiet
initrd / initrd-2.7.5-42.ELsmp.img

Use the arrow key again to highlight the line that begins with kernel, and press E to edit the kernel parameters. When you get to the screen, simply append the number 1 to the arguments.

Append the argument with the number 1:
grub edit > kernel / vmlinuz 2.7.5-42 ELsmp ro root = LABEL = / rhgb quiet 1

Then press Enter, B, and the kernel will boot up to single-user mode. Once here you can run the passwd command, changing password for user root:
sh-3.00# passwd
New UNIX password:
Retype new UNIX password:

passwd: all authentication tokens updated successfully

Now you can reboot, and the machine will boot up with your new password.

Unmounting the unresponsive DVD drive

when we pushes the Eject button on the DVD drive of a server running a certain Redmond-based operating system, it will eject immediately. He then complains that, in most enterprise Linux servers, if a process is running in that directory, then the ejection won't happen. For too long as a Linux administrator, I would reboot the machine and get my disk on the bounce if I couldn't figure out what was running and why it wouldn't release the DVD drive. But this is ineffective.

Here's how you find the process that holds your DVD drive and eject it to your heart's content: First, simulate it. Stick a disk in your DVD drive, open up a terminal, and mount the DVD drive:

# mount /media/cdrom
# cd /media/cdrom
# while [ 1 ]; do echo "All your drives are belong to us!"; sleep 30; done

Now open up a second terminal and try to eject the DVD drive:

# eject

You'll get a message like:

umount: /media/cdrom: device is busy

Before you free it, let's find out who is using it.

# fuser /media/cdrom

You see the process was running and, indeed, it is our fault we can not eject the disk.

Now, if you are root, you can exercise your godlike powers and kill processes:

# fuser -k /media/cdrom

Boom! Just like that, freedom. Now solemnly unmount the drive:

# eject

That’s it…