Tomas-M / linux-live

Linux Live Kit
http://www.linux-live.org/
1.01k stars 250 forks source link

Bug: can not poweroff #230

Closed qiang-yu closed 2 years ago

qiang-yu commented 2 years ago

2022-08-12 , make live ISO, the system can not poweroff

/sbin/poweroff

it would reboot intead of poweroff

it seems this is a bug

Tomas-M commented 2 years ago

What distro do you use as base? Does it have systemd?

uHash64 commented 2 years ago

same issue with debian 11 bullseye distro won't poweroff instead reboot if tyiping sudo poweroff systemctl shutdown -n now

nathanrsfba commented 2 years ago

I think I'm seeing the same problem using Slackware 15, which does not use systemd.

It looks like the shutdown script is calling 'reboot' or 'poweroff' without any arguments. Assuming the busybox versions work the same way as the normal ones, if the current runlevel isn't 0 or 6, it will call shutdown(8) to change the runlevel, instead of physically rebooting or powering off. The initramfs environment doesn't seem to have a utmp file (which stores the runlevel) so I think this is indeed what is happening.

Since the poweroff command fails, the script continues to a fallback command, which is to run "reboot -f"; the -f forces it to actually reboot instead of calling shutdown, so it works this time.

It seems that the fix is to call "reboot -f" or "poweroff -f" as appropriate, in the shutdown scripts.

Tomas-M commented 2 years ago

In general, it is necessary ro run the shutdown script from initramfs at the end of your distro's shutdown procedure instead of reboot/halt.

If your distro uses systemd, then this is done automatically, like it does in debian. However if your distro does not use systemd, you need to modify your shutdown scripts to call the shutdown script in /run/initramfs/shutdown manually at the end. For an examle, you can see https://github.com/Tomas-M/linux-live/blob/master/Slax/slackware15/modules/01-core/rootcopy/etc/rc.d/rc.6 (My changes are at the bottom)

I am unfortunately not sure why it does not work for @uHash64

ghost commented 2 years ago

Hello everyone.

Debian sid. I try to poweroff by systemctl like this:

#systemctl poweroff

Live system from USB-flash does reboot the machine instead of turning it off.0 On the actual system working from HDD, this command turns off the machine.

ghost commented 2 years ago

I am not sure I understand it quite well but the shutdown script in /run/initramfs shows this result:

shutdown

Tomas-M commented 2 years ago

The script is not meant to he started directly. It has to be started during the shutdown procedure of your distro with chroot (the directory /run/initramfs is chrooted). For examle Debian does that automatically because it uses systemd, and systemd knows what to do.

ghost commented 2 years ago

Unfortunately, on Debian sid with systemd It does not work.

ghost commented 2 years ago

I've made new flash-drive with ver. 2.6 - the same system, the same list of packages, and now halting machine works fine.

Tomas-M commented 2 years ago

Can you send me your ISO which does not work? Maybe upload it to some file sharing website.

ghost commented 2 years ago

Sure. Just, I do not do iso, I prefer Tar. It is a bit bigger than you might expect though...

https://disk.yandex.ru/d/Fm9_AyVBQMjDyw

$ md5sum livekit-sid.tar 
2d4d290c4c3d7c520db63278c2a12516  livekit-sid.tar

Let me know when you get it.