sudo halt or sudo shutdown


24 posts
by winkleink » Fri Jan 18, 2013 10:04 am
Hi,

I have been using
Code: Select all
sudo shutdown
with my Raspberry Pi and I saw on the tip of the day that it is recommended to use
Code: Select all
sudo halt
Is one better than the other.

Thanks.
Albert.
Twitter:Winkleink
Google+: Winkleink
User avatar
Posts: 218
Joined: Mon Nov 07, 2011 9:12 am
Location: UK
by RaTTuS » Fri Jan 18, 2013 10:19 am
if you use halt then if it is running in normal mode it will use shutdown
so they are functionally the same.
personally I use
sudo shutdown -h now
as i've always done
or sudo shutdown -r now
depending
YMMC
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 5179
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by Cloudcentric » Fri Jan 18, 2013 10:36 am
I have always used sudo shutdown -h now
I know everything about nothing"
Posts: 982
Joined: Fri Sep 14, 2012 9:13 am
by pjc123 » Fri Jan 18, 2013 12:55 pm
It is best practice to use the shutdown command. There are caveats using halt with various versions of Linux and UNIX that can lead to unexpected results, so just get used to using shutdown. Also, although most likely not the case with the typical pi user, shutdown allows you to send a message to all users that are logged in to notify them of a shutdown or reboot so they can properly finish what they are working on or save their work.
My Project Website:
http://www.flaminghellmet.com/
Posts: 910
Joined: Thu Mar 29, 2012 3:37 pm
by luan0ma » Fri Jan 18, 2013 2:50 pm
I use "sudo init 0" to shutdown. save some typing. :D
Posts: 3
Joined: Wed Jan 16, 2013 11:25 am
by penguintutor » Fri Jan 18, 2013 3:47 pm
Halt actually calls the shutdown command.

as taken from the Linux man page for halt:
"this simply invokes the shutdown(8) tool with the appropriate arguments"

It's true that the shutdown command can be used to send out a message to users about the impending shutdown, but how many people manage a system where multiple users are connected via a terminal / command shell session these days?
User avatar
Posts: 338
Joined: Tue May 08, 2012 9:11 am
Location: UK
by Jim JKla » Fri Jan 18, 2013 3:53 pm
luan0ma wrote:I use "sudo init 0" to shutdown. save some typing. :D


sudo halt

Even less typing

but more if you count typo corrections here. :lol:
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick
User avatar
Posts: 2195
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK
by pjc123 » Fri Jan 18, 2013 10:04 pm
penguintutor wrote:Halt actually calls the shutdown command.

as taken from the Linux man page for halt:
"this simply invokes the shutdown(8) tool with the appropriate arguments"


Yes, that is true for Linux on the pi, but it can be very different for other similar operating systems. Here is just one example. Take Solaris UNIX for instance where you only want to do a Halt as an absolute last resort. That is why it is good practice to use the command that offers the cleanest shutdown among various Linux/UNIX operating systems so you don't make a fatal mistake:

For Solaris:

Halt= Ungraceful shutdown. Stops the processor and syncs the disks, but performs an unconditional shutdown for system processes. It does not shut down any services because it does not run through the rc scripts. There is a good chance of lost data and corrupt files.

Shutdown= Shuts down the system in a clean orderly fashion.


penguintutor wrote:It's true that the shutdown command can be used to send out a message to users about the impending shutdown, but how many people manage a system where multiple users are connected via a terminal / command shell session these days?


This is very common in the corporate world. In my last few positions I worked with other system administrators who were many times simultaneously logged into the same machines from various locations in the building. In my most recent position we had 100 UNIX/Linux servers running a myriad of different applications, and all kinds of people were logged in from simple terminals simultaneously (system administrators, software developers, software testers, users running applications, outside vendors installing or running applications or repairing hardware, etc.).
My Project Website:
http://www.flaminghellmet.com/
Posts: 910
Joined: Thu Mar 29, 2012 3:37 pm
by bulletmark » Fri Jan 18, 2013 11:01 pm
I always shut unix/linux boxes down with "sudo poweroff". Or reboot them with "sudo reboot".
Posts: 86
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia
by Jim JKla » Fri Jan 18, 2013 11:40 pm
Sometimes I live dangerously and flip the mains breaker for the house.

Nothing to do with shutting down Linux just a pastime. :shock:
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick
User avatar
Posts: 2195
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK
by andrum99 » Fri Jan 18, 2013 11:52 pm
You should not get in the habit of using 'sudo halt' to shutdown your Pi as on other UNIX systems this performs an immediate unclean shutdown, which is usually a bad thing. ;-) If you ever find yourself using one of these other systems, this would be problematic.

Personally I use 'sudo poweroff' on debian, although on (Open)Solaris I favoured 'init 0'.

Cheers

Andrew.
My blog, with lots of Raspberry Pi goodness: andrum99.blogspot.co.uk
Posts: 217
Joined: Fri Jul 20, 2012 2:41 pm
by SimonSmall » Sat Jan 19, 2013 3:05 pm
andrum99 wrote:You should not get in the habit of using 'sudo halt' to shutdown your Pi as on other UNIX systems this performs an immediate unclean shutdown

Do you have any source for this information? I have checked and I cannot find anything about an unclean shutdown

It seems that the default behaviour of halt may have changed recently regarding the implementation of the power off action. When you use halt on a full Linux system, there may be an issue about whether the system cuts the power or not, but the Pi cannot do this so it may not matter

Otherwise, halt just calls shutdown with the required parameters (see "man halt" on your Pi). Using "sudo poweroff" looks like it does the same as "sudo halt" but does cut the power. Using "init 0" also seems to call shutdown and halt routines. I don't have time at the moment to analyse exactly which processes and commands and scripts are affected
Posts: 200
Joined: Tue Oct 09, 2012 8:13 pm
by andrum99 » Sat Jan 19, 2013 8:53 pm
SimonSmall wrote:
andrum99 wrote:You should not get in the habit of using 'sudo halt' to shutdown your Pi as on other UNIX systems this performs an immediate unclean shutdown

Do you have any source for this information? I have checked and I cannot find anything about an unclean shutdown.


How about this:

http://docs.oracle.com/cd/E23824_01/htm ... lt-1m.html

Quoting that page:

"The halt and poweroff utilities do not cleanly shutdown smf(5) services, execute the scripts in /etc/rcnum.d, or execute shutdown actions in inittab(4). To ensure a complete shutdown of system services, use shutdown(1M) or init(1M) to reboot a Solaris system."

Note that I said UNIX, not Linux. UNIX is more that Linux.

Cheers

Andrew.
My blog, with lots of Raspberry Pi goodness: andrum99.blogspot.co.uk
Posts: 217
Joined: Fri Jul 20, 2012 2:41 pm
by pjc123 » Sun Jan 20, 2013 1:29 pm
SimonSmall wrote:Do you have any source for this information? I have checked and I cannot find anything about an unclean shutdown


I suggest that you give it a try. Get a job as a system administrator and make sure that this is the very first thing that you do on your first day at work. To kick it up a notch, open a bunch of terminals to various servers; a very common every day task for a system administrator (Open terminals to some Linux servers, Solaris servers, HP-UX servers, and throw in a couple AIX servers as well). Now run the halt command on all of them. The next day, when you are told to hold the lettuce on the Whopper you are making at Burger King, it will give you plenty of time to ponder what happened.

On a serious note, we are talking about mixed UNIX/Linux environments, as we have stated. So, does the average raspberry pi user care about all this. Maybe yes, maybe not, but it is just good practice to develop good habits from the start.
My Project Website:
http://www.flaminghellmet.com/
Posts: 910
Joined: Thu Mar 29, 2012 3:37 pm
by SimonSmall » Sun Jan 20, 2013 3:46 pm
I am all for encouraging good practice, and what you say makes sense. However, I was not sure that this thread had made in clear about the pros and cons of halt. I tried several searches but none of the results suggested the behaviour mentioned. If I look specifically for Solaris, then it does suggest that halt behaves differently to Linux. Hopefully the last few posts have cleared up a few things.

I am still not too sure what should be the recommended way to stop the Pi:
* Using sudo halt is better than unplugging it (and it is the smallest number of characters)
* Using sudo halt with additional parameters can provide the message and other options to shutdown
* The Pi cannot have the power turned off by the software, so halt / poweroff does not matter

And for the wider world:
* The halt issue seems to be with flavours of UNIX, not Linux
* Can anyone get a job as a Solaris administrator by claiming several years of using the Pi?
* There are other differences between UNIX and Linux (init 5 ?). I would expect a system administrator to know these

As I said above, there are several tasks that seem to happen on shutdown, and I don't have time at the moment to look into it. Perhaps later ;)
Posts: 200
Joined: Tue Oct 09, 2012 8:13 pm
by jojopi » Mon Jan 21, 2013 11:24 am
SimonSmall wrote:* Using sudo halt with additional parameters can provide the message and other options to shutdown
No, halt takes very limited options, many of them dangerous. shutdown is the only method that allows to specify a time delay and message, and the only method that would be acceptable on a production server. (In a non-emergency.)
* The Pi cannot have the power turned off by the software, so halt / poweroff does not matter
There is a difference between "halt -f" (instant halt) and "poweroff -f" (instant poweroff). The Pi can have the SoC put into a low-power state.

You can get these two different behaviours by using "shutdown -h -H" or "shutdown -h -P". But when you run shutdown indirectly via halt or poweroff, this distinction is lost, and you always get the poweroff behaviour.
User avatar
Posts: 2064
Joined: Tue Oct 11, 2011 8:38 pm
by penguintutor » Mon Jan 21, 2013 2:30 pm
Now run the halt command on all of them.


Suspect that will get you fired regardless of whether you do a clean shutdown or not.

As a sysadmin I did normally use the shutdown command (I managed AIX, Solaris and Linux), where even the options used on the shutdown command weren't the same across the systems. On Linux the halt command is the same as a shutdown (except for the lack of notification to other shell users).

In the case of my 7 year old daughter I have taught her that you use reboot to restart the Pi (eg. so she can switch to OpenElec) and halt before powering it off rather than telling her about the shutdown command and the various options.

But if you wanted to become a sysadmin then you would need to learn the shutdown command as well as the following (taken from LPI 101 objectives): /etc/inittab; shutdown; init; /etc/init.d; telinit

I think the Raspberry Pi can be useful for learning sysadmin skills for those that want to, but let's not over-complicate it for users that don't want to learn Solaris / AIX / HP-UX. It's already a steep learning curve for some users.

As far as most Raspberry Pi users are concerned:
There are two commands that can be used to cleanly shutdown the Raspberry Pi running Linux - halt and shutdown.
User avatar
Posts: 338
Joined: Tue May 08, 2012 9:11 am
Location: UK
by cantfindausername » Wed Jan 23, 2013 12:28 pm
Sorry to take this topic on possibly another tangent, but once we've sent the shutdown command and its just sat there with the red PWR light on, how can we restart it? Is it a case of unplugging and plugging back in? Reason I ask is because I want it all hidden, so pulling power is not going to be easy. Is there any other way to restart the pi after shutdown?

Thanks
Ant
Posts: 8
Joined: Thu Jan 17, 2013 8:26 am
by RaTTuS » Wed Jan 23, 2013 12:34 pm
cantfindausername wrote:Sorry to take this topic on possibly another tangent, but once we've sent the shutdown command and its just sat there with the red PWR light on, how can we restart it? Is it a case of unplugging and plugging back in? Reason I ask is because I want it all hidden, so pulling power is not going to be easy. Is there any other way to restart the pi after shutdown?

Thanks
Ant

you have to power cycle it though on the later boards there is a reset header
but if it's hidden away then you don't need to
sudo shutdown - h now
you can
sudo shutdown -r now
to reboot it.
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 5179
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by cantfindausername » Wed Jan 23, 2013 3:23 pm
RaTTuS wrote:you have to power cycle it though on the later boards there is a reset header
but if it's hidden away then you don't need to
sudo shutdown - h now
you can
sudo shutdown -r now
to reboot it.


Thanks RaTTuS for the reply. So sending the 'sudo shutdown -h now' will send it to a sort of hibernated state, which you can then reboot/restore from with the -r switch? And while its in the hibernated state you can still ssh to it?

Any ideas where the reset header is?

Thanks again
Anthony
Posts: 8
Joined: Thu Jan 17, 2013 8:26 am
by RaTTuS » Wed Jan 23, 2013 4:10 pm
no when it is shutdown with a -h it halts so you have to power cycle it
http://raspi.tv/tag/raspberry-pi-reset-switch <- may help
the reset header is on the resent boards
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 5179
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by cantfindausername » Wed Jan 23, 2013 5:18 pm
Thanks for the link, that helps for sure. Will check my board out tonight for that.
Posts: 8
Joined: Thu Jan 17, 2013 8:26 am
by Maine_guy » Thu Jan 24, 2013 4:37 am
penguintutor wrote:how many people manage a system where multiple users are connected via a terminal / command shell session these days?

Actually quite a few. Since one of the goals of the Raspberry Pi Foundation is to get them into classrooms, I could see a case where an entire school could be logged into one Pi. :o
Posts: 14
Joined: Thu Sep 13, 2012 12:44 am
by Jim JKla » Thu Jan 24, 2013 7:07 am
This multiple user RPicould be an interesting project worthy of a new thread. ;)
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick
User avatar
Posts: 2195
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK