dufault.info

Ramblings of a phone weenie, Linux sysadmin, and other things geeky

08 2008

Hotswap a SCSI, SAS, or SATA drive in Linux

There seems to be not a lot of information on Google about this, thus, I post.

At my work, the majority of our servers have hot-swappable drive bays — however, Linux doesn’t usually automatically notice the drive is gone. Worse, sometimes it doesn’t even notice new drives hooked up.

Now, SCSI and SAS both support hot-plugging on a protocol level, and SATA II does as well. If your chassis is equipped with a hotswap drive bays, then that’s all you really need. I haven’t noticed any problems with SATA I hotswaps, but they appear to be less successful.

A common task I need to do is either:

  • upgrade a drive in a server
  • replace a dying drive with a new one

If the drive is in a RAID, or if it’s a separate sized drive for a disk upgrade, it’s a good idea to trigger the kernel driver to rescan information about the new disk.

In /sys/bus/scsi/devices, you’ll find a number of numbers that’ll correspond to your disk drives:
server devices # ls -1
0:0:0:0@
1:0:0:0@
2:0:0:0@

You can determine more information about the drive by cat’ing it’s model file:
server devices # cat "0:0:0:0/model"
ST3250410AS

Now, to cause the kernel to rescan the drive attached to the port, do this:
echo > "0:0:0:0/rescan"

Check dmesg now:
server devices # dmesg
---snip---
SCSI device sda: 488397168 512-byte hdwr sectors (250059 MB)
sda: Write Protect is off
sda: Mode Sense: 00 3a 00 00
SCSI device sda: drive cache: write back

Now, that’s pretty exciting, as this can be used to skip a reboot.  If you switch the drive, and trigger the rescan, it’ll update the drive information including the partition layout.  Make sure you don’t swap out your main system drive, otherwise your computer will freeze, and there will be data loss and possibly corruption.

Sometimes, this strategy fails to work, and I don’t know why (and resort to rebooting.)  I’m currently researching how to do this a bit better, I have a buggy script that I use to improve this method, but it’s not ready for public release yet. Does anyone have a better method?  Please comment!


31  07 2008

Typespeed

It came up in IRC today that there was a typing game called typespeed — one of the categories is “Unix Commands.”  Better yet, this supports head to head networking mode, so you can play against people in your office, I didn’t even need to edit my firewall configuration on Ubuntu.

Playing your coworkers is good fun, give it a try!


26  07 2008

Installing libtidy in PHP5 on a CentOS cPanel server

To install libtidy in PHP5, it’s really quite easy.

Make sure your /tmp directory doesn’t have something like noexec set on it, otherwise this would be more difficult.

Here’s the install command:
pecl install http://pecl.php.net/get/tidy-1.2.tgz

Find where your main php.ini file is:
root@server [~]# php -i|grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

Add the module to your php.ini:
$EDITOR /usr/local/lib/php.ini

You’ll need to scroll down to the extensions area, I just keep searching for extension till I find it.
Add this line:
extension=tidy.so

Save, and restart your Apache web service:
service httpd restart

Test via phpinfo(); to make sure it’s working.


25  07 2008

Sysadmin day

Today is the annual Sysadmin Day, so take the time and honour your hard working local sysadmins that keep things running.

http://www.sysadminday.com/

Update: My boss bought me lunch as a present.  Hooray!


25  07 2008

Another update regarding Android on the Vogue

This in from Martin’s page:

Update(24/7/08): I’ve repackaged the files in android.zip and updated a few things. Now you don’t need to copy 256M to your SD card, just put system.gz and data.gz on the card and the first time it boots they will be extracted to system.img and data.img (thanks to Kevin’s initramfs installer for the idea). Keep your data.img if you have saved anything on it and delete system.img to use the new stiff. Audio in calls should be better, vibrate on receiving calls and SMS should work better. When the screen is off only the power button should wake it up. SDHC cards should work better. Volume up and down are not left and right any more because i’m working on audio, they are useful for zooming in the browser too.

Looks pretty cool, I’m starting to get curious about what settings he’s changing, and where; a Changelog would be nice for each update.

Here’s Martin’s homepage:
http://it029000.massey.ac.nz/vogue/


22  07 2008

The Wordpress Google Analytics plugin screwed me

I just noticed that after upgrading the Google Analytics plugin for Wordpress, my settings weren’t carried over, and that Google Analytics hasn’t been able to track my pageloads.

:(

I guess it should have squawked someplace that it wasn’t configured… that’d of been nice.  It’s not like the tracking data is critical, but I was definately starting to wonder why my traffic halved one day, and dried up the next.


19  07 2008

The Linux Magic SysRq key

I find it shocking how many people don’t know about this neat Linux key combination that let’s you execute various low level commands regardless of the system’s state (as long as it’s running and hasn’t panicked.)

From the Wikipedia page:

It is often used to recover from freezes, or to reboot a computer without corrupting the filesystem.

How it works: you press a key combination consisting of Alt, SysRq and your command key, and the Linux kernel will trigger that action, regardless of system load. This is a great way to recover a system quickly without triggering a hard reboot, as disk fscks can be lengthy, and involve data loss. Not to mention, the ability to sync the cached data from RAM to the disk is great, especially with computers running database services.

How to enable it? Easy, just add this to /etc/sysctl.conf on your Linux-based system, and run sysctl -p for the settings to become active:
kernel.sysrq = 1
# Copy paste command for the lazy...
$EDITOR /etc/sysctl.conf
sysctl -p

The best way to recover a system will involve multiple commands, this is taken from the Wikipedia excerpt:

unRaw (take control of keyboard back from X),
tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
kIll (send SIGKILL to all processes, forcing them to terminate immediately),
Sync (flush data to disk),
Unmount (remount all filesystems read-only),
reBoot. These keystrokes should be entered a few seconds apart.

For more information about this nifty Linux-only feature, check out Wikipedia

Source: http://en.wikipedia.org/wiki/Magic_SysRq_key


17  07 2008

Scripts To Make Administrating Lots of MySQL Databases a Little Easier

This post is probably only helpful to a system administrator of large shared servers that happen to have a lot of MySQL databases.

These scripts are meant to administrate all of the databases and tables on a single server currently, I might refine them to also work only database or table name’s supplied.

One of the scripts, tableCheck, will access mysql using the username and password in /root/.mysql.cnf, and run a “check table $name” command, and error out if a table has been corrupted.

Another of the scripts, probably a bit heavy-handed, tableRepair, doing the same thing as tableCheck only running a repair query.

tableOptimize runs a “optimize table $name” query on all tables available, which is nice to do occasionally to speed up queries due to nasty things like table fragmentation.

Lastly, findLargeDatabases is a simple script that’ll show you the largest databases you have in order of size, so you can refine your efforts to optimizing those.

Here’s the goods!
scripts.tgz


17  07 2008

Forcibly Triggering a Kernel Panic on Linux

This might sound strange, as people usually want to fix or prevent these from happening, I’m trying to test/ create a method of logging kernel panic messages to a remote logging server. All of the existing tutorials I found on the net were for Linux 2.4, or were incomplete.

My method involves creating a Linux kernel module, that when it’s inserted, causes the panic.

Here’s my my tarball: (includes the module source and a makefile)
kernelpanic.tgz

Here’s how to compile it: (you’ll need the the kernel sources installed at /usr/src/linux of your current running version)
make -C /lib/modules/$(uname -r)/build M=$(pwd)

After it’s done compiling: (WARNING, THIS WILL CRASH THE MACHINE, and you need to be root)
insmod panic.ko

To recover from the crash, just reboot your computer.

Let me know if this is any good in the comments, and any improvements I can make!

Should I obfuscate the source code at all to prevent misuse of this? Since you need root access to insert a kernel module, and anyone with root access can halt the machine, I find the ramifications of releasing this information moot. Comment!

Here’s where I found a quick howto on creating a Linux 2.6 kernel module:
http://tldp.org/LDP/lkmpg/2.6/html/x279.html


15  07 2008

Gnome Do

I use Ubuntu at work, and today one of my coworkers linked me to Gnome Do:
https://wiki.ubuntu.com/GnomeDo

I remember seeing it a few weeks ago, but was busy with something and brushed it off.  Now, I’ve installed it and played with it some — it’s awesome.  Kind of like launchy for Windows, but on steriods.

Give it a try!


« Previous PageNext Page »