[solved] Are shutdown and init command the same?

Questions about hardware, drivers and peripherals
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
deepakdeshp
Level 20
Level 20
Posts: 12341
Joined: Sun Aug 09, 2015 10:00 am

[solved] Are shutdown and init command the same?

Post by deepakdeshp »

Hello,
What is the difference between following commands? Which should be used preferably?

Code: Select all

sudo init 0
sudo shutdown 0
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
User avatar
kc1di
Level 18
Level 18
Posts: 8180
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Are shutdown and init command the same?

Post by kc1di »

Hello,
in mint 18.3 init was replaced by systemd as default and unless you've purposefully changed the boot system init commands are no longer needed.
simply

Code: Select all

sudo shutdown -h now
for shutdown or

Code: Select all

 sudo shutdown -r now
for restart will suffice. there are no run levels in systemd , but they are called targets.
you can read more here: https://unix.stackexchange.com/question ... nux-server read the section starting at <86>
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Mute Ant

Re: Are shutdown and init command the same?

Post by Mute Ant »

"Are shutdown and init command the same?" Not exactly the same no...
md5sum $(which init) $(which shutdown)
520afdca7fd55654f737f5f07e2327c4 /sbin/init
e3b947f8c0c716efdb20f84be19e67fb /sbin/shutdown
...although in Mint 17.3 they both come from package upstart
apt-get source upstart
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Are shutdown and init command the same?

Post by all41 »

systemctl poweroff
Everything in life was difficult before it became easy.
Sir Charles

Re: Are shutdown and init command the same?

Post by Sir Charles »

all41 wrote: Sat Mar 17, 2018 9:54 pm systemctrl poweroff
Thanks for this!
I had keyboard shortcuts for suspend and hibernate. The trio is now complete :D
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Are shutdown and init command the same?

Post by all41 »

There is also systemctl reboot
systemd is new turf
Everything in life was difficult before it became easy.
Sir Charles

Re: Are shutdown and init command the same?

Post by Sir Charles »

I am running out of key-combinations :D
Thanks!
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Are shutdown and init command the same?

Post by all41 »

Check out
yelp man:systemctl
Everything in life was difficult before it became easy.
Sir Charles

Re: Are shutdown and init command the same?

Post by Sir Charles »

systemctl --kill-who= :?:
LOL
Cheers
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Are shutdown and init command the same?

Post by all41 »

just to acknowledge op deepakdeshp's question remains unanswered here.
I do not know the answer
Everything in life was difficult before it became easy.
User avatar
AZgl1800
Level 20
Level 20
Posts: 11184
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: Are shutdown and init command the same?

Post by AZgl1800 »

deepakdeshp wrote: Fri Mar 16, 2018 1:38 pm Hello,
What is the difference between following commands? Which should be used preferably?

Code: Select all

sudo init 0
sudo shutdown 0
init 0 is old and outdated: https://askubuntu.com/questions/75427/u ... n-computer

you don't need 'sudo' for shutdown 0, I use it everyday to shut my laptop down to avoid the keyring damen coming up and making my shutdowns greatly extended.

I just simply do Control-ALT-T and type in 'shutdown 0' and every thing is gracefully closed and down it goes. now.

I am using:
Kernel: 4.13.0-26-generic x86_64 (64 bit)
Desktop: Cinnamon 3.6.7 Distro: Linux Mint 18.3 Sylvia
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Are shutdown and init command the same?

Post by rene »

deepakdeshp wrote: Fri Mar 16, 2018 1:38 pm What is the difference between following commands? Which should be used preferably?

Code: Select all

sudo init 0
sudo shutdown 0
The second, although not with unadorned 0 but with either +0 or its alias now; the fact that 0 works at all is essentially a parser bug. The sudo is not necessary either: being an administrator user (which on Mint means being root and/or a member of groups "sudo" and/or "admin") will make polkit grant permission to shutdown the system. Among the two given choices shutdown now is the preferred command, then.

The init program used to in not so olden times be the name of the actual system init, the program launched by the kernel directly so as to create process 1, the init process. The telinit program was used to communicate with said process and specifically telinit <number> would instruct said process to switch to runlevel <number>. telinit moreover used to in fact simply be a link to init with the program deciding at runtime whether to behave as init or as telinit simply by seeing if it was in fact process 1 or not.

These days init is itself a link to /lib/systemd/systemd but systemd emulates the above behaviour: init 0 is still equivalent to telinit 0 and the latter you in man telinit find to be in turn equivalent to systemctl poweroff; like before, sudo is not in fact necessary. shutdown is a link to systemctl with the systemctl program at runtime deciding how to behave depending on what name it was called through. In the case of that name being "shutdown" it behaves exactly as, again, systemctl poweroff.

This is to say that while in the end there's no difference between the presented choices, the preferred command should in fact be systemctl poweroff. Your options are two levels of historical baggage...
User avatar
all41
Level 19
Level 19
Posts: 9523
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Are shutdown and init command the same?

Post by all41 »

deepakdeshp wrote: Fri Mar 16, 2018 1:38 pm Hello,
What is the difference between following commands? Which should be used preferably?

Code: Select all

sudo init 0
sudo shutdown 0
@rene
Yes, I agree.
Yet Mint 17.3 is still in support and systemd solutions are not an option for Mint 17.3 users.
I think op wants to know how running services are terminated in each instance?
@deepakdeshp please ring back in here.
Everything in life was difficult before it became easy.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Are shutdown and init command the same?

Post by rene »

all41 wrote: Sun Mar 18, 2018 1:51 am Yet Mint 17.3 is still in support and systemd solutions are not an option for Mint 17.3 users. I think op wants to know how running services are terminated in each instance?
In case you have disabled display of signatures: he specifically mentions to be running Mint 18.3 in it. No mention of 17 anywhere so I do believe he's asking simply in the Mint 18 context. Anyways...

In Mint 17 init used to be upstart rather than systemd but the "same" as above holds in the sense of both init 0 and shutdown -h now being equivalent to telinit 0; to init switching the system to runlevel 0. I do believe that leaving out -h in that case in fact meant telinit 1 instead, single-user mode. And you do need sudo on 17.

In even older sysvinit days shutdown was or could be supplied by util-linux and was at the very least conceptually different from telinit 0 in the sense of it signalling processes itself. It of course depended on a specific distribution's implementation of going to runlevel 0 whether or not that was actually all that different, and I seem to recall not all distributions using the util-linux shutdown back then. Slackware I fully trust did the most obsolete thing it could think of and used the util-linux one directly, but if I'm not mistaken RedHat for example did not; if not simply misremembering then I trust they in fact implemented it as telinit 0.
User avatar
kc1di
Level 18
Level 18
Posts: 8180
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Are shutdown and init command the same?

Post by kc1di »

to answer the original question.
In a multi user system under init if you issue init 0 the system will go down without any notification where using shutdown -h will send a message to anyone on the system that the system is about to go down. so shutdown is delayed a bit.

But it was a good discussion and provided lots of info for other to consider.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Are shutdown and init command the same?

Post by rene »

kc1di wrote: Sun Mar 18, 2018 6:26 am to answer the original question. In a multi user system under init if you issue init 0 the system will go down without any notification where using shutdown -h will send a message to anyone on the system that the system is about to go down. so shutdown is delayed a bit.
If by "under init" you specifically mean "not under systemd" then fine but note this to be untrue for Mint 18.3 which is what the poster runs. On it, shutdown -h now goes down as fast and as quietly as init 0 (although "as quietly" might judging from the manpages in fact be unintended).

Don't get it. Why do both you and all41 assume the question is not about Mint 18? There's no mention of anything other than Mint 18.3 and hence of systemd.
User avatar
kc1di
Level 18
Level 18
Posts: 8180
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Are shutdown and init command the same?

Post by kc1di »

rene wrote: Sun Mar 18, 2018 8:06 am
kc1di wrote: Sun Mar 18, 2018 6:26 am to answer the original question. In a multi user system under init if you issue init 0 the system will go down without any notification where using shutdown -h will send a message to anyone on the system that the system is about to go down. so shutdown is delayed a bit. Th
If by "under init" you specifically mean "not under systemd" then fine but note this to be untrue for Mint 18.3 which is what the poster runs. On it, shutdown -h now goes down as fast and as quietly as init 0 (although "as quietly" might judging from the manpages in fact be unintended).

Don't get it. Why do both you and all41 assume the question is not about Mint 18? There's no mention of anything other than Mint 18.3 and hence of systemd.
that is why I Specifically said Under init - If you look at my first post you will see I told the op that 18.3 runs under systemd and that there are no run levels in that system. Cheers :)
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
deepakdeshp
Level 20
Level 20
Posts: 12341
Joined: Sun Aug 09, 2015 10:00 am

Re: Are shutdown and init command the same?

Post by deepakdeshp »

That's an excellent discussion , thanks all. And yes I do use Mint 18.3 and the context to my question is 18.3.
I learnt many things. Systems is quite involved, I don't intend to read something voluminous. Does anybody know a link or slideshow explaining the basics of systemd?
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Are shutdown and init command the same?

Post by rene »

https://www.digitalocean.com/community/ ... he-journal looks useful.

I would however primarily suggest man pages. In this case ls -l $(which init) followed by man systemd would for example inform you that
For compatibility with SysV, if systemd is called as init and a PID that is not 1, it will execute telinit and pass all command line arguments unmodified. That means init and telinit are mostly equivalent when invoked from normal login sessions. See telinit(8) for more information.
and the subsequent man telinit that init 0 is hence ...
[ ... ] translated into an activation request for poweroff.target and is equivalent to systemctl poweroff.
Other than an init system systemd is much more these days; be sure to separate the two (ha! two!) when studying it.
Last edited by rene on Sun Mar 18, 2018 9:27 am, edited 1 time in total.
User avatar
kc1di
Level 18
Level 18
Posts: 8180
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Are shutdown and init command the same?

Post by kc1di »

deepakdeshp wrote: Sun Mar 18, 2018 8:54 am That's an excellent discussion , thanks all. And yes I do use Mint 18.3 and the context to my question is 18.3.
I learnt many things. Systems is quite involved, I don't intend to read something voluminous. Does anybody know a link or slideshow explaining the basics of systemd?
This page is pretty good and concise.
https://www.digitalocean.com/community/ ... he-journal
and you can always get the basic command structure by entering

Code: Select all

man systemd
in the terminal.
Happy learning :)
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Locked

Return to “Hardware Support”