Shutting down and rebooting the system are important, if basic, aspects of system administration.
- [Narrator] When a system goes from powered off to up and running, it goes through a boot process to bring up the operating system to a usable state. This process, as well see in another video in this course, has some technical details that make it work. It's not just about applying power to the components and having them suddenly work. In that vein, we also can't just remove power from the system when we're done with it. So in this video, we'll take a look at rebooting and powering down a machine safely. Modern computers are complex, so we can't necessarily just treat them like appliances.
When we go to shut off a light, we can flick a switch, and that's that, but a computer has a lot more going on, and simply removing power from it can cause all kinds of problems. If there were information waiting in cache to be written to the disc, it could be lost. If another user is currently using the system, their work would be interrupted or lost. So we have a procedure that shuts down a computer in an orderly way to try and avoid these problems. If we want to tell a system to power down and remain off, we shut it down. If we want to instruct the system to shut down and then immediately come back online, we tell it to reboot.
Both of these operations, though, involve the system going through the shutdown process. That process notifies other users of the system that the system is going down, and whoever initiates the shutdown can optionally set a period of time before it happens and send a message to other logged in users. Users with the appropriate access level can cancel the shutdown too, if need be. When the shutdown process takes place, the system notifies processes that are running, telling them they need to do whatever they're designed to do in the case of a shutdown, including saving data, writing log entries, or anything else needed to correctly end what they're doing to minimize data loss and end up in an expected state.
Data in caches, operations in cues, and information in memory need to be dealt with in a way that's appropriate for each of them. Here at the command line, we can reboot or shutdown the system with the shutdown command which can take a few options. Normally, we'd write shutdown -r now, or shutdown -h now, either to restart or power off the system. The now parameter tells the system to go down now, though we could add a time either with + and some number of minutes, or with a 24-hour format time, if we want the system to go down at a specific time rather than in a specific amount of time.
Let's practice a little bit with a shutdown command. I'll write sudo shutdown -h +5 to tell the system to shut off in five minutes. If I wanted to, I could cancel the shutdown with shutdown -c, and now, after five minutes, the system won't shut down after all. I mentioned before that we can say now instead of a specific time, so let's use that and reboot the system with shutdown -r now.
The machine notifies users that it's going down, and then immediately informing processes that it's going down. The operating system kicks off its shutdown sequence, and the machine restarts. I'll log back in here, and get back to my terminal. There are a few other options in the manual pages too, if you'd like to explore them. I want to talk for a moment about runlevels.
I'll write man runlevel so we can see a convenient little chart. For a long time, we represented various power and interactivity states of the system as runlevels, a number from zero to six that we could use to set how a system operated. Runlevel zero represented powering off. One represented the rescue mode or single user mode. Two, three, and four represented various multi-user modes. Five was a graphical mode, and six represented the system rebooting. In modern versions of Ubuntu, using the systemd service, we use what are called targets instead to talk about this kind of difference in operating modes.
You can see the mapping here in this table, inside the man page for the runlevel command. To switch between them, we can use the systemctl isolate command, and the name of the target we want to switch to. In this case, we could restart the system by saying systemctl isolate reboot.target, or any of the other runlevels in the man page. Normally, you'd want your system to come up in multi-user or graphical mode, but if for some reason you want to change the default target, you can write sudo systemctl set-default and the target that you want the system to come up in.
Let's restart in rescue mode with rescue.target. Now I'll restart the system with sudo shutdown -r now. And when the system comes up, it'll be in rescue mode. Let's change that back with systemctl set-default graphical.target.
I'll restart and the system will come back up in the graphical mode. I'll log in, and we're back to where we started.
- Booting the system
- Managing the startup process
- Updating software
- Understanding shared libraries
- Examining resource utilization
- Upgrading or adding hardware
- Exploring system log files
- Scheduling and verifying tasks
- Incident management