4

Is it possible to power off a Ubuntu 22.04-5 desktop booted into single user by using grub to add init=/bin/bash to the end of the standard Linux boot command line + ctrl-x or F10.

No init is running so cmds like: shutdown, poweroff, sysctl, init 0, halt do nothing

An almost identical question/answer already exists from a few months ago, but nothing works Note: No reputation so I couldn't add a quick comment -- hense the new question. Link: is there a proper way to shut down from single user mode

4
  • 1
    I rolled back an edit to the question which put the answer into the question text. Instead, consider accepting (and up-voting) one of the given answers below. See also unix.stackexchange.com/help/someone-answers Commented Aug 13 at 13:48
  • 4
    It’s debatable whether booting directly into a shell like this is actually ‘single-user mode’. The very concept of single-user mode is very much a function of your init system, but if you boot directly into a shell you have no init system running. Separately, on systemd-based systems like Ubuntu, you probably want to use rescue mode or emergency mode (entered from boot by psecifying rescue or emergency on the kernel command line) instead of booting directly into a shell. Commented Aug 14 at 10:59
  • 1
    @AustinHemmelgarn: Was going to say the same thing. init=/bin/bash isn't "single user mode" (traditionally runlevel 1 in SysV init), it's "full manual mode" or something. Commented Aug 14 at 19:38
  • Thank you for that. I'm an old PDP11 BSD Unix kernel guy where we only had single user aka root mode. Commented Aug 14 at 23:03

2 Answers 2

9
  1. Try poweroff -f. The -f flag should also work for reboot and halt.
  2. Try Alt-SysRq-o

Note that either way, you should unmount everything you can first. At the very least, everything you mounted yourself.

2
  • 1
    Thanks for the helpful advice. Poweroff worked. Blame fat fingers. Know I tried it. The Alt-SysRq-o is something to investigate Commented Aug 13 at 13:18
  • 1
    @Mes. Run sync and/or hit Alt-SysRq-s before power-off via alt-sysrq-o, if you had any filesystems mounted read-write. See en.wikipedia.org/wiki/Magic_SysRq_key / docs.kernel.org/admin-guide/sysrq.html for Alt-SysrQ. The only documentation I've ever printed, from the days when I only had one computer. Alt-Sysrq-U unmounts (or actually remounts read-only), so on wedged systems it's A-S-U, A-S-S, wait for disk activity to stop, A-S-B (reBoot). Apparently poweroff by default makes a sync system call, unless you use --no-sync. Magic-Sysrq doesn't. Commented Aug 14 at 19:42
7

Normally, when you shut down a linux machine from multi-user mode, a number of steps are taken (not necessarily in this order):

  • All services are stopped
  • All user processes are killed
  • All filesystems are unmounted or remounted read only

In single user mode, all of that is moot, because (at least initially), single user mode doesn't start services and the only process should be the root shell, and any mounted filesystems are mounted read only.

So immediately after booting into single user mode, you could just immediately power off by any method, including hard power or poweroff -f

However, if you've mounted anything writable or started services, etc., you will need to undo what you've done before shutting off. The system isn't keeping track of that, so you have to do it yourself. (Technically, you don't have to shut down services, but if you don't, it might prevent you from unmounting filesystems.)

TL;DR: Before powering off, the critical issue is that all filesystems are unmounted or mounted read only and all their dirty data is written to disk. Any other pre-shutdown actions are meant to make that possible.

3
  • I learned this 40 years ago after needing to reinstall the system after power-off corruption. kill + sync, repeat. Commented Aug 14 at 23:08
  • @Mes Isn't it supposed to be sync<return>sync<return>sync? This allows the first sync to finish before you do anything stupid. Commented Sep 2 at 18:37
  • I think modern Linux completes the flush before the sync finishes, so doing it 3x is kinda sily now, not that it wasn't always. Commented Sep 2 at 22:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.