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 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826
|
<!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
]>
<book>
<bookinfo>
<date>$Date: 2001/11/06 11:26:32 $</date>
<title>The Linux System Administrator's Guide</title>
<subtitle>Version 0.7</subtitle>
<author>
<firstname>Lars</firstname>
<surname>Wirzenius</surname>
<affiliation>
<address>
<email>liw@iki.fi</email>
</address>
</affiliation>
</author>
<author>
<firstname>Joanna</firstname>
<surname>Oja</surname>
<affiliation>
<address>
<email>viu@iki.fi</email>
</address>
</affiliation>
</author>
<author>
<firstname>Stephen</firstname>
<surname>Stafford</surname>
<affiliation>
<address>
<email>stephen@clothcat.demon.co.uk</email>
</address>
</affiliation>
</author>
<abstract>
<para>An introduction to system administration of a
Linux system for novices.</para> </abstract>
<legalnotice>
<para>Copyright 1993--1998 Lars Wirzenius.</para>
<para>Copyright 1998--2001 Joanna Oja.</para>
<para>Copyright 2001 Stephen Stafford.</para>
<para>Trademarks are owned by their owners.</para>
<para>Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.1; with no Invariant Sections, with no Front-Cover Texts,
and with no Back-Cover Texts. A copy of the license is included in
the section entitled "GNU Free Documentation
License".</para>
</legalnotice>
</bookinfo>
<toc></toc>
<preface> <title>Source and pre-formatted versions available</title>
<para>The source code and other machine readable formats
of this book can be found on the Internet via anonymous FTP at the
Linux Documentation Project home page <ulink
url="http://www.linuxdoc.org/">http://www.linuxdoc.org/</ulink>, or
at the home page of this book at <ulink
url="http://people.debian.org/~bagpuss/">http://people.debian.org/~ba
gpuss/</ulink>.
Available are at least Postscript and TeX .DVI formats.</para>
</preface>
<chapter>
<title>Introduction</title>
<blockquote><para><quote>In the beginning, the file was without
form, and void; and emptiness was upon the face of the bits.
And the Fingers of the Author moved upon the face of the
keyboard. And the Author said, Let there be words, and there
were words.</quote></para></blockquote>
<para>The Linux System Administrator's Guide,
describes the system administration aspects of using Linux.
It is intended for people who know next to nothing about system
administration (those saying ``what is it?''), but who have already
mastered at least the basics of normal usage. This manual
doesn't tell you how to install Linux; that is described in the
Installation and Getting Started document. See below for more
information about Linux manuals.</para>
<para>System administration covers all the things that you have to
do to keep a computer system in usable order. It includes
things like backing up files (and restoring them if necessary),
installing new programs, creating accounts for users (and deleting
them when no longer needed), making certain that the filesystem
is not corrupted, and so on. If a computer were, say, a house,
system administration would be called maintenance, and would
include cleaning, fixing broken windows, and other such things.
</para>
<para>The structure of this manual is such that many of the
chapters should be usable independently, so if you need information
about backups, for example, you can read just that chapter. However,
this manual is first and foremost a tutorial and can be read
sequentially or as a whole.</para>
<para>This manual is not intended to be used completely
independently. Plenty of the rest of the Linux documentation is also
important for system administrators. After all, a system
administrator is just a user with special privileges and duties.
Very useful resources are the manual pages, which should always be
consulted when you are not familiar with a command. If you do not
know which command you need, then the <command>apropos</command>
command can be used. Consult its manual page for more details.</para>
<para>While this manual is targeted at Linux, a general principle
has been that it should be useful with other UNIX based operating
systems as well. Unfortunately, since there is so much variance
between different versions of UNIX in general, and in system
administration in particular, there is little hope to cover
all variants. Even covering all possibilities for Linux is
difficult, due to the nature of its development.</para>
<para>There is no one official Linux distribution, so different
people have different setups and many people have a setup they
have built up themselves. This book is not targeted at any
one distribution. Distributions can and do vary considerably.
When possible, differences have been noted and alternatives
given.</para>
<para>In trying to describe how things work, rather than just
listing ``five easy steps'' for each task, there is much information
here that is not necessary for everyone, but those parts are marked
as such and can be skipped if you use a preconfigured system.
Reading everything will, naturally, increase your understanding of
the system and should make using and administering it more
productive.
<footnote><para>Understanding is the key to success with
Linux. This book could just provide recipes, but what
would you do when confronted by a problem this book had
no recipe for? If the book can provide understanding
then recipes are not required, they will be self evident
</para></footnote>
</para>
<para>Like all other Linux related development, the work
to write this manual was done on a volunteer basis: I did it because
I thought it might be fun and because I felt it should be done.
However, like all volunteer work, there is a limit to how much time,
knowledge and experience people have. This means that the manual is
not necessarily as good as it would be if a wizard had been paid
handsomely to write it
and had spent millennia to perfect it. Be warned.</para>
<para>One particular point where corners have been cut is that
many things that are already well documented in other freely
available manuals and so are mostly not covered here. This applies
especially to program specific documentation, such as all the
details of using <command>mkfs</command>. Only the purpose of the
program and as much of its usage as is necessary for the purposes of
this manual is described. For further information, consult these
other manuals. Usually, all of the referred to documentation is
part of the full Linux
documentation set.</para>
</chapter>
<chapter>
<title>About This Book</title>
<sect1>
<title>Acknowledgements</title>
<sect2><title>Joanna's acknowledgements</title>
<para>Lars has tried to make this manual as good as possible
and I would like, as a current maintainer, to keep up the good
work. I would really like to hear from you if you have any
ideas on how to make it better. Bad language, factual errors,
ideas for new areas to cover, rewritten sections, information
about how various UNIX versions do things, I am interested in
all of it. My contact information is available via the World
Wide Web at <ulink url="http://www.iki.fi/viu/">
http://www.iki.fi/viu/</ulink>.
</para>
<para>Many people have helped me with this book, directly or
indirectly. I would like to especially thank Matt Welsh for
inspiration and LDP leadership, Andy Oram for getting me to work
again with much-valued feedback, Olaf Kirch for showing me that it
can be done, and Adam Richter at Yggdrasil and others for showing
me that other people can find it interesting as well.</para>
<para>Stephen Tweedie, H. Peter Anvin, Remy Card, Theodore
Ts'o, and Stephen Tweedie have let me borrow their work (and
thus make the book look thicker and much more impressive):
a comparison between the xia and ext2 filesystems, the device
list and a description of the ext2 filesystem. These aren't
part of the book any more. I am most grateful for this, and
very apologetic for the earlier versions that sometimes lacked
proper attribution.</para>
<para>In addition, I would like to thank Mark Komarinski for
sending his material in 1993 and the many system administration
columns in Linux Journal. They are quite informative and
inspirational.</para>
<para>Many useful comments have been sent by a large number
of people. My miniature black hole of an archive doesn't let
me find all their names, but some of them are, in alphabetical
order: Paul Caprioli, Ales Cepek, Marie-France Declerfayt,
Dave Dobson, Olaf Flebbe, Helmut Geyer, Larry Greenfield and
his father, Stephen Harris, Jyrki Havia, Jim Haynes, York Lam,
Timothy Andrew Lister, Jim Lynch, Michael J. Micek, Jacob Navia,
Dan Poirier, Daniel Quinlan, Jouni K Seppänen, Philippe Steindl,
G.B. Stotte. My apologies to anyone I have forgotten.</para>
</sect2>
<sect2><title>Stephen's acknowledgements</title>
<para>As the newest maintainer I would like to thank Lars and
Joanna for their hard work on the guide.</para>
<para>In a guide like this one there are likely to be at least
some minor inaccuracies. And there are almost certainly going to
be sections that become out of date from time to time. If you
notice any of this then please let me know by sending me an email
to: <email>bagpuss@debian.org</email>. I will take virtually
any form of input (diffs, just plain text, html, whatever), I am
in no way above allowing others to help me maintain such a large
text as this :) </para>
<para>Many thanks to Helen Topping Shaw for getting the red pen out
and making the text far better than it would otherwise have been.
Also thanks are due just for being wonderful.</para>
<para>The current web home of the guide is
<ulink url="http://people.debian.org/~bagpuss">
http://people.debian.org/~bagpuss
</ulink></para>
</sect1>
<sect1>
<title>Typographical Conventions</title>
<para>Throughout this book, I have tried to use uniform
typographical conventions. Hopefully they aid readability. If
you can suggest any improvements please contact me.</para>
<para>Filenames are expressed as:
<filename>/usr/share/doc/foo</filename>.</para>
<para>Command names are expressed as: <command>fsck</command>
<para>Email addresses are expressed as:
<email>stephen@clothcat.demon.co.uk</email></para>
<para>URLs are expressed as: <ulink
url="http://www.linuxdoc.org">http://www.linuxdoc.org</ulink>
</para>
<para>I will add to this section as things come up whilst
editing. If you notice anything that should be added then
please let me know.</para>
</sect1>
</chapter>
<chapter>
<title>Overview of a Linux System</title>
<blockquote><para><quote>God saw everything that he
had made, and saw that it was very good. </quote> -- Bible
King James Version. Genesis 1:31</para></blockquote>
<para>This chapter gives an overview of a Linux system. First,
the major services provided by the operating system are described.
Then, the programs that implement these services are described
with a considerable lack of detail. The purpose of this chapter
is to give an understanding of the system as a whole, so that
each part is described in detail elsewhere.</para>
<sect1>
<title>Various parts of an operating system</title>
<para>A UNIX operating system consists
of a <glossterm>kernel</glossterm> and some
<glossterm>system programs</glossterm>. There are also some
<glossterm>application programs</glossterm> for doing work.
The kernel is the heart of the operating system.
<footnote><para>In fact, it is often mistakenly considered
to be the operating system itself, but it is not.
An operating system provides many more services than a
plain kernel.</footnote>
It keeps track of files on the disk, starts programs and runs them
concurrently, assigns memory and other resources to various
processes, receives packets from and sends packets to the network,
and so on. The kernel does very little by itself, but it provides
tools with which all services can be built. It also prevents anyone
from accessing the hardware directly, forcing everyone to use the
tools it provides.
<footnote><para>I always think of this as a form of encapsulation
which may help those of you with an object oriented programming
background to visualise it better.</para></footnote>
This way the kernel provides some protection for users from each
other. The tools provided by the kernel are used via
<glossterm>system calls<glossterm>. See manual page section 2 for more
information on these. </para>
<para>The system programs use the tools provided by the kernel to
implement the various services required from an operating system.
System programs, and all other programs, run `on top of the
kernel', in what is called the <glossterm>user mode</glossterm>.
The difference between system and application programs is
one of intent: applications are intended for getting useful
things done (or for playing, if it happens to be a game),
whereas system programs are needed to get the system working.
A word processor is an application; <command>mount</command>
is a system program. The difference is often somewhat blurry,
however, and is important only to compulsive categorisers.</para>
<para>An operating system can also contain compilers and their
corresponding libraries (GCC and the C library in particular under
Linux), although not all programming languages need be part of
the operating system. Documentation, and sometimes even games,
can also be part of it. Traditionally, the operating system has
been defined by the contents of the installation tape or disks;
with Linux it is not as clear since it is spread all over the
FTP sites of the world.</para>
</sect1>
<sect1>
<title>Important parts of the kernel</title>
<para>The Linux kernel consists of several important parts: process
management, memory management, hardware device drivers, filesystem
drivers, network management, and various other bits and pieces.
<xref linkend="kerneloverview">
shows some of them.</para>
<figure id="kerneloverview" float="1">
<title>Some of the more important parts of the Linux kernel</title>
<graphic fileref="overview-kernel"></graphic>
</figure>
<para>Probably the most important parts of the kernel (nothing else
works without them) are memory management and
process management. Memory management takes care of assigning
memory areas and swap space areas to processes, parts of the
kernel, and for the buffer cache. Process management creates
processes, and implements multitasking by switching the
active process on the processor.</para>
<para>At the lowest level, the kernel contains a hardware device
driver for each kind of hardware it supports. Since the world is
full of different kinds of hardware, the number of hardware device
drivers is large. There are often many otherwise similar pieces
of hardware that differ in how they are controlled by software.
The similarities make it possible to have general classes of
drivers that support similar operations; each member of the class
has the same interface to the rest of the kernel but differs in
what it needs to do to implement them. For example, all disk
drivers look alike to the rest of the kernel, i.e., they all
have operations like `initialise the drive', `read sector N',
and `write sector N'.</para>
<para>Some software services provided by the kernel itself have
similar properties, and can therefore be abstracted into classes.
For example, the various network protocols have been abstracted
into one programming interface, the BSD socket library. Another
example is the <glossterm>virtual filesystem</glossterm> (VFS)
layer that abstracts the filesystem operations away from their
implementation. Each filesystem type provides an implementation
of each filesystem operation. When some entity tries to use
a filesystem, the request goes via the VFS, which routes the
request to the proper filesystem driver.</para>
</sect1>
<sect1>
<title>Major services in a UNIX system</title>
<para>This section describes some of the more important UNIX
services, but without much detail. They are described more
thoroughly in later chapters.</para>
<sect2>
<title><command>init</command></title>
<para>The single most important service in a UNIX system is
provided by <command>init</command>. <command>init</command>
is started as the first process of every UNIX system, as the last
thing the kernel does when it boots. When <command>init</command>
starts, it continues the boot process by doing various startup
chores (checking and mounting filesystems, starting daemons,
etc).</para>
<para>The exact list of things that <command>init</command>
does depends on which flavour it is; there are several to choose
from. <command>init</command> usually provides the concept of
<glossterm>single user mode</glossterm>, in which no one can
log in and root uses a shell at the console; the usual mode is
called <glossterm>multiuser mode</glossterm>. Some flavours
generalise this as <glossterm>run levels</glossterm>; single
and multiuser modes are considered to be two run levels, and
there can be additional ones as well, for example, to run X on
the console.</para>
<para>Linux allows for up to 10
<glossterm>runlevels</glossterm>, 0-9, but usually only some of
these are defined by default. Runlevel 0 is defined as ``system
halt''. Runlevel 1 is defined as ``single user mode''.
Runlevel 6 is defined as ``system reboot''. Other runlevels are
dependent on how your particular distribution has defined them,
and they vary significantly between distributions. Looking at
the contents of <filename>/etc/inittab</filename> usually will
give some hint what the predefined runlevels are and what they
have been defined as.</para>
<para>In normal operation, <command>init</command> makes sure
<command>getty</command> is working (to allow users to log in),
and to adopt orphan processes (processes whose parent has died; in
UNIX <emphasis>all</emphasis> processes <emphasis>must</emphasis>
be in a single tree, so orphans must be adopted).</para>
<para>When the system is shut down, it is <command>init</command>
that is in charge of killing all other processes, unmounting all
filesystems and stopping the processor, along with anything else
it has been configured to do.</para>
</sect2>
<sect2>
<title>Logins from terminals</title>
<para>Logins from terminals (via serial lines) and the console
(when not running X) are provided by the <command>getty</command>
program. <command>init</command> starts a separate instance of
<command>getty</command> for each terminal upon which logins are to
be allowed. <command>getty</command> reads the username and runs
the <command>login</command> program, which reads the password. If
the username and password are correct, <command>login</command> runs
the shell. When the shell terminates, i.e., the user logs out, or
when <command>login</command> terminated because the username and
password didn't match, <command>init</command> notices this and
starts a new instance of <command>getty</command>. The kernel has no
notion of logins, this is all handled by the
<glossterm>system programs</glossterm>.</para>
</sect2>
<sect2>
<title>Syslog</title>
<para>The kernel and many <glossterm>system programs</glossterm>
produce error, warning, and other messages. It is often important
that these messages can be viewed later, even much later, so they
should be written to a file. The program doing this is
<command>syslog</command>. It can be configured to sort the
messages to different files according to writer or degree of
importance. For example, kernel messages are often directed to a
separate file from the others, since kernel messages are often more
important and need to be read
regularly to spot problems.</para>
</sect2>
<sect2>
<title>Periodic command execution: <command>cron</command> and
<command>at</command></title>
<para>Both users and system administrators often need
to run commands periodically. For example, the system administrator
might want to run a command to clean the directories with temporary
files (<filename>/tmp</filename> and <filename>/var/tmp</filename>)
from old files, to keep the disks from filling up, since not all
programs clean up after
themselves correctly.</para>
<para>The <command>cron</command> service is set up to do this.
Each user can have a <filename>crontab</filename> file, where she
lists the commands she wishes to execute and the times they should
be executed. The <command>cron</command> daemon takes care of
starting the commands when specified.</para>
<para>The <command>at</command> service is similar to
<command>cron</command>, but it is once only: the command is
executed at the given time, but it is not repeated.</para>
<para>See the manual pages cron(1), crontab(1), crontab(5), at(1) and
atd(8) for more in depth information.</para>
</sect2>
<sect2>
<title>Graphical user interface</title>
<para>UNIX and Linux don't incorporate the user interface
into the kernel; instead, they let it be implemented by user level
programs. This applies for both text mode and graphical
environments.</para>
<para>This arrangement makes the system more flexible, but has
the disadvantage that it is simple to implement a different user
interface for each program, making the system harder to
learn.</para>
<para>The graphical environment primarily used with Linux
is called the X Window System (X for short). X also does
not implement a user interface; it only implements a window
system, i.e., tools with which a graphical user interface can
be implemented. Some popular window managers are: fvwm, icewm,
blackbox and windowmaker. There are also two popular desktop
managers, KDE and Gnome.</para>
</sect2>
<sect2>
<title>Networking</title>
<para>Networking is the act of connecting two or more computers
so that they can communicate with each other. The actual methods
of connecting and communicating are slightly complicated, but
the end result is very useful.</para>
<para>UNIX operating systems have many networking features.
Most basic services (filesystems, printing, backups, etc) can
be done over the network. This can make system administration
easier, since it allows centralised administration, while
still reaping in the benefits of microcomputing and distributed
computing, such as lower costs and better fault tolerance.</para>
<para>However, this book merely glances at networking; see the
<citetitle>Linux Network Administrators' Guide</citetitle>
<ulink url="http://www.linuxdoc.org/LDP/nag2/index.html">
http://www.linuxdoc.org/LDP/nag2/index.html</ulink> for
more information, including a basic description of how networks
operate.</para>
</sect2>
<sect2>
<title>Network logins</title>
<para>Network logins work a little differently than normal logins.
There is a separate physical serial line for each terminal via
which it is possible to log in. For each person logging in via
the network, there is a separate virtual network connection,
and there can be any number of these.
<footnote><para>Well, at least there can be many. Network
bandwidth still being a scarce resource, there is still
some practical upper limit to the number of concurrent
logins via one network connection. </para></footnote>
It is therefore not possible to run a separate
<command>getty</command> for each possible virtual connection.
There are also several different ways to log in via a network,
<command>telnet</command> and <command>rlogin</command> being
the major ones in TCP/IP networks.
<footnote><para>These days many Linux system administrators
consider <command>telnet</command> and <command>rlogin
</command> to be insecure and prefer <command>ssh
</command>, the ``secure shell'', which encrypts traffic
going over the network, thereby making it far less likely
that the malicious can ``sniff'' your connection and gain
sensitive data like usernames and passwords. It is
highly recommended you use <command>ssh</command> rather than
<command>telnet</command> or <command>rlogin</command>.
</para></footnote>
</para>
<para>Network logins have, instead of a herd of
<command>getty</command>s, a single daemon per way of logging in
(<command>telnet</command> and <command>rlogin</command> have
separate daemons) that listens for all incoming login attempts.
When it notices one, it starts a new instance of itself to
handle that single attempt; the original instance continues to
listen for other attempts. The new instance works similarly
to <command>getty</command>.</para>
</sect2>
<sect2>
<title>Network file systems</title>
<para>One of the more useful things that can be done with
networking services is sharing files via a <glossterm>network
file system</glossterm>. The one usually used is called the
Network File System, or NFS, developed by Sun.</para>
<para>With a network file system any file operations done by
a program on one machine are sent over the network to another
computer. This fools the program to think that all the files
on the other computer are actually on the computer the program
is running on. This makes information sharing extremely simple,
since it requires no modifications to programs.</para>
<para>Another popular way of sharing files is Samba <ulink
url="http://www.samba.org">http://www.samba.org</ulink>. This
protocol allows the sharing of files with MS Windows machines
(via Network Neighbourhood). It also allows the sharing of
printers across machines.</para>
</sect2>
<sect2>
<title>Mail</title>
<para>Electronic mail is the most popularly used method for
communicating via computer. An electronic letter is stored in a
file using a special format, and special mail programs are used
to send and read the letters.</para>
<para>Each user has an <glossterm>incoming mailbox</glossterm>
(a file in the special format), where all new mail is stored.
When someone sends mail, the mail program locates the receiver's
mailbox and appends the letter to the mailbox file. If the
receiver's mailbox is in another machine, the letter is sent to
the other machine, which delivers it to the mailbox as it best
sees fit.</para>
<para>The mail system consists of many programs. The
delivery of mail to local or remote mailboxes is done by one
program (the <glossterm>mail transfer agent</glossterm> (MTA),
e.g., <command>sendmail</command>
or <command>smail</command>), while the programs users use
are many and varied (<glossterm>mail user agent</glossterm> (MUA),
e.g., <command>pine</command>, <command>mutt</command>
or <command>elm</command>). The mailboxes are usually stored
in <filename>/var/spool/mail</filename>.</para>
</sect2>
<sect2>
<title>Printing</title>
<para>Only one person can use a printer at one time, but it is
uneconomical not to share printers between users. The printer is
therefore managed by software that implements a <glossterm>print
queue</glossterm>: all print jobs are put into a queue and
whenever the printer is done with one job, the next one is sent
to it automatically. This relieves the users from organising
the print queue and fighting over control of the printer.
<footnote><para>Instead, they form a new queue
<emphasis>at</emphasis> the printer, waiting for their
printouts, since no one ever seems to be able to get the
queue software to know exactly when anyone's printout is
really finished. This is a great boost to intra-office
social relations.</para></footnote>
</para>
<para>The print queue software also <glossterm>spools</glossterm>
the printouts on disk, i.e., the text is kept in a file while
the job is in the queue. This allows an application program
to spit out the print jobs quickly to the print queue software;
the application does not have to wait until the job is actually
printed to continue. This is really convenient, since it
allows one to print out one version, and not have to wait for
it to be printed before one can make a completely revised new
version.</para>
</sect2>
<sect2>
<title>The filesystem layout</title>
<para>The filesystem is divided into many parts;
usually along the lines of a root filesystem with
<filename>/bin</filename>, <filename>/lib</filename>,
<filename>/etc</filename>, <filename>/dev</filename>, and
a few others; a <filename>/usr</filename> filesystem with
programs and unchanging data; a <filename>/var</filename>
filesystem with changing data (such as log files); and a
<filename>/home</filename> filesystem for everyone's personal
files. Depending on the hardware configuration and the decisions
of the system administrator, the division can be different;
it can even be all in one filesystem.</para>
<para><xref linkend="dir-tree-overview"> describes the filesystem
layout in some little detail; the Filesystem Hierarchy Standard covers it
in somewhat more detail.
<footnote><para><ulink url="http://www.pathname.com/fhs/">
http://www.pathname.com/fhs/</ulink></para></footnote>
</para>
</sect2>
</sect1>
</chapter>
<chapter id="dir-tree-overview">
<title>Overview of the Directory Tree</title>
<blockquote><para><quote> Two days later, there was Pooh, sitting
on his branch, dangling his legs, and there, beside him, were
four pots of honey...</quote> (A.A. Milne) </para></blockquote>
<para>This chapter describes the important parts of a standard Linux
directory tree, based on the Filesystem Hierarchy Standard. It
outlines the normal way of breaking the directory tree into separate
filesystems with different purposes and gives the motivation behind
this particular split. Not all Linux distributions follow this
standard slavishly, but it is generic enough to give you an
overview.</para>
<sect1>
<title>Background</title>
<para>This chapter is loosely based on the <citetitle>Filesystems
Hierarchy Standard</citetitle> (FHS)
<footnote><para><ulink url="hhtp://www.pathname.com/fhs/">
http://www.pathname.com/fhs/</ulink></para></footnote>
version 2.1, which attempts to
set a standard for how the directory tree in a Linux
<footnote><para>Or any Unix like system. For example the BSD
derivatives.</para></footnote>
system is organised. Such a standard has the advantage that it will
be easier to write or port software for Linux, and to administer
Linux machines, since everything should be in standardised places.
There is no authority behind the standard that forces anyone to
comply with it, but it has gained the support of many Linux
distributions. It is not a good idea to break with the FHS without
very compelling reasons. The FHS attempts to follow Unix tradition
and current trends, making Linux systems familiar to those with
experience with other Unix systems, and vice versa.</para>
<para>This chapter is not as detailed as the FHS. A system
administrator should also read the full FHS for a complete
understanding.</para>
<para>This chapter does not explain all files in detail. The
intention is not to describe every file, but to give an overview of
the system from a filesystem point of view. Further information on
each file is available elsewhere in this manual or in the Linux
manual pages.</para>
<para>The full directory tree is intended to be breakable into
smaller parts, each capable of being on its own disk or partition,
to accommodate to disk size limits and to ease backup and other
system administration tasks. The major parts are the root
(<filename>/</filename>), <filename>/usr</filename>,
<filename>/var</filename>, and <filename>/home</filename>
filesystems (see <xref linkend="fstree">). Each part has a
different purpose. The directory tree has been designed so that it
works well in a network of Linux machines which may share some parts
of the filesystems over a read-only device (e.g., a CD-ROM), or over
the network with NFS.</para>
<figure id="fstree" float="1"> <title>Parts of a Unix
directory tree. Dashed lines indicate partition
limits.</title> <graphic fileref="fstree"></graphic>
</figure>
<para>The roles of the different parts of the directory tree are
described below.
<itemizedlist>
<listitem> <para>The root filesystem is specific for
each machine (it is generally stored on a local disk,
although it could be a ramdisk or network drive as well) and
contains the files that are necessary for booting the system
up, and to bring it up to such a state that the other
filesystems may be mounted. The contents of the root
filesystem will therefore be sufficient for the single user
state. It will also contain tools for fixing a broken
system, and for recovering lost files
from backups.</para> </listitem>
<listitem><para> The <filename>/usr</filename> filesystem
contains all commands, libraries, manual pages, and other
unchanging files needed during normal operation. No files in
<filename>/usr</filename> should be specific for any given
machine, nor should they be modified during normal use. This
allows the files to be shared over the network, which can be
cost-effective since it saves disk space (there can easily
be hundreds of megabytes, increasingly multiple gigabytes in
<filename>/usr</filename>). It can make administration
easier (only the master <filename>/usr</filename> needs to
be changed when updating an application, not each machine
separately) to have /usr network mounted. Even if the
filesystem is on a local disk, it could be mounted
read-only, to lessen the chance of filesystem corruption
during a crash.</para></listitem>
<listitem><para>The <filename>/var</filename>
filesystem contains files that change, such as spool
directories (for mail, news, printers, etc), log files,
formatted manual pages, and temporary files. Traditionally
everything in <filename>/var</filename> has been somewhere
below <filename>/usr</filename>, but that made it impossible
to mount <filename>/usr</filename>
read-only.<para></listitem>
<listitem><para> The <filename>/home</filename>
filesystem contains the users' home directories, i.e., all
the real data on the system. Separating home directories to
their own directory tree or filesystem makes backups easier;
the other parts often do not have to be backed up, or at
least not as often as they seldom change. A big
<filename>/home</filename> might have to be broken across
several filesystems, which requires adding an extra naming
level below <filename>/home</filename>, for example
<filename>/home/students</filename> and
<filename>/home/staff</filename>.</para></listitem>
</itemizedlist> </para>
<para>Although the different parts have been called filesystems
above, there is no requirement that they actually be on separate
filesystems. They could easily be kept in a single one if the
system is a small single-user system and the user wants to keep
things simple. The directory tree might also be divided into
filesystems differently, depending on how large the disks are, and
how space is allocated for various purposes. The important part,
though, is that all the standard <emphasis>names</emphasis> work;
even if, say, <filename>/var</filename> and
<filename>/usr</filename> are actually on the same partition, the
names <filename>/usr/lib/libc.a</filename> and
<filename>/var/log/messages</filename> must work, for example by
moving files below <filename>/var</filename> into
<filename>/usr/var</filename>, and making <filename>/var</filename>
a symlink to
<filename>/usr/var</filename>.</para>
<para>The Unix filesystem structure groups files according to
purpose, i.e., all commands are in one place, all data files in
another, documentation in a third, and so on. An alternative would
be to group files files according to the program they belong to,
i.e., all Emacs files would be in one directory, all TeX in another,
and so on. The problem with the latter approach is that it makes it
difficult to share files (the program directory often contains both
static and sharable and changing and non-sharable files), and
sometimes to even find the files (e.g., manual pages in a huge
number of places, and making the manual page programs find all of
them is a maintenance
nightmare).</para>
</sect1>
<sect1>
<title>The root filesystem</title>
<para>The root filesystem should generally be small, since
it contains very critical files and a small, infrequently
modified filesystem has a better chance of not getting corrupted.
A corrupted root filesystem will generally mean that the system
becomes unbootable except with special measures (e.g., from a
floppy), so you don't want to risk it.</para>
<para>The root directory generally doesn't contain any files, except
perhaps the standard boot image for the system, usually called
<filename>/vmlinuz</filename>. All other files are in
subdirectories in the root filesystems:
<glosslist>
<glossentry>
<glossterm><filename>/bin</filename></glossterm>
<glossdef><para>Commands needed during bootup
that might be used by normal users (probably after
bootup).</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/sbin</filename></glossterm>
<glossdef><para>Like <filename>/bin</filename>, but the
commands are not intended for normal users, although they
may use them if necessary and allowed.
<filename>/sbin</filename> is not usually in the default
path of normal users, but will be in root's default
path.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc</filename></glossterm>
<glossdef><para>Configuration files specific to the
machine.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/root</filename></glossterm>
<glossdef><para>The home directory for user root. This is
usually not accessible to other users on the
system</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/lib</filename></glossterm>
<glossdef><para>Shared libraries needed by the programs on
the root filesystem.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/lib/modules</filename></glossterm>
<glossdef><para>Loadable kernel modules, especially those
that are needed to boot the system when recovering from
disasters (e.g., network and filesystem
drivers).</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev</filename></glossterm>
<glossdef><para>Device files. Some of the more commonly
used device files are examined in <xref linkend="device-list">
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/tmp</filename></glossterm>
<glossdef><para>Temporary files. Programs running after
bootup should use <filename>/var/tmp</filename>, not
<filename>/tmp</filename>, since the former is probably on a
disk with more space. Often /tmp will be a symbolic link to
/var/tmp.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/boot</filename></glossterm>
<glossdef><para>Files used by the bootstrap loader,
e.g., LILO. Kernel images are often kept here instead
of in the root directory. If there are many kernel
images, the directory can easily grow rather big, and it
might be better to keep it in a separate filesystem.
Another reason would be to make sure the kernel
images are within the first 1024 cylinders of an IDE
disk.
<footnote><para>This 1024 cylinder limit is no
longer true in most cases. With modern BIOSes and
later versions of LILO (the LInux LOader) the 1024
cylinder limit can be passed with logical block
addressing (LBA). See the <command>lilo</command>
manual page for more details.</para></footnote>
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/mnt</filename></glossterm>
<glossdef><para>Mount point for temporary mounts by
the system administrator. Programs aren't supposed to mount
on <filename>/mnt</filename> automatically.
<filename>/mnt</filename> might be divided into
subdirectories (e.g., <filename>/mnt/dosa</filename> might
be the floppy drive using an MS-DOS filesystem, and
<filename>/mnt/exta</filename> might be the same
with an ext2 filesystem).</para></glossdef></glossentry>
<glossentry> <glossterm><filename>/proc</filename>,
<filename>/usr</filename>, <filename>/var</filename>,
<filename>/home</filename></glossterm>
<glossdef><para>Mount points
for the other filesystems.
<footnote><para>Although <filename>/proc</filename> does not
reside on any disk in reality. See the section about
<filename>/proc</filename> later in the
chapter.</para></footnote>
</para></glossdef></glossentry>
</glosslist>
</para>
</sect1>
<sect1>
<title>The <filename>/etc</filename> directory</title>
<para>The <filename>/etc</filename> directory contains a lot
of files. Some of them are described below. For others, you
should determine which program they belong to and read the manual
page for that program. Many networking configuration files are
in <filename>/etc</filename> as well, and are described in the
<citetitle>Networking Administrators' Guide</citetitle>.
<glosslist>
<glossentry>
<glossterm><filename>/etc/rc</filename> or
<filename>/etc/rc.d</filename> or
<filename>/etc/rc?.d</filename></glossterm>
<glossdef><para>Scripts or directories of scripts
to run at startup or when changing the run level.
See <xref linkend="init"> for further
information. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/passwd</filename></glossterm>
<glossdef><para>The user database, with fields giving the
username, real name, home directory, encrypted password, and
other information about each user. The format is documented
in the <command>passwd</command> manual page. The encrypted
passwords are much more commonly found in the
<filename>/etc/shadow</filename> these days. This means
that almost everything about the user
<emphasis>except</emphasis> the password is stored in the
<filename>passwd</filename> file. History and convention
make a name change undesirable.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/fdprm</filename></glossterm>
<glossdef><para>Floppy disk parameter table.
Describes what different floppy disk formats look
like. Used by <command>setfdprm</command>. See the
<command>setfdprm</command> manual page for more
information. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/fstab</filename></glossterm>
<glossdef><para>Lists the filesystems mounted automatically
at startup by the <command>mount -a</command> command (in
<filename>/etc/rc</filename> or equivalent startup file).
Under Linux, also contains information about swap areas used
automatically by <command>swapon -a</command>. See <xref
linkend="mount-and-umount"> and the <command>mount</command>
manual page for more information. Also
<filename>fstab</filename> usually has its own manual page in
section 5. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/group</filename></glossterm>
<glossdef><para>Similar to <filename>/etc/passwd</filename>,
but describes groups instead of users. See the
<filename>group</filename> manual page in section 5 for more
information. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/inittab</filename></glossterm>
<glossdef><para>Configuration file for
<command>init</command>. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/issue</filename></glossterm>
<glossdef><para>Output by <command>getty</command> before
the login prompt. Usually contains a short description or
welcoming message to the system. The contents are up to
the system administrator. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/magic</filename></glossterm>
<glossdef><para>The configuration file
for <command>file</command>. Contains the
descriptions of various file formats based on
which <command>file</command> guesses the type of
the file. See the <filename>magic</filename> and
<command>file</command> manual pages for more information.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/motd</filename></glossterm>
<glossdef><para>The message of the day, automatically
output after a successful login. Contents are up to the
system administrator. Often used for getting information
to every user, such as warnings about planned downtimes.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/mtab</filename></glossterm>
<glossdef><para>List of currently mounted filesystems.
Initially set up by the bootup scripts, and updated
automatically by the <command>mount</command>
command. Used when a list of mounted filesystems is
needed, e.g., by the <command>df</command> command.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/shadow</filename></glossterm>
<glossdef><para>Shadow password file on systems with shadow
password software installed. Shadow passwords move the
encrypted password from <filename>/etc/passwd</filename>
into <filename>/etc/shadow</filename>; the latter is not
readable by anyone except root. This makes it harder to
crack passwords. If your distribution gives you a choice
(many do) of whether or not to use shadow passwords then you
are highly recommended to do
so.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/login.defs</filename></glossterm>
<glossdef><para>Configuration file for the
<command>login</command> command. The
<filename>login.defs</filename> file usually has a manual
page in section 5. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/printcap</filename></glossterm>
<glossdef><para>Like <filename>/etc/termcap</filename>, but
intended for printers. However it uses different syntax.
The <filename>printcap</filename> has a manual page in
section 5. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/profile</filename>,
<filename>/etc/csh.login</filename>,
<filename>/etc/csh.cshrc</filename></glossterm>
<glossdef><para>Files executed at login or startup time
by the Bourne or C shells. These allow the system
administrator to set global defaults for all users.
See the manual pages for the respective shells.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/securetty</filename></glossterm>
<glossdef><para>Identifies secure terminals, i.e., the
terminals from which root is allowed to log in. Typically
only the virtual consoles are listed, so that it becomes
impossible (or at least harder) to gain superuser privileges
by breaking into a system over a modem or a network. Do not
allow root logins over a network. Prefer to log in as an
unprivileged user and use <command>su</command> or
<command>sudo</command> to gain root
privileges.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/shells</filename></glossterm>
<glossdef><para>Lists trusted shells. The
<command>chsh</command> command allows users to change
their login shell only to shells listed in this file.
<command>ftpd</command>, the server process that provides
FTP services for a machine, will check that the user's
shell is listed in <filename>/etc/shells</filename>
and will not let people log in unless the shell is
listed there. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/etc/termcap</filename></glossterm>
<glossdef><para>The terminal capability database.
Describes by what ``escape sequences'' various terminals
can be controlled. Programs are written so that instead
of directly outputting an escape sequence that only
works on a particular brand of terminal, they look up
the correct sequence to do whatever it is they want to
do in <filename>/etc/termcap</filename>. As a result
most programs work with most kinds of terminals.
See the <filename>termcap</filename>, curs_termcap,
and <filename>terminfo</filename> manual pages for
more information. </para></glossdef></glossentry>
</glosslist>
</para>
</sect1>
<sect1>
<title>The <filename>/dev</filename> directory</title>
<para>The <filename>/dev</filename> directory contains
the special device files for all the devices. The device files are
named using special conventions; these are described in <xref
linkend="device-list">. The device files are created during
installation, and later with the <command>/dev/MAKEDEV</command>
script. The <command>/dev/MAKEDEV.local</command> is a script
written by the system administrator that creates local-only device
files or links (i.e. those that are not part of the standard
<command>MAKEDEV</command>, such as device files for some
non-standard device driver).</para>
</sect1>
<sect1>
<title>The <filename>/usr</filename> filesystem</title>
<para>The <filename>/usr</filename> filesystem is often
large, since all programs are installed there. All files
in <filename>/usr</filename> usually come from a Linux
distribution; locally installed programs and other stuff goes
below <filename>/usr/local</filename>. This makes it possible
to update the system from a new version of the distribution,
or even a completely new distribution, without having to
install all programs again. Some of the subdirectories of
<filename>/usr</filename> are listed below (some of the less
important directories have been dropped; see the FSSTND for
more information).
<glosslist>
<glossentry>
<glossterm><filename>/usr/X11R6</filename></glossterm>
<glossdef><para>The X Window System, all files. To simplify
the development and installation of X, the X files have not
been integrated into the rest of the system. There is a
directory tree below <filename>/usr/X11R6</filename> similar
to that below <filename>/usr</filename> itself.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/bin</filename></glossterm>
<glossdef><para>Almost all user commands. Some commands are
in <filename>/bin</filename> or in
<filename>/usr/local/bin</filename>.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/sbin</filename></glossterm>
<glossdef><para>System administration commands that are not
needed on the root filesystem, e.g., most server programs.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/share/man</filename>,
<filename>/usr/share/info</filename>,
<filename>/usr/share/doc</filename></glossterm>
<glossdef><para>Manual pages, GNU Info documents, and
miscellaneous other documentation files, respectively.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/include</filename></glossterm>
<glossdef><para>Header files for the C
programming language. This should actually be below
<filename>/usr/lib</filename> for consistency, but the
tradition is overwhelmingly in support for this name.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/lib</filename></glossterm>
<glossdef><para>Unchanging data files for programs and
subsystems, including some site-wide configuration
files. The name <filename>lib</filename> comes from library;
originally libraries of programming subroutines
were stored in <filename>/usr/lib</filename>.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/usr/local</filename></glossterm>
<glossdef><para>The place for locally installed software and
other files. Distributions may not install anything in
here. It is reserved solely for the use of the local
administrator. This way he can be absolutely certain that
no updates or upgrades to his distribution will overwrite
any extra software he has installed
locally.</para></glossdef></glossentry>
</glosslist></para>
</sect1>
<sect1>
<title>The <filename>/var</filename> filesystem</title>
<para>The <filename>/var</filename> contains data that is changed
when the system is running normally. It is specific for each
system, i.e., not shared over the network with other computers.
<glosslist>
<glossentry>
<glossterm><filename>/var/cache/man</filename></glossterm>
<glossdef><para>A cache for man pages that are formatted on
demand. The source for manual pages is usually stored in
<filename>/usr/share/man/man?/</filename> (where ? is the
manual section. See the manual page for
<command>man</command> in section 7); some manual pages
might come with a pre-formatted version, which might be
stored in <filename>/usr/share/man/cat*</filename>. Other
manual pages need to be formatted when they are first
viewed; the formatted version is then stored in
<filename>/var/cache/man</filename> so that the next person
to view the same page won't have to wait for it to be
formatted. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/games</filename></glossterm>
<glossdef><para>Any variable data belonging to games in
<filename>/usr</filename> should be placed here. This is in
case /usr is mounted read only.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/lib</filename></glossterm>
<glossdef><para>Files that change while the system is
running normally.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/local</filename></glossterm>
<glossdef><para>Variable data for programs that are
installed in <filename>/usr/local</filename> (i.e.,
programs that have been installed by the system
administrator). Note that even locally installed
programs should use the other <filename>/var</filename>
directories if they are appropriate, e.g.,
<filename>/var/lock</filename>.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/lock</filename></glossterm>
<glossdef><para>Lock files. Many programs
follow a convention to create a lock file in
<filename>/var/lock</filename> to indicate that they
are using a particular device or file. Other programs
will notice the lock file and won't attempt to use the
device or file.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/log</filename></glossterm>
<glossdef><para>Log files from various programs, especially
<command>login</command>
(<filename>/var/log/wtmp</filename>, which logs all logins
and logouts into the system) and <command>syslog</command>
(<filename>/var/log/messages</filename>, where all kernel
and system program message are usually stored). Files in
<filename>/var/log</filename> can often grow indefinitely,
and may require cleaning at regular
intervals.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/mail</filename></glossterm>
<glossdef><para>This is the FHS approved location for user
mailbox files. Depending on how far your distribution has
gone towards FHS compliance, these files may still be held
in <filename>/var/spool/mail</filename>.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/run</filename></glossterm>
<glossdef><para>Files that contain information about the
system that is valid until the system is next booted.
For example, <filename>/var/run/utmp</filename>
contains information about people currently logged
in.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/spool</filename></glossterm>
<glossdef><para>Directories for news, printer queues, and
other queued work. Each different spool has its own
subdirectory below <filename>/var/spool</filename>, e.g.,
the news spool is in <filename>/var/spool/news</filename>.
Note that some installations which are not fully compliant
with the latest version of the FHS may have user mailboxes
under <filename>/var/spool/mail</filename>.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/var/tmp</filename></glossterm>
<glossdef><para>Temporary files that are large
or that need to exist for a longer time than
what is allowed for <filename>/tmp</filename>.
(Although the system administrator might not allow
very old files in <filename>/var/tmp</filename>
either.)</para></glossdef></glossentry>
</glosslist></para>
</sect1>
<sect1>
<title>The <filename>/proc</filename> filesystem</title>
<para>The <filename>/proc</filename> filesystem contains a
illusionary filesystem. It does not exist on a disk. Instead, the
kernel creates it in memory. It is used to provide information
about the system (originally about processes, hence the name). Some
of the more important files and directories are explained below.
The <filename>/proc</filename> filesystem is described in more
detail in the <filename>proc</filename> manual page.
<glosslist>
<glossentry>
<glossterm><filename>/proc/1</filename></glossterm>
<glossdef><para>A directory with information about
process number 1. Each process has a directory below
<filename>/proc</filename> with the name being its process
identification number. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/cpuinfo</filename></glossterm>
<glossdef><para>Information about the processor,
such as its type, make, model, and performance.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/devices</filename></glossterm>
<glossdef><para>List of device drivers configured into the
currently running kernel. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/dma</filename></glossterm>
<glossdef><para>Shows which DMA channels are being used
at the moment. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/filesystems</filename></glossterm>
<glossdef><para>Filesystems configured into the kernel.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/interrupts</filename></glossterm>
<glossdef><para>Shows which interrupts are
in use, and how many of each there have been.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/ioports</filename></glossterm>
<glossdef><para>Which I/O ports are in use at the moment.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/kcore</filename></glossterm>
<glossdef><para>An image of the physical memory of
the system. This is exactly the same size as your
physical memory, but does not really take up that much
memory; it is generated on the fly as programs access it.
(Remember: unless you copy it elsewhere, nothing under
<filename>/proc</filename> takes up any disk space
at all.) </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/kmsg</filename></glossterm>
<glossdef><para>Messages output by the kernel.
These are also routed to <command>syslog</command>.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/ksyms</filename></glossterm>
<glossdef><para>Symbol table for the kernel.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/loadavg</filename></glossterm>
<glossdef><para>The `load average' of the system; three
meaningless indicators of how much work the system has
to do at the moment. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/meminfo</filename></glossterm>
<glossdef><para>Information about memory usage, both
physical and swap. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/modules</filename></glossterm>
<glossdef><para>Which kernel modules are loaded at
the moment. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/net</filename></glossterm>
<glossdef><para>Status information about network
protocols. </para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/self</filename></glossterm>
<glossdef><para>A symbolic link to the process
directory of the program that is looking at
<filename>/proc</filename>. When two processes look at
<filename>/proc</filename>, they get different links.
This is mainly a convenience to make it easier
for programs to get at their process directory.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/stat</filename></glossterm>
<glossdef><para>Various statistics about the system, such
as the number of page faults since the system was booted.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/uptime</filename></glossterm>
<glossdef><para>The time the system has been up.
</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/proc/version</filename></glossterm>
<glossdef><para>The kernel version.
</para></glossdef></glossentry>
</glosslist></para>
<para>Note that while the above files tend to be easily readable
text files, they can sometimes be formatted in a way that is not
easily digestible. There are many commands that do little more than
read the above files and format them for easier understanding. For
example, the <command>free</command> program reads
<filename>/proc/meminfo</filename> and converts the amounts given in
bytes to kilobytes (and adds a little more information, as
well).</para>
</sect1>
</chapter>
<chapter id="device-list">
<title>Device Files</title>
<para>This chapter gives an overview of what a device file is, and how to
create one. It also lists some of the more common device files. The
canonical list of device files is
<filename>/usr/src/linux/Documentation/devices.txt</filename> if you have
the Linux kernel source code installed on your system. The devices listed
here are correct as of kernel version 2.2.17.</para>
<sect1>
<title>The <command>MAKEDEV</command> Script</title>
<para>Most device files will already be created and will be there
ready to use after you install your Linux system. If by some chance
you need to create one which is not provided then you should first
try to use the <command>MAKEDEV</command> script. This script is
usually located in <filename>/dev/MAKEDEV</filename> but might also
have a copy (or a symbolic link) in
<filename>/sbin/MAKEDEV</filename>. If it turns out not to be in
your path then you will need to specify the path to it
explicitly.</para>
<para>In general the command is used as:
<screen>
<prompt>#</prompt> <userinput>/dev/MAKEDEV -v ttyS0</userinput>
<computeroutput>create ttyS0 c 4 64 root:dialout 0660</computeroutput>
</screen>
This will create the device file <filename>/dev/ttyS0</filename>
with major node 4 and minor node 64 as a character device with
access permissions 0660 with owner root and group dialout.</para>
<para><filename>ttyS0</filename> is a serial port. The major and
minor node numbers are numbers understood by the kernel. The kernel
refers to hardware devices as numbers, this would be very difficult
for us to remember, so we use filenames. Access permissions of 0660
means read and write permission for the owner (root in this case)
and read and write permission for members of the group (dialout in
this case) with no access for anyone else.</para>
</sect1>
<sect1>
<title>The <command>mknod</command> command</title>
<para><command>MAKEDEV</command> is the preferred way of creating
device files which are not present. However sometimes the
<command>MAKEDEV</command> script will not know about the device
file you wish to create. This is where the <command>mknod</command>
command comes in. In order to use <command>mknod</command> you need
to know the major and minor node numbers for the device you wish to
create. The <filename>devices.txt</filename> file in the kernel
source documentation is the canonical source of this
information.</para>
<para>To take an example, let us suppose that our version of the
<command>MAKEDEV</command> script does not know how to create the
<filename>/dev/ttyS0</filename> device file. We need to use
<command>mknod</command> to create it. We know from looking at the
<filename>devices.txt</filename> file that it should be a character
device with major number 4 and minor number 64. So we now know all
we need to create the file.
<screen>
<prompt>#</prompt> <userinput>mknod /dev/ttyS0 c 4 64</userinput>
<prompt>#</prompt> <userinput>chown root.dialout /dev/ttyS0</userinput>
<prompt>#</prompt> <userinput>chmod 0644 /dev/ttyS0</userinput>
<prompt>#</prompt> <userinput>ls -l /dev/ttyS0</userinput>
<computeroutput>crw-rw---- 1 root dialout 4, 64 Oct 23 18:23 /dev/ttyS0</computeroutput>
</screen>
As you can see, many more steps are required to create the file. In
this example you can see the process required however. It is
unlikely in the extreme that the ttyS0 file would not be provided by
the <command>MAKEDEV</command> script, but it suffices to illustrate
the point.</para>
</sect1>
<sect1>
<title>Device List</title>
<para>This list which follows is by no means exhaustive or as
detailed as it could be. Many of these device files will need
support compiled into your kernel for the hardware. Read the kernel
documentation to find details of any particular device.</para>
<para>If you think there are other devices which should be included here but
aren't then let me know. I will try to include them in the next revision.</para>
<glosslist>
<glossentry>
<glossterm><filename>/dev/dsp</filename></glossterm>
<glossdef><para>Digital Signal Processor. Basically this forms
the interface between software which produces sound and your
soundcard. It is a character device on major node 14 and minor
3.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/fd0</filename></glossterm>
<glossdef><para>The first floppy drive. If you are lucky enough
to have several drives then they will be numbered sequentially.
It is a character device on major node 2 and minor
0.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/fb0</filename></glossterm>
<glossdef><para>The first framebuffer device. A framebuffer is
an abstraction layer between software and graphics hardware.
This means that applications do not need to know about what kind
of hardware you have but merely how to communicate with the
framebuffer driver's API (Application Programming Interface)
which is well defined and standardised. The framebuffer is a
character device and is on major node 29 and minor
0.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/hda</filename></glossterm>
<glossdef><para><filename>/dev/hda</filename> is the master IDE
drive on the primary IDE controller.
<filename>/dev/hdb</filename> is the slave drive on the primary
controller. <filename>/dev/hdc</filename> and
<filename>/dev/hdd</filename> are the master and slave devices
on the secondary controller respectively. Each disk is divided
into partitions. Partitions 1-4 are primary partitions and
partitions 5 and above are logical partitions inside extended
partitions. Therefore the device file which references each
partition is made up of several parts. For example
<filename>/dev/hdc9</filename> references partition 9 (a logical
partition inside an extended partition type) on the master IDE
drive on the secondary IDE controller. The major and minor node
numbers are somewhat complex. For the first IDE controller all
partitions are block devices on major node 3. The master drive
<filename>hda</filename> is at minor 0 and the slave drive
<filename>hdb</filename> is at minor 64. For each partition
inside the drive add the partition number to the minor node
number for the drive. For example
<filename>/dev/hdb5</filename> is major 3, minor 69 (64 + 5 =
69). Drives on the secondary interface are handled the same way,
but with major node 22.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/ht0</filename></glossterm>
<glossdef><para>The first IDE tape drive. Subsequent drives are
numbered <filename>ht1</filename> etc. They are character
devices on major node 37 and start at minor node 0 for
<filename>ht0</filename> 1 for <filename>ht1</filename>
etc.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/js0</filename></glossterm>
<glossdef><para>The first analogue joystick. Subsequent joysticks
are numbered <filename>js1</filename>, <filename>js2</filename>
etc. Digital joysticks are called <filename>djs0</filename>,
<filename>djs1</filename> and so on. They are character devices
on major node 15. The analogue joysticks start at minor node 0
and go up to 127 (more than enough for even the most fanatic
gamer). Digital joysticks start at minor node
128.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/lp0</filename></glossterm>
<glossdef><para>The first parallel printer device. Subsequent
printers are numbered <filename>lp1</filename>,
<filename>lp2</filename> etc. They are character devices on
major mode 6 and minor nodes starting at 0 and numbered
sequentially.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/loop0</filename></glossterm>
<glossdef><para>The first loopback device. Loopback devices are
used for mounting filesystems which are not located on other
block devices such as disks. For example if you wish to mount
an iso9660 CD ROM image without burning it to CD then you need
to use a loopback device to do so. This is usually transparent
to the user and is handled by the <command>mount</command>
command. Refer to the manual pages for <command>mount</command>
and <command>losetup</command>. The loopback devices are block
devices on major node 7 and with minor nodes starting at 0 and
numbered sequentially.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/md0</filename></glossterm>
<glossdef><para>First metadisk group. Metadisks are related to
RAID (Redundant Array of Independent Disks) devices. Please
refer to the various RAID HOWTOs at the LDP for more details.
Metadisk devices are block devices on major node 9 with minor
nodes starting at 0 and numbered
sequentially.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/mixer</filename></glossterm>
<glossdef><para>This is part of the OSS (Open Sound System)
driver. Refer to the OSS documentation at <ulink
url="http://www.opensound.com">http://www.opensound.com</ulink>
for more details. It is a character device on major node 14,
minor node 0.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/null</filename></glossterm>
<glossdef><para>The bit bucket. A black hole where you can send
data for it never to be seen again. Anything sent to
<filename>/dev/null</filename> will disappear. This can be
useful if, for example, you wish to run a command but not have
any feedback appear on the terminal. It is a character device
on major node 1 and minor node 3.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/psaux</filename></glossterm>
<glossdef><para>The PS/2 mouse port. This is a character device
on major node 10, minor node 1.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/pda</filename></glossterm>
<glossdef><para>Parallel port IDE disks. These are named
similarly to disks on the internal IDE controllers
(<filename>/dev/hd*</filename>). They are block devices on major
node 45. Minor nodes need slightly more explanation here. The
first device is <filename>/dev/pda</filename> and it is on minor
node 0. Partitions on this device are found by adding the
partition number to the minor number for the device. Each
device is limited to 15 partitions each rather than 63 (the
limit for internal IDE disks). <filename>/dev/pdb</filename>
minor nodes start at 16, <filename>/dev/pdc</filename> at 32 and
<filename>/dev/pdd</filename> at 48. So for example the minor
node number for <filename>/dev/pdc6</filename> would be 38 (32 +
6 = 38). This scheme limits you to 4 parallel disks of 15
partitions each.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/pcd0</filename></glossterm>
<glossdef><para>Parallel port CD ROM drives. These are numbered
from 0 onwards. All are block devices on major node 46.
<filename>/dev/pcd0</filename> is on minor node 0 with
subsequent drives being on minor nodes 1, 2, 3
etc.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/pt0</filename></glossterm>
<glossdef><para>Parallel port tape devices. Tapes do not have
partitions so these are just numbered sequentially. They are
character devices on major node 96. The minor node numbers
start from 0 for <filename>/dev/pt0</filename>, 1 for
<filename>/dev/pt1</filename>, and so on.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/parport0</filename></glossterm>
<glossdef><para>The raw parallel ports. Most devices which are
attached to parallel ports have their own drivers. This is a
device to access the port directly. It is a character device on
major node 99 with minor node 0. Subsequent devices after the
first are numbered sequentially incrementing the minor
node.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/random</filename> or <filename>/dev/urandom</filename></glossterm>
<glossdef><para>These are kernel random number generators.
<filename>/dev/random</filename> is a non-deterministic
generator which means that the value of the next number cannot
be guessed from the preceding ones. It uses the entropy of the
system hardware to generate numbers. When it has no more
entropy to use then it must wait until it has collected more
before it will allow any more numbers to be read from it.
<filename>/dev/urandom</filename> works similarly. Initially it
also uses the entropy of the system hardware, but when there is
no more entropy to use it will continue to return numbers using
a pseudo random number generating formula. This is considered
to be less secure for vital purposes such as cryptographic key
pair generation. If security is your overriding concern then
use <filename>/dev/random</filename>, if speed is more important
then <filename>/dev/urandom</filename> works fine. They are
character devices on major node 1 with minor nodes 8 for
<filename>/dev/random</filename> and 9 for
<filename>/dev/urandom</filename>.</para></glossdef></glossentry>
<glossentry>
<glossterm><filename>/dev/zero</filename></glossterm>
<glossdef><para>This is a simple way of getting many 0s. Every
time you read from this device it will return 0. This can be
useful sometimes, for example when you want a file of fixed
length but don't really care what it contains. It is a
character device on major node 1 and minor node
5.</para></glossdef></glossentry>
</glosslist>
</sect1>
</chapter>
<chapter>
<title>Using Disks and Other Storage Media</title>
<blockquote><para><quote>On a clear disk you can seek forever.
</quote></para></blockquote>
<!--
% the following metas need too much work for the next version
%
% \meta copying a directory/disk verbatim
%
% \meta disaster recovery: program to scan for ext2 superblocks
%
% \meta explain lost+found; how to fix a filesystem; what to do when
% there is a bad block; identifying the file that has the bad block
%
% \meta chart that shows characteristics of various fs: max size,
% max file size, usable as root, max name length, speed, support
%
% \meta
% Recovering from a bad MBR or super block.
% Manually remounting (ro->rw, rw->ro, when, why)
% automounting
% MD patches
% Why does Linux read/write disk in background?
% how to mount a dos disk so that everyone can access it?
% supermount
% ide disks map away bad sectors (until they're too many, then
% use badblocks)
% mounting: mountee root becomes mount point, e.g.
permissions/ownership
% linux has maximum of 15 partitions (not inherent in partition
% scheme!)
% max ext2 part size is 2TB, file 2 GB
% ext2 fragmentation
% list important device files for disks et al as a table
-->
<para>When you install or upgrade your system, you need to do a
fair amount of work on your disks. You have to make filesystems on
your disks so that files can be stored on them and reserve
space for the different parts of your system.</para>
<para>This chapter explains all these initial activities. Usually,
once you get your system set up, you won't have to go through the
work again, except for using floppies. You'll need to come back to
this chapter if you add a new disk or want to fine-tune your disk usage.<para>
<para>The basic tasks in administering disks are:
<itemizedlist>
<listitem><para>
Format your disk. This does various things to prepare it for use,
such as checking for bad sectors. (Formatting is nowadays
not necessary for most hard disks.)</para></listitem>
<listitem><para>
Partition a hard disk, if you want to use it for several activities
that aren't supposed to interfere with one another. One reason for
partitioning is to store different operating systems on the same
disk. Another reason is to keep user files separate from system
files, which simplifies back-ups and helps protect the system files
from corruption.
</para></listitem>
<listitem><para>
Make a filesystem (of a suitable type) on each disk or partition.
The disk means nothing to Linux until you make a filesystem; then
files can be created and accessed on it.
</para></listitem>
<listitem><para>
Mount different filesystems to form a single tree structure, either
automatically, or manually as needed. (Manually mounted filesystems
usually need to be unmounted manually as well.)
</para></listitem>
</itemizedlist>
<para><xref linkend="memory-management"> contains information
about virtual memory and disk caching, of which you also need
to be aware when using disks.</para>
<sect1>
<title>Two kinds of devices</title>
<para>UNIX, and therefore Linux, recognises two different
kinds of device: random-access block devices (such as disks), and
character devices (such as tapes and serial lines), some of which
may be serial, and some random-access. Each supported device is
represented in the filesystem as a <glossterm>device
file</glossterm>. When you read or write a device file, the data
comes from or goes to the device it represents. This way no special
programs (and no special application programming methodology, such
as catching interrupts or polling a serial port) are necessary to
access devices; for example, to send a file to the printer, one
could just say
<screen>
<prompt>$</prompt> <userinput>cat filename > /dev/lp1</userinput>
<prompt>$</prompt>
</screen>
and the contents of the file are printed (the file must, of course,
be in a form that the printer understands). However, since it is
not a good idea to have several people cat their files to the
printer at the same time, one usually uses a special program to send
the files to be printed (usually <command>lpr</command>). This
program makes sure that only one file is being printed at a time,
and will automatically send files to the printer as soon as it
finishes with the previous file. Something similar is needed for
most devices. In fact, one seldom needs to worry
about device files at all.</para>
<para>Since devices show up as files in the filesystem (in the
<filename>/dev</filename> directory), it is easy to see just what
device files exist, using <command>ls</command> or another suitable
command. In the output of <command>ls -l</command>, the first
column contains the type of the file and its permissions. For
example, inspecting a serial device might give
<screen>
<prompt>$</prompt> <userinput>ls -l /dev/ttyS0</userinput>
<computeroutput>crw-rw-r-- 1 root dialout 4, 64 Aug 19 18:56 /dev/ttyS0</computeroutput>
<prompt>$</prompt>
</screen>
The first character in the first column, i.e.,
`<literal>c</literal>' in <literal>crw-rw-rw-</literal> above, tells
an informed user the type of the file, in this case a character
device. For ordinary files, the first character is
`<literal>-</literal>', for directories it is
`<literal>d</literal>', and for block devices
`<literal>b</literal>'; see the <command>ls</command> man page
for further information.</para>
<para>Note that usually all device files exist even though the
device itself might be not be installed. So just because you have a
file <filename>/dev/sda</filename>, it doesn't mean that you really
do have an SCSI hard disk. Having all the device files makes the
installation programs simpler, and makes it easier to add new
hardware (there is no need to find out the correct parameters
for and create the device files for the new device).</para>
</sect1>
<sect1>
<title>Hard disks</title>
<para>This subsection introduces terminology related to hard
disks. If you already know the terms and concepts, you can skip
this subsection.</para>
<para>See <xref linkend="hd-schematic"> for a schematic picture
of the important parts in a hard disk. A hard disk consists of one
or more circular <glossterm>platters</glossterm>,
<footnote><para>The platters are made of a hard
substance, e.g., aluminium, which gives the hard disk
its name.</para></footnote>
of which either or both <glossterm>surfaces</glossterm> are coated
with a magnetic substance used for recording the data. For each
surface, there is a <glossterm>read-write head</glossterm> that
examines or alters the recorded data. The platters rotate on a
common axis; typical rotation speed is 5400 or 7200 rotations per
minute, although high-performance hard disks have higher speeds and
older disks may have lower speeds. The heads move along the radius
of the platters; this movement combined with the rotation of the
platters allows the head to access all parts of the surfaces.</para>
<para>The processor (CPU) and the actual disk communicate through
a <glossterm>disk controller</glossterm>. This relieves the rest of
the computer from knowing how to use the drive, since the
controllers for different types of disks can be made to use the same
interface towards the rest of the computer. Therefore, the computer
can say just ``hey disk, give me what I want'', instead of a long
and complex series of electric signals to move the head to the
proper location and waiting for the correct position to come under
the head and doing all the other unpleasant stuff necessary. (In
reality, the interface to the controller is still complex, but much
less so than it would otherwise be.) The controller may also do
other things, such as caching, or automatic bad sector
replacement.</para>
<para>The above is usually all one needs to understand about the
hardware. There are also other things, such as the motor that
rotates the platters and moves the heads, and the electronics that
control the operation of the mechanical parts, but they are mostly
not relevant for understanding the working principles of a hard
disk.</para>
<para>The surfaces are usually divided into concentric rings,
called <glossterm>tracks</glossterm>, and these in turn are divided
into <glossterm>sectors</glossterm>. This division is used to
specify locations on the hard disk and to allocate disk space to
files. To find a given place on the hard disk, one might say
``surface 3, track 5, sector 7''. Usually the number of sectors is
the same for all tracks, but some hard disks put more sectors in
outer tracks (all sectors are of the same physical size, so more of
them fit in the longer outer tracks). Typically, a sector will hold
512 bytes of data. The disk itself
can't handle smaller amounts of data than one sector.</para>
<figure id="hd-schematic" float="1">
<title>A schematic picture of a hard disk.</title>
<graphic fileref="hd-schematic"></graphic>
</figure>
<para>Each surface is divided into tracks (and sectors) in
the same way. This means that when the head for one surface is on a
track, the heads for the other surfaces are also on the
corresponding tracks. All the corresponding tracks taken together
are called a <glossterm>cylinder</glossterm>. It takes time to
move the heads from one track (cylinder) to another, so by placing
the data that is often accessed together (say, a file) so that it is
within one cylinder, it is not necessary to move the heads to read
all of it. This improves performance. It is not always possible to
place files like this; files that are stored in several places on
the disk are called
<glossterm>fragmented</glossterm>.</para>
<para>The number of surfaces (or heads, which is the same thing),
cylinders, and sectors vary a lot; the specification of the number
of each is called the <glossterm>geometry</glossterm> of a hard
disk. The geometry is usually stored in a special, battery-powered
memory location called the <glossterm>CMOS RAM</glossterm>, from
where the operating system can fetch it during bootup or driver
initialisation.</para>
<para>Unfortunately, the BIOS
<footnote><para>The BIOS is some built-in software stored on
ROM chips. It takes care, among other things, of the
initial stages of booting.</para></footnote>
has a design limitation, which makes it impossible to specify a
track number that is larger than 1024 in the CMOS RAM, which is too
little for a large hard disk. To overcome this, the hard disk
controller lies about the geometry, and <glossterm>translates the
addresses</glossterm> given by the computer into something that fits
reality. For example, a hard disk might have 8 heads, 2048 tracks,
and 35 sectors per track.
<footnote><para>The numbers are completely
imaginary.</para></footnote>
Its controller could lie to the computer and claim that it has 16
heads, 1024 tracks, and 35 sectors per track, thus not exceeding the
limit on tracks, and translates the address that the computer gives
it by halving the head number, and doubling the track number. The
mathematics can be more complicated in reality, because the numbers
are not as nice as here (but again, the details are not relevant for
understanding the principle). This translation distorts the
operating system's view of how the disk is organised, thus making it
impractical to use the all-data-on-one-cylinder trick to boost
performance.</para>
<para>The translation is only a problem for IDE disks. SCSI disks
use a sequential sector number (i.e., the controller translates a
sequential sector number to a head, cylinder, and sector triplet),
and a completely different method for the CPU to talk with the
controller, so they are insulated from the problem. Note, however,
that the computer might not know the real geometry of an SCSI disk
either.</para>
<para>Since Linux often will not know the real geometry of a disk,
its filesystems don't even try to keep files within a single
cylinder. Instead, it tries to assign sequentially numbered sectors
to files, which almost always gives similar performance. The issue
is further complicated by on-controller caches, and automatic
prefetches done by the controller.</para>
<para>Each hard disk is represented by a separate device
file. There can (usually) be only two or four IDE hard disks. These
are known as <filename>/dev/hda</filename>,
<filename>/dev/hdb</filename>, <filename>/dev/hdc</filename>, and
<filename>/dev/hdd</filename>, respectively. SCSI hard disks are
known as <filename>/dev/sda</filename>,
<filename>/dev/sdb</filename>, and so on. Similar naming
conventions exist for other hard disk types; see <xref
linkend="device-list"> for more information. Note that the device
files for the hard disks give access to the entire disk, with no
regard to partitions (which will be discussed below), and it's easy
to mess up the partitions or the data in them if you aren't careful.
The disks' device files are usually used only to get access to the
master boot record (which will also be discussed below).</para>
</sect1>
<sect1>
<title>Floppies</title>
<para>A floppy disk consists of a flexible membrane covered on one
or both sides with similar magnetic substance as a hard disk. The
floppy disk itself doesn't have a read-write head, that is included
in the drive. A floppy corresponds to one platter in a hard disk,
but is removable and one drive can be used to access different
floppies, and the same floppy can be read by many drives, whereas
the hard disk is one indivisible unit.</para>
<para>Like a hard disk, a floppy is divided into tracks and sectors
(and the two corresponding tracks on either side of a floppy
form a cylinder), but there are many fewer of them than on a
hard disk.</para>
<para>A floppy drive can usually use several different types of disks;
for example, a 3.5 inch drive can use both 720 kB and 1.44 MB disks.
Since the drive has to operate a bit differently and the operating
system must know how big the disk is, there are many device files
for floppy drives, one per combination of drive and disk type.
Therefore, <filename>/dev/fd0H1440</filename> is the first floppy
drive (fd0), which must be a 3.5 inch drive, using a 3.5 inch, high
density disk (H) of size 1440 kB (1440), i.e., a normal 3.5 inch HD
floppy.
</para>
<para>The names for floppy drives are complex, however, and Linux
therefore has a special floppy device type that automatically
detects the type of the disk in the drive. It works by trying to
read the first sector of a newly inserted floppy using different
floppy types until it finds the correct one. This naturally requires
that the floppy is formatted first. The automatic devices are called
<filename>/dev/fd0</filename>, <filename>/dev/fd1</filename>, and so
on.</para>
<para>The parameters the automatic device uses to access a disk can
also be set using the program <command>setfdprm</command>. This can
be useful if you need to use disks that do not follow any usual
floppy sizes, e.g., if they have an unusual number of sectors, or if
the autodetecting for some reason fails and the proper device file is
missing.</para>
<para>Linux can handle many nonstandard floppy disk formats
in addition to all the standard ones. Some of these require using
special formatting programs. We'll skip these disk types for now,
but in the mean time you can examine the
<filename>/etc/fdprm</filename> file. It specifies the settings
that <command>setfdprm</command> recognises.</para>
<para>The operating system must know when a disk has been changed in
a floppy drive, for example, in order to avoid using cached data
from the previous disk. Unfortunately, the signal line that is used
for this is sometimes broken, and worse, this won't always be
noticeable when using the drive from within MS-DOS. If you are
experiencing weird problems using floppies, this might be the
reason. The only way to correct it is to repair the floppy drive.</para>
</sect1>
<sect1>
<title>CD-ROMs</title>
<para>A CD-ROM drive uses an optically read, plastic coated disk.
The information is recorded on the surface of the disk
<footnote><para>That is, the surface inside the disk, on
the metal disk inside the plastic coating.</para></footnote>
in small `holes' aligned along a spiral from the centre to the edge.
The drive directs a laser beam along the spiral to read the disk.
When the laser hits a hole, the laser is reflected in one way; when
it hits smooth surface, it is reflected in another way. This makes
it easy to code bits, and therefore information. The rest is easy,
mere mechanics.</para>
<para>CD-ROM drives are slow compared to hard disks. Whereas a
typical hard disk will have an average seek time less than 15
milliseconds, a fast CD-ROM drive can use tenths of a second for
seeks. The actual data transfer rate is fairly high at hundreds of
kilobytes per second. The slowness means that CD-ROM drives are not
as pleasant to use as hard disks (some Linux distributions provide
`live' filesystems on CD-ROMs, making it unnecessary to copy the
files to the hard disk, making installation easier and saving a lot
of hard disk space), although it is still possible. For installing
new software, CD-ROMs are very good, since maximum speed is not
essential during installation.</para>
<para>There are several ways to arrange data on a CD-ROM. The most
popular one is specified by the international standard ISO 9660.
This standard specifies a very minimal filesystem, which is even
more crude than the one MS-DOS uses. On the other hand, it is so
minimal that every operating system should be able to map it to its
native system.</para>
<para>For normal UNIX use, the ISO 9660 filesystem is not usable, so
an extension to the standard has been developed, called the Rock
Ridge extension. Rock Ridge allows longer filenames, symbolic
links, and a lot of other goodies, making a CD-ROM look more or less
like any contemporary UNIX filesystem. Even better, a Rock Ridge
filesystem is still a valid ISO 9660 filesystem, making it usable by
non-UNIX systems as well. Linux supports both ISO 9660 and the Rock
Ridge extensions; the extensions are recognised and used
automatically.</para>
<para>The filesystem is only half the battle, however. Most CD-ROMs
contain data that requires a special program to access, and most of
these programs do not run under Linux (except, possibly, under
dosemu, the Linux MS-DOS emulator, or wine, the Windows emulator.
<footnote><para>Ironically perhaps, wine actually stands
for ``Wine Is Not an Emulator''. Wine, more strictly, is an
API (Application Program Interface) replacement. Please see
the wine documentation at <ulink
url="http://www.winehq.com">http://www.winehq.com</ulink>
for more information.</para></footnote>
There is also VMWare, a commercial product which emulates an
entire x86 machine in software
<footnote><para>See the VMWare website, <ulink
url="http://www.vmware.com">http://www.vmware.com</ulink>
for more information.</para></footnote>)
.</para>
<para>A CD-ROM drive is accessed via the corresponding device file.
There are several ways to connect a CD-ROM drive to the computer:
via SCSI, via a sound card, or via EIDE. The hardware hacking
needed to do this is outside the scope of this book, but the
type of connection decides the device file.</para>
</sect1>
<sect1>
<title>Tapes</title>
<para>A tape drive uses a tape, similar
<footnote><para>But completely
different, of course.</para></footnote>
to cassettes used for music. A tape is serial in nature, which
means that in order to get to any given part of it, you first have
to go through all the parts in between. A disk can be accessed
randomly, i.e., you can jump directly to any place on the disk.
The serial access of tapes makes them slow.</para>
<para>On the other hand, tapes are relatively cheap to make,
since they do not need to be fast. They can also easily be made
quite long, and can therefore contain a large amount of data. This
makes tapes very suitable for things like archiving and backups,
which do not require large speeds, but benefit from
low costs and large storage capacities.</para>
</sect1>
<sect1>
<title>Formatting</title>
<para><glossterm>Formatting</glossterm> is the process of writing marks
on the magnetic media that are used to mark tracks and sectors.
Before a disk is formatted, its magnetic surface is a complete mess
of magnetic signals. When it is formatted, some order is brought
into the chaos by essentially drawing lines where the tracks go, and
where they are divided into sectors. The actual details are not
quite exactly like this, but that is irrelevant. What is important
is that a disk cannot be used unless it has been formatted.</para>
<para>The terminology is a bit confusing here: in MS-DOS and MS
Windows, the word formatting is used to cover also the process of
creating a filesystem (which will be discussed below). There, the
two processes are often combined, especially for floppies. When the
distinction needs to be made, the real formatting is called
<glossterm>low-level formatting</glossterm>, while making the
filesystem is called <glossterm>high-level formatting</glossterm>.
In UNIX circles, the two are called formatting and making a
filesystem, so that's what is used in this book as well.</para>
<para>For IDE and some SCSI disks the formatting is actually
done at the factory and doesn't need to be repeated; hence most
people rarely need to worry about it. In fact, formatting a hard
disk can cause it to work less well, for example because a disk
might need to be formatted in some very special way to
allow automatic bad sector replacement to work.</para>
<para>Disks that need to be or can be formatted often require a
special program anyway, because the interface to the formatting
logic inside the drive is different from drive to drive. The
formatting program is often either on the controller BIOS, or is
supplied as an MS-DOS program; neither of these can easily
be used from within Linux.</para>
<para>During formatting one might encounter bad spots on the
disk, called <glossterm>bad blocks</glossterm> or <glossterm>bad
sectors</glossterm>. These are sometimes handled by the drive
itself, but even then, if more of them develop, something needs to
be done to avoid using those parts of the disk. The logic to do
this is built into the filesystem; how to add the information into
the filesystem is described below. Alternatively, one might create
a small partition that covers just the bad part of the disk; this
approach might be a good idea if the bad spot is very large, since
filesystems can sometimes have trouble with very large bad areas.</para>
<para>Floppies are formatted with <command>fdformat</command>. The
floppy device file to use is given as the parameter. For example,
the following command would format a high density, 3.5 inch floppy
in the first floppy drive:
<screen>
<prompt>$</prompt> <userinput>fdformat /dev/fd0H1440</userinput>
<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity
1440 kB.</computeroutput>
<computeroutput>Formatting ... done</computeroutput>
<computeroutput>Verifying ... done</computeroutput>
<prompt>$</prompt>
</screen>
Note that if you want to use an autodetecting device (e.g.,
<filename>/dev/fd0</filename>), you <emphasis>must</emphasis> set
the parameters of the device with <command>setfdprm</command> first.
To achieve the same effect as above, one would have to do the
following:
<screen>
<prompt>$</prompt> <userinput>setfdprm /dev/fd0 1440/1440</userinput>
<prompt>$</prompt> <userinput>fdformat /dev/fd0</userinput>
<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity
1440 kB.</computeroutput>
<computeroutput>Formatting ... done</computeroutput>
<computeroutput>Verifying ... done</computeroutput>
<prompt>$</prompt>
</screen>
It is usually more convenient to choose the correct device file that
matches the type of the floppy. Note that it is unwise to format
floppies to contain more information than what they are
designed for.</para>
<para><command>fdformat</command> will also validate the floppy,
i.e., check it for bad blocks. It will try a bad block several
times (you can usually hear this, the drive noise changes
dramatically). If the floppy is only marginally bad (due to dirt on
the read/write head, some errors are false signals),
<command>fdformat</command> won't complain, but a real error will
abort the validation process. The kernel will print log messages for
each I/O error it finds; these will go to the console or, if
<command>syslog</command> is being used, to the file
<filename>/usr/log/messages</filename>. <command>fdformat</command>
itself won't tell where the error is (one usually doesn't care,
floppies are cheap enough that a bad one is automatically thrown
away).
<screen>
<prompt>$</prompt> <userinput>fdformat /dev/fd0H1440</userinput>
<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity
1440 kB.</computeroutput>
<computeroutput>Formatting ... done</computeroutput>
<computeroutput>Verifying ... read: Unknown error</computeroutput>
<prompt>$</prompt>
</screen>
The <command>badblocks</command> command can be used to search any
disk or partition for bad blocks (including a floppy). It does not
format the disk, so it can be used to check even existing
filesystems. The example below checks a 3.5 inch floppy with two
bad blocks.
<screen>
<prompt>$</prompt> <userinput>badblocks /dev/fd0H1440 1440</userinput>
<computeroutput>718</computeroutput>
<computeroutput>719</computeroutput>
<prompt>$</prompt>
</screen>
<command>badblocks</command> outputs the block numbers of the bad
blocks it finds. Most filesystems can avoid such bad blocks. They
maintain a list of known bad blocks, which is initialised when the
filesystem is made, and can be modified later. The initial search
for bad blocks can be done by the <command>mkfs</command> command
(which initialises the filesystem), but later checks should be done
with <command>badblocks</command> and the new blocks should be added
with <command>fsck</command>. We'll describe
<command>mkfs</command>
and <command>fsck</command> later.</para>
<para>Many modern disks automatically notice bad blocks, and attempt
to fix them by using a special, reserved good block instead. This is
invisible to the operating system. This feature should be
documented in the disk's manual, if you're curious if it is
happening. Even such disks can fail, if the number of bad blocks
grows too large, although chances are that by then the disk
will be so rotten as to be unusable.</para>
</sect1>
<sect1>
<title>Partitions</title>
<para>A hard disk can be divided into several
<glossterm>partitions</glossterm>. Each partition functions as if
it were a separate hard disk. The idea is that if you have one hard
disk, and want to have, say, two operating systems on it, you can
divide the disk into two partitions. Each operating system uses its
partition as it wishes and doesn't touch the other ones. This way
the two operating systems can co-exist peacefully on the same hard
disk. Without partitions one would have to buy a hard disk for each
operating system.</para>
<para>Floppies are not usually partitioned. There is no technical reason
against this, but since they're so small, partitions would be useful
only very rarely. CD-ROMs are usually also not partitioned, since
it's easier to use them as one big disk, and there is seldom a need
to have several operating systems on one.</para>
<sect2>
<title>The MBR, boot sectors and partition table</title>
<para>The information about how a hard disk has been partitioned
is stored in its first sector (that is, the first sector of the
first track on the first disk surface). The first sector is the
<glossterm>master boot record</glossterm> (MBR) of the disk; this is
the sector that the BIOS reads in and starts when the machine is
first booted. The master boot record contains a small program that
reads the partition table, checks which partition is active (that
is, marked bootable), and reads the first sector of that partition,
the partition's <glossterm>boot sector</glossterm> (the MBR is also
a boot sector, but it has a special status and therefore a special
name). This boot sector contains another small program that reads
the first part of the operating system stored on that partition
(assuming it is bootable), and then starts it.</para>
<para>The partitioning scheme is not built into the hardware, or
even into the BIOS. It is only a convention that many operating
systems follow. Not all operating systems do follow it, but they
are the exceptions. Some operating systems support partitions, but
they occupy one partition on the hard disk, and use their internal
partitioning method within that partition. The latter type exists
peacefully with other operating systems (including Linux), and does
not require any special measures, but an operating system that
doesn't support partitions cannot co-exist on the same disk with any
other operating system.</para>
<para>As a safety precaution, it is a good idea to write down the
partition table on a piece of paper, so that if it ever corrupts you
don't have to lose all your files. (A bad partition table can be
fixed with <command>fdisk</command>). The relevant information is
given by the <command>fdisk -l</command> command:
<screen>
<prompt>$</prompt> <userinput>fdisk -l /dev/hda</userinput>
<computeroutput></computeroutput>
<computeroutput>Disk /dev/hda: 15 heads, 57 sectors, 790 cylinders</computeroutput>
<computeroutput>Units = cylinders of 855 * 512 bytes</computeroutput>
<computeroutput></computeroutput>
<computeroutput> Device Boot Begin Start End Blocks Id System</computeroutput>
<computeroutput>/dev/hda1 1 1 24 10231+ 82 Linux swap</computeroutput>
<computeroutput>/dev/hda2 25 25 48 10260 83 Linux native</computeroutput>
<computeroutput>/dev/hda3 49 49 408 153900 83 Linux native</computeroutput>
<computeroutput>/dev/hda4 409 409 790 163305 5 Extended</computeroutput>
<computeroutput>/dev/hda5 409 409 744 143611+ 83 Linux native</computeroutput>
<computeroutput>/dev/hda6 745 745 790 19636+ 83 Linux native</computeroutput>
<prompt>$</prompt>
</screen>
</sect2>
<sect2>
<title>Extended and logical partitions</title>
<para>The original partitioning scheme for PC hard disks allowed
only four partitions. This quickly turned out to be too little in
real life, partly because some people want more than four operating
systems (Linux, MS-DOS, OS/2, Minix, FreeBSD, NetBSD, or Windows/NT,
to name a few), but primarily because sometimes it is a good idea to
have several partitions for one operating system. For example, swap
space is usually best put in its own partition for Linux instead of
in the main Linux partition for reasons of speed (see below).</para>
<para>To overcome this design problem, <glossterm>extended
partitions</glossterm> were invented. This trick allows
partitioning a <glossterm>primary partition</glossterm> into
sub-partitions. The primary partition thus subdivided is the
<glossterm>extended partition</glossterm>; the sub-partitions are
<glossterm>logical partitions</glossterm>. They behave like primary
partitions, but are created differently. There is no speed
difference between them.</para>
<para>The partition structure of a hard disk might look like that
in <xref linkend="hard-disk-layout">. The disk is divided into
three primary partitions, the second of which is divided into two
logical partitions. Part of the disk is not partitioned at all.
The disk as a whole and each primary partition has a boot sector.</para>
<figure id="hard-disk-layout" float="1">
<title>A sample hard disk partitioning.</title>
<graphic fileref="hd-layout"></graphic>
</figure>
</sect2>
<sect2>
<title>Partition types</title>
<para>The partition tables (the one in the MBR, and the ones for
extended partitions) contain one byte per partition that identifies
the type of that partition. This attempts to identify the operating
system that uses the partition, or what it uses it for. The purpose
is to make it possible to avoid having two operating systems
accidentally using the same partition. However, in reality,
operating systems do not really care about the partition type byte;
e.g., Linux doesn't care at all what it is. Worse, some of them use
it incorrectly; e.g., at least some versions of DR-DOS ignore the
most significant bit of the byte, while others don't.</para>
<para>There is no standardisation agency to specify what each byte
value means, but some commonly accepted ones are included in in
<xref linkend="partition-ids">. A more complete list is available
in the Linux <command>fdisk</command> program.</para>
<table id="partition-ids">
<title>Partition types (from the Linux <command>fdisk</command> program).</title>
<tgroup cols=6>
<tbody>
<row>
<entry>0</entry> <entry>Empty</entry>
<entry>40</entry> <entry>Venix 80286</entry>
<entry>94</entry> <entry>Amoeba BBT</entry>
</row>
<row>
<entry>1</entry> <entry>DOS 12-bit FAT</entry>
<entry>51</entry> <entry>Novell?</entry>
<entry>a5</entry> <entry>BSD/386</entry>
</row>
<row>
<entry>2</entry> <entry>XENIX root</entry>
<entry>52</entry> <entry>Microport</entry>
<entry>b7</entry> <entry>BSDI fs</entry>
</row>
<row>
<entry>3</entry> <entry>XENIX usr</entry>
<entry>63</entry> <entry>GNU HURD</entry>
<entry>b8</entry> <entry>BSDI swap</entry>
</row>
<row>
<entry>4</entry> <entry>DOS 16-bit FAT <32M</entry>
<entry>64</entry> <entry>Novell</entry>
<entry>c7</entry> <entry>Syrinx</entry>
</row>
<row>
<entry>5</entry> <entry>Extended</entry>
<entry>75</entry> <entry>PC/IX</entry>
<entry>db</entry> <entry>CP/M</entry>
</row>
<row>
<entry>6</entry> <entry>DOS 16-bit >=32M</entry>
<entry>80</entry> <entry>Old MINIX</entry>
<entry>e1</entry> <entry>DOS access</entry>
</row>
<row>
<entry>7</entry> <entry>OS/2 HPFS</entry>
<entry>81</entry> <entry>Linux/MINIX</entry>
<entry>e3</entry> <entry>DOS R/O</entry>
</row>
<row>
<entry>8</entry> <entry>AIX</entry>
<entry>82</entry> <entry>Linux swap</entry>
<entry>f2</entry> <entry>DOS secondary</entry>
</row>
<row>
<entry>9</entry> <entry>AIX bootable</entry>
<entry>83</entry> <entry>Linux native</entry>
<entry>ff</entry> <entry>BBT</entry>
</row>
<row>
<entry>a</entry> <entry>OS/2 Boot Manager</entry>
<entry>93</entry> <entry>Amoeba</entry>
<entry></entry> <entry></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2>
<title>Partitioning a hard disk</title>
<para>There are many programs for creating and removing
partitions. Most operating systems have their own, and it can be a
good idea to use each operating system's own, just in case it does
something unusual that the others can't. Many of the programs are
called <command>fdisk</command>, including the Linux one, or
variations thereof. Details on using the Linux
<command>fdisk</command> are given on its man page. The
<command>cfdisk</command> command is similar to
<command>fdisk</command>, but has a nicer (full screen) user
interface.</para>
<para>When using IDE disks, the boot partition (the partition
with the bootable kernel image files) must be completely within the
first 1024 cylinders. This is because the disk is used via the BIOS
during boot (before the system goes into protected mode), and BIOS
can't handle more than 1024 cylinders. It is sometimes possible to
use a boot partition that is only partly within the first 1024
cylinders. This works as long as all the files that are read with
the BIOS are within the first 1024 cylinders. Since this is
difficult to arrange, it is <emphasis>a very bad idea</emphasis> to
do it; you never know when a kernel update or disk defragmentation
will result in an unbootable system. Therefore, make sure your boot
partition is completely within the first 1024 cylinders
<footnote><para>This may no longer be true with newer
versions of LILO that support LBA (Logical Block
Addressing). Consult the documentation for your
distribution to see if it has a version of LILO where
LBA is supported.</para></footnote>
.</para>
<para>Some newer versions of the BIOS and IDE disks can, in fact,
handle disks with more than 1024 cylinders. If you have such a
system, you can forget about the problem; if you aren't quite
sure of it, put it within the first 1024 cylinders.</para>
<para>Each partition should have an even number of sectors,
since the Linux filesystems use a 1 kilobyte block size, i.e., two
sectors. An odd number of sectors will result in the last sector
being unused. This won't result in any problems, but it is ugly,
and some versions of <command>fdisk</command> will warn about it.</para>
<para>Changing a partition's size usually requires first backing up
everything you want to save from that partition (preferably the
whole disk, just in case), deleting the partition, creating new
partition, then restoring everything to the new partition. If the
partition is growing, you may need to adjust the sizes (and backup and
restore) of the adjoining partitions as well.</para>
<para>Since changing partition sizes is painful, it is preferable to
get the partitions right the first time, or have an effective and
easy to use backup system. If you're installing from a media that
does not require much human intervention (say, from CD-ROM, as
opposed to floppies), it is often easy to play with different
configuration at first. Since you don't already have data to back
up, it is not so painful to modify partition sizes several times.</para>
<para>There is a program for MS-DOS, called
<command>fips</command>
<footnote><para>The <command>fips</command> program is
included in most Linux distributions. The commercial
partition manager ``Partition Magic'' also has a similar
facility but with a nicer interface. Please do remember
that partitioning is dangerous. Make
<emphasis>sure</emphasis> you have a recent backup of
any important data before you try changing partition
sizes ``on the fly''. The GNU program
<command>parted</command> can resize other types of
partitions as well as MS-DOS, but sometimes in a limited
manner. Consult the <command>parted</command> documentation
before using it, better safe than sorry.
</para></footnote>
, which resizes an MS-DOS partition without requiring the backup and
restore, but for other filesystems it is still necessary.</para>
</sect2>
<sect2>
<title>Device files and partitions</title>
<para>Each partition and extended partition has its own
device file. The naming convention for these files is that a
partition's number is appended after the name of the whole disk,
with the convention that 1-4 are primary partitions (regardless of
how many primary partitions there are) and number greater than 5 are
logical partitions (regardless of within which primary partition
they reside). For example, <filename>/dev/hda1</filename> is the
first primary partition on the first IDE hard disk, and
<filename>/dev/sdb7</filename> is the third extended partition on
the second SCSI hard disk.</para>
</sect2>
</sect1>
<sect1>
<title>Filesystems</title>
<sect2>
<title>What are filesystems?</title>
<para>A <glossterm>filesystem</glossterm> is the methods and
data structures that an operating system uses to keep track of files
on a disk or partition; that is, the way the files are organised on
the disk. The word is also used to refer to a partition or disk
that is used to store the files or the type of the filesystem.
Thus, one might say ``I have two filesystems'' meaning one has two
partitions on which one stores files, or that one is using the
``extended filesystem'', meaning the type of the filesystem.</para>
<para>The difference between a disk or partition and the
filesystem it contains is important. A few programs (including,
reasonably enough, programs that create filesystems) operate
directly on the raw sectors of a disk or partition; if there is an
existing file system there it will be destroyed or seriously
corrupted. Most programs operate on a filesystem, and therefore
won't work on a partition that doesn't contain one (or that contains
one of the wrong type).</para>
<para>Before a partition or disk can be used as a filesystem, it
needs to be initialised, and the bookkeeping data structures need to
be written to the disk. This process is called
<glossterm>making a filesystem</glossterm>.</para>
<para>Most UNIX filesystem types have a similar general
structure, although the exact details vary quite a bit. The central
concepts are <glossterm>superblock</glossterm>,
<glossterm>inode</glossterm>, <glossterm>data block</glossterm>,
<glossterm>directory block</glossterm>, and <glossterm>indirection
block</glossterm>. The superblock contains information about the
filesystem as a whole, such as its size (the exact information here
depends on the filesystem). An inode contains all information about
a file, except its name. The name is stored in the directory,
together with the number of the inode. A directory entry consists of
a filename and the number of the inode which represents the file.
The inode contains the numbers of several data blocks, which are
used to store the data in the file. There is space only for a few
data block numbers in the inode, however, and if more are needed,
more space for pointers to the data blocks is allocated dynamically.
These dynamically allocated blocks are indirect blocks; the name
indicates that in order to find the data block, one has to find
its number in the indirect block first.</para>
<para>UNIX filesystems usually allow one to create a
<glossterm>hole</glossterm> in a file (this is done with the
<function>lseek()</function> system call; check the manual page),
which means that the filesystem just pretends that at a particular
place in the file there is just zero bytes, but no actual disk
sectors are reserved for that place in the file (this means that the
file will use a bit less disk space). This happens especially often
for small binaries, Linux shared libraries, some databases, and a
few other special cases. (Holes are implemented by storing a
special value as the address of the data block in the indirect block
or inode. This special address means that no data block is
allocated for that part of the file, ergo, there is a hole in the
file.)</para>
</sect2>
<sect2>
<title>Filesystems galore</title>
<para>Linux supports several types of filesystems. As of this
writing the most important ones are:
<glosslist>
<glossentry>
<glossterm>minix</glossterm>
<glossdef><para>The oldest, presumed to be the most
reliable, but quite limited in features (some time stamps
are missing, at most 30 character filenames) and restricted
in capabilities (at most 64 MB per filesystem).
</para></glossdef></glossentry>
<glossentry>
<glossterm>xia</glossterm>
<glossdef><para>A modified version of the minix filesystem
that lifts the limits on the filenames and filesystem sizes,
but does not otherwise introduce new features. It is not
very popular, but is reported to work very well.
</para></glossdef></glossentry>
<glossentry>
<glossterm>ext2</glossterm>
<glossdef><para>The most featureful of the native Linux
filesystems, currently also the most popular one. It is
designed to be easily upwards compatible, so that new
versions of the filesystem code do not require re-making the
existing filesystems.</para></glossdef></glossentry>
<glossentry>
<glossterm>ext</glossterm>
<glossdef><para>An older version of ext2 that wasn't upwards
compatible. It is hardly ever used in new installations any
more, and most people have converted to ext2.
</para></glossdef></glossentry>
<glossentry>
<glossterm>reiserfs</glossterm>
<glossdef><para>A more robust filesystem. Journalling is
used which makes data loss less likely. Journalling is a
mechanism whereby a record is kept of transaction which are
to be performed, or which have been performed. This allows
the filesystem to reconstruct itself fairly easily after
damage caused by, for example, improper
shutdowns.</para></glossdef></glossentry>
</glosslist>
</para>
<para>In addition, support for several foreign filesystem exists,
to make it easier to exchange files with other operating systems.
These foreign filesystems work just like native ones, except that
they may be lacking in some usual UNIX features, or have curious
limitations, or other oddities.
<glosslist>
<glossentry>
<glossterm>msdos</glossterm>
<glossdef><para>Compatibility with MS-DOS (and OS/2 and
Windows NT) FAT filesystems.</para></glossdef></glossentry>
<glossentry>
<glossterm>umsdos</glossterm>
<glossdef><para>Extends the msdos filesystem driver under
Linux to get long filenames, owners, permissions, links, and
device files. This allows a normal msdos filesystem to be
used as if it were a Linux one, thus removing the need for a
separate partition for Linux.</para></glossdef></glossentry>
<glossentry>
<glossterm>vfat</glossterm>
<glossdef><para>This is an extension of the FAT filesystem
known as FAT32. It supports larger disk sizes than FAT.
Most MS Windows disks are vfat.</para></glossdef>
</glossentry>
<glossentry>
<glossterm>iso9660</glossterm>
<glossdef><para>The standard CD-ROM filesystem; the popular
Rock Ridge extension to the CD-ROM standard that allows
longer file names is supported automatically.
</para></glossdef></glossentry>
<glossentry>
<glossterm>nfs</glossterm>
<glossdef><para>A networked filesystem that allows sharing a
filesystem between many computers to allow easy access to
the files from all of them.</para></glossdef></glossentry>
<glossentry>
<glossterm>smbfs</glossterm>
<glossdef><para>A networks filesystem which allows sharing
of a filesystem with an MS Windows computer. It is
compatible with the Windows file sharing protocols.
</para></glossdef></glossentry>
<glossentry>
<glossterm>hpfs</glossterm>
<glossdef><para>The OS/2 filesystem.
</para></glossdef></glossentry>
<glossentry>
<glossterm>sysv</glossterm>
<glossdef><para>SystemV/386, Coherent, and Xenix filesystems.
</para></glossdef></glossentry>
</glosslist>
</para>
<para>The choice of filesystem to use depends on the situation. If
compatibility or other reasons make one of the non-native
filesystems necessary, then that one must be used. If one can
choose freely, then it is probably wisest to use ext2, since it has
all the features but does not suffer from lack of performance.</para>
<para>There is also the proc filesystem, usually accessible as
the <filename>/proc</filename> directory, which is not really a
filesystem at all, even though it looks like one. The proc
filesystem makes it easy to access certain kernel data structures,
such as the process list (hence the name). It makes these data
structures look like a filesystem, and that filesystem can be
manipulated with all the usual file tools. For example, to get a
listing of all processes one might use the command
<screen>
<prompt>$</prompt> <userinput>ls -l /proc</userinput>
<computeroutput>total 0
dr-xr-xr-x 4 root root 0 Jan 31 20:37 1
dr-xr-xr-x 4 liw users 0 Jan 31 20:37 63
dr-xr-xr-x 4 liw users 0 Jan 31 20:37 94
dr-xr-xr-x 4 liw users 0 Jan 31 20:37 95
dr-xr-xr-x 4 root users 0 Jan 31 20:37 98
dr-xr-xr-x 4 liw users 0 Jan 31 20:37 99
-r--r--r-- 1 root root 0 Jan 31 20:37 devices
-r--r--r-- 1 root root 0 Jan 31 20:37 dma
-r--r--r-- 1 root root 0 Jan 31 20:37 filesystems
-r--r--r-- 1 root root 0 Jan 31 20:37 interrupts
-r-------- 1 root root 8654848 Jan 31 20:37 kcore
-r--r--r-- 1 root root 0 Jan 31 11:50 kmsg
-r--r--r-- 1 root root 0 Jan 31 20:37 ksyms
-r--r--r-- 1 root root 0 Jan 31 11:51 loadavg
-r--r--r-- 1 root root 0 Jan 31 20:37 meminfo
-r--r--r-- 1 root root 0 Jan 31 20:37 modules
dr-xr-xr-x 2 root root 0 Jan 31 20:37 net
dr-xr-xr-x 4 root root 0 Jan 31 20:37 self
-r--r--r-- 1 root root 0 Jan 31 20:37 stat
-r--r--r-- 1 root root 0 Jan 31 20:37 uptime
-r--r--r-- 1 root root 0 Jan 31 20:37
version</computeroutput>
<prompt>$</prompt>
</screen>
(There will be a few extra files that don't correspond to
processes, though. The above example has been shortened.)</para>
<para>Note that even though it is called a filesystem, no part of
the proc filesystem touches any disk. It exists only in the
kernel's imagination. Whenever anyone tries to look at any part of
the proc filesystem, the kernel makes it look as if the part existed
somewhere, even though it doesn't. So, even though there is a
multi-megabyte <filename>/proc/kcore</filename> file, it doesn't
take any disk space. </sect2>
<sect2>
<title>Which filesystem should be used?</title>
<para>There is usually little point in using many different
filesystems. Currently, ext2fs is the most popular one, and it is
probably the wisest choice. Depending on the overhead for
bookkeeping structures, speed, (perceived) reliability,
compatibility, and various other reasons, it may be advisable to use
another file system. This needs to be decided on a case-by-case
basis.
<footnote><para>Currently there are several filesystems vying
for replacement of ext2, these include reiserfs and ext3.
They include ``journalling''. A definition and explanation
of journalling is outside the (current) scope of this book,
but put very simply it is a mechanism whereby the filesystem
is more robust against power failure, or other inelegant
shutdowns. This makes data loss far less likely and so not
surprisingly it is looking like it will be the standard
in Linux filesystems eventually.</para></footnote>
</para>
</sect2>
<sect2>
<title>Creating a filesystem</title>
<para>Filesystems are created, i.e., initialised, with the
<command>mkfs</command> command. There is actually a separate
program for each filesystem type. <command>mkfs</command> is just a
front end that runs the appropriate program depending on the desired
filesystem type. The type is selected with the
<option>-t fstype</option> option.</para>
<para>The programs called by <command>mkfs</command> have slightly
different command line interfaces. The common and most important
options are summarised below; see the manual pages for more.
<glosslist>
<glossentry>
<glossterm><option>-t fstype</option></glossterm>
<glossdef><para>
Select the type of the filesystem.
</para></glossdef></glossentry>
<glossentry>
<glossterm><option>-c</option></glossterm>
<glossdef><para>
Search for bad blocks and initialise the bad
block list accordingly.
</para></glossdef></glossentry>
<glossentry>
<glossterm>-l filename</glossterm>
<glossdef><para>
Read the initial bad block list from the name file.
</para></glossdef></glossentry>
</glosslist>
</para>
<para>To create an ext2 filesystem on a floppy, one would give the
following commands:
<screen>
<prompt>$</prompt> <userinput>fdformat -n /dev/fd0H1440</userinput>
<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity
1440 kB.
Formatting ... done</computeroutput>
<prompt>$</prompt> <userinput>badblocks /dev/fd0H1440 1440 $>$
bad-blocks</userinput>
<prompt>$</prompt> <userinput>mkfs -t ext2 -l bad-blocks
/dev/fd0H1440</userinput>
<computeroutput>mke2fs 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
360 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group
Writing inode tables: done
Writing superblocks and filesystem accounting information:
done</computeroutput>
<prompt>$</prompt>
</screen>
First, the floppy was formatted (the <option>-n</option> option
prevents validation, i.e., bad block checking). Then bad blocks
were searched with <command>badblocks</command>, with the output
redirected to a file, <filename>bad-blocks</filename>. Finally, the
filesystem was created, with the bad block list initialised
by whatever <command>badblocks</command> found.</para>
<para>The <option>-c</option> option could have been used with
<command>mkfs</command> instead of <command>badblocks</command>
and a separate file. The example below does that.
<screen>
<prompt>$</prompt> <userinput>mkfs -t ext2 -c
/dev/fd0H1440</userinput>
<computeroutput>mke2fs 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
360 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group
Checking for bad blocks (read-only test): done
Writing inode tables: done
Writing superblocks and filesystem accounting information:
done</computeroutput>
<prompt>$</prompt>
</screen>
The <option>-c</option> option is more convenient than a separate
use of <command>badblocks</command>, but
<command>badblocks</command> is necessary for checking
after the filesystem has been created.</para>
<para>The process to prepare filesystems on hard disks or
partitions is the same as for floppies, except that the formatting
isn't needed.</para>
</sect2>
<sect2 id="mount-and-umount">
<title>Mounting and unmounting</title>
<para>Before one can use a filesystem, it has to be
<glossterm>mounted</glossterm>. The operating system then does
various bookkeeping things to make sure that everything works. Since
all files in UNIX are in a single directory tree, the mount
operation will make it look like the contents of the new filesystem
are the contents of an existing subdirectory in some already mounted
filesystem.</para>
<para>For example, <xref linkend="hd-mount-root"> shows three
separate filesystems, each with their own root directory. When the
last two filesystems are mounted below <filename>/home</filename>
and <filename>/usr</filename>, respectively, on the first
filesystem, we can get a single directory tree, as in
<xref linkend="hd-mount-all">.</para>
<figure id="hd-mount-root" float="1">
<title>Three separate filesystems.</title>
<graphic fileref="hd-mount-separate"></graphic>
</figure>
<figure id="hd-mount-all" float="1">
<title><filename>/home</filename> and <filename>/usr</filename>
have been
mounted.</title>
<graphic fileref="hd-mount-mounted"></graphic>
</figure>
<para>The mounts could be done as in the following example:
<screen>
<prompt>$</prompt> <userinput>mount /dev/hda2 /home</userinput>
<prompt>$</prompt> <userinput>mount /dev/hda3 /usr</userinput>
<prompt>$</prompt>
</screen>
The <command>mount</command> command takes two arguments. The first
one is the device file corresponding to the disk or partition
containing the filesystem. The second one is the directory below
which it will be mounted. After these commands the contents of the
two filesystems look just like the contents of the
<filename>/home</filename> and <filename>/usr</filename>
directories, respectively. One would then say that
``<filename>/dev/hda2</filename> <glossterm>is mounted
on</glossterm> <filename>/home</filename>'', and similarly for
<filename>/usr</filename>. To look at either filesystem, one would
look at the contents of the directory on which it has been mounted,
just as if it were any other directory. Note the difference between
the device file, <filename>/dev/hda2</filename>, and the mounted-on
directory, <filename>/home</filename>. The device file gives access
to the raw contents of the disk, the mounted-on directory gives
access to the files on the disk. The mounted-on directory is called
the <glossterm>mount point</glossterm>.</para>
<para>Linux supports many filesystem types.
<command>mount</command> tries to guess the type of the filesystem.
You can also use the <option>-t fstype</option> option to specify
the type directly; this is sometimes necessary, since the heuristics
<command>mount</command> uses do not always work. For example, to
mount an MS-DOS floppy, you could use the following command:
<screen>
<prompt>$</prompt> <userinput>mount -t msdos /dev/fd0
/floppy</userinput>
<prompt>$</prompt>
</screen>
</para>
<para>The mounted-on directory need not be empty, although it
must exist. Any files in it, however, will be inaccessible by name
while the filesystem is mounted. (Any files that have already been
opened will still be accessible. Files that have hard links from
other directories can be accessed using those names.) There is no
harm done with this, and it can even be useful. For instance, some
people like to have <filename>/tmp</filename> and
<filename>/var/tmp</filename> synonymous, and make
<filename>/tmp</filename> be a symbolic link to
<filename>/var/tmp</filename>. When the system is booted, before
the <filename>/var</filename> filesystem is mounted, a
<filename>/var/tmp</filename> directory residing on the root
filesystem is used instead. When <filename>/var</filename> is
mounted, it will make the <filename>/var/tmp</filename> directory
on the root filesystem inaccessible. If
<filename>/var/tmp</filename> didn't exist on the root filesystem,
it would be impossible to use temporary files
before mounting <filename>/var</filename>.</para>
<para>If you don't intend to write anything to the filesystem, use
the <option>-r</option> switch for <command>mount</command> to do a
<glossterm>read-only mount</glossterm>. This will make the kernel
stop any attempts at writing to the filesystem, and will also stop
the kernel from updating file access times in the inodes. Read-only
mounts are necessary for unwritable media, e.g., CD-ROMs.</para>
<para>The alert reader has already noticed a slight
logistical problem. How is the first filesystem (called the
<glossterm>root filesystem</glossterm>, because it contains the root
directory) mounted, since it obviously can't be mounted on another
filesystem? Well, the answer is that it is done by magic.
<footnote><para>For more
information, see the kernel source or the Kernel Hackers'
Guide.</para></footnote>
The root filesystem is magically mounted at boot time, and one can
rely on it to always be mounted. If the root filesystem can't be
mounted, the system does not boot. The name of the filesystem that
is magically mounted as root is either compiled into the kernel, or
set using LILO or <command>rdev</command>.</para>
<para>The root filesystem is usually first mounted read-only.
The startup scripts will then run <command>fsck</command> to verify
its validity, and if there are no problems, they will
<glossterm>re-mount</glossterm> it so that writes will also be
allowed. <command>fsck</command> must not be run on a mounted
filesystem, since any changes to the filesystem while
<command>fsck</command> is running <emphasis>will</emphasis> cause
trouble. Since the root filesystem is mounted read-only while
it is being checked, <command>fsck</command> can fix any problems
without worry, since the remount operation will flush
any metadata that the filesystem keeps in memory.</para>
<para>On many systems there are other filesystems that should
also be mounted automatically at boot time. These are specified
in the <filename>/etc/fstab</filename> file; see the fstab man
page for details on the format. The details of exactly when the
extra filesystems are mounted depend on many factors, and can be
configured by each administrator if need be; see
<xref linkend="boots-and-shutdowns">.</para>
<para>When a filesystem no longer needs to be mounted, it can be
unmounted with <command>umount</command>.
<footnote><para>It should of course be
<command>unmount</command>, but the n mysteriously disappeared in
the 70s, and hasn't been seen since. Please return it to Bell
Labs, NJ, if you find it.</footnote>
<command>umount</command> takes one argument:
either the device file or the mount point.
For example, to unmount the directories of
the previous example, one could use the commands
<screen>
<prompt>$</prompt> <userinput>umount /dev/hda2</userinput>
<prompt>$</prompt> <userinput>umount /usr</userinput>
<prompt>$</prompt>
</screen>
</para>
<para>See the man page for further instructions on how to
use the command. It is imperative that you always unmount a mounted
floppy. <emphasis>Don't just pop the floppy out of the
drive!</emphasis> Because of disk caching, the data is not
necessarily written to the floppy until you unmount it, so removing
the floppy from the drive too early might cause the contents to
become garbled. If you only read from the floppy, this is not very
likely, but if you write, even accidentally,
the result may be catastrophic.</para>
<para>Mounting and unmounting requires super user privileges, i.e.,
only root can do it. The reason for this is that if any user can
mount a floppy on any directory, then it is rather easy to create a
floppy with, say, a Trojan horse disguised as
<filename>/bin/sh</filename>, or any other often used program.
However, it is often necessary to allow users to use floppies, and
there are several ways to do this:
<itemizedlist>
<listitem><para>Give the users the root password. This is
obviously bad security, but is the easiest solution. It works well
if there is no need for security anyway, which is the case
on many non-networked, personal systems.</para></listitem>
<listitem><para>Use a program such as <command>sudo</command> to
allow users to use mount. This is still bad security, but doesn't
directly give super user privileges to everyone.
<footnote><para>It requires several seconds of hard
thinking on the users' behalf. Furthermore
<command>sudo</command> can be configured to only allow
users to execute certain commands. See the sudo(8),
sudoers(5), and visudo(8) manual pages.
</para></footnote>
</para></listitem>
<listitem><para>Make the users use <command>mtools</command>, a
package for manipulating MS-DOS filesystems, without mounting them.
This works well if MS-DOS floppies are all that is needed, but is
rather awkward otherwise.
</para></listitem>
<listitem><para>List the floppy devices and their allowable mount
points together with the suitable options in
<filename>/etc/fstab</filename>.
</itemizedlist>
The last alternative can be implemented by adding a line like the
following to the <filename>/etc/fstab</filename> file:
<screen>
/dev/fd0 /floppy msdos user,noauto 0 0
</screen>
The columns are: device file to mount, directory to mount on,
filesystem type, options, backup frequency (used by
<command>dump</command>), and <command>fsck</command> pass number
(to specify the order in which filesystems should be checked
upon boot; 0 means no check).</para>
<para>The <option>noauto</option> option stops this mount to be done
automatically when the system is started (i.e., it stops
<command>mount -a</command> from mounting it). The
<option>user</option> option allows any user to mount the
filesystem, and, because of security reasons, disallows execution of
programs (normal or setuid) and interpretation of device files from
the mounted filesystem. After this, any user can mount a floppy with
an msdos filesystem with the following command:
<screen>
<prompt>$</prompt> <userinput>mount /floppy</userinput>
<prompt>$</prompt>
</screen>
The floppy can (and needs to, of course) be unmounted with
the corresponding <command>umount</command> command.</para>
<para>If you want to provide access to several types of floppies,
you need to give several mount points. The settings can be
different for each mount point. For example, to give access to both
MS-DOS and ext2 floppies, you could have the following to lines in
<filename>/etc/fstab</filename>:
<screen>
/dev/fd0 /dosfloppy msdos user,noauto 0 0
/dev/fd0 /ext2floppy ext2 user,noauto 0 0
</screen>
For MS-DOS filesystems (not just floppies), you probably want to
restrict access to it by using the <option>uid</option>,
<option>gid</option>, and <option>umask</option> filesystem options,
described in detail on the <command>mount</command> manual page. If
you aren't careful, mounting an MS-DOS filesystem gives everyone at
least read access to the files in it, which
is not a good idea.</para>
</sect2>
<sect2>
<title>Checking filesystem integrity with
<command>fsck</command></title>
<para>Filesystems are complex creatures, and as such, they
tend to be somewhat error-prone. A filesystem's correctness and
validity can be checked using the <command>fsck</command> command.
It can be instructed to repair any minor problems it finds, and to
alert the user if there any unrepairable problems. Fortunately, the
code to implement filesystems is debugged quite effectively, so
there are seldom any problems at all, and they are usually caused by
power failures, failing hardware, or operator errors;
for example, by not shutting down the system properly.</para>
<para>Most systems are setup to run <command>fsck</command>
automatically at boot time, so that any errors are detected (and
hopefully corrected) before the system is used. Use of a corrupted
filesystem tends to make things worse: if the data structures are
messed up, using the filesystem will probably mess them up even
more, resulting in more data loss. However, <command>fsck</command>
can take a while to run on big filesystems, and since errors almost
never occur if the system has been shut down properly, a couple of
tricks are used to avoid doing the checks in such cases. The first
is that if the file <filename>/etc/fastboot</filename> exists, no
checks are made. The second is that the ext2 filesystem has a
special marker in its superblock that tells whether the filesystem
was unmounted properly after the previous mount. This allows
<command>e2fsck</command> (the version of <command>fsck</command>
for the ext2 filesystem) to avoid checking the filesystem if the
flag indicates that the unmount was done (the assumption being that
a proper unmount indicates no problems). Whether the
<filename>/etc/fastboot</filename> trick works on your system
depends on your startup scripts, but the ext2 trick works every time
you use <command>e2fsck</command>. It has to be explicitly bypassed
with an option to <command>e2fsck</command> to be avoided. (See
the <command>e2fsck</command> man page for
details on how.)</para>
<para>The automatic checking only works for the
filesystems that are mounted automatically at boot time. Use
<command>fsck</command> manually to check other filesystems,
e.g., floppies.</para>
<para>If <command>fsck</command> finds unrepairable problems,
you need either in-depth knowledge of how filesystems work in
general, and the type of the corrupt filesystem in particular, or
good backups. The latter is easy (although sometimes tedious) to
arrange, the former can sometimes be arranged via a friend, the
Linux newsgroups and mailing lists, or some other source of support,
if you don't have the know-how yourself. I'd like to tell you more
about it, but my lack of education and experience in this regard
hinders me. The <command>debugfs</command>
program by Theodore Ts'o should be useful.</para>
<para><command>fsck</command> must only be run on unmounted
filesystems, never on mounted filesystems (with the exception of the
read-only root during startup). This is because it accesses the raw
disk, and can therefore modify the filesystem without the operating
system realizing it. There <emphasis>will</emphasis>
be trouble, if the operating system is confused.</para>
</sect2>
<sect2>
<title>Checking for disk errors with <command>badblocks</command></title>
<para>It can be a good idea to periodically check for bad blocks.
This is done with the <command>badblocks</command> command. It
outputs a list of the numbers of all bad blocks it can find. This
list can be fed to <command>fsck</command> to be recorded in the
filesystem data structures so that the operating system won't try to
use the bad blocks for storing data. The following example will show
how this could be done.
<screen>
<prompt>$</prompt> <userinput>badblocks /dev/fd0H1440 1440 >
bad-blocks</userinput>
<prompt>$</prompt> <userinput>fsck -t ext2 -l bad-blocks
/dev/fd0H1440</userinput>
<computeroutput>Parallelising fsck version 0.5a (5-Apr-94)
e2fsck 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Check reference counts.
Pass 5: Checking group summary information.
/dev/fd0H1440: ***** FILE SYSTEM WAS MODIFIED *****
/dev/fd0H1440: 11/360 files, 63/1440 blocks</computeroutput>
<prompt>$</prompt>
</screen>
If badblocks reports a block that was already used,
<command>e2fsck</command> will try to move the block to another
place. If the block was really bad, not just marginal, the
contents of the file may be corrupted.</para>
</sect2>
<sect2>
<title>Fighting fragmentation</title>
<para>When a file is written to disk, it can't always be written
in consecutive blocks. A file that is not stored in consecutive
blocks is <glossterm>fragmented</glossterm>. It takes longer to
read a fragmented file, since the disk's read-write head will have
to move more. It is desirable to avoid fragmentation, although it
is less of a problem in a system with a good buffer
cache with read-ahead.</para>
<para>The ext2 filesystem attempts to keep fragmentation at a
minimum, by keeping all blocks in a file close together, even if
they can't be stored in consecutive sectors. Ext2 effectively
always allocates the free block that is nearest to other blocks in a
file. For ext2, it is therefore seldom necessary to worry about
fragmentation. There is a program for defragmenting an ext2
filesystem called, strangely enough, <command>defrag</command>
<footnote><para>
<ulink url="http://www.go.dlr.de/linux/src/defrag-0.73.tar.gz">
http://www.go.dlr.de/linux/src/defrag-0.73.tar.gz</ulink>
</para></footnote>
.</para>
<para>There are many MS-DOS defragmentation programs that
move blocks around in the filesystem to remove fragmentation. For
other filesystems, defragmentation must be done by backing up the
filesystem, re-creating it, and restoring the files from backups.
Backing up a filesystem before defragmenting is a good idea for all
filesystems, since many things can go wrong
during the defragmentation.</para>
</sect2>
<sect2>
<title>Other tools for all filesystems</title>
<para>Some other tools are also useful for managing filesystems.
<command>df</command> shows the free disk space on one or more
filesystems; <command>du</command> shows how much disk space a
directory and all its files contain. These can be used to hunt down
disk space wasters. Both have manual pages which detail
the (many) options which can be used.</para>
<para><command>sync</command> forces all unwritten blocks
in the buffer cache (see <xref linkend="buffer-cache">) to be
written to disk. It is seldom necessary to do this by hand; the
daemon process <command>update</command> does this automatically.
It can be useful in catastrophes, for example if
<command>update</command> or its helper process
<command>bdflush</command> dies, or if you must turn off power
<emphasis>now</emphasis> and can't wait for
<command>update</command> to run. Again, there are manual pages.
The <command>man</command> is your very best friend in linux. Its
cousin <command>apropos</command> is also very useful when you don't
know what the name of the command you want
is.</para>
</sect2>
<sect2>
<title>Other tools for the ext2 filesystem</title>
<para>In addition to the filesystem creator
(<command>mke2fs</command>) and checker (<command>e2fsck</command>)
accessible directly or via the filesystem type independent front
ends, the ext2
filesystem has some additional tools that can be useful.</para>
<para><command>tune2fs</command> adjusts filesystem parameters.
Some of the more interesting parameters are:
<itemizedlist>
<listitem><para>
A maximal mount count. <command>e2fsck</command> enforces a check
when filesystem has been mounted too many times, even if the clean
flag is set. For a system that is used for developing or testing
the system, it might be a good idea to reduce this limit.
</para></listitem>
<listitem><para>
A maximal time between checks. <command>e2fsck</command> can also
enforce a maximal time between two checks, even if the clean flag is
set, and the filesystem hasn't been mounted very often. This can be
disabled, however.
</para></listitem>
<listitem><para>
Number of blocks reserved for root. Ext2 reserves some blocks for
root so that if the filesystem fills up, it is still possible to do
system administration without having to delete anything. The
reserved amount is by default 5 percent, which on most disks isn't
enough to be wasteful. However, for floppies there is no point in
reserving any blocks.
</para></listitem>
</itemizedlist>
See the <command>tune2fs</command> manual page for more
information.</para>
<para><command>dumpe2fs</command> shows information about an ext2
filesystem, mostly from the superblock. <xref
linkend="dumpe2fs-output"> shows a sample output. Some of the
information in the output is technical and requires understanding of
how the filesystem works (see appendix XXX ext2fspaper), but much of
it is readily understandable even for layadmins.</para>
<figure id="dumpe2fs-output" float="1">
<title>Sample output from <command>dumpe2fs</command></title>
<literallayout>
dumpe2fs 0.5b, 11-Mar-95 for EXT2 FS 0.5a, 94/10/23
Filesystem magic number: 0xEF53
Filesystem state: clean
Errors behavior: Continue
Inode count: 360
Block count: 1440
Reserved block count: 72
Free blocks: 1133
Free inodes: 326
First block: 1
Block size: 1024
Fragment size: 1024
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 360
Last mount time: Tue Aug 8 01:52:52 1995
Last write time: Tue Aug 8 01:53:28 1995
Mount count: 3
Maximum mount count: 20
Last checked: Tue Aug 8 01:06:31 1995
Check interval: 0
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
Group 0:
Block bitmap at 3, Inode bitmap at 4, Inode table at 5
1133 free blocks, 326 free inodes, 2 directories
Free blocks: 307-1439
Free inodes: 35-360
</literallayout>
</figure>
<para><command>debugfs</command> is a filesystem debugger.
It allows direct access to the filesystem data structures stored on
disk and can thus be used to repair a disk that is so broken that
<command>fsck</command> can't fix it automatically. It has also been
known to be used to recover deleted files. However,
<command>debugfs</command> very much requires that you understand
what you're doing; a failure to understand can
destroy all your data.</para>
<para><command>dump</command> and <command>restore</command> can be
used to back up an ext2 filesystem. They are ext2 specific versions
of the traditional UNIX backup tools. See <xref linkend="backups">
for more information on backups.</para>
</sect2>
</sect1>
<sect1>
<title>Disks without filesystems</title>
<para>Not all disks or partitions are used as filesystems.
A swap partition, for example, will not have a filesystem on it.
Many floppies are used in a tape-drive emulating fashion, so that a
<command>tar</command> (tape archive) or other file is written
directly on the raw disk, without a filesystem. Linux boot floppies
don't
contain a filesystem, only the raw kernel.</para>
<para>Avoiding a filesystem has the advantage of making more of
the disk usable, since a filesystem always has some bookkeeping
overhead. It also makes the disks more easily compatible with other
systems: for example, the <command>tar</command> file format is the
same on all systems, while filesystems are different on most
systems. You will quickly get used to disks without filesystems if
you need them. Bootable Linux floppies
also do not necessarily have a filesystem, although they may.</para>
<para>One reason to use raw disks is to make image copies of them.
For instance, if the disk contains a partially damaged filesystem,
it is a good idea to make an exact copy of it before trying to fix
it, since then you can start again if your fixing breaks things even
more. One way to do this is to use <command>dd</command>:
<screen>
<prompt>$</prompt> <userinput>dd if=/dev/fd0H1440
of=floppy-image</userinput>
<computeroutput>2880+0 records in
2880+0 records out</computeroutput>
<prompt>$</prompt> <userinput>dd if=floppy-image
of=/dev/fd0H1440</userinput>
<computeroutput>2880+0 records in
2880+0 records out</computeroutput>
<prompt>$</prompt>
</screen>
The first <command>dd</command> makes an exact image of the floppy
to the file <filename>floppy-image</filename>, the second one writes
the image to the floppy. (The user has presumably switched the
floppy before the second command. Otherwise the
command pair is of doubtful usefulness.)</para>
</sect1>
<sect1>
<title>Allocating disk space</title>
<sect2>
<title>Partitioning schemes</title>
<para>It is not easy to partition a disk in the best possible way.
Worse, there is no universally correct way to do it; there are
too many factors involved.</para>
<para>The traditional way is to have a (relatively) small
root filesystem, which contains <filename>/bin</filename>,
<filename>/etc</filename>, <filename>/dev</filename>,
<filename>/lib</filename>, <filename>/tmp</filename>, and other
stuff that is needed to get the system up and running. This way,
the root filesystem (in its own partition or on its own disk) is all
that is needed to bring up the system. The reasoning is that if the
root filesystem is small and is not heavily used, it is less likely
to become corrupt when the system crashes, and you will therefore
find it easier to fix any problems caused by the crash. Then you
create separate partitions or use separate disks for the directory
tree below <filename>/usr</filename>, the users' home directories
(often under <filename>/home</filename>), and the swap space.
Separating the home directories (with the users' files) in their own
partition makes backups easier, since it is usually not necessary to
backup programs (which reside below <filename>/usr</filename>). In
a networked environment it is also possible to share
<filename>/usr</filename> among several machines (e.g., by using
NFS), thereby reducing the total disk space required by several tens
or hundreds of megabytes times
the number of machines.</para>
<para>The problem with having many partitions is that it splits
the total amount of free disk space into many small pieces.
Nowadays, when disks and (hopefully) operating systems are more
reliable, many people prefer to have just one partition that holds
all their files. On the other hand, it can be less
painful to back up (and restore) a small partition.</para>
<!--
% \meta more reasons for many partitions: users/temp files/spools
% can't fill up all disks, readonly partitions less likely to
corrupt,
% fsck is faster, limits losses a filesystem goes really wrong,
% logging must not be disturbed, boots from >1023 cylinders do not
% work on all BIOSs, /usr/local won't be disturbed by an upgrade,
% easy to divide backup on many tapes, spare (scratch) partition for
% experimentation (e.g., a new Linux distribution), scratch can
% also be used to backup root during upgrades
-->
<para>For a small hard disk (assuming you don't do kernel
development), the best way to go is probably to have just one
partition. For large hard disks, it is probably better to have a
few large partitions, just in case something does go wrong. (Note
that `small' and `large' are used in a relative sense here; your
needs for disk space
decide what the threshold is.)</para>
<para>If you have several disks, you might wish to have the
root filesystem (including <filename>/usr</filename>) on one,
and the users' home directories on another.</para>
<para>It is a good idea to be prepared to experiment a bit
with different partitioning schemes (over time, not just while first
installing the system). This is a bit of work, since it essentially
requires you to install the system from scratch several times
<footnote><para>
This is not actually true, it is possible to move partitions
and mountpoints without reinstalling, but it is (currently)
beyond the scope of this book to explain how. It is on the
TODO list to write a section on this. If you have
experience and knowledge in this area then perhaps you could
write it for me and save me the bother? :)
</para></footnote>
, but it is the only way to be sure you do
it right.</para>
</sect2>
<sect2>
<title>Space requirements</title>
<para>The Linux distribution you install will give some indication
of how much disk space you need for various configurations. Programs
installed separately may also do the same. This will help you plan
your disk space usage, but you should prepare for the future and
reserve some extra space for things you will
notice later that you need.</para>
<para>The amount you need for user files depends on what your
users wish to do. Most people seem to need as much space for their
files as possible, but the amount they will live happily with varies
a lot. Some people do only light text processing and will survive
nicely with a few megabytes, others do heavy
image processing and will need gigabytes.</para>
<para>By the way, when comparing file sizes given in
kilobytes or megabytes and disk space given in megabytes, it can be
important to know that the two units can be different. Some disk
manufacturers like to pretend that a kilobyte is 1000 bytes and a
megabyte is 1000 kilobytes, while all the rest of the computing
world uses 1024 for both factors. Therefore, my 345 MB hard disk
was really a 330 MB hard disk.</para>
<para>Swap space allocation is discussed in <xref
linkend="swap-allocation">.</para>
</sect2>
<sect2>
<title>Examples of hard disk allocation</title>
<para>I used to have a 109 MB hard disk. Now I am using a 330 MB
hard disk. I'll explain how and why I partitioned those
disks.</para>
<para>The 109 MB disk I partitioned in a lot of ways, when my
needs and the operating systems I used changed; I'll explain
two typical scenarios. First, I used to run MS-DOS together
with Linux. For that, I needed about 20 MB of hard disk, or
just enough to have MS-DOS, a C compiler, an editor, a few other
utilities, the program I was working on, and enough free disk
space to not feel claustrophobic. For Linux, I had a 10 MB swap
partition, and the rest, or 79 MB, was a single partition with all
the files I had under Linux. I experimented with having separate
root, <filename>/usr</filename>, and <filename>/home</filename>
partitions, but there was never enough free disk space in one
piece to do much interesting.</para>
<para>When I didn't need MS-DOS anymore, I repartitioned the
disk so that I had a 12 MB swap partition, and again had the
rest as a single filesystem.</para>
<para>The 330 MB disk is partitioned into several partitions, like
this:
<informaltable>
<tgroup cols=2>
<tbody>
<row> <entry>5 MB</entry> <entry>root filesystem</entry> </row>
<row> <entry> 10 MB</entry> <entry>swap partition</entry> </row>
<row> <entry>180 MB</entry> <entry><filename>/usr</filename>
filesystem</entry>
</row>
<row> <entry>120 MB</entry> <entry><filename>/home</filename>
filesystem</entry>
</row>
<row> <entry> 15 MB</entry> <entry>scratch partition</entry> </row>
</tbody>
</tgroup>
</informaltable>
The scratch partition is for playing around with things that
require their own partition, e.g., trying different Linux
distributions, or comparing speeds of filesystems. When not
needed for anything else, it is used as swap space (I like to
have a lot of open windows).
<footnote><para>This section is somewhat out of date. Most people
these days have disks that stretch into the multiple
Gigabytes. It is still quite scalable (just multiply by
some factor to make it fit your hardware) for the moment
though, updating it to take
account of larger disks is planned.</para></footnote>
</para>
</sect2>
<sect2>
<title>Adding more disk space for Linux</title>
<para>Adding more disk space for Linux is easy, at least after the
hardware has been properly installed (the hardware installation
is outside the scope of this book). You format it if necessary,
then create the partitions and filesystem as described above,
and add the proper lines to <filename>/etc/fstab</filename>
so that it is mounted automatically.</para>
</sect2>
<sect2>
<title>Tips for saving disk space</title>
<para>The best tip for saving disk space is to avoid installing
unnecessary programs. Most Linux distributions have an
option to install only part of the packages they contain,
and by analysing your needs you might notice that you don't
need most of them. This will help save a lot of disk space,
since many programs are quite large. Even if you do need a
particular package or program, you might not need all of it.
For example, some on-line documentation might be unnecessary,
as might some of the Elisp files for GNU Emacs, some of the
fonts for X11, or some of the libraries for programming.</para>
<para>If you cannot uninstall packages, you might look into
compression. Compression programs such as <command>gzip</command>
or <command>zip</command> will compress (and uncompress)
individual files or groups of files. The <command>gzexe</command>
system will compress and uncompress programs invisibly to the
user (unused programs are compressed, then uncompressed as they
are used). The experimental DouBle system will compress all
files in a filesystem, invisibly to the programs that use them.
(If you are familiar with products such as Stacker for MS-DOS
or DriveSpace for Windows, the principle is the same.)</para>
</sect2>
</sect1>
</chapter>
<chapter id="memory-management">
<title>Memory Management</title>
<blockquote><para><quote>Minnet, jag har tappat mitt minne,
är jag svensk eller finne, kommer inte ihåg...</quote>
(Bosse Österberg)
</para>
<para>A Swedish drinking song, (rough) translation: ``Memory, I
have lost my memory. Am I Swedish or Finnish? I can't
remember''</para>
</blockquote>
<para> This section describes the Linux memory management
features, i.e., virtual memory and the disk buffer cache.
The purpose and workings and the things the system administrator
needs to take into consideration are described.</para>
<sect1>
<title>What is virtual memory?</title>
<para>Linux supports <glossterm>virtual memory</glossterm>, that
is, using a disk as an extension of RAM so that the effective
size of usable memory grows correspondingly. The kernel will
write the contents of a currently unused block of memory to the
hard disk so that the memory can be used for another purpose.
When the original contents are needed again, they are read back
into memory. This is all made completely transparent to the
user; programs running under Linux only see the larger amount of
memory available and don't notice that parts of them reside on
the disk from time to time. Of course, reading and writing the
hard disk is slower (on the order of a thousand times slower)
than using real memory, so the programs don't run as fast.
The part of the hard disk that is used as virtual memory is
called the <glossterm>swap space</glossterm>.</para>
<para>Linux can use either a normal file in the filesystem or a
separate partition for swap space. A swap partition is
faster, but it is easier to change the size of a swap file
(there's no need to repartition the whole hard disk, and
possibly install everything from scratch). When you know how
much swap space you need, you should go for a swap partition,
but if you are uncertain, you can use a swap file first, use
the system for a while so that you can get a feel for how much
swap you need, and then make a swap partition when you're
confident about its size.</para>
<para>You should also know that Linux allows one to use several swap
partitions and/or swap files at the same time. This means
that if you only occasionally need an unusual amount of swap space,
you can set up an extra swap file at such times, instead of
keeping the whole amount allocated all the time.</para>
<para>A note on operating system terminology: computer science
usually distinguishes between swapping (writing the whole process
out to swap space) and paging (writing only fixed size parts,
usually a few kilobytes, at a time). Paging is usually more
efficient, and that's what Linux does, but traditional Linux
terminology talks about swapping anyway.
<footnote><para>Thus quite needlessly annoying a
number of computer scientists greatly.
</para></footnote>
</para>
</sect1>
<sect1>
<title>Creating a swap space</title>
<para>A swap file is an ordinary file; it is in no way special
to the kernel. The only thing that matters to the kernel is that it
has no holes, and that it is prepared for use with
<command>mkswap</command>. It must reside on a local disk, however;
it can't reside in a filesystem that has been mounted
over NFS due to implementation reasons.</para>
<para>The bit about holes is important. The swap file reserves
the disk space so that the kernel can quickly swap out a page
without having to go through all the things that are necessary
when allocating a disk sector to a file. The kernel merely
uses any sectors that have already been allocated to the file.
Because a hole in a file means that there are no disk sectors
allocated (for that place in the file), it is not good for the
kernel to try to use them.</para>
<para>One good way to create the swap file without holes is through
the following command:
<screen>
<prompt>$</prompt> <userinput>dd if=/dev/zero of=/extra-swap bs=1024
count=1024</userinput>
<computeroutput>1024+0 records in
1024+0 records out</computeroutput>
<prompt>$</prompt>
</screen>
where <filename>/extra-swap</filename> is the name of the swap
file and the size of is given after the <literal>count=</literal>.
It is best for the size to be a multiple of 4, because the
kernel writes out <glossterm>memory pages</glossterm>, which
are 4 kilobytes in size. If the size is not a multiple of 4,
the last couple of kilobytes may be unused.</para>
<para>A swap partition is also not special in any way. You create
it just like any other partition; the only difference is that
it is used as a raw partition, that is, it will not contain any
filesystem at all. It is a good idea to mark swap partitions
as type 82 (Linux swap); this will the make partition listings
clearer, even though it is not strictly necessary to the
kernel.</para>
<para>After you have created a swap file or a swap partition, you
need to write a signature to its beginning; this contains some
administrative information and is used by the kernel. The
command to do this is <command>mkswap</command>, used like this:
<screen>
<prompt>$</prompt> <userinput>mkswap /extra-swap 1024</userinput>
<computeroutput>Setting up swapspace, size = 1044480
bytes</computeroutput>
<prompt>$</prompt>
</screen>
Note that the swap space is still not in use yet: it exists,
but the kernel does not use it to provide virtual memory.</para>
<para>You should be very careful when using
<command>mkswap</command>, since it does not check that the
file or partition isn't used for anything else. <emphasis>You
can easily overwrite important files and partitions with
<command>mkswap</command>!</emphasis> Fortunately, you should
only need to use <command>mkswap</command> when you install
your system.</para>
<para>The Linux memory manager limits the size of each swap space to
about 127 MB (for various technical reasons, the actual limit
is (4096-10) * 8 * 4096 = 133890048$ bytes, or
127.6875 megabytes). You can, however, use up to
8 swap spaces simultaneously, for a total of almost
1 GB.
<footnote><para>A gigabyte here, a gigabyte there, pretty
soon we start talking about real memory.</para></footnote>
</para>
<para>This is actually no longer true, this section is slated
for a rewrite Real Soon Now (tm). With newer kernels and versions
of the <command>mkswap</command> command the actual limit depends on
architecture. For i386 and compatibles it is 2Gigabytes, other
architectures vary. Consult the mkswap(8) manual page for more
details.</para>
</sect1>
<sect1>
<title>Using a swap space</title>
<para>An initialised swap space is taken into use with
<command>swapon</command>. This command tells the kernel that
the swap space can be used. The path to the swap space is given
as the argument, so to start swapping on a temporary swap file
one might use the following command.
<screen>
<prompt>$</prompt> <userinput>swapon /extra-swap</userinput>
<prompt>$</prompt>
</screen>
Swap spaces can be used automatically by listing them in
the <filename>/etc/fstab</filename> file.
<screen>
/dev/hda8 none swap sw 0 0
/swapfile none swap sw 0 0
</screen>
The startup scripts will run the command <command>swapon
-a</command>, which will start swapping on all the swap
spaces listed in <command>/etc/fstab</command>. Therefore,
the <command>swapon</command> command is usually used only when
extra swap is needed.</para>
<para>You can monitor the use of swap spaces with
<command>free</command>. It will tell the total amount of swap
space used.
<screen>
<prompt>$</prompt> <userinput>free</userinput>
<computeroutput> total used free shared
buffers
Mem: 15152 14896 256 12404 2528
-/+ buffers: 12368 2784
Swap: 32452 6684 25768</computeroutput>
<prompt>$</prompt>
</screen>
The first line of output (<literal>Mem:</literal>) shows the
physical memory. The total column does not show the physical
memory used by the kernel, which is usually about a megabyte.
The used column shows the amount of memory used (the second
line does not count buffers). The free column shows completely
unused memory. The shared column shows the amount of memory
shared by several processes; the more, the merrier. The buffers
column shows the current size of the disk buffer cache.</para>
<para>That last line (<literal>Swap:</literal>) shows similar
information for the swap spaces. If this line is all zeroes,
your swap space is not activated.</para>
<para>The same information is available via
<command>top</command>, or using the proc filesystem in file
<filename>/proc/meminfo</filename>. It is currently difficult
to get information on the use of a specific swap space.</para>
<para>A swap space can be removed from use with
<command>swapoff</command>. It is usually not necessary to do it,
except for temporary swap spaces. Any pages in use in the swap
space are swapped in first; if there is not sufficient physical
memory to hold them, they will then be swapped out (to some other
swap space). If there is not enough virtual memory to hold all
of the pages Linux will start to thrash; after a long while it
should recover, but meanwhile the system is unusable. You should
check (e.g., with <command>free</command>) that there is enough
free memory before removing a swap space from use.</para>
<para>All the swap spaces that are used automatically
with <command>swapon -a</command> can be removed from use
with <command>swapoff -a</command>; it looks at the file
<filename>/etc/fstab</filename> to find what to remove.
Any manually used swap spaces will remain in use.</para>
<para>Sometimes a lot of swap space can be in use even though
there is a lot of free physical memory. This can happen for
instance if at one point there is need to swap, but later a big
process that occupied much of the physical memory terminates
and frees the memory. The swapped-out data is not automatically
swapped in until it is needed, so the physical memory may remain
free for a long time. There is no need to worry about this,
but it can be comforting to know what is happening. </para>
</sect1>
<sect1>
<title>Sharing swap spaces with other operating systems</title>
<para>Virtual memory is built into many operating systems.
Since they each need it only when they are running, i.e., never at
the same time, the swap spaces of all but the currently running
one are being wasted. It would be more efficient for them to
share a single swap space. This is possible, but can require a
bit of hacking. The Tips-HOWTO contains some advice on how to
implement this. </para>
</sect1>
<sect1 id="swap-allocation">
<title>Allocating swap space</title>
<para>Some people will tell you that you should allocate twice as
much swap space as you have physical memory, but this is a bogus
rule. Here's how to do it properly:
<itemizedlist>
<listitem>
<para> Estimate your total memory needs. This is the largest
amount of memory you'll probably need at a time, that is the
sum of the memory requirements of all the programs you want to
run at the same time. This can be done by running at the same
time all the programs you are likely to ever be running at the
same time. </para>
<para>For instance, if you want to run X, you should allocate
about 8 MB for it, gcc wants several megabytes (some
files need an unusually large amount, up to tens of
megabytes, but usually about four should do), and so on.
The kernel will use about a megabyte by itself, and the
usual shells and other small utilities perhaps a few
hundred kilobytes (say a megabyte together). There is
no need to try to be exact, rough estimates are fine,
but you might want to be on the pessimistic side.</para>
<para>Remember that if there are going to be several people
using the system at the same time, they are all going
to consume memory. However, if two people run the same
program at the same time, the total memory consumption
is usually not double, since code pages and shared
libraries exist only once.</para>
<para>The <command>free</command> and <command>ps</command>
commands are useful for estimating the memory needs.
</listitem>
<listitem>
<para>Add some security to the estimate in step 1. This is because
estimates of program sizes will probably be wrong, because
you'll probably forget some programs you want to run, and to
make certain that you have some extra space just in case. A
couple of megabytes should be fine. (It is better to allocate
too much than too little swap space, but there's no need to
over-do it and allocate the whole disk, since unused swap space
is wasted space; see later about adding more swap.) Also,
since it is nicer to deal with even numbers, you can round the
value up to the next full megabyte.</para>
</listitem>
<listitem>
<para>Based on the computations above, you know how much memory
you'll be needing in total. So, in order to allocate swap
space, you just need to subtract the size of your physical
memory from the total memory needed, and you know how much
swap space you need. (On some versions of UNIX, you need to
allocate space for an image of the physical memory as well, so
the amount computed in step 2 is what you need and you shouldn't
do the subtraction.)</para>
</listitem>
<listitem>
<para>If your calculated swap space is very much larger than your
physical memory (more than a couple times larger), you should
probably invest in more physical memory, otherwise performance
will be too low.</para>
</itemizedlist>
<para>It's a good idea to have at least some swap space, even if
your calculations indicate that you need none. Linux uses
swap space somewhat aggressively, so that as much physical
memory as possible can be kept free. Linux will swap out
memory pages that have not been used, even if the memory
is not yet needed for anything. This avoids waiting for
swapping when it is needed: the swapping can be done
earlier, when the disk is otherwise idle.</para>
<para>Swap space can be divided among several disks. This
can sometimes improve performance, depending on the
relative speeds of the disks and the access patterns
of the disks. You might want to experiment with a few
schemes, but be aware that doing the experiments
properly is quite difficult. You should not believe
claims that any one scheme is superior to any other,
since it won't always be true.
</para>
</sect1>
<sect1 id="buffer-cache">
<title>The buffer cache</title>
<para>Reading from a disk
<footnote><para>Except a RAM disk, for obvious
reasons.</para></footnote>
is very slow compared to accessing (real) memory. In addition,
it is common to read the same part of a disk several times
during relatively short periods of time. For example, one
might first read an e-mail message, then read the letter into
an editor when replying to it, then make the mail program read
it again when copying it to a folder. Or, consider how often
the command <command>ls</command> might be run on a system with
many users. By reading the information from disk only once
and then keeping it in memory until no longer needed, one can
speed up all but the first read. This is called <glossterm>disk
buffering</glossterm>, and the memory used for the purpose is
called the <glossterm>buffer cache</glossterm>.</para>
<para>Since memory is, unfortunately, a finite, nay, scarce
resource, the buffer cache usually cannot be big enough (it
can't hold all the data one ever wants to use). When the cache
fills up, the data that has been unused for the longest time
is discarded and the memory thus freed is used for the new
data.</para>
<para>Disk buffering works for writes as well. On the one hand,
data that is written is often soon read again (e.g., a source
code file is saved to a file, then read by the compiler),
so putting data that is written in the cache is a good idea.
On the other hand, by only putting the data into the cache, not
writing it to disk at once, the program that writes runs quicker.
The writes can then be done in the background, without slowing
down the other programs.</para>
<para>Most operating systems have buffer caches (although
they might be called something else), but not all of
them work according to the above principles. Some are
<glossterm>write-through</glossterm>: the data is written to disk
at once (it is kept in the cache as well, of course). The cache
is called <glossterm>write-back</glossterm> if the writes are done
at a later time. Write-back is more efficient than write-through,
but also a bit more prone to errors: if the machine crashes,
or the power is cut at a bad moment, or the floppy is removed
from the disk drive before the data in the cache waiting to be
written gets written, the changes in the cache are usually lost.
This might even mean that the filesystem (if there is one) is
not in full working order, perhaps because the unwritten data
held important changes to the bookkeeping information.</para>
<para>Because of this, you should never turn off the
power without using a proper shutdown procedure (see <xref
linkend="boots-and-shutdowns">), or remove a floppy from the
disk drive until it has been unmounted (if it was mounted)
or after whatever program is using it has signalled that it
is finished and the floppy drive light doesn't shine anymore.
The <command>sync</command> command <glossterm>flushes</glossterm>
the buffer, i.e., forces all unwritten data to be written to disk,
and can be used when one wants to be sure that everything is
safely written. In traditional UNIX systems, there is a program
called <command>update</command> running in the background
which does a <command>sync</command> every 30 seconds, so
it is usually not necessary to use <command>sync</command>.
Linux has an additional daemon, <command>bdflush</command>,
which does a more imperfect sync more frequently to avoid the
sudden freeze due to heavy disk I/O that <command>sync</command>
sometimes causes.</para>
<para>Under Linux, <command>bdflush</command> is started by
<command>update</command>. There is usually no reason to worry
about it, but if <command>bdflush</command> happens to die for
some reason, the kernel will warn about this, and you should
start it by hand (<command>/sbin/update</command>).</para>
<para>The cache does not actually buffer files, but blocks, which
are the smallest units of disk I/O (under Linux, they are usually
1 kB). This way, also directories, super blocks, other filesystem
bookkeeping data, and non-filesystem disks are cached.</para>
<para>The effectiveness of a cache is primarily decided by its
size. A small cache is next to useless: it will hold so little
data that all cached data is flushed from the cache before it
is reused. The critical size depends on how much data is read
and written, and how often the same data is accessed. The only
way to know is to experiment.</para>
<para>If the cache is of a fixed size, it is not very good to have
it too big, either, because that might make the free memory too
small and cause swapping (which is also slow). To make the most
efficient use of real memory, Linux automatically uses all free
RAM for buffer cache, but also automatically makes the cache
smaller when programs need more memory.</para>
<para>Under Linux, you do not need to do anything to make use
of the cache, it happens completely automatically. Except for
following the proper procedures for shutdown and removing
floppies, you do not need to worry about it. </para>
</chapter>
<chapter id="boots-and-shutdowns">
<title>Boots And Shutdowns</title>
<blockquote><para><literallayout>
Start me up
Ah... you've got to... you've got to
Never, never never stop
Start it up
Ah... start it up, never, never, never
You make a grown man cry,
you make a grown man cry
(Rolling Stones)
</literallayout></para></blockquote>
<para> This section explains what goes on when a Linux system is
brought up and taken down, and how it should be done properly.
If proper procedures are not followed, files might be corrupted
or lost.</para>
<sect1>
<title>An overview of boots and shutdowns</title>
<para>The act of turning on a computer system and causing its
operating system to be loaded
<footnote><para>On early computers, it wasn't enough
to merely turn on the computer, you had to manually load the
operating system as well. These new-fangled thing-a-ma-jigs do
it all by themselves.</para></footnote>
is called <glossterm>booting</glossterm>. The name comes from
an image of the computer pulling itself up from its bootstraps,
but the act itself slightly more realistic.</para>
<para>During bootstrapping, the computer first loads a small piece
of code called the <glossterm>bootstrap loader</glossterm>, which
in turn loads and starts the operating system. The bootstrap
loader is usually stored in a fixed location on a hard disk
or a floppy. The reason for this two step process is that
the operating system is big and complicated, but the first
piece of code that the computer loads must be very small (a
few hundred bytes), to avoid making the firmware unnecessarily
complicated.</para>
<para>Different computers do the bootstrapping differently.
For PCs, the computer (its BIOS) reads in the first sector
(called the <glossterm>boot sector</glossterm>) of a floppy or
hard disk. The bootstrap loader is contained within this sector.
It loads the operating system from elsewhere on the disk (or
from some other place).</para>
<para>After Linux has been loaded, it initialises the hardware and
device drivers, and then runs <command>init</command>.
<command>init</command>
starts other processes to allow users to log in, and do things.
The details of this part will be discussed below.</para>
<para>In order to shut down a Linux system, first all processes
are told to terminate (this makes them close any files and
do other necessary things to keep things tidy), then filesystems
and swap areas are unmounted, and finally a message is printed
to the console that the power can be turned off. If the proper
procedure is not followed, terrible things can and will happen;
most importantly, the filesystem buffer cache might not be flushed,
which means that all data in it is lost and the filesystem on
disk is inconsistent, and therefore possibly unusable.
</para>
</sect1>
<sect1>
<title>The boot process in closer look</title>
<para>You can boot Linux either from a floppy or from the hard
disk. The installation section in the Installation and
Getting Started guide (XXX citation)
tells you how to install Linux so you can boot it the way
you want to.</para>
<para>When a PC is booted, the BIOS will do various tests to
check that everything looks all right,
<footnote><para>This is called
the <glossterm>power on self test</glossterm>, or
<glossterm>POST</glossterm> for short.</para></footnote>
and will then start the actual booting. It will choose a disk
drive (typically the first floppy drive, if there is a floppy
inserted, otherwise the first hard disk, if one is installed
in the computer; the order might be configurable, however)
and will then read its very first sector. This is called the
<glossterm>boot sector</glossterm>; for a hard disk, it is also
called the <glossterm>master boot record</glossterm>, since a
hard disk can contain several partitions, each with their own
boot sectors.</para>
<para>The boot sector contains a small program (small enough to
fit into one sector) whose responsibility is to read the actual
operating system from the disk and start it. When booting Linux
from a floppy disk, the boot sector contains code that just reads
the first few hundred blocks (depending on the actual kernel
size, of course) to a predetermined place in memory. On a Linux
boot floppy, there is no filesystem, the kernel is just stored
in consecutive sectors, since this simplifies the boot process.
It is possible, however, to boot from a floppy with a filesystem,
by using LILO, the LInux LOader.</para>
<para>When booting from the hard disk, the code in the master
boot record will examine the partition table (also in the master
boot record), identify the active partition (the partition that is
marked to be bootable), read the boot sector from that partition,
and then start the code in that boot sector. The code in the
partition's boot sector does what a floppy disk's boot sector
does: it will read in the kernel from the partition and start it.
The details vary, however, since it is generally not useful to
have a separate partition for just the kernel image, so the
code in the partition's boot sector can't just read the disk
in sequential order, it has to find the sectors wherever the
filesystem has put them. There are several ways around this
problem, but the most common way is to use LILO. (The details
about how to do this are irrelevant for this discussion, however;
see the LILO documentation for more information; it is most
thorough.)</para>
<para>When booting with LILO, it will normally go right ahead
and read in and boot the default kernel. It is also possible
to configure LILO to be able to boot one of several kernels,
or even other operating systems than Linux, and it is possible
for the user to choose which kernel or operating system is to
be booted at boot time. LILO can be configured so that if one
holds down the <keycap>alt</keycap>, <keycap>shift</keycap>, or
<keycap>ctrl</keycap> key at boot time (when LILO is loaded),
LILO will ask what is to be booted and not boot the default
right away. Alternatively, LILO can be configured so that it
will always ask, with an optional timeout that will cause the
default kernel to be booted.</para>
<para>With LILO, it is also possible to give a <glossterm>kernel
command line argument</glossterm>, after the name of the kernel
or operating system.</para>
<para>Booting from floppy and from hard disk have both their
advantages, but generally booting from the hard disk is nicer,
since it avoids the hassle of playing around with floppies.
It is also faster. However, it can be more troublesome to install
the system to boot from the hard disk, so many people will first
boot from floppy, then, when the system is otherwise installed
and working well, will install LILO and start booting from the
hard disk.</para>
<para>After the Linux kernel has been read into the memory, by
whatever means, and is started for real, roughly the following
things happen:
<itemizedlist>
<listitem><para>
The Linux kernel is installed compressed, so it will first
uncompress itself. The beginning of the kernel image
contains a small program that does this.
</para></listitem>
<listitem><para>
If you have a super-VGA card that Linux
recognises and that has some special text modes (such as 100
columns by 40 rows), Linux asks you which mode
you want to use. During the kernel compilation, it is
possible to preset a video mode, so that this is never asked.
This can also be done with LILO or <command>rdev</command>.
</para></listitem>
<listitem><para>
After this, the kernel checks what other hardware there is
(hard disks, floppies, network adapters, etc), and configures
some of its device drivers appropriately; while it does this,
it outputs messages about its findings. For example, when I
boot, I it looks like this:
<screen>
<computeroutput>
LILO boot:
Loading linux.
Console: colour EGA+ 80x25, 8 virtual consoles
Serial driver version 3.94 with no serial options enabled
tty00 at 0x03f8 (irq = 4) is a 16450
tty01 at 0x02f8 (irq = 3) is a 16450
lp_init: lp1 exists (0), using polling driver
Memory: 7332k/8192k available (300k kernel code, 384k reserved, 176k
data)
Floppy drive(s): fd0 is 1.44M, fd1 is 1.2M
Loopback device init
Warning WD8013 board not found at i/o = 280.
Math coprocessor using irq13 error reporting.
Partition check:
hda: hda1 hda2 hda3
VFS: Mounted root (ext filesystem).
Linux version 0.99.pl9-1 (root@haven) 05/01/93 14:12:20
</computeroutput>
</screen>
The exact texts are different on different systems, depending
on the hardware, the version of Linux being used, and how
it has been configured.
</para></listitem>
<listitem><para> Then the kernel will try to mount the root
filesystem. The place is configurable at compilation time, or
any time with <command>rdev</command> or LILO. The filesystem
type is detected automatically. If the mounting of the root
filesystem fails, for example because you didn't remember to
include the corresponding filesystem driver in the kernel, the
kernel panics and halts the system (there isn't much it can do,
anyway). </para>
<para>The root filesystem is usually mounted read-only (this can
be set in the same way as the place). This makes it possible
to check the filesystem while it is mounted; it is not a good
idea to check a filesystem that is mounted read-write.
</para></listitem>
<listitem><para> After this, the kernel starts
the program <command>init</command> (located in
<filename>/sbin/init</filename>) in the background (this will
always become process number 1). <command>init</command> does
various startup chores. The exact things it does depends on how
it is configured; see <xref linkend="init"> for more information
(not yet written). It will at least start some essential
background daemons. </para></listitem>
<listitem><para> <command>init</command> then switches to
multi-user mode, and starts a <command>getty</command> for virtual
consoles and serial lines. <command>getty</command> is the
program which lets people log in via virtual consoles and serial
terminals. <command>init</command> may also start some other
programs, depending on how it is configured. </para></listitem>
<listitem><para> After this, the boot is complete, and the system
is up and running normally. </para></listitem>
</itemizedlist>
</para>
</sect1>
<sect1>
<title>More about shutdowns</title>
<para>It is important to follow the correct procedures when you shut
down a Linux system. If you fail do so, your filesystems probably
will become trashed and the files probably will become scrambled.
This is because Linux has a disk cache that won't write things
to disk at once, but only at intervals. This greatly improves
performance but also means that if you just turn off the power
at a whim the cache may hold a lot of data and that what is on
the disk may not be a fully working filesystem (because only
some things have been written to the disk).</para>
<para>Another reason against just flipping the power switch is that
in a multi-tasking system there can be lots of things going on
in the background, and shutting the power can be quite
disastrous. By using the proper shutdown sequence, you ensure
that all background processes can save their data.</para>
<para>The command for properly shutting down a Linux system
is <command>shutdown</command>. It is usually used in one of
two ways.</para>
<para>If you are running a system where you are the only user,
the usual way of using <command>shutdown</command> is to quit
all running programs, log out on all virtual consoles, log
in as root on one of them (or stay logged in as root if you
already are, but you should change to root's home directory or
the root directory, to avoid problems with unmounting), then
give the command <command>shutdown -h now</command> (substitute
<literal>now</literal> with a plus sign and a number in minutes
if you want a delay, though you usually don't on a single user
system).</para>
<para>Alternatively, if your system has many users, use the command
<command>shutdown -h +time message</command>, where
<literal>time</literal>
is the
time in minutes until the system is halted, and
<literal>message</literal>
is a short explanation of why the system is shutting down.
<screen>
<prompt>#</prompt> <userinput>shutdown -h +10 'We will install a new
disk. System should
> be back on-line in three hours.'</userinput>
<prompt>#</prompt>
</screen>
This will warn everybody that the system will shut down in
ten minutes, and that they'd better get lost or lose data.
The warning is printed to every terminal on which someone is
logged in, including all <command>xterm</command>s:
<screen>
<computeroutput>
Broadcast message from root (ttyp0) Wed Aug 2 01:03:25 1995...
We will install a new disk. System should
be back on-line in three hours.
The system is going DOWN for system halt in 10 minutes !!
</computeroutput>
</screen>
The warning is automatically repeated a few times before the boot,
with shorter and shorter intervals as the time runs out.</para>
<para>When the real shutting down starts after any delays, all
filesystems (except the root one) are unmounted, user processes
(if anybody is still logged in) are killed, daemons are shut down,
all filesystem are unmounted, and generally everything settles
down. When that is done, <command>init</command> prints out a
message that you can power down the machine. Then, and only then,
should you move your fingers towards the power switch.</para>
<para>Sometimes, although rarely on any good system, it is
impossible to shut down properly. For instance, if the kernel
panics and crashes and burns and generally misbehaves, it might
be completely impossible to give any new commands, hence shutting
down properly is somewhat difficult, and just about everything
you can do is hope that nothing has been too severely damaged
and turn off the power. If the troubles are a bit less severe
(say, somebody hit your keyboard with an axe), and the kernel
and the <command>update</command> program still run normally,
it is probably a good idea to wait a couple of minutes to give
<command>update</command> a chance to flush the buffer cache,
and only cut the power after that.</para>
<para>Some people like to shut down using the command
<command>sync</command>
<footnote><para><command>sync</command> flushes the
buffer cache. </para></footnote>
three times, waiting for the disk I/O to stop, then turn off
the power. If there are no running programs, this is about
equivalent to using <command>shutdown</command>. However, it
does not unmount any filesystems and this can lead to problems
with the ext2fs ``clean filesystem'' flag. The triple-sync
method is <emphasis>not recommended</emphasis>.</para>
<para>(In case you're wondering: the reason for three syncs is
that in the early days of UNIX, when the commands were
typed separately, that usually gave sufficient time for most
disk I/O to be finished.)
</para>
</sect1>
<sect1>
<title>Rebooting</title>
<para>Rebooting means booting the system again. This can be
accomplished by first shutting it down completely, turning
power off, and then turning it back on. A simpler way is to
ask <command>shutdown</command> to reboot the system, instead
of merely halting it. This is accomplished by using the
<option>-r</option> option to <command>shutdown</command>,
for example, by giving the command <command>shutdown -r
now</command>.</para>
<para>Most Linux systems run <command>shutdown -r now</command>
when ctrl-alt-del is pressed on the keyboard. This reboots the
system. The action on ctrl-alt-del is configurable, however, and
it might be better to allow for some delay before the reboot on
a multiuser machine. Systems that are physically accessible to
anyone might even be configured to do nothing when ctrl-alt-del
is pressed. </para>
</sect1>
<sect1>
<title>Single user mode</title>
<para>The <command>shutdown</command> command can also be used
to bring the system down to single user mode, in which no one
can log in, but root can use the console. This is useful for
system administration tasks that can't be done while the system is
running normally.</para>
</sect1>
<sect1>
<title>Emergency boot floppies</title>
<para>It is not always possible to boot a computer from the hard
disk.
For example, if you make a mistake in configuring LILO, you might
make your system unbootable. For these situations, you need an
alternative way of booting that will always work (as long as the
hardware works). For typical PCs, this means booting from the
floppy drive.</para>
<para>Most Linux distributions allow one to create an
<glossterm>emergency boot floppy</glossterm> during installation.
It is a good idea to do this. However, some such boot disks
contain only the kernel, and assume you will be using the programs
on the distribution's installation disks to fix whatever problem
you have. Sometimes those programs aren't enough; for example,
you might have to restore some files from backups made with
software not on the installation disks.</para>
<para>Thus, it might be necessary to create a custom root floppy
as well. The <citetitle>Bootdisk HOWTO</citetitle> by Graham
Chapman (XXX citation) contains instructions for doing this.
You must, of course, remember to keep your emergency boot and
root floppies up to date.</para>
<para>You can't use the floppy drive you use to mount the root
floppy for anything else. This can be inconvenient if you only
have one floppy drive. However, if you have enough memory, you
can configure your boot floppy to load the root disk to a ramdisk
(the boot floppy's kernel needs to be specially configured for
this). Once the root floppy has been loaded into the ramdisk,
the floppy drive is free to mount other disks. </para>
</chapter>
<chapter id="init">
<title><command>init</command></title>
<para>
<blockquote><para><quote>Uuno on numero yksi</quote>
(Slogan for a series of Finnish movies.)</para></blockquote>
<para> This chapter describes the <command>init</command> process,
which is the first user level process started by the kernel.
<command>init</command> has many important duties, such as
starting <command>getty</command> (so that users can log in),
implementing run levels, and taking care of orphaned processes.
This chapter explains how <command>init</command> is configured
and how you can make use of the different run levels.</para>
<sect1>
<title><command>init</command> comes first</title>
<para><command>init</command> is one of those programs that
are absolutely essential to the operation of a Linux system,
but that you still can mostly ignore. A good Linux distribution
will come with a configuration for <command>init</command>
that will work for most systems, and on these systems there is
nothing you need to do about <command>init</command>. Usually,
you only need to worry about <command>init</command> if you hook
up serial terminals, dial-in (not dial-out) modems, or if you
want to change the default run level.</para>
<para>When the kernel has started itself (has been loaded
into memory, has started running, and has initialised all
device drivers and data structures and such), it finishes its
own part of the boot process by starting a user level program,
<command>init</command>. Thus, <command>init</command> is always
the first process (its process number is always 1).</para>
<para>The kernel looks for <command>init</command>
in a few locations that have been historically used
for it, but the proper location for it (on a Linux
system) is <filename>/sbin/init</filename>. If the
kernel can't find <command>init</command>, it tries to run
<filename>/bin/sh</filename>, and if that also fails, the startup
of the system fails.</para>
<para>When <command>init</command> starts, it finishes the
boot process by doing a number of administrative tasks, such
as checking filesystems, cleaning up <filename>/tmp</filename>,
starting various services, and starting a <command>getty</command>
for each terminal and virtual console where users should be able
to log in (see <xref linkend="log-in-and-out">).</para>
<para>After the system is properly up, <command>init</command>
restarts <command>getty</command> for each terminal
after a user has logged out (so that the next user can log
in). <command>init</command> also adopts orphan processes: when
a process starts a child process and dies before its child, the
child immediately becomes a child of <command>init</command>.
This is important for various technical reasons, but it is good
to know it, since it makes it easier to understand process lists
and process tree graphs.
<footnote><para><command>init</command> itself is not
allowed to die. You can't kill <command>init</command>
even with SIGKILL. </para></footnote>
There are a few variants of <command>init</command>
available. Most Linux distributions
use <command>sysvinit</command> (written by Miquel
van Smoorenburg), which is based on the System V
<command>init</command> design. The BSD versions of Unix have
a different <command>init</command>. The primary difference
is run levels: System V has them, BSD does not (at least
traditionally). This difference is not essential. We'll look
at <command>sysvinit</command> only. </para>
</sect1>
<sect1>
<title>Configuring <command>init</command> to start
<command>getty</command>: the
<filename>/etc/inittab</filename> file</title>
<para>When it starts up, <command>init</command> reads the
<filename>/etc/inittab</filename>
configuration file. While the system is running, it will
re-read it, if sent the HUP signal;
<footnote><para>Using the command <command>kill -HUP
1</command> as root, for example </para></footnote>
this feature makes it unnecessary to boot the system to make
changes to the <command>init</command> configuration take
effect.</para>
<para>The <filename>/etc/inittab</filename> file is
a bit complicated. We'll start with the simple case
of configuring <command>getty</command> lines. Lines in
<filename>/etc/inittab</filename> consist of four colon-delimited
fields:
<screen>
id:runlevels:action:process
</screen>
The fields are described below. In addition,
<filename>/etc/inittab</filename> can contain empty lines, and
lines that begin with a number sign (`<literal>#</literal>');
these are both ignored.
<glosslist>
<glossentry><glossterm>id</glossterm>
<glossdef><para>
This identifies the line in the file. For
<command>getty</command> lines, it specifies the terminal
it runs on (the characters after <filename>/dev/tty</filename>
in the device file name). For other lines,
it doesn't matter (except for length restrictions),
but it should be unique.
</para></glossdef></glossentry>
<glossentry><glossterm>runlevels</glossterm>
<glossdef><para>
The run levels the line should be considered
for. The run levels are given as single digits,
without delimiters. (Run levels are described
in the next section.)
</para></glossdef></glossentry>
<glossentry><glossterm>action</glossterm>
<glossdef><para>
What action should be taken by the line, e.g.,
<literal>respawn</literal> to run the command in the
next field again, when it exits, or <literal>once</literal>
to run it just once.
</para></glossdef></glossentry>
<glossentry><glossterm>process</glossterm>
<glossdef><para>
The command to run.
</para></glossdef></glossentry>
</glosslist>
To start a <command>getty</command> on the first virtual terminal
(<filename>/dev/tty1</filename>), in all the normal multi-user
run levels (2-5), one would write the following line:
<screen>
1:2345:respawn:/sbin/getty 9600 tty1
</screen>
The first field says that this is the line for
<filename>/dev/tty1</filename>.
The second field says that it applies to run levels 2, 3, 4,
and 5. The third field means that the command should be run
again, after it exits (so that one can log in, log out, and
then log in again). The last field is the command that runs
<command>getty</command> on the first virtual terminal.
<footnote><para>Different versions of
<command>getty</command> are run differently. Consult
your manual page, and make sure it is the correct
manual page.</para></footnote>
</para>
<para>If you wanted to add terminals or dial-in modem lines to a
system, you'd add more lines to <filename>/etc/inittab</filename>,
one for each terminal or dial-in line. For more details, see the
manual pages <command>init</command>, <filename>inittab</filename>,
and <command>getty</command>.</para>
<para>If a command fails when it starts,
and <command>init</command> is configured to
<literal>restart</literal> it, it will use a lot of
system resources: <command>init</command> starts it,
it fails, <command>init</command> starts it, it fails,
<command>init</command> starts it, it fails, and so on, ad
infinitum. To prevent this, <command>init</command> will keep
track of how often it restarts a command, and if the frequency
grows to high, it will delay for five minutes before restarting
again. </para>
</sect1>
<sect1>
<title>Run levels</title>
<para>A <glossterm>run level</glossterm> is a state of
<command>init</command> and the whole system that defines what
system services are operating. Run levels are identified by
numbers, see <xref linkend="run-levels">. There is no consensus of
how to use the
user defined run levels (2 through 5). Some system administrators
use run levels to define which subsystems are working, e.g.,
whether X is running, whether the network is operational, and
so on. Others have all subsystems always running or start and
stop them individually, without changing run levels, since run
levels are too coarse for controlling their systems. You need
to decide for yourself, but it might be easiest to follow the
way your Linux distribution does things.</para>
<table id="run-levels">
<title>Run level numbers</title>
<tgroup cols=2>
<tbody>
<row> <entry>0</entry> <entry>Halt the system.</entry> </row>
<row> <entry>1</entry> <entry>Single-user mode (for special
administration).</entry> </row>
<row> <entry>2-5</entry> <entry>Normal operation (user
defined).</entry> </row>
<row> <entry>6</entry> <entry>Reboot.</entry> </row>
</tbody>
</tgroup>
</table>
<para>Run levels are configured in <filename>/etc/inittab</filename>
by lines like
the following:
<screen>
l2:2:wait:/etc/init.d/rc 2
</screen>
The first field is an arbitrary label, the second one means
that this applies for run level 2. The third field means
that <command>init</command> should run the command in the
fourth field once, when the run level is entered, and that
<command>init</command> should wait for it to complete. The
<filename>/etc/init.d/rc</filename> command runs whatever
commands are necessary to start and stop services to enter run
level 2.</para>
<para>The command in the fourth field does all the hard work of
setting up a run level. It starts services that aren't already
running, and stops services that shouldn't be running in the
new run level any more. Exactly what the command is, and how run
levels are configured, depends on the Linux distribution.</para>
<para>When <command>init</command> starts, it looks for a line
in <filename>/etc/inittab</filename> that specifies the default
run level:
<screen>
id:2:initdefault:
</screen>
You can ask <command>init</command> to go to a non-default run
level at startup by giving the kernel a command line argument
of <literal>single</literal> or <literal>emergency</literal>.
Kernel command line arguments can be given via LILO, for example.
This allows you to choose the single user mode (run level 1).</para>
<para>While the system is running, the <command>telinit</command>
command can change the run level. When the run level is
changed, <command>init</command> runs the relevant command from
<filename>/etc/inittab</filename>. </para>
</sect1>
<sect1>
<title>Special configuration in
<filename>/etc/inittab</filename></title>
<para>The <filename>/etc/inittab</filename> has some special
features that allow <command>init</command> to react to special
circumstances. These special features are marked by special
keywords in the third field. Some examples:
<glosslist>
<glossentry><glossterm><literal>powerwait</literal></glossterm>
<glossdef><para>
Allows <command>init</command> to shut the system
down, when the power fails. This assumes the use of
a UPS, and software that watches the UPS and informs
<command>init</command> that the power is off.
</para></glossdef></glossentry>
<glossentry><glossterm><literal>ctrlaltdel</literal></glossterm>
<glossdef><para>
Allows <command>init</command> to reboot the system, when
the user presses ctrl-alt-del on the console keyboard.
Note that the system administrator can configure the
reaction to ctrl-alt-del to be something else instead,
e.g., to be ignored, if the system is in a public
location. (Or to start <command>nethack</command>.)
</para></glossdef></glossentry>
<glossentry><glossterm><literal>sysinit</literal></glossterm>
<glossdef><para>
Command to be run when the system is booted. This command
usually cleans up <filename>/tmp</filename>, for example.
</para></glossdef></glossentry>
</glosslist>
The list above is not exhaustive. See your
<filename>inittab</filename> manual page for all possibilities,
and for details on how to use the above ones. </para>
</sect1>
<sect1>
<title>Booting in single user mode</title>
<para>An important run level is <glossterm>single user
mode</glossterm> (run level 1),
in which only the system administrator is using the machine
and as few system services, including logins, as possible are
running. Single user mode is necessary for a few administrative
tasks,
<footnote><para>It probably shouldn't be used for playing
<command>nethack</command>.</para></footnote>
such as running <command>fsck</command> on a
<filename>/usr</filename> partition, since this requires that
the partition be unmounted, and that can't happen, unless just
about all system services are killed.</para>
<para>A running system can be taken to single user mode by using
<command>telinit</command> to request run level 1. At bootup,
it can be entered by giving the word <literal>single</literal>
or <literal>emergency</literal> on the kernel command line: the
kernel gives the command line to <command>init</command> as well,
and <command>init</command> understands from that word that it
shouldn't use the default run level. (The kernel command line is
entered in a way that depends on how you boot the system.)</para>
<para>Booting into single user mode is sometimes necessary so
that one can run <command>fsck</command> by hand, before anything
mounts or otherwise touches a broken <filename>/usr</filename>
partition (any activity on a broken filesystem is likely to
break it more, so <command>fsck</command> should be run as soon
as possible).</para>
<para>The bootup scripts <command>init</command> runs
will automatically enter single user mode, if the automatic
<command>fsck</command> at bootup fails. This is an attempt to
prevent the system from using a filesystem that is so broken that
<command>fsck</command> can't fix it automatically. Such breakage
is relatively rare, and usually involves a broken hard disk or an
experimental kernel release, but it's good to be prepared.</para>
<para>As a security measure, a properly configured system
will ask for the root password before starting the shell in
single user mode. Otherwise, it would be simple to just enter
a suitable line to LILO to get in as root. (This will break if
<filename>/etc/passwd</filename> has been broken by filesystem
problems, of course, and in that case you'd better have a boot
floppy handy.)</para>
</chapter>
<chapter id="log-in-and-out">
<title>Logging In And Out</title>
<blockquote><para><quote>I don't care to belong to a club
that accepts people like me as a member.</quote>
(Groucho Marx)</para></blockquote>
<para>
This section describes what happens when a user logs
in or out. The various interactions of background processes,
log files, configuration files, and so on are described in
some detail.
</para>
<sect1>
<title>Logins via terminals</title>
<para><xref linkend="terminal-logins"> shows how logins happen via
terminals. First, <command>init</command> makes sure there is
a <command>getty</command> program for the terminal connection
(or console). <command>getty</command> listens at the terminal
and waits for the user to notify that he is ready to login in
(this usually means that the user must type something). When it
notices a user, <command>getty</command> outputs a welcome message
(stored in <filename>/etc/issue</filename>), and prompts for
the username, and finally runs the <command>login</command>
program. <command>login</command> gets the username as a
parameter, and prompts the user for the password. If these
match, <command>login</command> starts the shell configured
for the user; else it just exits and terminates the process
(perhaps after giving the user another chance at entering the
username and password). <command>init</command> notices that
the process terminated, and starts a new <command>getty</command>
for the terminal.
</para>
<figure id="terminal-logins" float="1">
<title>Logins via terminals: the interaction of
<command>init</command>,
<command>getty</command>, <command>login</command>, and the
shell.</title>
<graphic fileref="logins-via-terminals"></graphic>
</figure>
<para> Note that the only new process is the
one created by <command>init</command> (using the
<function>fork</function> system call); <command>getty</command>
and <command>login</command> only replace the program running in
the process (using the <function>exec</function> system call).
</para>
<para> A separate program, for noticing the user, is needed
for serial lines, since it can be (and traditionally was)
complicated to notice when a terminal becomes active.
<command>getty</command> also adapts to the speed and other
settings of the connection, which is important especially for
dial-in connections, where these parameters may change from call
to call. </para>
<para> There are several versions of <command>getty</command>
and <command>init</command> in use, all with their good and
bad points. It is a good idea to learn about the versions on
your system, and also about the other versions (you could use the
Linux Software Map to search them). If you don't have dial-ins,
you probably don't have to worry about <command>getty</command>,
but <command>init</command> is still important. </para>
</sect1>
<sect1>
<title>Logins via the network</title>
<para>Two computers in the same network are usually linked via a
single physical cable. When they communicate over the network,
the programs in each computer that take part in the communication
are linked via a <glossterm>virtual connection</glossterm>, a sort
of imaginary cable. As far as the programs at either end of the
virtual connection are concerned, they have a monopoly on their
own cable. However, since the cable is not real, only imaginary,
the operating systems of both computers can have several virtual
connections share the same physical cable. This way, using just
a single cable, several programs can communicate without having
to know of or care about the other communications. It is even
possible to have several computers use the same cable; the virtual
connections exist between two computers, and the other computers
ignore those connections that they don't take part in. </para>
<para> That's a complicated and over-abstracted description of
the reality. It might, however, be good enough to understand
the important reason why network logins are somewhat different
from normal logins. The virtual connections are established
when there are two programs on different computers that wish
to communicate. Since it is in principle possible to login
from any computer in a network to any other computer, there is
a huge number of potential virtual communications. Because of
this, it is not practical to start a <command>getty</command>
for each potential login. </para>
<para> There is a single process inetd (corresponding to
<command>getty</command>) that handles all network logins.
When it notices an incoming network login (i.e., it notices
that it gets a new virtual connection to some other computer),
it starts a new process to handle that single login. The original
process remains and continues to listen for new logins. </para>
<para> To make things a bit more complicated, there is
more than one communication protocol for network logins.
The two most important ones are <command>telnet</command> and
<command>rlogin</command>. In addition to logins, there are many
other virtual connections that may be made (for FTP, Gopher, HTTP,
and other network services). It would be ineffective to have a
separate process listening for a particular type of connection,
so instead there is only one listener that can recognise the type
of the connection and can start the correct type of program to
provide the service. This single listener is called
<command>inetd</command>;
see the <citetitle>Linux Network Administrators' Guide</citetitle>
for more information. </para>
</sect1>
<sect1>
<title>What <command>login</command> does</title>
<para>The <command>login</command> program takes care of
authenticating the user (making sure that the username and
password match), and of setting up an initial environment for
the user by setting permissions for the serial line and starting
the shell. </para>
<para> Part of the initial setup is outputting the contents of
the file <filename>/etc/motd</filename> (short for message of the
day) and checking for electronic mail. These can be disabled
by creating a file called <filename>.hushlogin</filename> in
the user's home directory. </para>
<para> If the file <filename>/etc/nologin</filename>
exists, logins are disabled. That file is typically
created by <command>shutdown</command> and relatives.
<command>login</command> checks for this file, and will
refuse to accept a login if it exists. If it does exist,
<command>login</command> outputs its contents to the terminal
before it quits. </para>
<para> <command>login</command> logs all failed login attempts in
a system log file (via <command>syslog</command>). It also logs
all logins by root. Both of these can be useful when tracking
down intruders. </para>
<para> Currently logged in people are listed in
<filename>/var/run/utmp</filename>. This file is valid only
until the system is next rebooted or shut down; it is cleared
when the system is booted. It lists each user and the terminal
(or network connection) he is using, along with some other useful
information. The <command>who</command>, <command>w</command>,
and other similar commands look in <filename>utmp</filename>
to see who are logged in. </para>
<para> All successful logins are recorded into
<filename>/var/log/wtmp</filename>. This file will grow without
limit, so it must be cleaned regularly, for example by having
a weekly <command>cron</command> job to clear it.
<footnote><para>Good Linux distributions do this out
of the box.</para></footnote>
The <command>last</command> command browses
<filename>wtmp</filename>. </para>
<para> Both <filename>utmp</filename> and
<filename>wtmp</filename> are in a binary format (see the
<filename>utmp</filename> manual page); it is unfortunately not
convenient to examine them without special programs. </para>
</sect1>
<sect1>
<title>X and xdm</title>
<para> XXX X implements logins via xdm; also: xterm -ls </para>
</sect1>
<sect1>
<title>Access control</title>
<para> The user database is traditionally contained in the
<filename>/etc/passwd</filename> file. Some systems use
<glossterm>shadow passwords</glossterm>, and have moved the
passwords to <command>/etc/shadow</command>. Sites with many
computers that share the accounts use NIS or some other method
to store the user database; they might also automatically copy
the database from one central location to all other computers.
</para>
<para> The user database contains not only the passwords, but
also some additional information about the users, such as their
real names, home directories, and login shells. This other
information needs to be public, so that anyone can read it.
Therefore the password is stored encrypted. This does have
the drawback that anyone with access to the encrypted password
can use various cryptographic methods to guess it, without
trying to actually log into the computer. Shadow passwords try
to avoid this by moving the password into another file, which
only root can read (the password is still stored encrypted).
However, installing shadow passwords later onto a system that
did not support them can be difficult. </para>
<para> With or without passwords, it is important to make
sure that all passwords in a system are good, i.e., not easily
guessed. The <command>crack</command> program can be used
to crack passwords; any password it can find is by definition
not a good one. While <command>crack</command> can be run
by intruders, it can also be run by the system administrator
to avoid bad passwords. Good passwords can also be enforced
by the <command>passwd</command> program; this is in fact more
effective in CPU cycles, since cracking passwords requires quite
a lot of computation. </para>
<para> The user group database is kept in
<filename>/etc/group</filename>; for systems with shadow
passwords, there can be a <filename>/etc/shadow.group</filename>.
</para>
<para> root usually can't login via most terminals
or the network, only via terminals listed in the
<filename>/etc/securetty</filename> file. This makes it necessary
to get physical access to one of these terminals. It is, however,
possible to log in via any terminal as any other user, and use
the <command>su</command> command to become root. </para>
</sect1>
<sect1>
<title>Shell startup</title>
<para> When an interactive login shell starts, it automatically
executes one or more pre-defined files. Different shells execute
different files; see the documentation of each shell for further
information. </para>
<para> Most shells first run some global file, for example, the
Bourne shell (<command>/bin/sh</command>) and its derivatives
execute <filename>/etc/profile</filename>; in addition,
they execute <filename>.profile</filename> in the user's
home directory. <filename>/etc/profile</filename> allows the
system administrator to have set up a common user environment,
especially by setting the <envar>PATH</envar> to include local
command directories in addition to the normal ones. On the other
hand, <filename>.profile</filename> allows the user to customise
the environment to his own tastes by overriding, if necessary,
the default environment. </para>
</chapter>
<chapter>
<title>Managing user accounts</title>
<blockquote><para><quote>The similarities of sysadmins and drug
dealers: both measure stuff in Ks, and both have users.</quote>
(Old, tired computer joke.)</para></blockquote>
<para> This chapter explains how to create new user accounts,
how to modify the properties of those accounts, and how to remove
the accounts. Different Linux systems have different tools for
doing this.</para>
<sect1>
<title>What's an account?</title>
<para> When a computer is used by many people it is usually
necessary to differentiate between the users, for example, so that
their private files can be kept private. This is important even
if the computer can only be used by a single person at a time,
as with most microcomputers.
<footnote><para>It might be quite embarrassing if my
sister could read my love letters.</para></footnote>
Thus, each user is given a unique username, and that name is
used to log in. </para>
<para> There's more to a user than just a name, however. An
<glossterm>account</glossterm> is all the files, resources,
and information belonging to one user. The term hints at banks,
and in a commercial system each account usually has some money
attached to it, and that money vanishes at different speeds
depending on how much the user stresses the system. For example,
disk space might have a price per megabyte and day, and processing
time might have a price per second. </para>
</sect1>
<sect1>
<title>Creating a user</title>
<para> The Linux kernel itself treats users are mere numbers.
Each user is identified by a unique integer, the <glossterm>user
id</glossterm> or <glossterm>uid</glossterm>, because numbers are
faster and easier for a computer to process than textual names.
A separate database outside the kernel assigns a textual name,
the <glossterm>username</glossterm>, to each user id. The database
contains additional information as well. </para>
<para> To create a user, you need to add information about
the user to the user database, and create a home directory for
him. It may also be necessary to educate the user, and set up
a suitable initial environment for him. </para>
<para> Most Linux distributions come with a program for
creating accounts. There are several such programs available.
Two command line alternatives are <command>adduser</command>
and <command>useradd</command>; there may be a GUI tool as well.
Whatever the program, the result is that there is little if
any manual work to be done. Even if the details are many and
intricate, these programs make everything seem trivial. However,
<xref linkend="manual-adduser"> describes how to do it by hand.
</para>
<sect2>
<title><filename>/etc/passwd</filename> and other informative
files</title>
<para> The basic user database in a Unix system is the text file,
<filename>/etc/passwd</filename> (called the <glossterm>password
file</glossterm>), which lists all valid usernames and their
associated information. The file has one line per username,
and is divided into seven colon-delimited fields:
<itemizedlist>
<listitem><para>Username.</para></listitem>
<listitem><para>Password, in an encrypted form.</para></listitem>
<listitem><para>Numeric user id.</para></listitem>
<listitem><para>Numeric group id.</para></listitem>
<listitem><para>Full name or other description of
account.</para></listitem>
<listitem><para>Home directory.</para></listitem>
<listitem><para>Login shell (program to run at
login).</para></listitem>
</itemizedlist>
The format is explained in more detail on the
<filename>passwd</filename> manual page. </para>
<para> Any user on the system may read the password file,
so that they can, for example, learn the name of another user.
This means that the password (the second field) is also available
to everyone. The password file encrypts the password, so in
theory there is no problem. However, the encryption is breakable,
especially if the password is weak (e.g., it is short or it can
be found in a dictionary). Therefore it is not a good idea to
have the password in the password file. </para>
<para>
Many Linux systems have <glossterm>shadow passwords</glossterm>.
This is
an alternative way of storing the password: the encrypted
password is stored in a separate file,
<filename>/etc/shadow</filename>,
which only root can read. The <filename>/etc/passwd</filename>
file only contains a special marker in the second field.
Any program that needs to verify a user is setuid, and
can therefore access the shadow password file. Normal
programs, which only use the other fields in the password
file, can't get at the password.
<footnote><para>Yes, this means that the
password file has all the information about a user
<emphasis>except</emphasis> his password. The wonder
of development.</para></footnote>
</para>
</sect2>
<sect2>
<title>Picking numeric user and group ids</title>
<para> On most systems it doesn't matter what the numeric user
and group ids are, but if you use the Network filesystem (NFS),
you need to have the same uid and gid on all systems. This
is because NFS also identifies users with the numeric uids.
If you aren't using NFS, you can let your account creation tool
pick them automatically. </para>
<para> If you are using NFS, you'll have to be invent a mechanism
for synchronising account information. One alternative is to
the NIS system (see XXX network-admin-guide). </para>
<para> However, you should try to avoid re-using numeric uids
(and textual usernames), because the new owner of the uid (or
username) may get access to the old owner's files (or mail,
or whatever). </para>
</sect2>
<!--
%\subsection{Managing groups}
%
% \meta Debian creates a new group for each user; give reason for
this;
% give reasons against.
-->
<sect2>
<title>Initial environment: <filename>/etc/skel</filename></title>
<para> When the home directory for a new user is created, it is
initialised with files from the <filename>/etc/skel</filename>
directory. The system administrator can create files in
<filename>/etc/skel</filename> that will provide a nice
default environment for users. For example, he might create a
<filename>/etc/skel/.profile</filename> that sets the EDITOR
environment variable to some editor that is friendly towards
new users. </para>
<para> However, it is usually best to try to keep
<filename>/etc/skel</filename> as small as possible, since it
will be next to impossible to update existing users' files. For
example, if the name of the friendly editor changes, all existing
users would have to edit their <filename>.profile</filename>. The
system administrator could try to do it automatically, with a
script, but that is almost certain going to break someone's file.
</para>
<para> Whenever possible, it is better to put global configuration
into global files, such as <filename>/etc/profile</filename>. This
way it is possible to update it without breaking users'
own setups. </para>
</sect2>
<sect2 id="manual-adduser">
<title>Creating a user by hand</title>
<para> To create a new account manually, follow these steps:
<itemizedlist>
<listitem><para> Edit <filename>/etc/passwd</filename> with
<command>vipw</command> and add a new line for the new account. Be
careful with the syntax. <emphasis>Do not edit directly with an
editor!</emphasis> <command>vipw</command> locks the file, so
that other commands won't try to update it at the same time. You
should make the password field be `<literal>*</literal>', so
that it is impossible to log in. </para></listitem>
<listitem><para> Similarly, edit <filename>/etc/group</filename>
with <command>vigr</command>, if you need to create a new group
as well. </para></listitem>
<listitem><para> Create the home directory of the user with
<command>mkdir</command>. </para></listitem>
<listitem><para> Copy the files from
<filename>/etc/skel</filename> to the new home directory.
</para></listitem>
<listitem><para> Fix ownerships and permissions with
<command>chown</command> and <command>chmod</command>. The
<option>-R</option> option is most useful. The correct
permissions vary a little from one site to another, but usually
the following commands do the right thing:
<screen>
<userinput>cd /home/newusername
chown -R username.group .
chmod -R go=u,go-w .
chmod go= .</userinput>
</screen>
</para></listitem>
<listitem><para> Set the password with <command>passwd</command>.
</para></listitem>
</itemizedlist>
</para>
<para> After you set the password in the last step, the account
will work. You shouldn't set it until everything else has been
done, otherwise the user may inadvertently log in while you're
still copying the files. </para>
<para>
It is sometimes necessary to create dummy
accounts
<footnote><para>Surreal users?</para></footnote>
that are not used by people. For example, to set up an anonymous
FTP server (so that anyone can download files from it, without
having to get an account first), you need to create an account
called ftp. In such cases, it is usually not necessary to set
the password (last step above). Indeed, it is better not to, so
that no-one can use the account, unless they first become root,
since root can become any user. </para>
</sect2>
</sect1>
<!--
%\section{Educating a new user}
%
% \meta
% make sure they know how to get help
% large sites might want to write a small booklet (or even just
% a couple of pages) with important stuff: how to log in
% and out, how to change password, which systems there are,
% how to use mail, list of people that answer questions
-->
<sect1>
<title>Changing user properties</title>
<para>
There are a few commands for changing various
properties of an account (i.e., the relevant field
in <filename>/etc/passwd</filename>):
<glosslist>
<glossentry><glossterm><command>chfn</command></glossterm>
<glossdef><para> Change the full name field.
</para></glossdef></glossentry>
<glossentry><glossterm><command>chsh</command></glossterm>
<glossdef><para> Change the login shell.
</para></glossdef></glossentry>
<glossentry><glossterm><command>passwd</command></glossterm>
<glossdef><para>Change the password.
</para></glossdef></glossentry>
</glosslist>
The super-user may use these commands to change the properties
of any account. Normal users can only change the properties
of their own account. It may sometimes be necessary to disable
these commands (with <command>chmod</command>) for normal users,
for example in an environment with many novice users. </para>
<para>
Other tasks need to be done by hand. For example, to
change the username, you need to edit
<filename>/etc/passwd</filename>
directly (with <command>vipw</command>, remember). Likewise, to add
or remove the user to more groups, you need to edit
<filename>/etc/group</filename> (with <command>vigr</command>). Such
tasks tend to
be rare, however, and should be done with caution: for
example, if
you change the username, e-mail will no longer reach the
user, unless you also create a mail alias.
<footnote><para>The user's name might change due to
marriage, for example, and he might want to have his
username reflect his new name.</para></footnote>
</para>
</sect1>
<sect1>
<title>Removing a user</title>
<para> To remove a user, you first remove all
his files, mailboxes, mail aliases, print jobs,
<command>cron</command> and <command>at</command> jobs,
and all other references to the user. Then you remove the
relevant lines from <filename>/etc/passwd</filename> and
<filename>/etc/group</filename> (remember to remove the username
from all groups it's been added to). It may be a good idea to
first disable the account (see below), before you start removing
stuff, to prevent the user from using the account while it is
being removed. </para>
<para>
Remember that users may have files outside their home
directory. The <command>find</command> command can find them:
<screen>
find / -user username
</screen>
However, note that the above command will take a
<emphasis>long</emphasis> time, if you have large disks. If you
mount network disks, you need to be careful so that you won't
trash the network or the server. </para>
<para> Some Linux distributions come with special
commands to do this; look for <command>deluser</command> or
<command>userdel</command>. However, it is easy to do it by
hand as well, and the commands might not do everything. </para>
</sect1>
<sect1>
<title>Disabling a user temporarily</title>
<para> It is sometimes necessary to temporarily disable an
account, without removing it. For example, the user might not
have paid his fees, or the system administrator may suspect that
a cracker has got the password of that account. </para>
<para> The best way to disable an account is to change its shell
into a special program that just prints a message. This way,
whoever tries to log into the account, will fail, and will
know why. The message can tell the user to contact the system
administrator so that any problems may be dealt with. </para>
<para>
It would also be possible to change the username
or password to something else, but then the user
won't know what is going on. Confused users mean more
work.
<footnote><para>But they can be <emphasis>so</emphasis>
fun, if you're a BOFH.</para></footnote>
</para>
<para> A simple way to create the special programs is to write
`tail scripts':
<screen>
#!/usr/bin/tail +2
This account has been closed due to a security breach.
Please call 555-1234 and wait for the men in black to arrive.
</screen>
The first two characters (`<literal>#!</literal>') tell the
kernel that the rest of the line is a command that needs to be
run to interpret this file. The <command>tail</command> command
in this case outputs everything except the first line to the
standard output. </para>
<para>
If user billg is suspected of a security breach,
the system administrator would do something like this:
<screen>
<prompt>#</prompt> <userinput>chsh -s
/usr/local/lib/no-login/security billg</userinput>
<prompt>#</prompt> <userinput>su - tester</userinput>
This account has been closed due to a security breach.
Please call 555-1234 and wait for the men in black to arrive.
<prompt>#</prompt>
</screen>
The purpose of the <command>su</command> is to test that the
change worked, of course. </para>
<para> Tail scripts should be kept in a separate directory,
so that their names don't interfere with normal user commands.
</para>
</sect1>
<!--
%\section{Accounting}
%
% \meta
% sac et al
-->
</chapter>
<chapter id="backups">
<title>Backups</title>
<blockquote><para><literallayout>
Hardware is indeterministically reliable.
Software is deterministically unreliable.
People are indeterministically unreliable.
Nature is deterministically reliable.
</literallayout></para></blockquote>
<para> This chapter explains about why, how, and when to make
backups, and how to restore things from backups.</para>
<sect1>
<title>On the importance of being backed up</title>
<para> Your data is valuable. It will cost you time and effort
re-create it, and that costs money or at least personal grief
and tears; sometimes it can't even be re-created, e.g., if it
is the results of some experiments. Since it is an investment,
you should protect it and take steps to avoid losing it. </para>
<para> There are basically four reasons why you might lose data:
hardware failures, software bugs, human action, or natural
disasters.
<footnote><para>The fifth reason is ``something
else''.</para></footnote>
Although modern hardware tends to be quite reliable, it can
still break seemingly spontaneously. The most critical piece
of hardware for storing data is the hard disk, which relies on
tiny magnetic fields remaining intact in a world filled with
electromagnetic noise. Modern software doesn't even tend to
be reliable; a rock solid program is an exception, not a rule.
Humans are quite unreliable, they will either make a mistake, or
they will be malicious and destroy data on purpose. Nature might
not be evil, but it can wreak havoc even when being good. All in
all, it is a small miracle that anything works at all. </para>
<para> Backups are a way to protect the investment in data.
By having several copies of the data, it does not matter as much
if one is destroyed (the cost is only that of the restoration
of the lost data from the backup). </para>
<para> It is important to do backups properly. Like everything
else that is related to the physical world, backups will fail
sooner or later. Part of doing backups well is to make sure
they work; you don't want to notice that your backups didn't work.
<footnote><para>Don't laugh. This has happened to
several people.</para></footnote>
Adding insult to injury, you might have a bad crash just as
you're making the backup; if you have only one backup medium,
it might destroyed as well, leaving you with the smoking ashes
of hard work.
<footnote><para>Been there, done that...</para></footnote>
Or you might notice, when trying to restore, that you forgot to
back up something important, like the user database on a 15000
user site. Best of all, all your backups might be working
perfectly, but the last known tape drive reading the kind of
tapes you used was the one that now has a bucketful of water
in it. </para>
<para> When it comes to backups, paranoia is in the job
description. </para>
</sect1>
<sect1>
<title>Selecting the backup medium</title>
<para> The most important decision regarding backups is the choice
of backup medium. You need to consider cost, reliability, speed,
availability, and usability. </para>
<para> Cost is important, since you should preferably have
several times more backup storage than what you need for the data.
A cheap medium is usually a must. </para>
<para> Reliability is extremely important, since a broken
backup can make a grown man cry. A backup medium must be able
to hold data without corruption for years. The way you use the
medium affects it reliability as a backup medium. A hard disk
is typically very reliable, but as a backup medium it is not
very reliable, if it is in the same computer as the disk you
are backing up. </para>
<para> Speed is usually not very important, if backups can be done
without interaction. It doesn't matter if a backup takes two
hours, as long as it needs no supervision. On the other hand,
if the backup can't be done when the computer would otherwise
be idle, then speed is an issue. </para>
<para> Availability is obviously necessary, since you can't
use a backup medium if it doesn't exist. Less obvious is the
need for the medium to be available even in the future, and on
computers other than your own. Otherwise you may not be able
to restore your backups after a disaster. </para>
<para> Usability is a large factor in how often backups are made.
The easier it is to make backups, the better. A backup medium
mustn't be hard or boring to use. </para>
<para> The typical alternatives are floppies and tapes.
Floppies are very cheap, fairly reliable, not very fast,
very available, but not very usable for large amounts of data.
Tapes are cheap to somewhat expensive, fairly reliable, fairly
fast, quite available, and, depending on the size of the tape,
quite comfortable. </para>
<para> There are other alternatives. They are usually not very
good on availability, but if that is not a problem, they can
be better in other ways. For example, magneto-optical disks
can have good sides of both floppies (they're random access,
making restoration of a single file quick) and tapes (contain
a lot of data). </para>
</sect1>
<sect1>
<title>Selecting the backup tool</title>
<para> There are many tools that can be used to make
backups. The traditional UNIX tools used for backups
are <command>tar</command>, <command>cpio</command>, and
<command>dump</command>. In addition, there are large number
of third party packages (both freeware and commercial) that
can be used. The choice of backup medium can affect the choice
of tool. </para>
<para> <command>tar</command> and <command>cpio</command> are
similar, and mostly equivalent from a backup point of view.
Both are capable of storing files on tapes, and retrieving
files from them. Both are capable of using almost any media,
since the kernel device drivers take care of the low level
device handling and the devices all tend to look alike to user
level programs. Some UNIX versions of <command>tar</command>
and <command>cpio</command> may have problems with unusual files
(symbolic links, device files, files with very long pathnames, and
so on), but the Linux versions should handle all files correctly.
</para>
<para> <command>dump</command> is different in that it reads
the filesystem directly and not via the filesystem. It is
also written specifically for backups; <command>tar</command>
and <command>cpio</command> are really for archiving files,
although they work for backups as well. </para>
<para> Reading the filesystem directly has some advantages.
It makes it possible to back files up without affecting their time
stamps; for <command>tar</command> and <command>cpio</command>,
you would have to mount the filesystem read-only first.
Directly reading the filesystem is also more effective, if
everything needs to be backed up, since it can be done with
much less disk head movement. The major disadvantage is that
it makes the backup program specific to one filesystem type;
the Linux <command>dump</command> program understands the ext2
filesystem only. </para>
<para> <command>dump</command> also directly supports
backup levels (which we'll be discussing below); with
<command>tar</command> and <command>cpio</command> this has to
be implemented with other tools. </para>
<para> A comparison of the third party backup tools is beyond
the scope of this book. The Linux Software Map lists many of
the freeware ones. </para>
</sect1>
<sect1>
<title>Simple backups</title>
<para> A simple backup scheme is to back up everything once,
then back up everything that has been modified since the
previous backup. The first backup is called a <glossterm>full
backup</glossterm>, the subsequent ones are <glossterm>incremental
backups</glossterm>. A full backup is often more labourious
than incremental ones, since there is more data to write to the
tape and a full backup might not fit onto one tape (or floppy).
Restoring from incremental backups can be many times more work
than from a full one. Restoration can be optimised so that
you always back up everything since the previous full backup;
this way, backups are a bit more work, but there should never
be a need to restore more than a full backup and an incremental
backup. </para>
<para> If you want to make backups every day and have six
tapes, you could use tape 1 for the first full backup (say, on
a Friday), and tapes 2 to 5 for the incremental backups (Monday
through Thursday). Then you make a new full backup on tape 6
(second Friday), and start doing incremental ones with tapes 2
to 5 again. You don't want to overwrite tape 1 until you've got
a new full backup, lest something happens while you're making
the full backup. After you've made a full backup to tape 6,
you want to keep tape 1 somewhere else, so that when your other
backup tapes are destroyed in the fire, you still have at least
something left. When you need to make the next full backup,
you fetch tape 1 and leave tape 6 in its place. </para>
<para> If you have more than six tapes, you can use the extra
ones for full backups. Each time you make a full backup, you
use the oldest tape. This way you can have full backups from
several previous weeks, which is good if you want to find an old,
now deleted file, or an old version of a file. </para>
<sect2>
<title>Making backups with <command>tar</command></title>
<para>
A full backup can easily be made with <command>tar</command>:
<screen>
<prompt>#</prompt> <userinput>tar --create --file /dev/ftape
/usr/src</userinput>
<computeroutput>tar: Removing leading / from absolute path names in
the archive</computeroutput>
<prompt>#</prompt>
</screen>
The example above uses the GNU version of <command>tar</command>
and its long option names. The traditional version of
<command>tar</command> only understands single character
options. The GNU version can also handle backups that don't
fit on one tape or floppy, and also very long paths; not all
traditional versions can do these things. (Linux only uses
GNU <command>tar</command>.) </para>
<para> If your backup doesn't fit on one tape, you need to use
the <option>--multi-volume</option> (<option>-M</option>) option:
<screen>
<prompt>#</prompt> <userinput>tar -cMf /dev/fd0H1440
/usr/src</userinput>
<computeroutput>tar: Removing leading / from absolute path names in
the archive
Prepare volume #2 for /dev/fd0H1440 and hit return:</computeroutput>
<prompt>#</prompt>
</screen>
Note that you should format the floppies before you begin the
backup, or else use another window or virtual terminal and do
it when <command>tar</command> asks for a new floppy. </para>
<para> After you've made a backup, you should check that it is OK,
using the <option>--compare</option> (<option>-d</option>) option:
<screen>
<prompt>#</prompt> <userinput>tar --compare --verbose -f
/dev/ftape</userinput>
<computeroutput>usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
....</computeroutput>
<prompt>#</prompt>
</screen>
Failing to check a backup means that you will not notice that your
backups aren't working until after you've lost the original data.
</para>
<para> An incremental backup can be done with
<command>tar</command> using the <option>--newer</option>
(<option>-N</option>) option:
<screen>
<prompt>#</prompt> <userinput>tar --create --newer '8 Sep 1995'
--file /dev/ftape /usr/src
--verbose</userinput>
<computeroutput>tar: Removing leading / from absolute path names in
the archive
usr/src/
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/modules/
usr/src/linux-1.2.10-includes/include/asm-generic/
usr/src/linux-1.2.10-includes/include/asm-i386/
usr/src/linux-1.2.10-includes/include/asm-mips/
usr/src/linux-1.2.10-includes/include/asm-alpha/
usr/src/linux-1.2.10-includes/include/asm-m68k/
usr/src/linux-1.2.10-includes/include/asm-sparc/
usr/src/patch-1.2.11.gz</computeroutput>
<prompt>#</prompt>
</screen>
Unfortunately, <command>tar</command> can't notice when a file's
inode information has changed, for example, that its permission
bits have been changed, or when its name has been changed.
This can be worked around using <command>find</command> and
comparing current filesystem state with lists of files that have
been previously backed up. Scripts and programs for doing this
can be found on Linux ftp sites. </para>
</sect2>
<sect2>
<title>Restoring files with <command>tar</command></title>
<para> The <option>--extract</option> (<option>-x</option>)
option for <command>tar</command> extracts files:
<screen>
<prompt>#</prompt> <userinput>tar --extract --same-permissions
--verbose --file
/dev/fd0H1440</userinput>
<computeroutput>usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
usr/src/linux-1.2.10-includes/include/linux/kernel.h
...</computeroutput>
<prompt>#</prompt>
</screen>
You also extract only specific files or directories (which
includes all their files and subdirectories) by naming on the
command line:
<screen>
<prompt>#</prompt> <userinput>tar xpvf /dev/fd0H1440
usr/src/linux-1.2.10-includes/include/linux/hdreg.h</userinput>
<computeroutput>usr/src/linux-1.2.10-includes/include/linux/hdreg.h</computeroutput>
<prompt>#</prompt>
</screen>
Use the <option>--list</option> (<option>-t</option>) option,
if you just want to see what files are on a backup volume:
<screen>
<prompt>#</prompt> <userinput>tar --list --file
/dev/fd0H1440</userinput>
<computeroutput>usr/src/
usr/src/linux
usr/src/linux-1.2.10-includes/
usr/src/linux-1.2.10-includes/include/
usr/src/linux-1.2.10-includes/include/linux/
usr/src/linux-1.2.10-includes/include/linux/hdreg.h
usr/src/linux-1.2.10-includes/include/linux/kernel.h
...</computeroutput>
<prompt>#</prompt>
</screen>
Note that <command>tar</command> always reads the backup volume
sequentially, so for large volumes it is rather slow. It is not
possible, however, to use random access database techniques when
using a tape drive or some other sequential medium. </para>
<para> <command>tar</command> doesn't handle deleted files
properly. If you need to restore a filesystem from a full and
an incremental backup, and you have deleted a file between
the two backups, it will exist again after you have done the
restore. This can be a big problem, if the file has sensitive
data that should no longer be available. </para>
</sect2>
</sect1>
<sect1>
<title>Multilevel backups</title>
<para> The simple backup method outlined in the previous section
is often quite adequate for personal use or small sites. For more
heavy duty use, multilevel backups are more appropriate. </para>
<para> The simple method has two backup levels: full and
incremental backups. This can be generalised to any number of
levels. A full backup would be level 0, and the different levels
of incremental backups levels 1, 2, 3, etc. At each incremental
backup level you back up everything that has changed since the
previous backup at the same or a previous level. </para>
<para> The purpose for doing this is that it allows a longer
<glossterm>backup history</glossterm> cheaply. In the example in
the previous section, the backup history went back to the previous
full backup. This could be extended by having more tapes, but
only a week per new tape, which might be too expensive. A longer
backup history is useful, since deleted or corrupted files are
often not noticed for a long time. Even a version of a file that
is not very up to date is better than no file at all. </para>
<para> With multiple levels the backup history can be extended
more cheaply. For example, if we buy ten tapes, we could use
tapes 1 and 2 for monthly backups (first Friday each month),
tapes 3 to 6 for weekly backups (other Fridays; note that there
can be five Fridays in one month, so we need four more tapes),
and tapes 7 to 10 for daily backups (Monday to Thursday).
With only four more tapes, we've been able to extend the backup
history from two weeks (after all daily tapes have been used)
to two months. It is true that we can't restore every version
of each file during those two months, but what we can restore
is often good enough. </para>
<para><xref linkend="backup-history-timeline"> shows which backup
level is used each day, and which backups can be restored from
at the end of the month. </para>
<figure id="backup-history-timeline" float="1">
<title>A sample multilevel backup schedule.</title>
<graphic fileref="backup-timeline"></graphic>
</figure>
<para> Backup levels can also be used to keep filesystem
restoration time to a minimum. If you have many incremental
backups with monotonously growing level numbers, you need to
restore all of them if you need to rebuild the whole filesystem.
Instead you can use level numbers that aren't monotonous, and
keep down the number of backups to restore. </para>
<para> To minimise the number of tapes needed to restore, you
could use a smaller level for each incremental tape. However,
then the time to make the backups increases (each backup copies
everything since the previous full backup). A better scheme is
suggested by the <command>dump</command> manual page and described
by the table XX (efficient-backup-levels). Use the following
succession of backup levels: 3, 2, 5, 4, 7, 6, 9, 8, 9, etc.
This keeps both the backup and restore times low. The most you
have to backup is two day's worth of work. The number of tapes
for a restore depends on how long you keep between full backups,
but it is less than in the simple schemes. </para>
<table id="efficient-backup-levels">
<title>Efficient backup scheme using many backup levels</title>
<tgroup cols=4>
<thead>
<row><entry>Tape</entry> <entry>Level</entry> <entry>Backup
(days)</entry> <entry>Restore
tapes</entry></row>
</thead>
<tbody>
<row><entry>1</entry> <entry>0</entry> <entry>n/a</entry>
<entry>1</entry></row>
<row><entry>2</entry> <entry>3</entry> <entry>1</entry> <entry>1,
2</entry></row>
<row><entry>3</entry> <entry>2</entry> <entry>2</entry> <entry>1,
3</entry></row>
<row><entry>4</entry> <entry>5</entry> <entry>1</entry> <entry>1, 2,
4</entry></row>
<row><entry>5</entry> <entry>4</entry> <entry>2</entry> <entry>1, 2,
5</entry></row>
<row><entry>6</entry> <entry>7</entry> <entry>1</entry> <entry>1, 2,
5, 6</entry></row>
<row><entry>7</entry> <entry>6</entry> <entry>2</entry> <entry>1, 2,
5, 7</entry></row>
<row><entry>8</entry> <entry>9</entry> <entry>1</entry> <entry>1, 2,
5, 7, 8</entry></row>
<row><entry>9</entry> <entry>8</entry> <entry>2</entry> <entry>1, 2,
5, 7, 9</entry></row>
<row><entry>10</entry> <entry>9</entry> <entry>1</entry> <entry>1, 2,
5, 7, 9, 10</entry></row>
<row><entry>11</entry> <entry>9</entry> <entry>1</entry> <entry>1, 2,
5, 7, 9, 10,
11</entry></row>
<row><entry>...</entry> <entry>9</entry> <entry>1</entry> <entry>1,
2, 5, 7, 9, 10, 11,
...</entry></row>
</tbody>
</tgroup>
</table>
<para> A fancy scheme can reduce the amount of labour needed, but
it does mean there are more things to keep track of. You must
decide if it is worth it. </para>
<para> <command>dump</command> has built-in support for backup
levels. For <command>tar</command> and <command>cpio</command>
it must be implemented with shell scripts. </para>
</sect1>
<sect1>
<title>What to back up</title>
<para> You want to back up as much as possible. The major
exception is software that can be easily reinstalled,
<footnote><para>You get to decide what's easy.
Some people consider installing from dozens of floppies
easy.</para></footnote>
but even they may have configuration files that it is
important to back up, lest you need to do all the work to
configure them all over again. Another major exception is
the <filename>/proc</filename> filesystem; since that only
contains data that the kernel always generates automatically,
it is never a good idea to back it up. Especially the
<filename>/proc/kcore</filename> file is unnecessary, since it
is just an image of your current physical memory; it's pretty
large as well. </para>
<para> Gray areas include the news spool, log files, and many
other things in <filename>/var</filename>. You must decide what
you consider important. </para>
<para> The obvious things to back up are user files
(<filename>/home</filename>) and system configuration files
(<filename>/etc</filename>, but possibly other things scattered
all over the filesystem). </para>
</sect1>
<sect1>
<title>Compressed backups</title>
<para> Backups take a lot of space, which can cost quite
a lot of money. To reduce the space needed, the backups
can be compressed. There are several ways of doing this.
Some programs have support for for compression built in; for
example, the <option>--gzip</option> (<option>-z</option>)
option for GNU <command>tar</command> pipes the whole backup
through the <command>gzip</command> compression program, before
writing it to the backup medium. </para>
<para> Unfortunately, compressed backups can cause trouble.
Due to the nature of how compression works, if a single bit is
wrong, all the rest of the compressed data will be unusable.
Some backup programs have some built in error correction, but no
method can handle a large number of errors. This means that if
the backup is compressed the way GNU <command>tar</command> does
it, with the whole output compressed as a unit, a single error
makes all the rest of the backup lost. Backups must be reliable,
and this method of compression is not a good idea. </para>
<para> An alternative way is to compress each file separately.
This still means that the one file is lost, but all other files
are unharmed. The lost file would have been corrupted anyway,
so this situation is not much worse than not using compression
at all. The <command>afio</command> program (a variant of
<command>cpio</command>) can do this. </para>
<para>
Compression takes some time, which may make the backup program
unable to write data fast enough for a tape drive.
<footnote><para>If a tape drive doesn't data fast enough,
it has to stop; this makes backups even slower, and can
be bad for the tape and the drive.</para></footnote>
This can be avoided by buffering the output (either internally, if
the backup program if smart enough, or by using another program),
but even that might not work well enough. This should only be
a problem on slow computers. </para>
</sect1>
</chapter>
<chapter>
<title>Keeping Time</title>
<blockquote><para><quote>Time is an illusion. Lunchtime double
so.</quote> (Douglas Adams.)</para></blockquote>
<para> This chapter explains how a Linux system keeps time,
and what you need to do to avoid causing trouble. Usually,
you don't need to do anything about time, but it is good to
understand it.</para>
<sect1>
<title>Time zones</title>
<para> Time measurement is based on mostly regular natural
phenomena, such as alternating light and dark periods caused
by the rotation of the planet. The total time taken by two
successive periods is constant, but the lengths of the light
and dark period vary. One simple constant is noon. </para>
<para> Noon is the time of the day when the Sun is at its
highest position. Since the Earth is round,
<footnote><para>According to
recent research.</para></footnote>
noon happens at different times in different places. This leads
to the concept of <glossterm>local time</glossterm>. Humans
measure time in many units, most of which are tied to natural
phenomena like noon. As long as you stay in the same place,
it doesn't matter that local times differ. </para>
<para> As soon as you need to communicate with distant places,
you'll notice the need for a common time. In modern times,
most of the places in the world communicate with most other
places in the world, so a global standard for measuring time
has been defined. This time is called <glossterm>universal
time</glossterm> (UT or UTC, formerly known as Greenwich Mean Time
or GMT, since it used to be local time in Greenwich, England).
When people with different local times need to communicate,
they can express times in universal time, so that there is no
confusion about when things should happen. </para>
<para> Each local time is called a time zone. While geography
would allow all places that have noon at the same time have the
same time zone, politics makes it difficult. For various reasons,
many countries use <glossterm>daylight savings time</glossterm>,
that is, they move their clocks to have more natural light
while they work, and then move the clocks back during winter.
Other countries do not do this. Those that do, do not agree when
the clocks should be moved, and they change the rules from year
to year. This makes time zone conversions definitely non-trivial.
</para>
<para> Time zones are best named by the location or by telling
the difference between local and universal time. In the US
and some other countries, the local time zones have a name and
a three letter abbreviation. The abbreviations are not unique,
however, and should not be used unless the country is also named.
It is better to talk about the local time in, say, Helsinki,
than about East European time, since not all countries in Eastern
Europe follow the same rules. </para>
<para> Linux has a time zone package that knows about all
existing time zones, and that can easily be updated when the
rules change. All the system administrator needs to do is to
select the appropriate time zone. Also, each user can set his
own time zone; this is important since many people work with
computers in different countries over the Internet. When the
rules for daylight savings time change in your local time zone,
make sure you'll upgrade at least that part of your Linux system.
Other than setting the system time zone and upgrading the time
zone data files, there is little need to bother about time.
</para>
</sect1>
<sect1>
<title>The hardware and software clocks</title>
<para> A personal computer has a battery driven hardware clock.
The battery ensures that the clock will work even if the rest of
the computer is without electricity. The hardware clock can be
set from the BIOS setup screen or from whatever operating system
is running. </para>
<para> The Linux kernel keeps track of time independently from
the hardware clock. During the boot, Linux sets its own clock
to the same time as the hardware clock. After this, both clocks
run independently. Linux maintains its own clock because looking
at the hardware is slow and complicated. </para>
<para> The kernel clock always shows universal time. This way,
the kernel does not need to know about time zones at all. The
simplicity results in higher reliability and makes it easier
to update the time zone information. Each process handles time
zone conversions itself (using standard tools that are part of
the time zone package). </para>
<para> The hardware clock can be in local time or in universal
time. It is usually better to have it in universal time,
because then you don't need to change the hardware clock when
daylight savings time begins or ends (UTC does not have DST).
Unfortunately, some PC operating systems, including MS-DOS,
Windows, and OS/2, assume the hardware clock shows local time.
Linux can handle either, but if the hardware clock shows local
time, then it must be modified when daylight savings time begins
or ends (otherwise it wouldn't show local time). </para>
</sect1>
<sect1>
<title>Showing and setting time</title>
<para> In the Debian system, the system time zone is determined
by the symbolic link <filename>/etc/localtime</filename>.
This link points at a time zone data file that describes
the local time zone. The time zone data files are stored in
<filename>/usr/lib/zoneinfo</filename>. Other Linux distributions
may do this differently. </para>
<para> A user can change his private time zone by setting the
TZ environment variable. If it is unset, the system time zone
is assumed. The syntax of the TZ variable is described in the
<function>tzset</function> manual page. </para>
<para>
The <command>date</command> command shows the current date and
time.
<footnote><para>Beware of the <command>time</command> command,
which does
not show the current time.</para></footnote>
For example:
<screen>
<prompt>$</prompt> <userinput>date</userinput>
<computeroutput>Sun Jul 14 21:53:41 EET DST 1996</computeroutput>
<prompt>$</prompt>
</screen>
That time is Sunday, 14th of July, 1996, at about ten before
ten at the evening, in the time zone called ``EET DST''
(which might be East European Daylight Savings Time).
<command>date</command> can also show the universal time:
<screen>
<prompt>$</prompt> <userinput>date -u</userinput>
Sun Jul 14 18:53:42 UTC 1996
<computeroutput>Sun Jul 14 18:53:42 UTC 1996</computeroutput>
<prompt>$</prompt>
</screen>
<command>date</command> is also used to set the kernel's software
clock:
<screen>
<prompt>#</prompt> <userinput>date 07142157</userinput>
<computeroutput>Sun Jul 14 21:57:00 EET DST 1996</computeroutput>
<prompt>#</prompt> <userinput>date</userinput>
<computeroutput>Sun Jul 14 21:57:02 EET DST 1996</computeroutput>
<prompt>#</prompt>
</screen>
See the <command>date</command> manual page for more details;
the syntax is a bit arcane. Only root can set the time.
While each user can have his own time zone, the clock is the
same for everyone. </para>
<para> <command>date</command> only shows or sets the software
clock. The <command>clock</command> commands synchronises
the hardware and software clocks. It is used when the system
boots, to read the hardware clock and set the software clock.
If you need to set both clocks, you first set the software clock
with <command>date</command>, and then the hardware clock with
<command>clock -w</command>. </para>
<para> The <option>-u</option> option to <command>clock</command>
tells it that the hardware clock is in universal time.
You <emphasis>must</emphasis> use the <option>-u</option>
option correctly. If you don't, your computer will be quite
confused about what the time is. </para>
<para> The clocks should be changed with care. Many parts of a
Unix system require the clocks to work correctly. For example,
the <command>cron</command> daemon runs commands periodically.
If you change the clock, it can be confused of whether
it needs to run the commands or not. On one early Unix
system, someone set the clock twenty years into the future,
and <command>cron</command> wanted to run all the periodic
commands for twenty years all at once. Current versions of
<command>cron</command> can handle this correctly, but you should
still be careful. Big jumps or backward jumps are more dangerous
than smaller or forward ones. </para>
</sect1>
<sect1>
<title>When the clock is wrong</title>
<para> The Linux software clock is not always accurate. It is
kept running by a periodic <glossterm>timer interrupt</glossterm>
generated by PC hardware. If the system has too many processes
running, it may take too long to service the timer interrupt, and
the software clock starts slipping behind. The hardware clock
runs independently and is usually more accurate. If you boot
your computer often (as is the case for most systems that aren't
servers), it will usually keep fairly accurate time. </para>
<para> If you need to adjust the hardware clock, it is usually
simplest to reboot, go into the BIOS setup screen, and do it
from there. This avoids all trouble that changing system time
might cause. If doing it via BIOS is not an option, set the new
time with <command>date</command> and <command>clock</command>
(in that order), but be prepared to reboot, if some part of the
system starts acting funny. </para>
<para> A networked computer (even if just over the modem) can
check its own clock automatically, by comparing it to some other
computer's time. If the other computer is known to keep very
accurate time, then both computers will keep accurate time.
This can be done by using the <command>rdate</command> and
<command>netdate</command> commands. Both check the time of a
remote computer (<command>netdate</command> can handle several
remote computers), and set the local computer's time to that.
By running one these commands regularly, your computer will keep
as accurate time as the remote computer. </para>
<para> XXX say something intelligent about NTP </para>
</sect1>
</chapter>
<chapter>
<title>Finding Help</title>
<blockquote><para><quote>Help me if you can I'm feeling down. And I do
appreciate you being 'round.</quote> - The
Beatles</para></blockquote>
<sect1>
<title>Newsgroups and Mailing Lists</title>
<para>
This guide cannot teach you everything about Linux. There
just isn't enough space. It is almost inevitable that at some point
you will find something you need to do, that isn't covered in
this (or any other) document at the LDP.
</para>
<para>
One of the nicest things about Linux is the large number of forums
devoted to it. There are forums relating to almost all facets of
Linux ranging from newbie FAQs to in depth kernel development issues.
To receive the most from them, there are a few things you can do.
</para>
<sect2>
<title>Finding The Right Forum</title>
<para>
The first thing to do is to find an appropriate forum. There are many
newsgroups and mailing lists devoted to Linux, so try to find and use
the
one which most closely matches your question. For example, there
isn't much point in you asking a question about sendmail in a forum
devoted to Linux kernel development. At best the people there will
think
you are stupid and you will get few responses, at worst you may
receive
lots of highly insulting replies (flames). A quick look
through the newsgroups available finds comp.mail.sendmail, which
looks like an appropriate place to ask a sendmail question. Your news
client probably has a list of the newsgroups available to you, but if
not then a full list of newsgroups is available at <ulink
url="http://groups.google.com/groups?group=*">
http://groups.google.com/groups?group=*</ulink>.
</para>
</sect2>
<sect2>
<title>Before You Post</title>
<para>
Now that you have found your appropriate forum, you may think you are
ready
to post your question. Stop. You aren't ready yet. Have you already
looked for the answer yourself? There are a huge number of HOWTOs and
FAQs available, if any of them relate to the thing you are having a
problem with then <emphasis>read them first</emphasis>. Even if they
don't
contain the answer to your problem, what they will do is give you a
better understanding of the subject area, and that understanding will
allow you
to ask a more informed and sensible question. There are also archives
of newsgroups and mailing lists and it is entirely possible that your
question has been asked and answered previously. <ulink
url="http://www.google.com">http://www.google.com</ulink> or a similar
search engine should be something you try <emphasis>before</emphasis>
posting a question.
</para>
</sect2>
<sect2>
<title>Writing Your Post</title>
<para>Okay, you have found your appropriate forum, you have read the
relevant HOWTOs and FAQs, you have searched the web, but you still
have
not found the answer you need. Now you can start writing your post.
It is always a good idea to make it clear that you already have read
up
on the subject by saying something like ``I have read the
Winmodem-HOWTO and
the PPP FAQ, but neither contained what I was looking for,
searching for `Winmodem Linux PPP Setup' on google didn't return
anything
of use either''. This shows you to be someone who is willing to make
an
effort rather than a lazy idiot who requires spoonfeeding. The former
is likely to receive help if anyone knows the answer, the latter
is likely to meet with either stony silence or outright
derision.</para>
<para>Write in clear, grammatical and correctly spelt English. This
is
incredibly important. It marks you as a precise and considered
thinker.
There are no such words as ``u'' or ``b4.'' Try to make yourself look
like an educated and intelligent person rather than an idiot. It will
help. I promise.</para>
<para>Similarly do not type in all capitals LIKE THIS. That is
considered shouting and looks very rude.</para>
<para>Provide clear details stating what the problem is and what you
have
already tried to do to fix it. A question like ``My linux has stopped
working, what can I do?'' is totally useless. Where has it stopped
working? In what way has it stopped working? You need to be as
precise
as possible. There are limits however. Try not to include irrelevant
information either. If you are having problems with your mail client
it
is unlikely that a dump of your kernel boot log
(<command>dmesg</command>) would be of help.<para>
<para>Don't ask for replies by private email. The point of most Linux
forums is that everybody can learn something from each other. Asking
for private replies simply removes value from the newsgroup or mailing
list.</para>
</sect2>
<sect2>
<title>Formatting Your Post</title>
<para> Do not post in HTML. Many Linux users have mail clients which
can't easily read HTML email. Whilst with some effort, they
<emphasis>can</emphasis> read HTML email, they usually don't. If you
send them HTML
mail it often gets deleted unread. Send plain text
emails, they will reach a wider audience that way.</para>
</sect2>
<sect2>
<title>Follow Up</title>
<para>After your problem has been solved, post a short followup
explaining what the problem was and how you solved it. People will
appreciate this as it not only gives a sense of closure about the
problem but
also helps the next time someone has a similar question. When they
look at the archives of the newsgroup or mailing list, they will see
you
had the same problem, the discussion that followed your question and
your final solution.</para>
</sect2>
<sect2>
<title>More Information</title>
<para>This short guide is simply a paraphrase
and summary of the excellent (and more detailed) document ``How To
Ask
Questions The Smart Way'' by Eric S Raymond. <ulink
url="http://www.tuxedo.org/~esr/faqs/smart-questions.html">
http://www.tuxedo.org/~esr/faqs/smart-questions.html</ulink>. It is
recommend that you read it before you post anything. It will help
you formulate
your question to maximise your
chances of getting the answer you are looking for.</para>
</sect2>
</sect1>
<sect1>
<title>IRC</title>
<para>IRC (Internet Relay Chat) is not covered in the Eric Raymond
document, but IRC
can also be an excellent way of finding the answers you need.
However it
does require some practice in asking questions in the right way.
Most IRC
networks have busy #linux channels and if the answer to your question
is contained in the manpages, or in the HOWTOs then expect to be told
to
go read them. The rule about typing in clear and grammatical English
still applies.</para>
<para>Most of what has been said about newsgroups and mailing lists
is still
relevant for IRC, with a the following additions</para>
<sect2>
<title>Colours</title>
<para>Do not use colours, bold, underline or strange (non ASCII)
characters. This breaks some older terminals and is just plain ugly
to
look at. If you arrive in a channel and start spewing colour or bold
then expect to be kicked out.</para>
</sect2>
<sect2><title>Be Polite</title>
<para>Remember you are not entitled to an answer. If you ask the
question in the right way then you will probably get one, but you have
no right to get one. The people in Linux IRC channels are all there
on
their own time, nobody is paying them, especially not you.</para>
<para>Be polite. Treat others as you would like to be
treated. If you think people are not being polite to you then don't
start calling them names or getting annoyed, become even politer.
This makes
them look foolish rather than dragging you down to their level.</para>
<para>Don't go slapping anyone with large trouts. Would you believe
this
has been done before once or twice? And that we it wasn't
funny the first time?</para>
</sect2>
<sect2><title>Type Properly, in English</title>
<para>Most #linux channels are English channels. Speak English whilst
in them. Most of the larger IRC networks also have #linux channel in
other languages, for example the French language channel might be
called #linuxfr, the Spanish one might be #linuxes or #linuxlatino.
If
you can't find the right channel then asking in the main #linux
channel
(preferably in English) should help you find the one you are looking
for.</para>
<para>Do not type like a ``1337 H4X0R d00d!!!''. Even if other people
are. It looks silly and thereby makes you look silly. At best you
will only
look like an idiot, at worst you will be derided then kicked
out.</para>
</sect2>
<sect2><title>Port scanning</title>
<para>Never <emphasis>ever</emphasis> as anyone to port scan you, or
try
to ``hack'' you. This is inviolable. There is no way of knowing that
you are who you say you are, or that the IP that you are connected
from
belongs to you. Don't put people in the position where they have to
say
no to a request like this.</para>
<para><emphasis>Don't ever port scan anyone</emphasis>, even if they
ask you
to. You have no way to tell
that they are who they say they are or that the IP they are connected
from
is their own IP. In some jurisdictions port scanning may be illegal
and it
is certainly against the Terms of Service of most ISPs.
Most people log TCP connections, they will notice they are being
scanned. Most people <emphasis>will</emphasis> report you to your ISP
for this (it is trivial to find out who that is).</para>
</sect2>
<sect2><title>Keep it in the Channel</title>
<para>Don't /msg anyone unless they ask you to. It diminishes the
usefulness of the channel and some people just prefer that
you not do it.</para>
</sect2>
<sect2><title>Stay On Topic</title>
<para>Stay on topic. The channel is a ``Linux'' channel, not a ``What
Uncle Bob Got Up To Last Weekend'' channel. Even if you see other
people being off topic, this does not mean that you should be. They
are
probably channel regulars and different conventions apply to
them.</para>
</sect2>
<sect2><title>CTCPs</title>
<para>If you are thinking of mass CTCP
<footnote><para>If you are not familiar with IRC, CTCP stands
for Client To Client Protocol. It is a method whereby you can
find out things about other peoples' clients. See the
documentation for your IRC client for more
details</para></footnote>
pinging the channel or CTCP
version or CTCP anything, then think again. It is liable to get you
kicked out very quickly.</para>
</sect2>
<sect2><title>Hacking, Cracking, Phreaking, Warezing</title>
<para>Don't ask about exploits, unless you are looking for a further
way
to be unceremoniously kicked out.</para>
<para>Don't be in hacker/cracker/phreaker/warezer channels whilst in a
#linux channel. For some reason the people in charge of #linux
channels
seem to hate people who like causing destruction to people's machines
or who like to steal software. Can't imagine why.</para>
</sect2>
<sect2><title>Round Up</title>
<para>Apologies if that seems like a lot of DON'Ts, and very few DOs.
The
DOs were already pretty much covered in the section on newsgroups and
mailing lists.</para>
<para>Probably the best thing you can do is to go into a #linux
channel,
sit there and watch, getting the feel for a half hour before
you say anything. This can help you to recognise the correct tone you
should be using.</para>
</sect2>
<sect2>
<title>Further Reading</title>
<para>There are excellent FAQs about how to get the most of IRC #linux
channels. Most #linux channels have an FAQ and/or set or channel
rules.
How to find this will usually be in the channel topic (which you can
see
at any time using the <command>/topic</command> command. Make sure
you
read the rules if there are any and follow them. One fairly generic
set
of rules and advice is the ``Undernet #linux FAQ'' which can be found
at
<ulink
url="http://linuxfaq.quartz.net.nz">http://linuxfaq.quartz.net.nz
</ulink>.</para>
</sect2>
</sect1>
</chapter>
<appendix id="gfdl">
<title>GNU Free Documentation License</title>
<!-- - GNU Project - Free Software Foundation (FSF) -->
<!-- LINK REV="made" HREF="mailto:webmasters@gnu.org" -->
<!-- sect1>
<title>GNU Free Documentation License</title -->
<para>Version 1.1, March 2000</para>
<blockquote>
<para>Copyright (C) 2000 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.</para>
</blockquote>
<sect1 label="0">
<title>PREAMBLE</title>
<para>The purpose of this License is to make a manual, textbook,
or other written document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or
noncommercially. Secondarily, this License preserves for the
author and publisher a way to get credit for their work, while not
being considered responsible for modifications made by
others.</para>
<para>This License is a kind of "copyleft", which means that
derivative works of the document must themselves be free in the
same sense. It complements the GNU General Public License, which
is a copyleft license designed for free software.</para>
<para>We have designed this License in order to use it for manuals
for free software, because free software needs free documentation:
a free program should come with manuals providing the same
freedoms that the software does. But this License is not limited
to software manuals; it can be used for any textual work,
regardless of subject matter or whether it is published as a
printed book. We recommend this License principally for works
whose purpose is instruction or reference.</para>
</sect1>
<sect1 label="1">
<title>APPLICABILITY AND DEFINITIONS</title>
<para>This License applies to any manual or other work that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. The "Document",
below, refers to any such manual or work. Any member of the
public is a licensee, and is addressed as "you".</para>
<para>A "Modified Version" of the Document means any work
containing the Document or a portion of it, either copied
verbatim, or with modifications and/or translated into another
language.</para>
<para>A "Secondary Section" is a named appendix or a front-matter
section of the Document that deals exclusively with the
relationship of the publishers or authors of the Document to the
Document's overall subject (or to related matters) and contains
nothing that could fall directly within that overall subject.
(For example, if the Document is in part a textbook of
mathematics, a Secondary Section may not explain any mathematics.)
The relationship could be a matter of historical connection with
the subject or with related matters, or of legal, commercial,
philosophical, ethical or political position regarding
them.</para>
<para>The "Invariant Sections" are certain Secondary Sections
whose titles are designated, as being those of Invariant Sections,
in the notice that says that the Document is released under this
License.</para>
<para>The "Cover Texts" are certain short passages of text that
are listed, as Front-Cover Texts or Back-Cover Texts, in the
notice that says that the Document is released under this
License.</para>
<para>A "Transparent" copy of the Document means a
machine-readable copy, represented in a format whose specification
is available to the general public, whose contents can be viewed
and edited directly and straightforwardly with generic text
editors or (for images composed of pixels) generic paint programs
or (for drawings) some widely available drawing editor, and that
is suitable for input to text formatters or for automatic
translation to a variety of formats suitable for input to text
formatters. A copy made in an otherwise Transparent file format
whose markup has been designed to thwart or discourage subsequent
modification by readers is not Transparent. A copy that is not
"Transparent" is called "Opaque".</para>
<para>Examples of suitable formats for Transparent copies include
plain ASCII without markup, Texinfo input format, LaTeX input
format, SGML or XML using a publicly available DTD, and
standard-conforming simple HTML designed for human modification.
Opaque formats include PostScript, PDF, proprietary formats that
can be read and edited only by proprietary word processors, SGML
or XML for which the DTD and/or processing tools are not generally
available, and the machine-generated HTML produced by some word
processors for output purposes only.</para>
<para>The "Title Page" means, for a printed book, the title page
itself, plus such following pages as are needed to hold, legibly,
the material this License requires to appear in the title page.
For works in formats which do not have any title page as such,
"Title Page" means the text near the most prominent appearance of
the work's title, preceding the beginning of the body of the
text.</para>
</sect1>
<sect1 label="2">
<title>VERBATIM COPYING</title>
<para>You may copy and distribute the Document in any medium,
either commercially or noncommercially, provided that this
License, the copyright notices, and the license notice saying this
License applies to the Document are reproduced in all copies, and
that you add no other conditions whatsoever to those of this
License. You may not use technical measures to obstruct or
control the reading or further copying of the copies you make or
distribute. However, you may accept compensation in exchange for
copies. If you distribute a large enough number of copies you
must also follow the conditions in section 3.</para>
<para>You may also lend copies, under the same conditions stated
above, and you may publicly display copies.</para>
</sect1>
<sect1 label="3">
<title>COPYING IN QUANTITY</title>
<para>If you publish printed copies of the Document numbering more
than 100, and the Document's license notice requires Cover Texts,
you must enclose the copies in covers that carry, clearly and
legibly, all these Cover Texts: Front-Cover Texts on the front
cover, and Back-Cover Texts on the back cover. Both covers must
also clearly and legibly identify you as the publisher of these
copies. The front cover must present the full title with all
words of the title equally prominent and visible. You may add
other material on the covers in addition. Copying with changes
limited to the covers, as long as they preserve the title of the
Document and satisfy these conditions, can be treated as verbatim
copying in other respects.</para>
<para>If the required texts for either cover are too voluminous to
fit legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto
adjacent pages.</para>
<para>If you publish or distribute Opaque copies of the Document
numbering more than 100, you must either include a
machine-readable Transparent copy along with each Opaque copy, or
state in or with each Opaque copy a publicly-accessible
computer-network location containing a complete Transparent copy
of the Document, free of added material, which the general
network-using public has access to download anonymously at no
charge using public-standard network protocols. If you use the
latter option, you must take reasonably prudent steps, when you
begin distribution of Opaque copies in quantity, to ensure that
this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you
distribute an Opaque copy (directly or through your agents or
retailers) of that edition to the public.</para>
<para>It is requested, but not required, that you contact the
authors of the Document well before redistributing any large
number of copies, to give them a chance to provide you with an
updated version of the Document.</para>
</sect1>
<sect1 label="4">
<title>MODIFICATIONS</title>
<para>You may copy and distribute a Modified Version of the
Document under the conditions of sections 2 and 3 above, provided
that you release the Modified Version under precisely this
License, with the Modified Version filling the role of the
Document, thus licensing distribution and modification of the
Modified Version to whoever possesses a copy of it. In addition,
you must do these things in the Modified Version:</para>
<orderedlist numeration="upperalpha">
<listitem><para>Use in the Title Page
(and on the covers, if any) a title distinct from that of the
Document, and from those of previous versions (which should, if
there were any, be listed in the History section of the
Document). You may use the same title as a previous version if
the original publisher of that version gives permission.</para>
</listitem>
<listitem><para>List on the Title Page,
as authors, one or more persons or entities responsible for
authorship of the modifications in the Modified Version,
together with at least five of the principal authors of the
Document (all of its principal authors, if it has less than
five).</para>
</listitem>
<listitem><para>State on the Title page
the name of the publisher of the Modified Version, as the
publisher.</para>
</listitem>
<listitem><para>Preserve all the
copyright notices of the Document.</para>
</listitem>
<listitem><para>Add an appropriate
copyright notice for your modifications adjacent to the other
copyright notices.</para>
</listitem>
<listitem><para>Include, immediately
after the copyright notices, a license notice giving the public
permission to use the Modified Version under the terms of this
License, in the form shown in the Addendum below.</para>
</listitem>
<listitem><para>Preserve in that license
notice the full lists of Invariant Sections and required Cover
Texts given in the Document's license notice.</para>
</listitem>
<listitem><para>Include an unaltered
copy of this License.</para>
</listitem>
<listitem><para>Preserve the section
entitled "History", and its title, and add to it an item stating
at least the title, year, new authors, and publisher of the
Modified Version as given on the Title Page. If there is no
section entitled "History" in the Document, create one stating
the title, year, authors, and publisher of the Document as given
on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.</para>
</listitem>
<listitem><para>Preserve the network
location, if any, given in the Document for public access to a
Transparent copy of the Document, and likewise the network
locations given in the Document for previous versions it was
based on. These may be placed in the "History" section. You
may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.</para>
</listitem>
<listitem><para>In any section entitled
"Acknowledgements" or "Dedications", preserve the section's
title, and preserve in the section all the substance and tone of
each of the contributor acknowledgements and/or dedications
given therein.</para>
</listitem>
<listitem><para>Preserve all the
Invariant Sections of the Document, unaltered in their text and
in their titles. Section numbers or the equivalent are not
considered part of the section titles.</para>
</listitem>
<listitem><para>Delete any section
entitled "Endorsements". Such a section may not be included in
the Modified Version.</para>
</listitem>
<listitem><para>Do not retitle any
existing section as "Endorsements" or to conflict in title with
any Invariant Section.</para>
</listitem>
</orderedlist>
<para>If the Modified Version includes new front-matter sections
or appendices that qualify as Secondary Sections and contain no
material copied from the Document, you may at your option
designate some or all of these sections as invariant. To do this,
add their titles to the list of Invariant Sections in the Modified
Version's license notice. These titles must be distinct from any
other section titles.</para>
<para>You may add a section entitled "Endorsements", provided it
contains nothing but endorsements of your Modified Version by
various parties--for example, statements of peer review or that
the text has been approved by an organization as the authoritative
definition of a standard.</para>
<para>You may add a passage of up to five words as a Front-Cover
Text, and a passage of up to 25 words as a Back-Cover Text, to the
end of the list of Cover Texts in the Modified Version. Only one
passage of Front-Cover Text and one of Back-Cover Text may be
added by (or through arrangements made by) any one entity. If the
Document already includes a cover text for the same cover,
previously added by you or by arrangement made by the same entity
you are acting on behalf of, you may not add another; but you may
replace the old one, on explicit permission from the previous
publisher that added the old one.</para>
<para>The author(s) and publisher(s) of the Document do not by
this License give permission to use their names for publicity for
or to assert or imply endorsement of any Modified Version.</para>
</sect1>
<sect1 label="5">
<title>COMBINING DOCUMENTS</title>
<para>You may combine the Document with other documents released
under this License, under the terms defined in section 4 above for
modified versions, provided that you include in the combination
all of the Invariant Sections of all of the original documents,
unmodified, and list them all as Invariant Sections of your
combined work in its license notice.</para>
<para>The combined work need only contain one copy of this
License, and multiple identical Invariant Sections may be replaced
with a single copy. If there are multiple Invariant Sections with
the same name but different contents, make the title of each such
section unique by adding at the end of it, in parentheses, the
name of the original author or publisher of that section if known,
or else a unique number. Make the same adjustment to the section
titles in the list of Invariant Sections in the license notice of
the combined work.</para>
<para>In the combination, you must combine any sections entitled
"History" in the various original documents, forming one section
entitled "History"; likewise combine any sections entitled
"Acknowledgements", and any sections entitled "Dedications". You
must delete all sections entitled "Endorsements."</para>
</sect1>
<sect1 label="6">
<title>COLLECTIONS OF DOCUMENTS</title>
<para>You may make a collection consisting of the Document and
other documents released under this License, and replace the
individual copies of this License in the various documents with a
single copy that is included in the collection, provided that you
follow the rules of this License for verbatim copying of each of
the documents in all other respects.</para>
<para>You may extract a single document from such a collection,
and distribute it individually under this License, provided you
insert a copy of this License into the extracted document, and
follow this License in all other respects regarding verbatim
copying of that document.</para>
</sect1>
<sect1 label="7">
<title>AGGREGATION WITH INDEPENDENT WORKS</title>
<para>A compilation of the Document or its derivatives with other
separate and independent documents or works, in or on a volume of
a storage or distribution medium, does not as a whole count as a
Modified Version of the Document, provided no compilation
copyright is claimed for the compilation. Such a compilation is
called an "aggregate", and this License does not apply to the
other self-contained works thus compiled with the Document, on
account of their being thus compiled, if they are not themselves
derivative works of the Document.</para>
<para>If the Cover Text requirement of section 3 is applicable to
these copies of the Document, then if the Document is less than
one quarter of the entire aggregate, the Document's Cover Texts
may be placed on covers that surround only the Document within the
aggregate. Otherwise they must appear on covers around the whole
aggregate.</para>
</sect1>
<sect1 label="8">
<title>TRANSLATION</title>
<para>Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section
4. Replacing Invariant Sections with translations requires
special permission from their copyright holders, but you may
include translations of some or all Invariant Sections in addition
to the original versions of these Invariant Sections. You may
include a translation of this License provided that you also
include the original English version of this License. In case of
a disagreement between the translation and the original English
version of this License, the original English version will
prevail.</para>
</sect1>
<sect1 label="9">
<title>TERMINATION</title>
<para>You may not copy, modify, sublicense, or distribute the
Document except as expressly provided for under this License. Any
other attempt to copy, modify, sublicense or distribute the
Document is void, and will automatically terminate your rights
under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses
terminated so long as such parties remain in full
compliance.</para>
</sect1>
<sect1 label="10">
<title>FUTURE REVISIONS OF THIS LICENSE</title>
<para>The Free Software Foundation may publish new, revised
versions of the GNU Free Documentation License from time to time.
Such new versions will be similar in spirit to the present
version, but may differ in detail to address new problems or
concerns. See <ulink
url="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</ulink>.</para>
<para>Each version of the License is given a distinguishing
version number. If the Document specifies that a particular
numbered version of this License "or any later version" applies to
it, you have the option of following the terms and conditions
either of that specified version or of any later version that has
been published (not as a draft) by the Free Software Foundation.
If the Document does not specify a version number of this License,
you may choose any version ever published (not as a draft) by the
Free Software Foundation.</para>
</sect1>
<sect1 label="">
<title>How to use this License for your documents</title>
<para>To use this License in a document you have written, include
a copy of the License in the document and put the following
copyright and license notices just after the title page:</para>
<blockquote><para>
Copyright (c) YEAR YOUR NAME.
Permission is granted to copy, distribute and/or modify this
document
under the terms of the GNU Free Documentation License, Version
1.1
or any later version published by the Free Software Foundation;
with the Invariant Sections being LIST THEIR TITLES, with the
Front-Cover Texts being LIST, and with the Back-Cover Texts
being LIST.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
</para></blockquote>
<para>If you have no Invariant Sections, write "with no Invariant
Sections" instead of saying which ones are invariant. If you have
no Front-Cover Texts, write "no Front-Cover Texts" instead of
"Front-Cover Texts being LIST"; likewise for Back-Cover
Texts.</para>
<para>If your document contains nontrivial examples of program
code, we recommend releasing these examples in parallel under your
choice of free software license, such as the GNU General Public
License, to permit their use in free software.</para>
</sect1>
</appendix>
<glossary>
<title>Glossary (DRAFT, but not for long hopefully)</title>
<blockquote><para><quote>The Librarian of the Unseen University
had unilaterally decided to aid comprehension
by producing an Orang-utan/Human Dictionary.
He'd been working on it for three months.
It wasn't easy. He'd got as far as `Oook.'</quote>
(Terry Pratchett, ``Men At Arms'')</para></blockquote>
<para> This is a short list of word definitions for concepts
relating to Linux and system administration. </para>
<glossentry>
<glossterm>CMOS RAM</glossterm>
<glossdef><para>
CMOS stands for "Complementary Metal Oxide Semiconductor".
It is a complex technology, but put very simply it is a type
of transistor which maintains its state even if there is no
power flowing, so it provides a sort of static RAM. ie RAM
which does not lose what it was storing when the power is
switched off.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>account</glossterm>
<glossdef><para>
A Unix system gives users <glossterm>accounts</glossterm>. It
gives them a username and a password with which to log on to the
account. A home directory in which to store files is usually
provided, and permissions to access hardware and software. These
things taken as a whole are an <glossterm>account</glossterm>.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>application program</glossterm>
<glossdef><para>
Software that does something useful. The results of using an
application program is what the computer was bought for.
See also system program, operating system.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>bad block</glossterm>
<glossdef><para>
A block (usually one sector on a disk) that cannot reliably hold
data.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>bad sector</glossterm>
<glossdef><para>
Similar to <glossterm>bad block</glossterm> but more precise in
the case where a block and a sector may be of differing sizes.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>boot sector</glossterm>
<glossdef><para>
Usually the first sector on any given partition. It contains
a very short program (on the order of a few hundred bytes) which
will load and start running the operating system proper.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>booting</glossterm>
<glossdef><para>
Everything that happens between the time the computer is
switched on and it is ready to accept commands/input from
the user is known as <glossterm>booting</glossterm>.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>bootstrap loader</glossterm>
<glossdef><para>
A very small program (usually residing in ROM) which reads
a fixed location on a disk (eg. the <glossterm>MBR</glossterm>)
and passes control over to it. The data residing on that fixed
location is, in general, slightly bigger and more sophisticated,
and it then takes responsibility for loading the actual operating
system and passing control to it.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>cylinder</glossterm>
<glossdef><para>
The set of <glossterm>tracks</glossterm> on a multi-headed disk
that may be accessed without head movement. In other words the
tracks which are the same distance from the spindle about which
the disk <glossterm>platters</glossterm> rotate. Placing data
that is more likely to be accessed at the same time on the same
cylinder can reduce the access time significantly as moving the
read-write heads is slow compared to the speed with which the
disks rotate.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>daemon</glossterm>
<glossdef><para>
A process lurking in the background, usually unnoticed, until
something triggers it into action. For example, the
<command>update</command>
daemon wakes up every thirty seconds or so to flush the buffer
cache, and the <command>sendmail</command> daemon awakes whenever
someone sends
mail.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>daylight savings time</glossterm>
<glossdef><para>
A time of the year during which clocks are set forward one hour.
Widely used around the world in summer so that evenings have more
daylight than they would otherwise.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>disk controller</glossterm>
<glossdef><para>
A hardware circuit which translates instructions about disk access
from the operating system to the physical disk. This provides a
layer of abstraction that means that an operating system does not
need to know how to talk to the many different types of disks, but
only needs to know about the (comparatively low) number of types of
disk controller. Common disk controller types are IDE and SCSI.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>file system</glossterm>
<glossdef><para>
The methods and data structures that an operating
system uses to keep track of files on a disk or partition;
the way the files are organised on the disk. Also used about
a partition or disk that is used to store the files
or the type of the filesystem.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>emergency boot floppy</glossterm>
<glossdef><para>
A floppy disk which can be used to boot the system even
if the hard disk has suffered damage on its filesystem.
Most linux distributions offer to make one of these during
installation, this is highly recommended. If your Linux
distribution does not offer this facility then read the
Boot floppy HOWTO, available at the LDP (**Find URL to cite**).
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>filesystem</glossterm>
<glossdef><para>
A term which is used for two purposes and which can have two
subtly different meanings. It is either the collection of
files and directories on a drive (whether hard drive, floppy,
Cd-ROM, etc). Or it is the markers put onto the disk media
which the OS uses to decide where to write files to (inodes,
blocks, superblocks etc). The actual meaning can almost
always be inferred from context.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>formatting</glossterm>
<glossdef><para>
Strictly, formatting is organising and marking the surface of
a disk into <glossterm>tracks</glossterm>, <glossterm>sectors
</glossterm>, and <glossterm>cylinders</glossterm>. It is also
sometimes (incorrectly) a term used to signify the action of
writing a <glossterm>filesystem</glossterm> to a disk (especially
in the MS Windows/MS DOS world).
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>fragmented</glossterm>
<glossdef><para>
When a file is not written to a disk in contiguous <glossterm>
blocks</glossterm>. If there is not enough free space to write
a full file to a disk in one continuous stream of <glossterm>
blocks</glossterm> then the file gets split up between two or
more parts of the disk surface. This is known as <glossterm>
fragmenting</glossterm> and can make the time for loading a
file longer as the disk has to seek for the rest of the file.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>full backup</glossterm>
<glossdef><para>
Taking a copy of the whole filesystem to a backup media
(eg tape, floppy, or CD).
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>geometry</glossterm>
<glossdef><para>
How many cylinders, sectors per cylinder and heads a disk
drive has.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>high level formatting</glossterm>
<glossdef><para>
An incorrect term for writing a filesystem to a disk. Often
used in the MS Windows and MS DOS world.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>incremental backups</glossterm>
<glossdef><para>
A backup of what has changed in a filesystem since the last
<glossterm>full backup</glossterm>. <glossterm>Incremental
backups</glossterm> if used sensibly as part of a backup regime,
can save a lot of time and effort in maintaining a backup of data.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>inode</glossterm>
<glossdef><para>
A data structure holding information about files in a Unix
file system. There is an inode for each file and a file is
uniquely identified by the file system on which it resides
and its inode number on that system. Each inode contains
the following information: the device where the inode resides,
locking information, mode and type of file, the number of links
to the file, the owner's user and group ids, the number of bytes
in the file, access and modification times, the time the inode
itself was last modified and the addresses of the file's
blocks on disk. A Unix directory is an association between
file leafnames and inode numbers. A file's inode number
can be found using the "-i" switch to ls.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>kernel</glossterm>
<glossdef><para>
Part of an operating system that implements the interaction with
hardware and the sharing of resources. See also system program.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>local time</glossterm>
<glossdef><para>
The official time in a local region (adjusted for location around
the Earth); established by law or custom.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>logical partition</glossterm>
<glossdef><para>
A partition inside an <glossterm>extended partition</glossterm>,
which is ``logical'' in that it does not exist in reality,
but only inside the logical structure of the software.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>low level formatting</glossterm>
<glossdef><para>
Synonymous with <glossterm>formatting</glossterm> and used in
the MS DOS world so differentiate from creating a filesystem
which is also known as formatting sometimes.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>mail transfer agent</glossterm>
<glossdef><para>
(MTA) The program responsible for delivering e-mail messages.
Upon receiving a message from a <glossterm>mail user agent
</glossterm> or another MTA it stores it temporarily locally
and analyses the recipients and either delivers it (local
addressee) or forwards it to another MTA. In either case
it may edit and/or add to the message headers. A widely used
MTA for Unix is sendmail.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>mail user agent</glossterm>
<glossdef><para>
(MUA) The program that allows the user to compose and read
electronic mail messages. The MUA provides the interface
between the user and the <glossterm>mail transfer agent
</glossterm>. Outgoing mail is eventually handed over to an
MTA for delivery while the incoming messages are picked up
from where the MTA left it (although MUAs running on
single-user machines may pick up mail using POP).
Examples of MUAs are pine, elm and mutt.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>master boot record</glossterm>
<glossdef><para>
(MBR) The first logical sector on a disk, this is (usually)
where the BIOS looks to load a small program that will boot
the computer.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>network file system</glossterm>
<glossdef><para>
(NFS) A protocol developed by Sun Microsystems, and defined in
RFC 1094 (FIND URL), which allows a computer to access files
over a network as if they were on its local disks.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>operating system</glossterm>
<glossdef><para>
Software that shares a computer system's resources (processor,
memory, disk space, network bandwidth, and so on) between
users and the application programs they run. Controls access
to the system to provide security. See also kernel, system program,
application program.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>partition</glossterm>
<glossdef><para>
A logical section of a disk. Each partition normally has its
own file system. Unix tends to treat partitions as though
they were separate physical entities.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>password file</glossterm>
<glossdef><para>
A file that holds usernames and information about their accounts
like their password. On Unix systems this file is usually
<filename>/etc/passwd</filename>. On most modern Linux systems
the <filename>/etc/passwd</filename> file does not actually hold
password data. That tends to be held in a different file <filename>
/etc/shadow</filename> for security reasons. See manual pages
passwd(5) and shadow(5) for more information.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>platters</glossterm>
<glossdef><para>
A physical disk inside a hard drive. Usually a hard drive is
made up of multiple physical disks stacked up on top of each
other. One individual disk is known as a <glossterm>platter
</glossterm>.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>power on self test</glossterm>
<glossdef><para>
(POST) A series of diagnostic tests which are run when a computer
is powered on. Typically this might include testing the memory,
testing that the hardware configuration is the same as the last
saved configuration, checking that any floppy drives, or hard
drives which are known about by the BIOS are installed and working.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>print queue</glossterm>
<glossdef><para>
A file (or set of files) which the print <glossterm>daemon
<glossterm> uses so that applications which wish to use the
printer do not have to wait until the print job they have sent
is finished before they can continue. It also allows multiple
users to share a printer.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>read-write head</glossterm>
<glossdef><para>
A tiny electromagnetic coil and metal pole used to write and read
magnetic patterns on a disk. These coils move laterally against
the rotary motion on the <glossterm>platters</glossterm>.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>root filesystem<glossterm>
<glossdef><para>
The parent of all the other filesystems mounted in a Unix filesystem
tree. Mounted as / it might have other filesystems mounted on it
(/usr for example). If the root filesystem cannot be mounted then
the
<glossterm>kernel</glossterm> will panic and the system will not be
able to continue <glossterm>booting</glossterm>
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>run level</glossterm>
<glossdef><para>
Linux has up to 10 runlevels (0-9) available (of which usually only
the first 7 are defined). Each runlevel may start a different set
of services, giving multiple different configurations in the same
system. Runlevel 0 is defined as ``system halt'', runlevel 1 is
defined as ``<glossterm>single user mode</glossterm>'', and runlevel
6 is defined as ``reboot system''. The remaining runlevels can,
theoretically, be defined by the system administrator in any way.
However most distributions provide some other predefined runlevels.
For example, runlevel 2 might be defined as ``multi-user console'',
and runlevel 5 as ``multi-user X-Window system''. These definitions
vary considerably from distribution to distribution, so please check
the documentation for your own distribution.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>sectors</glossterm>
<glossdef><para>
The minimum <glossterm>track</glossterm> length that can be
allocated
to store data. This is usually (but not always) 512 bytes.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>shadow passwords</glossterm>
<glossdef><para>
Because the <glossterm>password file</glossterm> on Unix systems
often
needs to be world readable it usually does not actually contain the
encrypted passwords for users' accounts. Instead a shadow file is
employed (which is not world readable) which holds the encrypted
passwords for users' accounts.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>single user mode</glossterm>
<glossdef><para>
Usually runlevel 1. A runlevel where logins are not allowed except
by the root account. Used either for system repairs (if the
filesystem is partially damaged it may still be possible to boot into
runlevel 1 and repair it), or for moving filesystems around between
partitions. These are just two examples. Any task that requires a
system where only one person can write to a disk at a time is a
candidate for requiring runlevel 1.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>spool</glossterm>
<glossdef><para>
To send a file (or other data) to a queue. Generally used in
conjunction with printers, but might also be used for other
things (mail for example). The term is reported to be an acronym
for ``Simultaneous Peripheral Operation On-Line'', but according
to the <ulink url="http://www.tuxedo.org/~esr/jargon">Jargon File
</ulink> it may have been a backronym (something made up later
for effect).
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>system call</glossterm>
<glossdef><para>
The services provided by the kernel to application programs,
and the way in which they are invoked. See section 2 of the
manual pages.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>swap space</glossterm>
<glossdef><para>
Space on a disk in which the system can write portions of memory
to. Usually this is a dedicated partition, but it may also be
a swapfile.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>system program</glossterm>
<glossdef><para>
Programs that implement high level functionality of an operating
system, i.e., things that aren't directly dependent on the
hardware. May sometimes require special privileges to run
(e.g., for delivering electronic mail), but often just commonly
thought of as part of the system (e.g., a compiler). See also
application program, kernel, operating system.
</para></glossdef>
</glossentry>
<glossentry>
<glossterm>track</glossterm>
<glossdef><para>
The part of a disk <glossterm>platter</glossterm> which passes
under one <glossterm>read-write head</glossterm> while the head
is stationary but the disk is spinning. Each track is divided
into <glossterm>sectors</glossterm>, and a vertical collection of
tracks is a <glossterm>cylinder</glossterm>
</para></glossdef>
</glossentry>
</glossary>
</book>
|