Saturday, November 10, 2012

VMware/Linux-Difference between init 6 and reboot commands

Here’s an interesting Linux tidbit that not many ESX admins realize.

reboot is not the same as init 6

In Linux, the init 6 command gracefully reboots the system running all the K* shutdown scripts first, before rebooting.  The reboot command does a very quick reboot.  It doesn’t execute any kill scripts, but just unmounts filesystems and restarts the system.  The reboot command is more forceful.

So, should I use reboot or init 6?  – neither!  My advice is to use the shutdown command.  shutdown will do a similar job to init 6, but it has more options and a better default action.  Along with kicking off an init 6, the shutdown command will also notify all logged in users (logged in at a tty), notify all processes the system is going down and by default will pause  for a set time before rebooting (giving you the chance to cancel the reboot if you realize that you made a mistake).  Jolly civil.

-

How does this advice apply to VMware ESX servers you ask?  Well I’m not a VMware kernel developer so to be honest I’m not the best person to ask (if you do know murky details, then please let us know in the comments).  However I will say this; I will always use shutdown -r first and foremost.  It’s just a better habit to get into.

Is there a difference on an ESX server? Yes, but as I said I’m entirely sure how it affects the VMkernel processes.  The reason I definitely know – a couple of times I’ve had to use the reboot command to force an unresponsive ESX shutdown -r.

P.S. This also applies to init 0 / halt (i.e. use shutdown -h instead).

***************

Update: Following Andrew’s comments below I’ve done a bit more digging.  He’s correct that the default action of the reboot command has now changed to call the shutdown command.  This upstream change (presumably because its a safer default action as I explained above) is now reflected in a lot of the current distributions, including the Service Console that comes with ESX 4.0.  So if you want to force a reboot you have run reboot -f.

Here’s the section on ESX4 man page explaining the change:

NOTES
Under older sysvinit releases , reboot and halt should never be called directly. From release 2.74 on  halt and reboot invoke shutdown(8) if the system is not in runlevel 0 or 6. This means that  if  halt  or  reboot cannot find out the current runlevel (for example, when /var/run/utmp hasn’t been initial ized correctly) shutdown will be called, which might not be what you want.  Use the -f  flag  if  you want to do a hard halt or reboot.

Does it change my advice?  No.
Firstly, ESX 3.x still uses the old style reboot command and doesn’t link to shutdown (as Greg points out the comments, this change was actually made much earlier on) .  Secondly, if your anything like me you are logging into a mix of unix/linux style command lines on servers, SANs, etc; you don’t want to guess what their version of reboot does. Thirdly, I’d still argue that

shutdown -r +1 “*** reboot for RAM upgrade by Forbes ***”

is still a better habit to get into.

  • It allows other users to finish what they are doing or ask you to postpone things.
  • It let’s you cancel the shutdown if you’ve made a boob (remember that sinking feeling in your stomach the last time you realized you’d just shutdown the wrong server).
  • It writes a message explaining why, so you can track the reboots.

Lastly, if you’ve read this far and survived or re-visited for the update, here is an extra tip for you.  Try this at the command line:

last -x|grep -e shutdown -e reboot

Source:

No comments: