- Is it possible to reboot a Linux OS without rebooting the hardware?
- 3 Answers 3
- Reboot without actually shutting down
- 1 Answer 1
- Reboot ubuntu without a complete hardware reboot
- 1 Answer 1
- Rebooting Ubuntu on Windows without rebooting Windows?
- 9 Answers 9
- Older versions
- Create alias:
- Add line:
- Enable Alias:
- Use
Is it possible to reboot a Linux OS without rebooting the hardware?
Is there a way to reboot a Linux system (Debian in particular) without rebooting the hardware? I have a RAID controller that takes a bit to get itself running before the OS starts up, and I would like it if there was a way to quickly reboot the Linux OS without having to go through the whole reboot process of restarting the RAID controller, etc.
All UEFI based systems are able to switch OS whtout rebooting. You also have kexec() which is like exec() , but for Unix kernels.
3 Answers 3
I use kexec-reboot on nearly all of my production systems.
It works incredibly well, allowing me to bypass the long POST time on HP ProLiant servers and reduce the boot cycle from 5 minutes to ~45 seconds.
The only caveat is that it doesn’t seem to work on RHEL/CentOS 6.x systems booting UEFI. But most sane OS/hardware combinations work.
Fascinating. So how does the actual process look? According to an article by Hariprasad Nellitheertha (linked to from the kexec wikipedia page), «Unlike the normal reboot process, kexec does not perform a clean shutdown of the system before rebooting. It is left to you to kill all applications and unmount file systems before attempting a kexec reboot.» I notice some questionable things, for example, Wim Coekaerts says that «sync; umount -a; kexec -e» will do a very fast reboot. But you can’t umount a busy filesystem. Perusing the web, it seems that many ignore the ‘kill all applications’ part.
@MikeS This isn’t kexec . It’s the kexec-reboot utility. The Github description outlines the difference and what the utility adds to the process.
@MikeS After staging kexec, you simply do a shutdown -r . Your system scripts will notice that kexec has been staged and do the right thing. How does it look? Three or four or fifteen minutes shorter. I have a very horrible quality video I took off the iDRAC console, but you really don’t want to suffer through that. The kexec-reboot script is meant to automate the process of getting the right command line arguments to kexec, which can be tricky.
@MichaelHampton — cool. I see that on CentOS 6.5 near the end of /etc/rc3d/rc6.d/S01reboot there is: [ -n «$kexec_command» ] && $kexec_command -e -x >& /dev/null . So, iff a kernel is loaded by kexec -l, the system will reboot into it without a complete /sbin/reboot. kexec is baked in! I didn’t know that, thanks. I suppose more modern distributions have it covered as well. BTW, if kexec wasn’t previously run with -l, the reboot script will say «Nothing has been loaded!» which is why the output is sent to /dev/null, and why I was never aware of this facility.
Reboot without actually shutting down
Is it possible to do a reboot, without actually rebooting? I have Ksplice, haven’t had the chance to use it yet, but need something different. My desktop only will boot into the HD if I enter the bios during boot and tell it to boot from USB then it will boot to the HD, very odd and I have checked my BIOS and set it to default settings in case I may have changed something, but that did not solve it. So basically I do not want to do an actual shutdown/reboot. I added my Brother MFC-295CN and changed the script needed to scan but now I need to reboot to make it work. This is non kernel related so Ksplice will not do. Is there any other way? Would restarting lighdm do the trick? Is it possible? Thank you for your time and answers
1 Answer 1
First, install the kexec tools using:
sudo apt-get install kexec-tools
Now, to reboot using kexec one needs to determine the version of the kernel you want to kexec into and also the the boot device and initrd you want to use.
For example, to find the current kernel you are running, use:
and a quick and dirty way to find the boot device is to look for the root device in /boot/grub/grub.cfg, e.g:
grep "set=root" /boot/grub/grub.cfg
and look for the UUID of the boot device.
So, for my machine, my kernel is 3.5.0-17-generic, and my UUID is 69822458-67e5-437a-84ab-0c9e5c139d43, so I can load this kernel and initrd images into memory using:
sudo kexec -l /boot/vmlinuz-3.5.0-17-generic --append=" linux /boot/vmlinuz-3.5.0-17-generic root=UUID=69822458-67e5-437a-84ab-0c9e5c139d43 ro quiet" --initrd=/boot/initrd.img-3.5.0-17-generic
and then boot the kernel using:
One can kexec into a different kernel version; you don’t need to use the one you are running.
Reboot ubuntu without a complete hardware reboot
I would like to reboot the OS as if it is pulled up from GRUB, but without actually rebooting the entire computer. This is because this machine has a bunch of different OSes on it and while a reboot is necessary human interaction for boot options selection is not under this scenario. Any ideas? I know you can drop down to various run-levels but I am not aware of (lets call it) «an incomplete software-reboot».
Do you know virtualbox ?! with this program you could use several distros without to reboot your machine — and change from one to the other — with vmware (something different program — but no freeware ) it is possible to change the desktop with keyboard-shortcuts from one to the other, without switching off the running systems.
1 Answer 1
Try kexec command it seems to do exactly what you need.
kexec -l kernel-image --append=command-line-options --initrd=initrd-image
kexec is a system call that enables you to load and boot into another kernel from the currently running kernel. kexec performs the function of the boot loader from within the kernel. The primary difference between a standard system boot and a kexec boot is that the hardware initialization normally performed by the BIOS or firmware (depending on architecture) is not performed during a kexec boot. This has the effect of reducing the time required for a reboot.
.
Insert the command-line parameters that must be passed to the new kernel into command-line-options . Passing the exact contents of /proc/cmdline into command-line-options is the safest way to ensure that correct values are passed to the rebooting kernel.
Never tried kexec myself (except maybe during crashdump to load the dump kernel, but it was an automatic process), I would go to single user mode first to stop all the processes before running kexec .
Rebooting Ubuntu on Windows without rebooting Windows?
Is it possible to reboot the Ubuntu sub-system without restarting my system? I tried to use the shutdown command after installing some updates, but that doesn’t seem to be an option here. The screenshot text :
~$ bin/rcheck.sh Reboot required. ~$ sudo shutdown -r now shutdown: Unable to shutdown system
Rebooting (standard) WSL is not a thing. Simply put, a WSL distribution is just a container (like Docker) with a shell. Even with WSL 2, rebooting the VM does nothing to a distribution.
9 Answers 9
You cannot reboot a distro with a single command. You must shut down and boot up the distro with two commands.
View the list of distros and their current state:
Terminate a specific distro: Windows 1903+
Boot up the default distro (marked with * ):
Boot up a specific distro:
Older versions
# PowerShell (admin) Restart-Service LxssManager # or CMD (admin) net stop LxssManager net start LxssManager
net worked in cmd (with admin). Just tested that my bat-file with sc did not work in Windows OS Build 1809.
I’m using the newest Windows Insider with WSL 2 and tried to use commands like C:\Users\xxx>wsl -l -v showing that three are «Ubuntu», «docker-desktop» and «docker-desktop-data» As in my case, there is also the newest docker running so wsl -shutdown works, but it also closes my docker environment After trial and error, I found that wsl -t «Ubuntu» works, but sometimes it takes time or is not reliable? Once it worked when I started command shell with admin rights.
At an administrative PowerShell prompt: Restart-Service LxssManager
I like it. Easy to remember, autocompletes with tab well enough. Amusing to see how well Windows got its service model down right from the beginning.
Since Windows 10 version 1803, closing all WSL terminal windows won’t kill background processes by default, unless the file /var/run/reboot-required is present. This file will be automatically created by apt on Ubuntu when an update requires a reboot, but if you want to manually reboot the subsystem, you can create the file yourself:
sudo touch /var/run/reboot-required
I haven’t tested this on other distributions available in the Microsoft Store. An alternative solution is to kill all processes yourself:
@Louis I see you’ve already accepted it, but you can do sudo touch /var/run/reboot-required . In fact, it seems the presence of the file causes WSL to kill all background processes and shut down the subsystem when all terminal windows are closed, so you can abuse that as well.
Touching reboot-required (and closing all terminals) didn’t do anything for me. In the end, I just did wsl —shutdown and wsl -d
Just open a cmd window as adminstrator and run these commands to restart it.
net stop LxssManager net start LxssManager
Doesn’t work. stays in «stopping» status. when I try to run it again I get «The service is starting or stopping. Please try again later.». never finishes. Always hangs after I run an rsync command from batch like «bash -c ‘rsync. ‘». This is a nightmare.
The following allows a shutdown from within WSL2 using the command wslreboot (or any custom command).
Technically, wslshutdown would be more appropriate for the code below:
Create alias:
Add line:
alias wslreboot='history -a && cmd.exe /C wsl --shutdown'
history -a ensures that the bash command history us saved before shutdown.
Enable Alias:
Use
I’m thinking you could use a variation of the above to run a batch file with the lines:
I wasted precious minutes reading documentation and figuring this out on my own before finding your answer 🙂 Thanks
Simply exiting the shell with exit and reopening seems to do the trick. The shell needs to be run as admin.
Louis@ATHENA:~$ bin/rcheck.sh Reboot not necessary. Louis@ATHENA:~$ bin/update.sh [sudo] password for Louis: The following packages will be upgraded: libssl1.0.0 openssl 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libssl1.0.0 amd64 1.0.1f-1ubuntu2.21 [830 kB] Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main openssl amd64 1.0.1f-1ubuntu2.21 [489 kB] Setting up libssl1.0.0:amd64 (1.0.1f-1ubuntu2.21) . Setting up openssl (1.0.1f-1ubuntu2.21) . Del libssl1.0.0 1.0.1f-1ubuntu2.20 [830 kB] Del openssl 1.0.1f-1ubuntu2.20 [489 kB] Louis@ATHENA:~$ bin/rcheck.sh Reboot required. Louis@ATHENA:~$ exec bash -l Louis@ATHENA:~$ bin/rcheck.sh Reboot required. Louis@ATHENA:~$ exit Louis@ATHENA:~$ bin/rcheck.sh Reboot not necessary. Louis@ATHENA:~$