Skip to contentSkip to conversation

Forcing an immediate reboot

DISCUSSION Marc Perkel 12 participants 20 messages Oct 15, 2005 – Oct 16, 2005

lore
Share & tools
lore
#0 lore raw

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

#1 lore raw
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Get one of those powerstrips that you can telnet into and power cycle things remotely.

Lee

#15 lore raw
In reply to Marc Perkel
Quoted 3 lines · On Fri, 14 Oct 2005 18:46:46 -0700 Marc Perkel wrote:

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

What kernel version?
Does it have sysrq enabled?

If 2.6.x and Yes, then you should be able to do:
echo b > /proc/sysrq-trigger

to cause a reboot.

---
~Randy

#16 lore raw
In reply to Marc Perkel
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

reboot -nf

Doesn't sync
just plain reboot

Danny

#17 lore raw
In reply to Marc Perkel
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If you can telnet it, simply use this :

# echo 1 >/proc/sys/kernel/sysrq
# echo b >/proc/sysrq-trigger

It's dirty and you'll have an fsck. But it will nearly always work. I use it a lot in local on distros on which the shutdown process is as long as the boot process (you know, the ones which display lots of 'OK' or wait indefinitely for some dead services to stop, when you really want them to reboot quickly).

Cheers,
Willy

#2 lore raw
In reply to Lee Revell
Quoted 11 lines · Lee Revell
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Get one of those powerstrips that you can telnet into and power cycle things remotely.

use reboot on panic.
--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/

#18 lore raw
In reply to Willy Tarreau
Quoted 11 lines · Willy Tarreau
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If you can telnet it, simply use this :

# echo 1 >/proc/sys/kernel/sysrq
# echo b >/proc/sysrq-trigger

It's dirty and you'll have an fsck. But it will nearly always work.

You may avoid the fsck by:

# echo s >/proc/sysrq-trigger
# echo u >/proc/sysrq-trigger
Quoted 4 lines

I use it a lot in local on distros on which the shutdown process is as long as the boot process (you know, the ones which display lots of 'OK' or wait indefinitely for some dead services to stop, when you really want them to reboot quickly).

--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/

#3 lore raw
In reply to Coywolf Qi Hunt
Quoted 14 lines · Coywolf Qi Hunt
Quoted 11 lines · Lee Revell
Quoted 5 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Quoted 9 lines
Quoted 5 lines

Get one of those powerstrips that you can telnet into and power cycle things remotely.

use reboot on panic.

But it didn't panic. It was still running - filtering spam. But reboot wouldn't work and I couldn't kill anything that was running. So it never paniced.

#4 lore raw
In reply to Lee Revell
Quoted 10 lines · Lee Revell
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Get one of those powerstrips that you can telnet into and power cycle things remotely.

If it has sysrq compiled in as root just do:

echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger

This will "sync", "umount/remount read-only", "sync", "immediate hardware reboot". Should always work...

Best regards,

Anton

Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
#5 lore raw
Quoted 9 lines · Anton Altaparmakov
Quoted 8 lines · Lee Revell
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Quoted 8 lines
Quoted 2 lines

Get one of those powerstrips that you can telnet into and power cycle things remotely.

If it has sysrq compiled in as root just do:

echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger

What the purpose of the second sync?

Quoted 4 lines

echo b > /proc/sysrq-trigger

This will "sync", "umount/remount read-only", "sync", "immediate hardware reboot". Should always work...

--
Coywolf Qi Hunt
http://sosdg.org/~coywolf/

#6 lore raw
Quoted 13 lines · Coywolf Qi Hunt
Quoted 12 lines · Anton Altaparmakov
Quoted 10 lines · Lee Revell
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Get one of those powerstrips that you can telnet into and power cycle things remotely.

Quoted 7 lines
Quoted 5 lines

If it has sysrq compiled in as root just do:

echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger

What the purpose of the second sync?

Allows any i/o initiated between the first sync and the remount r/o to complete. Remember that r/o mounting doesn't stop i/o. It only stops you from writing to the fs at the vfs layer. Once a write/modification has entered the fs driver it will get written no matter what, unless the "reboot" sysrq is triggered in which case the kernel just reboots immediately.

Maybe it is just paranoia on my part but I have gotten used to hitting Alt+PrtScr+S, +U, +S, +B so I do it automatically.

Best regards,

Anton

Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
#19 lore raw
In reply to Marc Perkel
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

See atttached
--
vda

/* Including <unistd.h> makes sure that on a glibc system
<features.h> is included, which again defines __GLIBC__ */

#include <unistd.h>
#include <stdio.h> /* puts */
#include <time.h> /* nanosleep */
#include <errno.h>

#include "linux_reboot.h" /* reboot magic */

#define USE_LIBC

#ifdef USE_LIBC

/* libc version */
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <sys/reboot.h>
# define REBOOT(cmd) reboot(cmd)
#else
extern int reboot(int, int, int);
# define REBOOT(cmd) reboot(LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,(cmd)) #endif

int my_reboot(int cmd) {
	return REBOOT(cmd);
}

#else /* no USE_LIBC */

/* direct syscall version */
#include <linux/unistd.h>

#ifdef _syscall3
_syscall3(int, reboot, int, magic, int, magic_too, int, cmd); #else
/* Let us hope we have a 3-argument reboot here */ extern int reboot(int, int, int);
#endif

int my_reboot(int cmd) {
	return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd);
}

#endif

void do_reboot() {
	my_reboot(LINUX_REBOOT_CMD_RESTART);
}
void do_poweroff() {
	my_reboot(LINUX_REBOOT_CMD_POWER_OFF);
}
void do_halt() {
	my_reboot(LINUX_REBOOT_CMD_HALT);
}
void usage() {
	puts(
	    "Usage: hardshutdown -h|-r|-p [NN]\n"
	    "	NN - seconds to sleep before requested action"
	);
	exit(1);
}

enum action_t {
SHUTDOWN, // do nothing
HALT,
POWEROFF,
REBOOT
};

int main(int argc, char *argv[]) {
	struct timespec t = {0,0};
	enum action_t action = SHUTDOWN;
	int c, i;
	char *prog, *ptr;

	//if(*argv[0] == '-') argv[0]++;	/* allow shutdown as login shell */
	prog = argv[0];
	if( (ptr=strrchr(prog,'/')) != 0 ) prog = ptr+1;

	/* All names (halt, reboot, shutdown)
	   refer to the same program with the same options,
	   only the defaults differ. */
	if(!strcmp("hardhalt", prog)) {
		action = HALT;
	} else if(!strcmp("hardpoweroff", prog)) {
		action = POWEROFF;
	} else if(!strcmp("hardreboot", prog)) {
		action = REBOOT;
	}
		
	for(c=1; c < argc; c++) {
		if(argv[c][0] >= '0' && argv[c][0] <= '9') {
			t.tv_sec = strtol(argv[c], NULL, 10);
			continue;
		}
		if(argv[c][0] != '-') {
			usage();
			return 1;
		}
		for(i=1; argv[c][i]; i++) {
			switch(argv[c][i]) {
			case 'h': 
				action = HALT;
				break;
			case 'p':
				action = POWEROFF;
				break;
			case 'r':
				action = REBOOT;
				break;
			default:
				usage();
				return 1;
			}
		}
	}

	if(action==SHUTDOWN) {
		usage();
		return 1;
	}

	chdir("/");
	while(nanosleep(&t,&t)<0)
		if(errno!=EINTR) break;

	switch(action) {
	case HALT:
		do_halt(); break;
	case POWEROFF:
		do_poweroff(); break;
	case REBOOT:
		do_reboot(); break;
	}
	return 1;
}

/*
* Magic values required to use _reboot() system call. */

#define LINUX_REBOOT_MAGIC1 0xfee1dead
#define LINUX_REBOOT_MAGIC2 672274793
#define LINUX_REBOOT_MAGIC2A 85072278
#define LINUX_REBOOT_MAGIC2B 369367448

/*
* Commands accepted by the _reboot() system call. *

 * RESTART     Restart system using default command and mode.
 * HALT        Stop OS and give system control to ROM monitor, if any.
 * CAD_ON      Ctrl-Alt-Del sequence causes RESTART command.
 * CAD_OFF     Ctrl-Alt-Del sequence sends SIGINT to init task.
 * POWER_OFF   Stop OS and remove all power from system, if possible.
 * RESTART2    Restart system using given command string.

*/

#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4

#8 lore raw

documentation? (i learned something today ;-) )

In reply to Anton Altaparmakov

hi all,

Le Saturday 15 October 2005 09:48, Anton Altaparmakov a écrit :

 | If it has sysrq compiled in as root just do:
 |
 | echo s > /proc/sysrq-trigger
 | echo u > /proc/sysre-trigger
 | echo s > /proc/sysrq-trigger
 | echo b > /proc/sysrq-trigger
 |
 | This will "sync", "umount/remount read-only", "sync", "immediate
 | hardware reboot".  Should always work...

i'm impressed that i see that sysrq also works from procfs.... the "PrintScreen/SysRq" button on my keyboard from time to time does not work (old keyboard) and then it's pain hitting this key if you have to.

great news that you can also pass sysrq requests using proc - i've learned something today... is this documented somewhere? maybe i'm bad in reading/finding docs but i think i'm not the only one here. can somebody point me to the links of docs where all this magic is specified? if not, i will try to start my own docs on how to use the linux kernel magic. mainly a collection of tricks like this and similar ones.

thank you in advance + greetings,
Damir

Signature · 2 lines
  Customer: (angrily) "You said I would get 98 windows with this computer. 
Where are they?" 
#9 lore raw

Re: documentation? (i learned something today ;-) )

Quoted 24 lines · Damir Perisa

hi all,

Le Saturday 15 October 2005 09:48, Anton Altaparmakov a écrit:

 | If it has sysrq compiled in as root just do:
 |
 | echo s > /proc/sysrq-trigger
 | echo u > /proc/sysre-trigger
 | echo s > /proc/sysrq-trigger
 | echo b > /proc/sysrq-trigger
 |
 | This will "sync", "umount/remount read-only", "sync", "immediate
 | hardware reboot". Should always work...

i'm impressed that i see that sysrq also works from procfs.... the "PrintScreen/SysRq" button on my keyboard from time to time does not work (old keyboard) and then it's pain hitting this key if you have to.

great news that you can also pass sysrq requests using proc - i've learned something today... is this documented somewhere? maybe i'm bad in reading/finding docs but i think i'm not the only one here. can somebody point me to the links of docs where all this magic is specified? if not, i will try to start my own docs on how to use the linux kernel magic. mainly a collection of tricks like this and similar ones.

Quoted 2 lines

thank you in advance + greetings,
Damir

it is mentionned in Documentation/sysrq.txt

On all - write a character to /proc/sysrq-trigger. eg:

echo t > /proc/sysrq-trigger

regards,

Benoit

#14 lore raw
In reply to Anton Altaparmakov
Quoted 17 lines · Anton Altaparmakov
Quoted 13 lines · Lee Revell
Quoted 3 lines · Marc Perkel

Is there any way to force an immediate reboot as if to push the reset button in software? Got a remote server that i need to reboot and shutdown isn't working.

If it has Oopsed, and the "reboot" command does not work, then all bets are off - kernel memory has probably been corrupted.

Get one of those powerstrips that you can telnet into and power cycle things remotely.

Quoted 12 lines

If it has sysrq compiled in as root just do:

echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger

This will "sync", "umount/remount read-only", "sync", "immediate hardware reboot". Should always work...

This worked great. If I had this last night it would probably have saved me a trip to San Jose. I especially like that it does the file system syncs. I've put it in a script I call "coldboot" and it is now one of my tools.

Very useful.

#10 lore raw

Documentation/files somewhere online?

In reply to Benoit Boissinot

thank you for the quick reply, Benoit,

Le Saturday 15 October 2005 15:40, Benoit Boissinot a écrit :

 | On 10/15/05, Damir Perisa <[email protected]> wrote:
 | > Le Saturday 15 October 2005 09:48, Anton Altaparmakov a écrit:
 | >  | echo s > /proc/sysrq-trigger
 | > i'm impressed that i see that sysrq also works from procfs.... 
 |
 | it is mentionned in Documentation/sysrq.txt

oh ... i definitely have to read the Documentation/files more often for updates... last time i did, i didn't remember seeing proc magic in this one.

is somebody keeping a online version of the kernel source docs (i mean the Documentation/* files) somewhere for surfing? i want to point people to pages with links without forcing them to download the sources to read what i tell them to.

often i'm asked questions about linux in general. an updated docs pages on the net would be helpful. of course if it does not exist, i can create one, but why re-inventing the wheel if it is easier to give credits to the first person who invented it and use it? ;-)

thanx + greetings,
Damir

Signature · 2 lines
The bureaucracy is expanding to meet the needs of an expanding 
bureaucracy.
#11 lore raw

Re: Documentation/files somewhere online?

Quoted 10 lines · Damir Perisa

thank you for the quick reply, Benoit,

Le Saturday 15 October 2005 15:40, Benoit Boissinot a écrit :

 | On 10/15/05, Damir Perisa <[email protected]> wrote:
 | > Le Saturday 15 October 2005 09:48, Anton Altaparmakov a écrit:
 | >  | echo s > /proc/sysrq-trigger
 | > i'm impressed that i see that sysrq also works from procfs.... 
 |
 | it is mentionned in Documentation/sysrq.txt
Quoted 8 lines

oh ... i definitely have to read the Documentation/files more often for updates... last time i did, i didn't remember seeing proc magic in this one.

is somebody keeping a online version of the kernel source docs (i mean the Documentation/* files) somewhere for surfing? i want to point people to pages with links without forcing them to download the sources to read what i tell them to.

http://lxr.linux.no/source/Documentation/

Quoted 4 lines

often i'm asked questions about linux in general. an updated docs pages on the net would be helpful. of course if it does not exist, i can create one, but why re-inventing the wheel if it is easier to give credits to the first person who invented it and use it? ;-)

--
vda

#12 lore raw

Re: Documentation/files somewhere online?

Quoted 9 lines · Denis Vlasenko
Quoted 3 lines · Damir Perisa

is somebody keeping a online version of the kernel source docs (i mean the Documentation/* files) somewhere for surfing? i want to point people to pages with links without forcing them to download the sources to read what i tell them to.

http://lxr.linux.no/source/Documentation/

I think that using the -git web interface to Linus' tree on kernel.org is even better.

The following is a link to the top-level of the kernel source tree:

http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree

You will notice a Documentation tree link (3rd file object link from the top).

This will get you the most current Documentation at the moment from Linus' tree, and it also gives you the ability to see the history of changes.

Hope this helps.

Signature · 1 line
Michael Krufky
#13 lore raw

Documentation/files online: available at git in webinterface

Le Saturday 15 October 2005 17:13, Michael Krufky a écrit :
| I think that using the -git web interface to Linus' tree on kernel.org | is even better.

great idea...

 | The following is a link to the top-level of the kernel source tree:
 |
 | 

http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree

i totally forgot that git has a webinterface. how very useful! :D

| Hope this helps.

it is even better: it's the solution. thank you!

greetings,
Damir

Signature · 1 line
Everything bows to success, even grammar.
#7 lore raw
In reply to Anton Altaparmakov
Quoted 8 lines · Anton Altaparmakov
Quoted 6 lines · Coywolf Qi Hunt
Quoted 3 lines · Anton Altaparmakov

echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger

Quoted 6 lines
Quoted 1 line

What the purpose of the second sync?

Allows any i/o initiated between the first sync and the remount r/o to complete. Remember that r/o mounting doesn't stop i/o. It only stops you from writing to the fs at the vfs layer. Once a write/modification has entered the fs driver it will get written no matter what, unless the "reboot" sysrq is triggered in which case the kernel just reboots immediately.

Maybe it is just paranoia on my part but I have gotten used to hitting Alt+PrtScr+S, +U, +S, +B so I do it automatically.

Second sync is a must, otherwise remounting read-only is not written to the filesystem (at least in my case) so no fsck is saved. But you can save first sync (before remount), and then you get nice sequence which even admins comming from Windows can remember - they have to use USB to safely reboot their Linux systems ;-) (alt-sysrq-U, S, B)
Petr