Ubuntu – How to correctly shutdown ubuntu in single-user mode

Ubuntuupstart

I have searched a lot,only to found that many people came across this problem.
By adding rw init=/bin/bash to the end of the vmlinuz line,I can enter the single-user mode of UBUNTU 10.04 LTS but,when I type shutdown or reboot,it just said it can't do that. Then I run "/sbin/init 0" and it said it can't connect to sock of upstart.

My guess is ,because we replace /sbin/init with /bin/bash and there is no init(nor upstart) thus shutdown can't be done.

I notice that some guy said by enter exit and I should go into next phase of normal boot.I tried that, and the ubuntu system in my VMWare became stuck,and behave weird,at least in the sense of the CAPLOCK light which kept flashing..(CPU occupation scored too)

Any intruction is appreciated,thanks all in advance~

====UPDATED=====
I tried single instead of init=/usr/bash but it went straight into multi-user mode.

Best Answer

When you have no init or other processes beside your shell, there is almost nothing to shutdown. In fact, the only important thing is the filesystem – sync it, then unmount all on-disk filesystems or remount as read-only (if they cannot be unmounted, for example, the rootfs):

sync
umount /home
mount -o remount,ro /

After this, you might as well pull the plug.


Another thing you could try (but I haven't) is to start the original init. Make sure no processes aside from your pid1 shell are running, then change to root directory and exec init:

cd /
sync
exec /sbin/init

exec replaces the current process with the one given, so started this way /sbin/init will take the special pid 1 from your shell.

However, if pid 1 ever exits, the kernel will immediately panic – so make sure you at least sync the filesystems before doing this.

When the kernel panics, it prints out a message, starts flashing the keyboard LEDs, and stops everything else – it stops even the loop that normally tells the CPU to remain idle; this probably is what causes the Caps Lock madness and the high CPU use by your virtual machine.

Your "some guy" was right – in real single-user mode, typing exit will usually switch to multi-user or at least clean-reboot. However, init=/bin/bash does not start this mode; it does not start anything at all, besides the kernel and the bash shell. To reach the real single-user mode, you would need to add single to the kernel command line. (Sometimes 1 or s works, but not all distributions use runlevels.) In Ubuntu, this used to be called "Recovery mode".

Related Question