Hard reset on linux command line.

Linux is not Windows and if reboot fail you usually still connect by SSH and do something. This commands will show you how to remotely hard reboot machine.

Hard reboot mean that shutdown scripts will not run and machine reboot immediately without syncing hard disk drives, shutdown applications etc, it’s like hitting the reset button on your server.

 

echo 1 > /proc/sys/kernel/sysrq

echo b > /proc/sysrq-trigger

This commands enable sysrq and after this calls fast reboot. If you want to force shutdown machine try this.
Force shutdown

 

echo 1 > /proc/sys/kernel/sysrq

echo o > /proc/sysrq-trigger

This came handy, when I had a server that had some IO error and it can no longer read from disk, only few cached binaries into memory kept it running (kernel, SSHD, bash), I could still access the machine via SSH but can no longer do anything, forcing the reboot as mentioned above was my only resort, and it worked like charm…

Using cat,ssh and dd to copy ISOs

Hi!
After a long time without posting on the blog here I come again with a tiny command line that can speed up the usual method of copying large amounts of data.

Sometime ago a college gave me a DVD that I would like to keep to myself but that other 2 colleges wanted too. I used dd, cat and ssh for the task. Taking less that 5 minutes to do it all.

First I started the .iso creation with dd:

dd if=/dev/cdrom of=/home/pedro/my_new_iso.iso

In other console you may start the copy of the iso file even if the iso it’s fully copied to the hard drive (just give a few seconds to have some data copied to the drive):

(cat /home/pedro/my_new_iso.iso | ssh user@remote.host.local dd of=~/my_new_iso.iso) ; (cat /home/pedro/my_new_iso.iso | ssh user2@remote2.host.local dd of=~/my_new_iso.iso)

The only thing you need to guarantee is that the first command ends before the second one.
Cheers,
See you all next time

Why use a redundant swap space or partition

Today I’ve had a problem in one of the servers we support, no web access, no ssh, and no console just a bunch of sentences passing so fast I couldn’t read it on the terminal. The solution a simple hard reset and the system came online, it was a hard disk failure but the system online without trouble because we were using a raid configuration. One of the disks didn’t show up in the RAID array, a few tests later and declared the hardware fault the cause of the downtime.

But why did the system came down because of a disk failure if there was a RAID system available, simple the swap was spread among the disks but not in a raid system so no redundant swap partitions, when the need for data in the swap of that file system came there wasn’t any data available and the system came to a stop.

From now on we’ll create a redundant swap partition using a RAID volume so this doesn’t happen again as a server should never stop because of a disk problem,  living and learning.

Cheers,

Pedro M. S. Oliveira

BTW – to reassemble the array I used mdadm, bellow there is a simple usage if you want to reassemble a previous build array:

mdadm –manage  /dev/md0 –add /dev/sda1

this command will add the partition /dev/sda1 to the raid array /dev/md0

if you want to learn more about RAID in linux just type man mdadm or mdadm –help