Article Title: system startup process: Init translated into Meaculpa. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Many clever things happen when you start your computer into FreeBSD. I cannot discuss all the details here, but FreeBSD handbook provides an excellent explanation of the pilot process. When you start your computer, you may notice that the kernel has detected the hardware and displayed relevant results on the terminal. When the detection ends, the kernel starts two processes: process 0 (swapper) and process 1 (init ).
The program responsible for process control Initialization is init; other processes cannot be started without it. During boot, init has two important tasks: first, it loads the startup script under rc control, and then it initializes the terminal so that users can log on. Let's describe these functions separately, starting with rc:
Whatis rc
Rc (8)-command scripts for auto-reboot and daemon startup
These scripts are actually located in/etc/rc; normally, the configuration file located in/etc corresponds to the fifth part of the Manual, so you can modify the configuration file correctly according to the manual. However, if you call:
Man 5 rc
You will get the following information:
No entry for rc in section 5 of the manual
This seems odd for the Part 8 in the manual mentioned above, because it contains system maintenance and operation commands, which are usually background processes. Let's take a further look at this file:
More/etc/rc
# System startup script run by init on autoboot
# Or after single-user.
# Output and error are redirected to console by init,
# And the console is the controlling terminal.
# Note that almost all of the user-Defined able behavior
# Is no longer in # this file, but rather in/etc/defaults/rc. conf.
# Please check that file first before contemplating any changes
# Here. If you do need to change this file for some reason, we
# Woshould like to know about it.
Good, very clear; it seems that we can't mess up the file ourselves. There are some important things that are necessary to guide our system correctly. Let's jump back and look at some important parts to find out what actually happened at startup. Note that when the rc Script is processed during the boot process, init records all output and error messages to the terminal.
One of the first tasks that rc does is to set the PATH variable so that it can find the executable program on your FreeBSD system:
PATH =/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
Then it looks for the/etc/defaults/rc. conf and/etc/rc. conf files:
# If there is a global system configuration file, suck it in.
If [-f/etc/defaults/rc. conf]; then
./Etc/defaults/rc. conf
Elif [-f/etc/rc. conf]; then
./Etc/rc. conf
Fi
Then it performs a file system consistency check. If you shut down the FreeBSD system abnormally, you will see it complaining during the boot process.
Echo Automatic boot in progress...
Fsck-p
Assuming that fsck has no problem, it will immediately load your file system:
# Mount everything snapshot t nfs filesystems.
Mount-a-t nonfs
Before any other process starts, your CMOS clock must be adjusted to an understandable form of kernel clock:
Adjkerntz-I
Then sort out the var directory and write the boot information to dmesg. boot:
Clean_var (){
If [! -F/var/run/clean_var]; then
Rm-rf/var/run /*
Find/var/spool/lock! -Type d-delete
Rm-rf/var/spool/uucp/. Temp /*
# Keep a copy of the boot messages around
Dmesg>/var/run/dmesg. boot
Then rc will read the following files:
/Etc/rc. sysctl
/Etc/rc. serial
/Etc/rc. pccard
/Etc/rc. network
/Etc/rc. network6
Then reset the terminal permission:
# Whack the pty perms back into shape.
Chflags 0/dev/tty [pqrsPQRS] *
Chmod 666/dev/tty [pqrsPQRS] *
Chown root: wheel/dev/tty [pqrsPQRS] *
And clear the "garbage" generated by yourself and the/tmp directory:
# Clean up left-over files
# Clearing/tmp at boot-time seems to have a long tradition. It doesn' t
# Help in any way for long-living systems, and it might accidentally
# Clobber files you wowould rather like to have preserved after a crash
# (If not using mfs/tmp anyway ).
# See also the example of another cleanup policy in/etc/periodic/daily.
# Remove X lock files, since they will prevent you from restarting X11
# After a system crash.
Now rc is ready to start some background processes, including syslogd and named:
# Start system logging and name service. Named needs to start before syslogd
# If you don't have a/etc/resolv. conf.
Then there are inetd, cron, lpd, sendmail, sshd, and usbd:
# Now start up miscellaneous daemons that don't belong anywhere else
Then rc will update motd (daily information) and execute "uname-m". This command will display the schema type on the screen.
(The end of the/etc/rc file)
When it reaches the end of/etc/rc, the rc work is completed. Here, let's review: init calls the rc Script, which reads some global and local configuration files to correctly load the file system and create an environment that can be started by the system background process. Your Operating System is now started and running, but so far, there is no environment in which users can actually interact with the operating system. This is the second important feature of init.
The configuration file/etc/ttys will be read to determine the initialization terminal. Unlike/etc/rc, this file can be frequently edited by super users to ensure that init is used to initialize the desired terminal.
To understand this file, we must understand that there are three types of terminals on your FreeBSD system. Virtual terminals starting with "ttyv" and followed by a number are all terminals that users can obtain physically stored on the FreeBSD system. By default, the first of these virtual terminals, or "ttyv0", indicates the console. A serial line or dial-up terminal starts with "ttyd" and is followed by a number. They are terminals that users can obtain when Remotely accessing your FreeBSD system using a modem. The last terminal type is a Pseudo Terminal or network terminal. They start with "ttyp" and follow a number or letter to access your FreeBSD system through a network connection.
If we use the following command to view this file:
More/etc/ttys
We can see that this file is divided into three parts, each corresponding to these three types of terminals. At the same time, each part is divided into four columns, which are summarized as the following chart:
Column name
Description
Name
Terminal Device Name
Getty
The program that starts running on the terminal, usually getty. Other projects include xdm, which is used to start the X Window System or none, indicating that no program exists.
Type
For virtual terminals, the corresponding type is cons25. Other common values include pseudo-terminal network, modem entry dialup, and unknown, which are used by the user to try to connect to a terminal of an undefined type.
Status
It must be on or off. If it is on, init runs the program specified in the getty column. If the word "secure" appears, it means that the tty can be logged on as root. To avoid this situation, you can use the word "insecure ".
Let's explain the file from the virtual terminal section. We can see that it starts with setting the console:
# If console is marked "insecure", then init will ask
# For the root password when going to single-user mode.
Console none unknown off secure
If a problem occurs when running the fsck command during the boot process, init will enable your FreeBSD system to enter the single-user mode so that the root user can fix the problem. If you use insecure instead of secure to set the console, init will ask for a password before you can continue.
Ttyv0 "/usr/libexec/getty Pc" cons25 on secure
# Virtual terminals
Ttyv1 "/usr/libexec/getty Pc" cons25 on secure
Ttyv2 "/usr/libexec/getty Pc" cons25 on secure
Ttyv3 "/usr/libexec/getty Pc" cons25 on secure
Ttyv4 "/usr/libexec/getty Pc" cons25 on secure
Ttyv5 "/usr/libexec/getty Pc" cons25 on secure
Ttyv6 "/usr/libexec/getty Pc" cons25 on secure
Ttyv7 "/usr/libexec/getty Pc" cons25 on secure
Ttyv8 "/usr/X11R6/bin/xdm-nodaemon" xterm off secure
You can see that there are eight virtual terminals in addition to the console on my FreeBSD system. I can access each terminal by pressing ALT and a control key. For example, ALT F1 can access the console, ALT F2 can access ttyv1, ALT F3 can access ttyv2, and so on. If I start the X session, it can be accessed using ALT F8. If I change the word off on ttyv8 to on, I can get an X terminal instead of the console at boot. Then, you can continue to access other terminals by using ALT and the function key. All of my virtual terminals are labeled as "secure", indicating that they can be logged on as root. The number of virtual terminals you can have is determined by your FreeBSD version. If you want to create more virtual terminals, read this faq.
Now let's move to the dialing terminal:
# Serial terminals
# The 'dialup' keyword identifies dialin lines to login, fingerd etc.
Ttyd0 "/usr/libexec/getty std.9600" dialup off secure
Ttyd1 "/usr/libexec/getty std.9600" dialup off secure
Ttyd2 "/usr/libexec/getty std.9600" dialup off secure
Ttyd3 "/usr/libexec/getty std.9600" dialup off secure
You can see that I have four available dial-up terminals, but they are all disabled.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service