/usr/share/debian-reference/ch03.zh-tw.html is in debian-reference-zh-tw 2.72.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 | <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>第 3 章 系統初始化</title>
<link rel="stylesheet" type="text/css" href="debian-reference.css"/>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="home" href="index.zh-tw.html" title="Debian 參考手冊"/>
<link rel="up" href="index.zh-tw.html" title="Debian 參考手冊"/>
<link rel="prev" href="ch02.zh-tw.html" title="第 2 章 Debian 軟體包管理"/>
<link rel="next" href="ch04.zh-tw.html" title="第 4 章 認證"/>
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">第 3 章 系統初始化</th>
</tr>
<tr>
<td align="left"><a accesskey="p" href="ch02.zh-tw.html"><img src="images/prev.png" alt="上一页"/></a> </td>
<th width="60%" align="center"> </th>
<td align="right"> <a accesskey="n" href="ch04.zh-tw.html"><img src="images/next.png" alt="下一页"/></a></td>
</tr>
</table>
<hr/>
</div>
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a id="_the_system_initialization"/>第 3 章 系統初始化</h1>
</div>
</div>
</div>
<div class="toc">
<p>
<strong>目录</strong>
</p>
<dl class="toc">
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_an_overview_of_the_boot_strap_process">3.1. 啓動過程概述</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_stage_1_the_bios">3.1.1. 第一階段:BIOS</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_stage_2_the_boot_loader">3.1.2. 第二階段:引載加載程序</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_stage_3_the_mini_debian_system">3.1.3. 第三階段:迷你 Debian 系統</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_stage_4_the_normal_debian_system">3.1.4. 第四階段:常規 Debian 系統</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_systemd_init">3.2. Systemd init</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_hostname">3.2.1. 主機名</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_filesystem">3.2.2. 檔案系統</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_network_interface_initialization">3.2.3. 網路介面初始化</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_kernel_message">3.2.4. 核心訊息</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_system_message">3.2.5. 系統訊息</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_system_management_under_systemd">3.2.6. System management under systemd</a>
</span>
</dt>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_customizing_systemd">3.2.7. Customizing systemd</a>
</span>
</dt>
</dl>
</dd>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_udev_system">3.3. udev 系統</a>
</span>
</dt>
<dd>
<dl>
<dt>
<span class="section">
<a href="ch03.zh-tw.html#_the_kernel_module_initialization">3.3.1. 核心模組初始化</a>
</span>
</dt>
</dl>
</dd>
</dl>
</div>
<p>作爲系統管理員,粗略地瞭解 Debian
系統的啓動和配置方式是明智的。儘管準確的細節在安裝的軟件包及對應的文檔中,但這些知識對我們大多數人來說都是必須掌握的。</p>
<p>筆者基於自己和其他人的過往及現在的知識,盡己所能地提供關於 Debian 系統的知識要點及其配置的快速概覽作爲讀者的參考。由於 Debian
系統在不斷地更新中,系統的狀況可能已經有所變化。在對系統做任何修改之前,請參考各個軟件包的最新文檔。</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p><span class="citerefentry"><span class="refentrytitle">bootup</span>(7)</span>
describes the system bootup process based on <code class="literal">systemd</code>
. (Recent Debian)</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p><span class="citerefentry"><span class="refentrytitle">boot</span>(7)</span>
describes the system bootup process based on UNIX System V Release 4. (Older
Debian)</p>
</td>
</tr>
</table>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="_an_overview_of_the_boot_strap_process"/>3.1. 啓動過程概述</h2>
</div>
</div>
</div>
<p>計算機系統從上電事件到能爲用戶提供完整的操作系統(OS)功能爲止,需要經歷幾個階段的<a class="ulink" href="https://zh.wikipedia.org/wiki/Booting">啓動過程</a>。</p>
<p>爲簡便起見,筆者將討論範圍限定在具有默認安裝的典型 PC 平臺上。</p>
<p>典型的啓動過程像是一個四級的火箭。每一級火箭將系統控制權交給下一級。</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
<a class="xref" href="ch03.zh-tw.html#_stage_1_the_bios" title="3.1.1. 第一階段:BIOS">第 3.1.1 节 “第一階段:BIOS”</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="ch03.zh-tw.html#_stage_2_the_boot_loader" title="3.1.2. 第二階段:引載加載程序">第 3.1.2 节 “第二階段:引載加載程序”</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="ch03.zh-tw.html#_stage_3_the_mini_debian_system" title="3.1.3. 第三階段:迷你 Debian 系統">第 3.1.3 节 “第三階段:迷你 Debian 系統”</a>
</p>
</li>
<li class="listitem">
<p>
<a class="xref" href="ch03.zh-tw.html#_stage_4_the_normal_debian_system" title="3.1.4. 第四階段:常規 Debian 系統">第 3.1.4 节 “第四階段:常規 Debian 系統”</a>
</p>
</li>
</ul>
</div>
<p>當然,這些階段可以有不同的配置。比如,你編譯了自己的內核,則可能會跳過迷你 Debian
系統的步驟。因此,在讀者親自確認之前,請勿假定自己系統的情況也是如此。</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[注意]" src="images/note.png"/>
</td>
<th align="left">注意</th>
</tr>
<tr>
<td align="left" valign="top">
<p>對於 SUN 或 Macintosh 系統等非傳統 PC 平臺來說,ROM 上的 BIOS 及磁盤上的分區可能大不相同(<a class="xref" href="ch09.zh-tw.html#_disk_partition_configuration" title="9.5.2. 硬碟分割槽配置">第 9.5.2 节 “硬碟分割槽配置”</a>)。對於這種情況,請另尋對應平臺相關的文檔。</p>
</td>
</tr>
</table>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_stage_1_the_bios"/>3.1.1. 第一階段:BIOS</h3>
</div>
</div>
</div>
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/BIOS">BIOS</a> 是啓動過程的第一階段,在上電事件後開始。CPU
的程序計數器在上電事件後被初始化爲一個特定的內存地址,駐留在<a class="ulink" href="https://zh.wikipedia.org/wiki/Read-only_memory">只讀存儲器(ROM)</a>中的 <a class="ulink" href="https://zh.wikipedia.org/wiki/BIOS">BIOS</a> 就是從這個特定的內存地址開始執行。</p>
<p>BIOS 執行硬件的基本初始化(<a class="ulink" href="https://zh.wikipedia.org/wiki/Power-on_self-test">POST:
上電自檢</a>)並將系統控制權交給你指定的下一步驟。BIOS 通常和硬件一同提供。</p>
<p>BIOS 啓動屏幕通常指示了進入 BIOS 配置界面所需的按鍵。流行的按鍵是 F1、F2、F10、Esc、Ins 和 Del
鍵。假如你的啓動屏幕被一個漂亮的圖形界面隱藏,你可以按下某些按鍵(比如 ESC)取消隱藏。這些按鍵高度依賴於硬件。</p>
<p>硬件位置和 BIOS 啓動的代碼的優先級可以在 BIOS
配置界面中選擇。通常,在已選擇的設備(硬盤、軟件、CD-ROM……)中,最先找到的設備的最開始的幾個扇區將被加載到內存,並執行其中的初始化代碼。初始化代碼可以是以下任意一種。</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
引導加載代碼
</p>
</li>
<li class="listitem">
<p>
類似 <a class="ulink" href="http://www.freedos.org/">FreeDOS</a> 這樣的過濾型操作系統的內核代碼
</p>
</li>
<li class="listitem">
<p>
能夠加載到如此小的空間中的目標操作系統的內核代碼
</p>
</li>
</ul>
</div>
<p>通常,系統從主硬件的特定分區中引導。傳統 PC 硬盤的最開始兩個扇區中包含了<a class="ulink" href="https://zh.wikipedia.org/wiki/Master_boot_record">主引導記錄(MBR)</a>。在 MBR 的末尾記錄了磁盤分區信息及引導選擇。BIOS
中執行的首段引導加載代碼佔據了 MBR 的其餘部分。</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_stage_2_the_boot_loader"/>3.1.2. 第二階段:引載加載程序</h3>
</div>
</div>
</div>
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/Boot_loader">引導加載程序</a>是啓動過程的第二階段,由 BIOS 啓動。引導加載程序將系統內核映像和
<a class="ulink" href="https://zh.wikipedia.org/wiki/Initrd">initrd</a> 映像加載到內存並將控制權交給它們。initrd
映像是根文件系統映像,其支持程度依賴於所使用的引導加載程序。</p>
<p>Debian 系統通常使用 Linux 內核作爲其默認的系統內核。當前 2.6/3.x 版本 Linux 內核的 initrd 映像從技術上說是
initramfs(初始化 RAM 文件系統)映像。initramfs 映像是根文件系統中所有文件的 cpio 歸檔再經過 gzip 壓縮得到。</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[警告]" src="images/warning.png"/>
</td>
<th align="left">警告</th>
</tr>
<tr>
<td align="left" valign="top">
<p>使用新的 multi-segment initramfs 之後,上述內容已不正確。請參見<a class="ulink" href="https://bugs.debian.org/790100">錯誤
#790100</a>。</p>
</td>
</tr>
</table>
</div>
<p>Debian 系統默認將 PC 平臺的 GRUB 引導加載程序的第一階段代碼安裝在 <a class="ulink" href="https://zh.wikipedia.org/wiki/Master_boot_record">MBR</a>
中。可用的引導加載程序和配置選項如下。</p>
<div class="table">
<a id="listofbootloaders"/>
<p class="title">
<strong>表 3.1. 引導加載程序列表</strong>
</p>
<div class="table-contents">
<table class="table" summary="引導加載程序列表" border="1">
<colgroup>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
</colgroup>
<thead>
<tr>
<th style="text-align: left">
軟件包
</th>
<th style="text-align: left">
流行度
</th>
<th style="text-align: left">
大小
</th>
<th style="text-align: left">
initrd
</th>
<th style="text-align: left">
引導加載程序
</th>
<th style="text-align: left">
說明
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/grub-legacy"> grub-legacy
</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=grub-legacy">V:0, I:2</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/g/grub-legacy.html">710</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/GNU_GRUB">傳統 GRUB</a>
</td>
<td style="text-align: left">
可智能識別磁盤分區和文件系統(例如 vfat、ext3…)。
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/grub-pc"> grub-pc </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=grub-pc">V:29, I:849</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/g/grub-pc.html">584</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/GNU_GRUB">GRUB 第 2 版</a>
</td>
<td style="text-align: left">
可智能識別磁盤分區和文件系統(例如 vfat、ext4…)。(默認安裝)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/grub-rescue-pc"> grub-rescue-pc
</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=grub-rescue-pc">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/g/grub-rescue-pc.html">6294</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/GNU_GRUB">GRUB 第 2 版</a>
</td>
<td style="text-align: left">
此爲 GRUB 第 2 版的可引導修復映像(CD 和軟盤)(PC / BIOS 版本)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/lilo"> lilo </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=lilo">V:0, I:3</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/l/lilo.html">693</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/LILO_(boot_loader)">Lilo</a>
</td>
<td style="text-align: left">
依賴於數據在硬盤上的扇區位置。(較老)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/syslinux"> syslinux </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=syslinux">V:5, I:59</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/syslinux.html">299</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/SYSLINUX">Isolinux</a>
</td>
<td style="text-align: left">
可識別 ISO9660 文件系統。引導 CD 使用此項。
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/syslinux"> syslinux </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=syslinux">V:5, I:59</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/syslinux.html">299</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/SYSLINUX">Syslinux</a>
</td>
<td style="text-align: left">
可識別 <a class="ulink" href="https://zh.wikipedia.org/wiki/File_Allocation_Table">MSDOS 文件系統(FAT)</a>。引導軟盤使用此項。
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/loadlin"> loadlin </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=loadlin">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/l/loadlin.html">84</a>
</td>
<td style="text-align: left">
支持
</td>
<td style="text-align: left">
<a class="ulink" href="https://zh.wikipedia.org/wiki/Loadlin">Loadlin</a>
</td>
<td style="text-align: left">
新系統從 FreeDOS 或 MSDOS 中啓動。
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/mbr"> mbr </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=mbr">V:0, I:10</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/m/mbr.html">50</a>
</td>
<td style="text-align: left">
不支持
</td>
<td style="text-align: left">
<a class="ulink" href="http://www.chiark.greenend.org.uk/~neilt/">Neil Turton 的 MBR</a>
</td>
<td style="text-align: left">
此爲取代 MSDOS <a class="ulink" href="https://zh.wikipedia.org/wiki/Master_boot_record">MBR</a> 的自由軟件。只可識別硬盤分區。
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[警告]" src="images/warning.png"/>
</td>
<th align="left">警告</th>
</tr>
<tr>
<td align="left" valign="top">
<p>Do not play with boot loaders without having bootable rescue media (USB
memory stick, CD or floppy) created from images in the
<code class="literal">grub-rescue-pc</code> package. It makes you boot your system
even without functioning bootloader on the hard disk.</p>
</td>
</tr>
</table>
</div>
<p>傳統 GRUB 的菜單配置文件位於 <code class="literal">/boot/grub/menu.lst</code>。例如,文件中有如下的配置條目。</p>
<pre class="screen">title Debian GNU/Linux
root (hd0,2)
kernel /vmlinuz root=/dev/hda3 ro
initrd /initrd.img</pre>
<p>GRUB 第 2 版的菜單配置文件位於 <code class="literal">/boot/grub/grub.cfg</code>。此文件由
<code class="literal">/usr/sbin/update-grub</code> 根據
"<code class="literal">/etc/grub.d/*</code>" 中的模板及
"<code class="literal">/etc/default/grub</code>" 中的設置自動生成。例如,文件中有如下的配置條目。</p>
<pre class="screen">menuentry "Debian GNU/Linux" {
set root=(hd0,3)
linux /vmlinuz root=/dev/hda3
initrd /initrd.img
}</pre>
<p>這些示例中,GRUB 參數的含義如下。</p>
<div class="table">
<a id="themeaningofgrubparameters"/>
<p class="title">
<strong>表 3.2. GRUB 參數的含義</strong>
</p>
<div class="table-contents">
<table class="table" summary="GRUB 參數的含義" border="1">
<colgroup>
<col style="text-align: left"/>
<col style="text-align: left"/>
</colgroup>
<thead>
<tr>
<th style="text-align: left">
GRUB 參數
</th>
<th style="text-align: left">
說明
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<code class="literal">root</code>
</td>
<td style="text-align: left">
使用主磁盤的第 3 個分區,在傳統 GRUB 中將此參數設置爲 "<code class="literal">(hd0,2)</code>",在 GRUB 第 2
版中將此參數設置爲 "<code class="literal">(hd0,3)</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
<code class="literal">kernel</code>
</td>
<td style="text-align: left">
使用位於 "<code class="literal">/vmlinuz</code>" 的內核,同時將 "<code class="literal">root=/dev/hda3
ro</code>" 作爲參數傳遞給內核
</td>
</tr>
<tr>
<td style="text-align: left">
<code class="literal">initrd</code>
</td>
<td style="text-align: left">
使用 <a class="ulink" href="https://zh.wikipedia.org/wiki/Initrd">initrd/initramfs</a> 映像,其位於
"<code class="literal">/initrd.img</code>"
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[注意]" src="images/note.png"/>
</td>
<th align="left">注意</th>
</tr>
<tr>
<td align="left" valign="top">
<p>傳統 GRUB 使用的分區號爲 Linux 內核及各種實用工具使用的分區號減 1。GRUB 第 2 版修復了這個問題。</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>在標識一個塊設備時,可能需要使用 <a class="ulink" href="https://zh.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</a>(參見<a class="xref" href="ch09.zh-tw.html#_accessing_partition_using_uuid" title="9.5.3. 使用 UUID 訪問分割槽">第 9.5.3 节 “使用 UUID 訪問分割槽”</a>)而不是類似
"<code class="literal">/dev/hda3</code>" 這樣的文件名,例如
"<code class="literal">root=UUID=81b289d5-4341-4003-9602-e254a17ac232 ro</code>"。</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>如果使用了 <a class="ulink" href="https://zh.wikipedia.org/wiki/GNU_GRUB">GRUB</a>,內核的啓動參數可以在
<code class="literal">/boot/grub/grub.cfg</code> 裏面設置。在 Debian 系統裏,你不應該直接編輯
<code class="literal">/boot/grub/grub.cfg</code>。你可以通過編輯
<code class="literal">/etc/default/grub</code> 文件中
<code class="literal">GRUB_CMDLINE_LINUX_DEFAULT</code> 的值並運行
<span class="citerefentry"><span class="refentrytitle">update-grub</span>(8)</span>
來更新 <code class="literal">/boot/grub/grub.cfg</code>。</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>通過使用<a class="ulink" href="https://zh.wikipedia.org/wiki/Chain_loading">鏈式引導</a>技術,你可以在一個引導裝載程序中啓動另一個引導裝載程序。</p>
</td>
</tr>
</table>
</div>
<p>參見 “<code class="literal">info grub</code>” 及
<span class="citerefentry"><span class="refentrytitle">grub-install</span>(8)</span>。</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_stage_3_the_mini_debian_system"/>3.1.3. 第三階段:迷你 Debian 系統</h3>
</div>
</div>
</div>
<p>迷你 Debian 系統是啓動流程的第三階段,由引導加載程序啓動。它會在內存中運行系統內核和根文件系統。這是啓動流程的一個可選準備階段。</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[注意]" src="images/note.png"/>
</td>
<th align="left">注意</th>
</tr>
<tr>
<td align="left" valign="top">
<p>“迷你 Debian 系統”是筆者自創的術語,用於在本文檔中描述啓動流程的第三個階段。這個系統通常被稱爲 <a class="ulink" href="https://zh.wikipedia.org/wiki/Initrd">initrd</a> 或 initramfs 系統。內存中類似的系統在 <a class="ulink" href="https://www.debian.org/devel/debian-installer/">Debian 安裝程序</a>中使用。</p>
</td>
</tr>
</table>
</div>
<p>The "<code class="literal">/init</code>" program is executed as the first program in
this root filesystem on the memory. It is a program which initializes the
kernel in user space and hands control over to the next stage. This
mini-Debian system offers flexibility to the boot process such as adding
kernel modules before the main boot process or mounting the root filesystem
as an encrypted one.</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
The "<code class="literal">/init</code>" program is a shell script program if
initramfs was created by <code class="literal">initramfs-tools</code>. <span class="strong"><strong> You can interrupt this part of the boot process to gain root
shell by providing "<code class="literal">break=init</code>" etc. to the kernel boot
parameter. See the "<code class="literal">/init</code>" script for more break
conditions. This shell environment is sophisticated enough to make a good
inspection of your machine's hardware. </strong></span> Commands available in
this mini-Debian system are stripped down ones and mainly provided by a GNU
tool called
<span class="citerefentry"><span class="refentrytitle">busybox</span>(1)</span>.
</p>
</li>
<li class="listitem">
<p>
The "<code class="literal">/init</code>" program is a binary
<code class="literal">systemd</code> program if initramfs was created by
<code class="literal">dracut</code>. ** Commands available in this mini-Debian system
are stripped down
<span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span>
environment.
</p>
</li>
</ul>
</div>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[小心]" src="images/caution.png"/>
</td>
<th align="left">小心</th>
</tr>
<tr>
<td align="left" valign="top">
<p>當在一個只讀的根文件系統上時,使用 <code class="literal">mount</code> 命令需要添加 <code class="literal">-n</code> 選項。</p>
</td>
</tr>
</table>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_stage_4_the_normal_debian_system"/>3.1.4. 第四階段:常規 Debian 系統</h3>
</div>
</div>
</div>
<p>常規 Debian 系統是啓動流程的第四階段,由迷你 Debian 系統啓動。迷你 Debian
系統的內核在此環境下繼續運行。根文件系統將由內存切換到實際的硬盤文件系統上。</p>
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/Init">init</a> 程序是系統執行的第一個程序(PID=1),它啓動其它各種程序以完成主引導流程。init
程序的默認路徑是 ”<code class="literal">/sbin/init</code>“,但可通過內核啓動參數修改,例如
”<code class="literal">init=/path/to/init_program</code>"。</p>
<p>默認的 init 程序一直在變化中:</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
<code class="literal">squeeze</code> 之前的 Debian,使用簡單的 <a class="ulink" href="https://zh.wikipedia.org/wiki/UNIX_System_V">SysV</a>
風格的 init。
</p>
</li>
<li class="listitem">
<p>
<code class="literal">wheezy</code> 版本的 Debian 對 SysV 風格的 init 做了改進:使用 LSB
頭將啓動步驟排序,同時並行執行啓動腳本。
</p>
</li>
<li class="listitem">
<p>
<code class="literal">jessie</code>版本的 Debian 將默認 init 切換成 <a class="ulink" href="https://zh.wikipedia.org/wiki/Systemd">systemd</a>,以使用事件驅動和並行初始化。
</p>
</li>
</ul>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>你的系統中實際使用的 init 命令可以使用 “<code class="literal">ps --pid 1 -f</code>” 命令確認。</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>"<code class="literal">/sbin/init</code>" is symlinked to
"<code class="literal">/lib/systemd/systemd</code>" after Debian
<code class="literal">jessie</code>.</p>
</td>
</tr>
</table>
</div>
<div class="table">
<a id="listofbootutilitrthedebiansystem"/>
<p class="title">
<strong>表 3.3. Debian 系統啓動工具列表</strong>
</p>
<div class="table-contents">
<table class="table" summary="Debian 系統啓動工具列表" border="1">
<colgroup>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
</colgroup>
<thead>
<tr>
<th style="text-align: left">
軟件包
</th>
<th style="text-align: left">
流行度
</th>
<th style="text-align: left">
大小
</th>
<th style="text-align: left">
說明
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/systemd">
<code class="literal">systemd</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=systemd">V:703, I:805</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/systemd.html">11933</a>
</td>
<td style="text-align: left">
基於事件且支持並發的
<span class="citerefentry"><span class="refentrytitle">init</span>(8)</span>
守護進程(可替代 <code class="literal">sysvinit</code>)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/systemd-sysv">
<code class="literal">systemd-sysv</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=systemd-sysv">V:684, I:798</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/systemd-sysv.html">112</a>
</td>
<td style="text-align: left">
the manual pages and links needed for <code class="literal">systemd</code> to replace
<code class="literal">sysvinit</code>
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/systemd-cron">
<code class="literal">systemd-cron</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=systemd-cron">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/systemd-cron.html">133</a>
</td>
<td style="text-align: left"><code class="literal">systemd</code> units to provide <code class="literal">cron</code> daemon
and <code class="literal">anacron</code> functionality
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/init-system-helpers">
<code class="literal">init-system-helpers</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=init-system-helpers">V:704, I:826</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/i/init-system-helpers.html">129</a>
</td>
<td style="text-align: left">
helper tools for switching between <code class="literal">sysvinit</code> and
<code class="literal">systemd</code>
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/initscripts">
<code class="literal">initscripts</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=initscripts">V:284, I:667</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/i/initscripts.html">205</a>
</td>
<td style="text-align: left">
用於初始化和關閉系統的腳本
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/sysvinit-core">
<code class="literal">sysvinit-core</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=sysvinit-core">V:13, I:17</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/sysvinit-core.html">225</a>
</td>
<td style="text-align: left">
類 System V 的
<span class="citerefentry"><span class="refentrytitle">init</span>(8)</span>
工具
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/sysv-rc">
<code class="literal">sysv-rc</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=sysv-rc">V:477, I:673</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/sysv-rc.html">123</a>
</td>
<td style="text-align: left">
類 System V 的運行級別修改機制
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/sysvinit-utils">
<code class="literal">sysvinit-utils</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=sysvinit-utils">V:791, I:999</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/sysvinit-utils.html">110</a>
</td>
<td style="text-align: left">
類 System V
的實用工具(<span class="citerefentry"><span class="refentrytitle">startpar</span>(8)</span>,<span class="citerefentry"><span class="refentrytitle">bootlogd</span>(8)</span>,……)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/lsb-base">
<code class="literal">lsb-base</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=lsb-base">V:877, I:999</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/l/lsb-base.html">49</a>
</td>
<td style="text-align: left"><a class="ulink" href="https://zh.wikipedia.org/wiki/Linux_Standard_Base">Linux 標準規範</a> 3.2 版的 init 腳本功能
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/insserv">
<code class="literal">insserv</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=insserv">V:539, I:660</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/i/insserv.html">140</a>
</td>
<td style="text-align: left">
利用 LSB init.d 腳本依賴性來組織啓動步驟的工具
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/uswsusp">
<code class="literal">uswsusp</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=uswsusp">V:4, I:11</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/u/uswsusp.html">699</a>
</td>
<td style="text-align: left">
使用 Linux 提供的使用者態軟體 suspend 的工具
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/kexec-tools">
<code class="literal">kexec-tools</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=kexec-tools">V:1, I:8</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/k/kexec-tools.html">270</a>
</td>
<td style="text-align: left">
用於
<span class="citerefentry"><span class="refentrytitle">kexec</span>(8)</span>
重啟(熱啟動)的 kexec 工具
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/systemd-bootchart">
<code class="literal">systemd-bootchart</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=systemd-bootchart">V:0, I:0</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/s/systemd-bootchart.html">122</a>
</td>
<td style="text-align: left">
啟動流程效能分析器
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/bootchart2">
<code class="literal">bootchart2</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=bootchart2">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/b/bootchart2.html">94</a>
</td>
<td style="text-align: left">
啟動流程效能分析器
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/pybootchartgui">
<code class="literal">pybootchartgui</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=pybootchartgui">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/p/pybootchartgui.html">177</a>
</td>
<td style="text-align: left">
啟動流程效能分析器(視覺化)
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/mingetty">
<code class="literal">mingetty</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=mingetty">V:0, I:3</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/m/mingetty.html">35</a>
</td>
<td style="text-align: left">
僅包含控制檯的
<span class="citerefentry"><span class="refentrytitle">getty</span>(8)</span>
</td>
</tr>
<tr>
<td style="text-align: left">
<a class="ulink" href="http://packages.debian.org/sid/mgetty">
<code class="literal">mgetty</code> </a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://qa.debian.org/popcon.php?package=mgetty">V:0, I:1</a>
</td>
<td style="text-align: left">
<a class="ulink" href="http://packages.qa.debian.org/m/mgetty.html">301</a>
</td>
<td style="text-align: left">
可智慧調製解調的
<span class="citerefentry"><span class="refentrytitle">getty</span>(8)</span>
替代品
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>有關啟動流程加速的最新資訊,請參見 <a class="ulink" href="https://wiki.debian.org/BootProcessSpeedup">Debian
維基:啟動流程加速</a>詞條。</p>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="_systemd_init"/>3.2. Systemd init</h2>
</div>
</div>
</div>
<p>This section describes how system is started by the
<span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span>
program with <code class="literal">PID=1</code> (i.e., init process).</p>
<p>The <code class="literal">systemd</code> init process spawns processes in parallel
based on the unit configuration files (see
<span class="citerefentry"><span class="refentrytitle">systemd.unit</span>(5)</span>)
which are written in declarative style instead of SysV-like procedural
style. These are loaded from a set of paths (see
<span class="citerefentry"><span class="refentrytitle">systemd-system.conf</span>(5)</span>)
as follows:</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
"<code class="literal">/lib/systemd/system</code>": OS default configuration files
</p>
</li>
<li class="listitem">
<p>
"<code class="literal">/etc/systemd/system</code>": system administrator configuration
files which override the OS default configuration files
</p>
</li>
<li class="listitem">
<p>
"<code class="literal">/run/systemd/system</code>": run-time generated configuration
files which override the installed configuration files
</p>
</li>
</ul>
</div>
<p>Their inter-dependencies are specified by the directives
"<code class="literal">Wants=</code>", "<code class="literal">Requires=</code>",
"<code class="literal">Before=</code>", "<code class="literal">After=</code>", … (see "MAPPING
OF UNIT PROPERTIES TO THEIR INVERSES" in
<span class="citerefentry"><span class="refentrytitle">systemd.unit</span>(5)</span>).
The resource controls are also defined (see
<span class="citerefentry"><span class="refentrytitle">systemd.resource-control</span>(5)</span>).</p>
<p>The suffix of the unit configuration file encodes their types as:</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p><span class="strong"><strong>*.service</strong></span> describes the process
controlled and supervised by <code class="literal">systemd</code>. See
<span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.device</strong></span> describes the device exposed in
the
<span class="citerefentry"><span class="refentrytitle">sysfs</span>(5)</span>
as
<span class="citerefentry"><span class="refentrytitle">udev</span>(7)</span>
device tree. See
<span class="citerefentry"><span class="refentrytitle">systemd.device</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.mount</strong></span> describes the file system mount
point controlled and supervised by <code class="literal">systemd</code>. See
<span class="citerefentry"><span class="refentrytitle">systemd.mount</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.automount</strong></span> describes the file system
auto mount point controlled and supervised by
<code class="literal">systemd</code>. See
<span class="citerefentry"><span class="refentrytitle">systemd.automount</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.swap</strong></span> describes the swap device or file
controlled and supervised by <code class="literal">systemd</code>. See
<span class="citerefentry"><span class="refentrytitle">systemd.swap</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.path</strong></span> describes the path monitored by
<code class="literal">systemd</code> for path-based activation. See
<span class="citerefentry"><span class="refentrytitle">systemd.path</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.socket</strong></span> describes the socket controlled
and supervised by <code class="literal">systemd</code> for socket-based
activation. See
<span class="citerefentry"><span class="refentrytitle">systemd.socket</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.timer</strong></span> describes the timer controlled
and supervised by <code class="literal">systemd</code> for timer-based activation. See
<span class="citerefentry"><span class="refentrytitle">systemd.timer</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.slice</strong></span> manages resources with the
<span class="citerefentry"><span class="refentrytitle">cgroups</span>(7)</span>.
See
<span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.scope</strong></span> is created programmatically using
the bus interfaces of <code class="literal">systemd</code> to manages a set of system
processes. See
<span class="citerefentry"><span class="refentrytitle">systemd.scope</span>(5)</span>.
</p>
</li>
<li class="listitem">
<p><span class="strong"><strong>*.target</strong></span> groups other unit configuration
files to create the synchronization point during start-up. See
<span class="citerefentry"><span class="refentrytitle">systemd.target</span>(5)</span>.
</p>
</li>
</ul>
</div>
<p>Upon system start up (i.e., init), the <code class="literal">systemd</code> process
tries to start the "<code class="literal">/lib/systemd/system/default.target</code>
(normally symlinked to "<code class="literal">graphical.target</code>"). First, some
special target units (see
<span class="citerefentry"><span class="refentrytitle">systemd.special</span>(7)</span>)
such as "<code class="literal">local-fs.target</code>",
"<code class="literal">swap.target</code>" and "<code class="literal">cryptsetup.target</code>"
are pulled in to mount the filesystems. Then, other target units are also
pulled in by the target unit dependencies. For details, read
<span class="citerefentry"><span class="refentrytitle">bootup</span>(7)</span>.</p>
<p><code class="literal">systemd</code> offers backward compatibility features.
SysV-style boot scripts in
"<code class="literal">/etc/init.d/rc[0123456S].d/[KS]<name></code>" are still
parsed and
<span class="citerefentry"><span class="refentrytitle">telinit</span>(8)</span>
is translated into systemd unit activation requests.</p>
<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[小心]" src="images/caution.png"/>
</td>
<th align="left">小心</th>
</tr>
<tr>
<td align="left" valign="top">
<p>Emulated runlevel 2 to 4 are all symlinked to the same
"<code class="literal">multi-user.target</code>".</p>
</td>
</tr>
</table>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_the_hostname"/>3.2.1. 主機名</h3>
</div>
</div>
</div>
<p>The kernel maintains the system <span class="strong"><strong>hostname</strong></span>. The system unit started by
<code class="literal">systemd-hostnamed.service</code> sets the system hostname at
boot time to the name stored in "<code class="literal">/etc/hostname</code>". This
file should contain <span class="strong"><strong>only</strong></span> the system
hostname, not a fully qualified domain name.</p>
<p>不帶引數執行
<span class="citerefentry"><span class="refentrytitle">hostname</span>(1)</span>
命令可以打印出當前的主機名。</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_the_filesystem"/>3.2.2. 檔案系統</h3>
</div>
</div>
</div>
<p>The mount options of normal disk and network filesystems are set in
"<code class="literal">/etc/fstab</code>". See
<span class="citerefentry"><span class="refentrytitle">fstab</span>(5)</span>
and <a class="xref" href="ch09.zh-tw.html#_optimization_of_filesystem_by_mount_options" title="9.5.7. 通過掛載選項優化檔案系統">第 9.5.7 节 “通過掛載選項優化檔案系統”</a>.</p>
<p>The configuration of the encrypted filesystem is set in
"<code class="literal">/etc/crypttab</code>". See
<span class="citerefentry"><span class="refentrytitle">crypttab</span>(5)</span></p>
<p>The configuration of software RAID with
<span class="citerefentry"><span class="refentrytitle">mdadm</span>(8)</span>
is set in "<code class="literal">/etc/mdadm/mdadm.conf</code>". See
<span class="citerefentry"><span class="refentrytitle">mdadm.conf</span>(5)</span>.</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[警告]" src="images/warning.png"/>
</td>
<th align="left">警告</th>
</tr>
<tr>
<td align="left" valign="top">
<p>每次啟動的時候,在掛載了所有檔案系統以後,"<code class="literal">/tmp</code>",
"<code class="literal">/var/lock</code>", 和 "<code class="literal">/var/run</code>" 中的臨時檔案會被清空。</p>
</td>
</tr>
</table>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_network_interface_initialization"/>3.2.3. 網路介面初始化</h3>
</div>
</div>
</div>
<p>Network interfaces are typically initialized in
"<code class="literal">networking.service</code>" for the <code class="literal">lo</code>
interface and "<code class="literal">NetworkManager.service</code>" for other
interfaces on modern Debian desktop system under <code class="literal">systemd</code>.</p>
<p>See <a class="xref" href="ch05.zh-tw.html" title="第 5 章 網絡設置">第 5 章 <em>網絡設置</em></a> for how to configure them.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_the_kernel_message"/>3.2.4. 核心訊息</h3>
</div>
</div>
</div>
<p>The kernel error message displayed to the console can be configured by
setting its threshold level.</p>
<pre class="screen"># dmesg -n3</pre>
<div class="table">
<a id="listofkernelerrorlevels"/>
<p class="title">
<strong>表 3.4. 核心錯誤級別表</strong>
</p>
<div class="table-contents">
<table class="table" summary="核心錯誤級別表" border="1">
<colgroup>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
</colgroup>
<thead>
<tr>
<th style="text-align: left">
錯誤級別值
</th>
<th style="text-align: left">
錯誤級別名稱
</th>
<th style="text-align: left">
說明
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
0
</td>
<td style="text-align: left">
KERN_EMERG
</td>
<td style="text-align: left">
系統不可用
</td>
</tr>
<tr>
<td style="text-align: left">
1
</td>
<td style="text-align: left">
KERN_ALERT
</td>
<td style="text-align: left">
行為必須被立即採取
</td>
</tr>
<tr>
<td style="text-align: left">
2
</td>
<td style="text-align: left">
KERN_CRIT
</td>
<td style="text-align: left">
危險條件
</td>
</tr>
<tr>
<td style="text-align: left">
3
</td>
<td style="text-align: left">
KERN_ERR
</td>
<td style="text-align: left">
錯誤條件
</td>
</tr>
<tr>
<td style="text-align: left">
4
</td>
<td style="text-align: left">
KERN_WARNING
</td>
<td style="text-align: left">
警告條件
</td>
</tr>
<tr>
<td style="text-align: left">
5
</td>
<td style="text-align: left">
KERN_NOTICE
</td>
<td style="text-align: left">
普通但重要的條件
</td>
</tr>
<tr>
<td style="text-align: left">
6
</td>
<td style="text-align: left">
KERN_INFO
</td>
<td style="text-align: left">
資訊提示
</td>
</tr>
<tr>
<td style="text-align: left">
7
</td>
<td style="text-align: left">
KERN_DEBUG
</td>
<td style="text-align: left">
debug 級別的資訊
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_the_system_message"/>3.2.5. 系統訊息</h3>
</div>
</div>
</div>
<p>Under <code class="literal">systemd</code>, both kernel and system messages are logged
by the journal service <code class="literal">systemd-journald.service</code> (a.k.a
<code class="literal">journald</code>) either into a persistent binary data below
"<code class="literal">/var/log/journal</code>" or into a volatile binary data below
"<code class="literal">/run/log/journal/</code>". These binary log data are accessed
by the
<span class="citerefentry"><span class="refentrytitle">journalctl</span>(1)</span>
command.</p>
<p>Under <code class="literal">systemd</code>, the system logging utility
<span class="citerefentry"><span class="refentrytitle">rsyslogd</span>(8)</span>
changes its behavior to read the volatile binary log data (instead of
pre-systemd default "<code class="literal">/dev/log</code>") and to create traditional
permanent ASCII system log data.</p>
<p>"<code class="literal">/etc/default/rsyslog</code>" 和
"<code class="literal">/etc/rsyslog.conf</code>" 能夠自定義系統訊息的日誌檔案和螢幕顯示。參見
<span class="citerefentry"><span class="refentrytitle">rsyslogd</span>(8)</span>
和
<span class="citerefentry"><span class="refentrytitle">rsyslog.conf</span>(5)</span>,也可以參見<a class="xref" href="ch09.zh-tw.html#_log_analyzer" title="9.2.2. 日誌分析">第 9.2.2 节 “日誌分析”</a>。</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_system_management_under_systemd"/>3.2.6. System management under systemd</h3>
</div>
</div>
</div>
<p>The <code class="literal">systemd</code> offers not only init system but also generic
system management functionalities such as journal logging, login management,
time management, network management. etc..</p>
<p>The
<span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span>
is managed by several commands:</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
the
<span class="citerefentry"><span class="refentrytitle">systemctl</span>(1)</span>
command controls the <code class="literal">systemd</code> system and service manager
(CLI),
</p>
</li>
<li class="listitem">
<p>
the
<span class="citerefentry"><span class="refentrytitle">systemsdm</span>(1)</span>
command controls the <code class="literal">systemd</code> system and service manager
(GUI),
</p>
</li>
<li class="listitem">
<p>
the
<span class="citerefentry"><span class="refentrytitle">journalctl</span>(1)</span>
command queries the <code class="literal">systemd</code> journal,
</p>
</li>
<li class="listitem">
<p>
the
<span class="citerefentry"><span class="refentrytitle">loginctl</span>(1)</span>
command controls the <code class="literal">systemd</code> login manager, and
</p>
</li>
<li class="listitem">
<p>
the
<span class="citerefentry"><span class="refentrytitle">systemd-analyze</span>(1)</span>
analyzes system boot-up performance.
</p>
</li>
</ul>
</div>
<p>Here are a list of typical <code class="literal">systemd</code> management command
snippets. For the exact meanings, please read the pertinent manpages.</p>
<div class="table">
<a id="listoftypicalsystcommandsnippets"/>
<p class="title">
<strong>表 3.5. List of typical <code class="literal">systemd</code> management command snippets</strong>
</p>
<div class="table-contents">
<table class="table" summary="List of typical systemd management command snippets" border="1">
<colgroup>
<col style="text-align: left"/>
<col style="text-align: left"/>
<col style="text-align: left"/>
</colgroup>
<thead>
<tr>
<th style="text-align: left">
Operation
</th>
<th style="text-align: left">
Type
</th>
<th style="text-align: left">
Command snippets
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
GUI for service manager
</td>
<td style="text-align: left">
GUI
</td>
<td style="text-align: left">
"<code class="literal">systemadm</code>" (<code class="literal">systemd-ui</code> package)
</td>
</tr>
<tr>
<td style="text-align: left">
List all target unit configuration
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-units --type=target</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List all service unit configuration
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-units --type=service</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List all unit configuration types
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-units --type=help</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List all socket units in memory
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-sockets</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List all timer units in memory
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-timers</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Start "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl start $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Stop "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl stop $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Reload service-specific configuration
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl reload $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Stop and start all "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl restart $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Start "<code class="literal">$unit</code>" and stop all others
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl isolate $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Switch to "<code class="literal">graphical</code>" (GUI system)
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl isolate graphical</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Switch to "<code class="literal">multi-user</code>" (CLI system)
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl isolate multi-user</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Switch to "<code class="literal">rescue</code>" (single user CLI system)
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl isolate rescue</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Send kill signal to "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl kill $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Send kill signal to "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl kill $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Check if "<code class="literal">$unit</code>" service is active
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl is-active $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Check if "<code class="literal">$unit</code>" service is failed
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl is-failed $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Check status of "<code class="literal">$unit|$PID|device</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl status $unit|$PID|$device</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Show properties of "<code class="literal">$unit|$job</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl show $unit|$job</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Reset failed "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl reset-failed $unit"</code>
</td>
</tr>
<tr>
<td style="text-align: left">
List dependency of all unit services
</td>
<td style="text-align: left">
Unit
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-dependencies --all</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List unit files installed on the system
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl list-unit-files</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Enable "<code class="literal">$unit</code>" (add symlink)
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl enable $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Disable "<code class="literal">$unit</code>" (remove symlink)
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl disable $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Unmask "<code class="literal">$unit</code>" (remove symlink to
"<code class="literal">/dev/null</code>")
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl unmask $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Mask "<code class="literal">$unit</code>" (add symlink to
"<code class="literal">/dev/null</code>")
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl mask $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Get default-target setting
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl get-default</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Set default-target to "<code class="literal">graphical</code>" (GUI system)
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl set-default graphical</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Set default-target to "<code class="literal">multi-user</code>" (CLI system)
</td>
<td style="text-align: left">
Unit file
</td>
<td style="text-align: left">
"<code class="literal">systemctl set-default multi-user</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Show job environment
</td>
<td style="text-align: left">
Environment
</td>
<td style="text-align: left">
"<code class="literal">systemctl show-environment</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Set job environment "<code class="literal">variable</code>" to
"<code class="literal">value</code>"
</td>
<td style="text-align: left">
Environment
</td>
<td style="text-align: left">
"<code class="literal">systemctl set-environment variable=value</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Unset job environment "<code class="literal">variable</code>"
</td>
<td style="text-align: left">
Environment
</td>
<td style="text-align: left">
"<code class="literal">systemctl unset-environment variable</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Reload all unit files and daemons
</td>
<td style="text-align: left">
Lifecycle
</td>
<td style="text-align: left">
"<code class="literal">systemctl daemon-reload</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Shut down the system
</td>
<td style="text-align: left">
System
</td>
<td style="text-align: left">
"<code class="literal">systemctl poweroff</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Shut down and reboot the system
</td>
<td style="text-align: left">
System
</td>
<td style="text-align: left">
"<code class="literal">systemctl reboot</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Suspend the system
</td>
<td style="text-align: left">
System
</td>
<td style="text-align: left">
"<code class="literal">systemctl suspend</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Hibernate the system
</td>
<td style="text-align: left">
System
</td>
<td style="text-align: left">
"<code class="literal">systemctl hibernate</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
View job log of "<code class="literal">$unit</code>"
</td>
<td style="text-align: left">
Journal
</td>
<td style="text-align: left">
"<code class="literal">journalctl -u $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
View job log of "<code class="literal">$unit</code>" ("<code class="literal">tail -f</code>"
style)
</td>
<td style="text-align: left">
Journal
</td>
<td style="text-align: left">
"<code class="literal">journalctl -u $unit -f</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Show time spent for each initialization steps
</td>
<td style="text-align: left">
Analyze
</td>
<td style="text-align: left">
"<code class="literal">systemd-analyze time</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
List of all units by the time to initialize
</td>
<td style="text-align: left">
Analyze
</td>
<td style="text-align: left">
"<code class="literal">systemd-analyze blame</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Load and detect errors in "<code class="literal">$unit</code>" file
</td>
<td style="text-align: left">
Analyze
</td>
<td style="text-align: left">
"<code class="literal">systemd-analyze verify $unit</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Track boot process by the
<span class="citerefentry"><span class="refentrytitle">cgroups</span>(7)</span>
</td>
<td style="text-align: left">
Cgroup
</td>
<td style="text-align: left">
"<code class="literal">systemd-cgls</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Track boot process by the
<span class="citerefentry"><span class="refentrytitle">cgroups</span>(7)</span>
</td>
<td style="text-align: left">
Cgroup
</td>
<td style="text-align: left">
"<code class="literal">ps xawf -eo pid,user,cgroup,args</code>"
</td>
</tr>
<tr>
<td style="text-align: left">
Track boot process by the
<span class="citerefentry"><span class="refentrytitle">cgroups</span>(7)</span>
</td>
<td style="text-align: left">
Cgroup
</td>
<td style="text-align: left">
Read <a class="ulink" href="https://zh.wikipedia.org/wiki/Sysfs">sysfs</a> under
"<code class="literal">/sys/fs/cgroup/systemd/</code>"
</td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="table-break"/>
<p>Here, "<code class="literal">$unit</code>" in the above examples may be a single unit
name (suffix such as <code class="literal">.service</code> and
<code class="literal">.target</code> are optional) or, in many cases, multiple unit
specifications (shell-style globs "<code class="literal">*</code>",
"<code class="literal">?</code>", "<code class="literal">[]</code>" using
<span class="citerefentry"><span class="refentrytitle">fnmatch</span>(3)</span>
which will be matched against the primary names of all units currently in
memory).</p>
<p>System state changing commands in the above examples are typically preceded
by the "<code class="literal">sudo</code>" to attain the required administrative
privilege.</p>
<p>The output of the "<code class="literal">systemctl status $unit|$PID|$device</code>"
uses color of the dot ("●") to summarize the unit state at a glance.</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>
White "●" indicates an "inactive" or "deactivating" state.
</p>
</li>
<li class="listitem">
<p>
Red "●" indicates a "failed" or "error" state.
</p>
</li>
<li class="listitem">
<p>
Green "●" indicates an "active", "reloading" or "activating" state.
</p>
</li>
</ul>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_customizing_systemd"/>3.2.7. Customizing systemd</h3>
</div>
</div>
</div>
<p>With default installation, many network services (see <a class="xref" href="ch06.zh-tw.html" title="第 6 章 網路應用">第 6 章 <em>網路應用</em></a>) are started as daemon processes after
<code class="literal">network.target</code> at boot time by
<code class="literal">systemd</code>. The "<code class="literal">sshd</code>" is no exception.
Let's change this to on-demand start of "<code class="literal">sshd</code>" as a
customization example.</p>
<p>First, disable system installed service unit.</p>
<pre class="screen"> $ sudo systemctl stop sshd.service
$ sudo systemctl mask sshd.service</pre>
<p>The on-demand socket activation system of the classic Unix services was
through the <code class="literal">indetd</code> superserver. Under
<code class="literal">systemd</code>, the equivalent can be enabled by adding
<span class="strong"><strong>*.socket</strong></span> and <span class="strong"><strong>*.service</strong></span> unit configuration files.</p>
<p><code class="literal">sshd.socket</code> for specifying a socket to listen on</p>
<pre class="screen">[Unit]
Description=SSH Socket for Per-Connection Servers
[Socket]
ListenStream=22
Accept=yes
[Install]
WantedBy=sockets.target</pre>
<p><code class="literal">sshd@.service</code> as the matching service file of
<code class="literal">sshd.socket</code></p>
<pre class="screen">[Unit]
Description=SSH Per-Connection Server
[Service]
ExecStart=-/usr/sbin/sshd -i
StandardInput=socket</pre>
<p>Then reload.</p>
<pre class="screen"> $ sudo systemctl daemon-reload</pre>
</div>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="_the_udev_system"/>3.3. udev 系統</h2>
</div>
</div>
</div>
<p>Linux 核心 2.6 和更新的核心,<a class="ulink" href="https://zh.wikipedia.org/wiki/Udev">udev 系統</a>
提供了自動硬體發現和初始化機制。(參見
<span class="citerefentry"><span class="refentrytitle">udev</span>(7)</span>).在核心發現每個裝置的基礎上,udev
系統使用從 <a class="ulink" href="https://zh.wikipedia.org/wiki/Sysfs">sysfs</a> 檔案系統 (參見 <a class="xref" href="ch01.zh-tw.html#_procfs_and_sysfs" title="1.2.12. procfs 和 sysfs">第 1.2.12 节 “procfs 和 sysfs”</a>)的資訊啟動一個使用者程序,使用
<span class="citerefentry"><span class="refentrytitle">modprobe</span>(8)</span>
程式 (參見 <a class="xref" href="ch03.zh-tw.html#_the_kernel_module_initialization" title="3.3.1. 核心模組初始化">第 3.3.1 节 “核心模組初始化”</a>)載入支援它所要求的核心模組,
建立相應的裝置節點。</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>如果由於某些理由,"<code class="literal">/lib/modules/<kernel-version>/modules.dep</code>"沒有被
<span class="citerefentry"><span class="refentrytitle">depmod</span>(8)</span>
正常生成,模組可能不會被 udev 系統按期望的方式載入。執行"<code class="literal">depmod -a</code>" 來修復它。</p>
</td>
</tr>
</table>
</div>
<p>裝置節點的名字,可以通過"<code class="literal">/etc/udev/rules.d/</code>"裡的 udev
檔案來配置.當前預設的規則傾向建立動態生成的名字,除了光碟機和網路裝置外,會生成非靜態的裝置名。通過新增和光碟機、網路裝置類似的個性化規則,你也可以為
USB 盤之類的其它裝置,生成靜態裝置名。 參見 "<a class="ulink" href="http://www.reactivated.net/writing_udev_rules.html">Writing udev
rules</a>" 或
"<code class="literal">/usr/share/doc/udev/writing_udev_rules/index.html</code>".</p>
<p>由於 udev 系統是一個正在變化的事物,我在其它文件進行了詳細描述,在這裡只提供了最少的資訊。</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>"<code class="literal">/etc/fstab</code>"裡面的掛載規則,裝置節點不必需是靜態的。你能夠使用 <a class="ulink" href="https://zh.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</a> 來掛載裝置,來代替"<code class="literal">/dev/sda</code>"之類的裝置名. 參見
<a class="xref" href="ch09.zh-tw.html#_accessing_partition_using_uuid" title="9.5.3. 使用 UUID 訪問分割槽">第 9.5.3 节 “使用 UUID 訪問分割槽”</a>.</p>
</td>
</tr>
</table>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="_the_kernel_module_initialization"/>3.3.1. 核心模組初始化</h3>
</div>
</div>
</div>
<p>通過
<span class="citerefentry"><span class="refentrytitle">modprobe</span>(8)</span>
程式新增和刪除核心模組,使我們能夠從使用者程序來配置正在執行的 Linux 核心。udev 系統(參見 <a class="xref" href="ch03.zh-tw.html#_the_udev_system" title="3.3. udev 系統">第 3.3 节 “udev 系統”</a>)自動化它的呼叫來幫助核心模組初始化。</p>
<p>下面的非硬體模組和特殊的硬體驅動模組,需要被預先載入,把它們在"<code class="literal">/etc/modules</code>"檔案裡列出 (參見
<span class="citerefentry"><span class="refentrytitle">modules</span>(5)</span>).</p>
<div class="itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/TUN/TAP">TUN/TAP</a> 模組提供虛擬的 Point-to-Point 網路裝置 (TUN) 和虛擬的
Ethernet 乙太網網路裝置 (TAP),
</p>
</li>
<li class="listitem">
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/Netfilter">netfilter</a> 模組提供 netfilter
防火牆能力(<span class="citerefentry"><span class="refentrytitle">iptables</span>(8)</span>,
<a class="xref" href="ch05.zh-tw.html#_netfilter_infrastructure" title="5.10. Netfilter 網路過濾框架">第 5.10 节 “Netfilter 網路過濾框架”</a>),
</p>
</li>
<li class="listitem">
<p><a class="ulink" href="https://zh.wikipedia.org/wiki/Watchdog_timer">watchdog timer</a> 驅動模組。
</p>
</li>
</ul>
</div>
<p><span class="citerefentry"><span class="refentrytitle">modprobe</span>(8)</span>
程式的配置檔案是按
<span class="citerefentry"><span class="refentrytitle">modprobe.conf</span>(5)</span>的說明放在"<code class="literal">/etc/modprobes.d/</code>"
目錄下,(如果你想避免自動載入某些核心模組,考慮把它們作為黑名單放在"<code class="literal">/etc/modprobes.d/blacklist</code>"
檔案裡.)</p>
<p>"<code class="literal">/lib/modules/<version>/modules.dep</code>" 檔案由
<span class="citerefentry"><span class="refentrytitle">depmod</span>(8)</span>
程式生成,它描述了
<span class="citerefentry"><span class="refentrytitle">modprobe</span>(8)</span>
程式使用的模組依賴性.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[注意]" src="images/note.png"/>
</td>
<th align="left">注意</th>
</tr>
<tr>
<td align="left" valign="top">
<p>如果你在啟動時出現模組載入問題,或者
<span class="citerefentry"><span class="refentrytitle">modprobe</span>(8)</span>時出現模組載入問題,
"<code class="literal">depmod -a</code>"
可以通過重構"<code class="literal">modules.dep</code>"來解決這些問題。</p>
</td>
</tr>
</table>
</div>
<p><span class="citerefentry"><span class="refentrytitle">modinfo</span>(8)</span>
程式顯示 Linux 核心模組資訊。</p>
<p><span class="citerefentry"><span class="refentrytitle">lsmod</span>(8)</span>
程式以好看的格式展示"<code class="literal">/proc/modules</code>"的內容,顯示當前核心載入了哪些模組。</p>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>你能夠精確識別你係統上的硬體。 參見<a class="xref" href="ch09.zh-tw.html#_hardware_identification" title="9.4.3. 硬體識別">第 9.4.3 节 “硬體識別”</a>.</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>你可以在啟動時配置硬體來啟用期望的硬體特徵。參見 <a class="xref" href="ch09.zh-tw.html#_hardware_configuration" title="9.4.4. 硬體配置">第 9.4.4 节 “硬體配置”</a>.</p>
</td>
</tr>
</table>
</div>
<div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
<table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top">
<img alt="[提示]" src="images/tip.png"/>
</td>
<th align="left">提示</th>
</tr>
<tr>
<td align="left" valign="top">
<p>你可以重新編譯核心來增加你的特殊裝置的支援。參見 <a class="xref" href="ch09.zh-tw.html#_the_kernel" title="9.9. 核心">第 9.9 节 “核心”</a>.</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="navfooter">
<hr/>
<table width="100%" summary="Navigation footer">
<tr>
<td align="left"><a accesskey="p" href="ch02.zh-tw.html"><img src="images/prev.png" alt="上一页"/></a> </td>
<td align="center"> </td>
<td align="right"> <a accesskey="n" href="ch04.zh-tw.html"><img src="images/next.png" alt="下一页"/></a></td>
</tr>
<tr>
<td align="left" valign="top">第 2 章 Debian 軟體包管理 </td>
<td align="center">
<a accesskey="h" href="index.zh-tw.html">
<img src="images/home.png" alt="起始页"/>
</a>
</td>
<td align="right" valign="top"> 第 4 章 認證</td>
</tr>
</table>
</div>
</body>
</html>
|