Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1331 / 47 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 29:

Starting and stopping the system

< Лекция 28 || Лекция 29: 12345 || Лекция 30 >

Single-user mode

Sometimes it's inconvenient that multiple users can access the system. For example, if you're repartitioning a disk, you don't want other people walking all over the disk while you're doing so. Even if you're the only user on the system, daemons may be doing things in the background. To avoid this problem, you can stop the boot process before most of the daemons have been started and enter single-user mode. To do this, set the boot_single variable, or specify the -s fag at boot time:

ok boot -s

As soon as the device probes have been completed, the system startup is interrupted, and you are prompted for a shell. Only the root file system is accessible, and it is mounted read-only. The reason for this is that the file system may be damaged and require repair before you can write to it. If you do need to write to the root file system, you should first check the consistency of the file system with fsck, after which you can mount it with the -u (update) option. For example,

npx0 on motherboard
npx0: INT 16 interface                     end of the probes (high intensity display)
Enter pathname of shell or RETURN for sh:  hit Enter
erase ^H, kill ^U, intr ^C    
# fsck -y /dev/ad0s1a                      check the integrity of the root file system
** /dev/ad0s1a
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
1064 files, 8190 used, 6913 free (61 frags, 1713 blocks, 0.4% fragmentation)
mount -u /                                  remount root file system read/write
mount /usr                                  mount any other file systems you need

To leave single-user mode and enter multi-user mode, just enter Ctrl-D:

# ^D
Skipping file system checks...
(the rest of the boot sequenc)

System V and Linux have the concept of run levels, which are controlled by init. Single-user mode corresponds to run level 1 or S, and multi-user mode corresponds roughly to System V run level 3 or Linux run level 4. Nothing corresponds with the other System V run levels, in particular run level 2, which starts a System V system without networking.

Networking is such an integral part of FreeBSD that this is just not practicable. FreeBSD init now understands a syntax similar to the System V init. Table 29-1 shows the supported levels. For example, to read in the /etc/ttys file, you could enter:

# init q
Таблица 29.1. init levels
Level Signal Action
0 SIGUSR2 Halt and turn the power off
1 SIGTERM Go to single-user mode
6 SIGINT Reboot the machine
C SIGTSTP Block further logins
q SIGHUP Rescan the ttys(5) file

You can also enter single-user mode from a running FreeBSD system with the shutdown command, which we'll look at in the next section.

Password protecting single-user mode

If you run a secure environment, you could be concerned about the fact that you can start up in single-user mode without entering a password. That's the default—normally, if somebody can access your system console, a password is no longer much use, and it can be a nuisance—but you can change it. Find this entry in /etc/ttys, and change the word

secure to insecure:

#If you want to be asked for password,    change "secure" to "insecure" here
console none    unknown off insecure

If you do this, you will be in real trouble if you forget the root password.

Shutting down and rebooting the system

FreeBSD uses a number of sophisticated techniques to achieve its high performance. In particular, when you write data to a disk, the system doesn't put it on the disk immediately: it waits for more data to arrive, which reduces the number of disk accesses by up to several orders of magnitude and thus improves performance dramatically.

The result of turning power off before the data is written is equally dramatic. You may just lose the data, but if the data is information on a change in file system structure, your file system will be damaged. To check for this, the system runs a program called fsck (File System Check) at startup. fsck can repair minor damage, but it's obviously a better idea to avoid damage by ensuring that the system is shut down in an orderly way.

Never stop your machine by just turning off the power. The results could be devastating.

The correct way to shut a system down is with the shutdown command. To quote the man page shutdown(8):

Shutdown provides an automated shutdown procedure for super-users to nicely notify users when the system is shutting down, saving them from system administrators, hackers, and gurus, who would otherwise not bother with such niceties.

This command has a number of useful options:

  • Use the -r option to reboot the computer. You sometimes need to do this, for example after installing a new kernel.
  • Use the -h option to stop the machine. This isn't the default.
  • Without an option, shutdown attempts to put the machine in single-user mode. This doesn't always work as well as booting in single-user mode.
  • shutdown requires a time parameter to tell it when to actually perform the shutdown. This is useful in a multi-user environment, but normally you'll want to shut down immediately, so shutdown understands the keyword now.

In the normal case, where you want to stop the machine immediately so you can turn the power off, you type:

# shutdown - h now
Feb 4 12:38:36 freebie shutdown: halt by grog:
Feb 4 12:38:39 freebie syslogd: exiting on signal 15
syncing disks...done
The operating system has halted.
Please press any key to reboot

Be sure to wait for this message before you turn off the power.

FreeBSD without disks

Disks are getting much cheaper and their capacity is continually increasing, so it's easy to think that there would never be a reason to want to run FreeBSD without a disk at all. Still, there are reasons:

  • Disks are unreliable. For a machine that you want to keep running for a long time, the most likely hardware failure is a disk failure.
  • Disks are noisy. There are places where you might not want the noise.
  • Disks are sensitive. You may not want to place them in some environments.
  • You may find systems administration easier if all the configuration files are in one place.
  • The "sweet spot" for hard disk prices, the place where you get the most storage for your dollar, is currently around 80 GB, about 10 times what it was five years before. You may not want that much disk space for anyone machine, but for a group, it might make more sense to have a disk for the whole group on one machine.

There are a number of ways to run a system without a disk. You can replace the disk with something else, such as a flash card, floppy disk or CD-ROM drive, or you can access a remote disk via a network. We'll consider network booting in the following section, and we'll look at the disk replacement strategy on page 549.

< Лекция 28 || Лекция 29: 12345 || Лекция 30 >