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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 99.2beta8 (1.46)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>19. Partitions, File Systems, Formatting, Mounting</TITLE>
<META NAME="description" CONTENT="19. Partitions, File Systems, Formatting, Mounting">
<META NAME="keywords" CONTENT="rute">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.2beta8">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="rute.css">
<LINK REL="next" HREF="node23.html">
<LINK REL="previous" HREF="node21.html">
<LINK REL="up" HREF="rute.html">
<LINK REL="next" HREF="node23.html">
</HEAD>
<BODY BGCOLOR=#FFFFFF >
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<TR><TD align=left bgcolor="#000000">
<FONT COLOR=white>
<A HREF="http://www.icon.co.za/~psheer/rute-purchase.html"><FONT COLOR=white>Purchase</FONT></A>
</FONT>
</TD><TD align=center bgcolor="#000000">
<FONT COLOR=white>
Copyright © 2002 Paul Sheer. <A HREF="copying.html"><FONT COLOR=white>Click here for copying permissions.</FONT></A>
</FONT>
</TD><TD align=right bgcolor="#000000">
<FONT COLOR=white>
<A HREF="http://www.icon.co.za/~psheer/rute-home.html"><FONT COLOR=white>Home</FONT></A>
</FONT>
</TD></TR>
<TR><TD colspan=2 align=left bgcolor="#ECEBF4">
<IMG SRC="va-btn-small-light-60.png">
</TD><TD align=right bgcolor="#ECEBF4">
<IMG SRC="sflogo2-steel-60.png">
</TD></TR>
</TABLE><BR>
<!--Navigation Panel-->
<A NAME="tex2html2087"
HREF="node23.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2083"
HREF="rute.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2077"
HREF="node21.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2085"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2088"
HREF="node23.html">20. Advanced Shell Scripting</A>
<B> Up:</B> <A NAME="tex2html2084"
HREF="rute.html">rute</A>
<B> Previous:</B> <A NAME="tex2html2078"
HREF="node21.html">18. UNIX Devices</A>
  <B> <A NAME="tex2html2086"
HREF="node1.html">Contents</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html2089"
HREF="#SECTION002210000000000000000">19.1 The Physical Disk Structure</A>
<UL>
<LI><A NAME="tex2html2090"
HREF="#SECTION002211000000000000000">19.1.1 Cylinders, heads, and sectors</A>
<LI><A NAME="tex2html2091"
HREF="#SECTION002212000000000000000">19.1.2 Large Block Addressing</A>
<LI><A NAME="tex2html2092"
HREF="#SECTION002213000000000000000">19.1.3 Extended partitions</A>
</UL>
<LI><A NAME="tex2html2093"
HREF="#SECTION002220000000000000000">19.2 Partitioning a New Disk</A>
<LI><A NAME="tex2html2094"
HREF="#SECTION002230000000000000000">19.3 Formatting Devices</A>
<UL>
<LI><A NAME="tex2html2095"
HREF="#SECTION002231000000000000000">19.3.1 File systems</A>
<LI><A NAME="tex2html2096"
HREF="#SECTION002232000000000000000">19.3.2 <TT>
<FONT COLOR="#0000ff">mke2fs</FONT></TT></A>
<LI><A NAME="tex2html2097"
HREF="#SECTION002233000000000000000">19.3.3 Formatting floppies and removable drives</A>
<LI><A NAME="tex2html2098"
HREF="#SECTION002234000000000000000">19.3.4 Creating MS-DOS floppies</A>
<LI><A NAME="tex2html2099"
HREF="#SECTION002235000000000000000">19.3.5 <TT>
<FONT COLOR="#0000ff">mkswap</FONT></TT>, <TT>
<FONT COLOR="#0000ff">swapon</FONT></TT>, and <TT>
<FONT COLOR="#0000ff">swapoff</FONT></TT></A>
</UL>
<LI><A NAME="tex2html2100"
HREF="#SECTION002240000000000000000">19.4 Device Mounting</A>
<UL>
<LI><A NAME="tex2html2101"
HREF="#SECTION002241000000000000000">19.4.1 Mounting CD-ROMs</A>
<LI><A NAME="tex2html2102"
HREF="#SECTION002242000000000000000">19.4.2 Mounting floppy disks</A>
<LI><A NAME="tex2html2103"
HREF="#SECTION002243000000000000000">19.4.3 Mounting Windows and NT partitions</A>
</UL>
<LI><A NAME="tex2html2104"
HREF="#SECTION002250000000000000000">19.5 File System Repair: <TT>
<FONT COLOR="#0000ff">fsck</FONT></TT></A>
<LI><A NAME="tex2html2105"
HREF="#SECTION002260000000000000000">19.6 File System Errors on Boot</A>
<LI><A NAME="tex2html2106"
HREF="#SECTION002270000000000000000">19.7 Automatic Mounts: <TT>
<FONT COLOR="#0000ff">fstab</FONT></TT></A>
<LI><A NAME="tex2html2107"
HREF="#SECTION002280000000000000000">19.8 Manually Mounting <TT>
<FONT COLOR="#0000ff">/proc</FONT></TT></A>
<LI><A NAME="tex2html2108"
HREF="#SECTION002290000000000000000">19.9 RAM and Loopback Devices</A>
<UL>
<LI><A NAME="tex2html2109"
HREF="#SECTION002291000000000000000">19.9.1 Formatting a floppy inside a file</A>
<LI><A NAME="tex2html2110"
HREF="#SECTION002292000000000000000">19.9.2 CD-ROM files</A>
</UL>
<LI><A NAME="tex2html2111"
HREF="#SECTION0022100000000000000000">19.10 Remounting</A>
<LI><A NAME="tex2html2112"
HREF="#SECTION0022110000000000000000">19.11 Disk <TT>
<FONT COLOR="#0000ff">sync</FONT></TT></A>
</UL>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION002200000000000000000">
19. Partitions, File Systems, Formatting, Mounting</A>
</H1>
<P>
<A NAME="chap:partfilesys"></A>
<P>
<H1><A NAME="SECTION002210000000000000000">
19.1 The Physical Disk Structure</A>
</H1>
<P>
Physical disks are divided into partitions. <FONT COLOR="#ffa500">[See <B><TT>
<FONT COLOR="#0000ff">/dev/hd??</FONT></TT></B>
under Section <A HREF="node21.html#sec:miscdevices">18.4</A>.]</FONT> Information as to how the
disk is partitioned up is stored in a <I>partition table</I>,
which is a small area of the disk separate from the partitions
themselves.
<P>
<H2><A NAME="SECTION002211000000000000000">
19.1.1 Cylinders, heads, and sectors</A>
</H2>
<P>
The physical drive itself usually comprises several actual
disks of which both sides are used. The sides
are labelled 0, 1, 2, 3, and so on, and are also called <I>heads</I> because
one magnetic head per side does the actual reading and writing.
Each side/head has tracks, and each track is divided into
segments called <I>sectors</I>. Each sector typically holds 512
bytes. The total amount of space on the drive in bytes is therefore:
<BLOCKQUOTE>
512 <FONT face=helvetica>x</FONT> (sectors-per-track) <FONT face=helvetica>x</FONT> (tracks-per-side) <FONT face=helvetica>x</FONT> (number-of-sides)
</BLOCKQUOTE>
<P>
A single track and all the tracks of the same diameter (on all the
sides) are called a <I>cylinder</I>. Disks are normally talked
about in terms of ``cylinders and sectors'' instead of ``sides,
tracks, and sectors.'' Partitions are (usually) divided along
cylinder boundaries. Hence, disks do not have arbitrarily sized
partitions; rather, the size of the partition is usually a multiple
of the amount of data held in a single cylinder. Partitions
therefore have a definite inner and outer diameter. Figure
<A HREF="node22.html#fig:hdplatters">19.1</A> illustrates the layout of a hard disk.
<P>
<P></P>
<DIV ALIGN="CENTER"><A NAME="fig:hdplatters"></A><A NAME="26126"></A>
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 19.1:</STRONG>
Hard drive platters and sector layout</CAPTION>
<TR><TD><IMG
WIDTH="411" HEIGHT="282" BORDER="0"
SRC="img23.png"
ALT="\begin{figure}\begin{center}
\setlength{\unitlength}{0.00083333in}\begin{picture...
...8,3462){\makebox(0,0)[l]{\small Cylinder}}
\end{picture}\end{center}\end{figure}"></TD></TR>
</TABLE>
</DIV><P></P>
<P>
<H2><A NAME="SECTION002212000000000000000">
19.1.2 Large Block Addressing</A>
</H2>
<P>
The system above is quite straightforward except for the
curious limitation that partition tables have only 10 bits in which to
store the partition's cylinder offset. This means that no disk can have
more than 1024 cylinders. This limitation was overcome by multiplying up
the number of heads in software to reduce the number of
cylinders, <FONT COLOR="#ffa500">[Called <I>LBA</I> (Large Block Addressing) mode.]</FONT>hence portraying a disk of impossible proportions.
The user, however, need never be concerned that the physical disk
is completely otherwise.
<P>
<H2><A NAME="SECTION002213000000000000000">
19.1.3 Extended partitions</A>
</H2>
<P>
The partition table has room for only four partitions. For
more partitions, one of these four partitions can be divided
into many smaller partitions, called <I>logical</I> partitions.
The original four are then called <I>primary</I> partitions. If
a primary partition is subdivided in this way, it is known
as an <I>extended</I> <I>primary</I> or <I>extended</I>
partition. Typically, the first primary partition will be small
(<TT>
<FONT COLOR="#0000ff">/dev/hda1</FONT></TT>, say). The second primary partition will
fill the rest of the disk as an extended partition
(<TT>
<FONT COLOR="#0000ff">/dev/hda2</FONT></TT>, say). In this case, the entries in the partition table
of <TT>
<FONT COLOR="#0000ff">/dev/hda3</FONT></TT> and <TT>
<FONT COLOR="#0000ff">/dev/hda4</FONT></TT> will be blank.
The extended partition can be subdivided repeatedly to
give <TT>
<FONT COLOR="#0000ff">/dev/hda5</FONT></TT>, <TT>
<FONT COLOR="#0000ff">/dev/hda6</FONT></TT>, and so on.
<P>
<H1><A NAME="SECTION002220000000000000000">
19.2 Partitioning a New Disk</A>
</H1>
<P>
A new disk has no partition information. Typing <TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT>
will start an interactive partitioning utility. The command
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>fdisk /dev/hda</code><br>
</FONT></TD></TR></TABLE><P>
<TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT>s your primary master.
<P>
What follows is an example of the partitioning of a new hard
drive. Most distributions these days have a simpler graphical
system for creating partitions, so using <TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT> will
not be necessary at installation time. However, adding a new
drive or transferring/copying a L<SMALL>INUX</SMALL> system to new hardware
will require partitioning.
<P>
On U<SMALL>NIX</SMALL>, each partition has its own <I>directory</I>. <I>Files under
one directory might be stored on a different disk or a different
partition to files in another directory</I>. Typically, the
<TT>
<FONT COLOR="#0000ff">/var</FONT></TT> directory (and all subdirectories beneath it)
is stored on a different partition from the <TT>
<FONT COLOR="#0000ff">/usr</FONT></TT>
directory (and all subdirectories beneath it).
<P>
Table <A HREF="node22.html#table:partitions">19.2</A> offers a general guideline as to how
a server machine should be set up (with home computers, you can
be far more liberal--most home PCs can do with merely a swap and
<TT>
<FONT COLOR="#0000ff">/</FONT></TT> partition.). When you install a new server, your
distribution should allow you to customize your partitions to
match this table.
<P>
<A NAME="sec:partnewdisk"></A>
<BR><P></P>
<DIV ALIGN="CENTER"><A NAME="table:partitions"></A><A NAME="26183"></A>
<TABLE>
<CAPTION><STRONG>Table 19.1:</STRONG>
Which directories should have their own partitions, and their partitions' sizes</CAPTION>
<TR><TD><IMG
WIDTH="556" HEIGHT="569" BORDER="0"
SRC="img24.png"
ALT="\begin{table}
% latex2html id marker 26182
{}{\scriptsize\begin{tabularx}{\textw...
...irst 500 megabytes
of your hard drive).
\\
\hline
\end{tabularx}}
\end{table}"></TD></TR>
</TABLE>
</DIV><P></P>
<BR>
<P>
If another operating system is already installed in the
first partition, you can type
<TT>
<FONT COLOR="#0000ff">p</FONT></TT> and might see:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>p</B></font></code><br>
<code> </code><br>
<code>Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders</code><br>
<code>Units = cylinders of 16065 * 512 bytes</code><br>
<code> </code><br>
<code> Device Boot Start End Blocks Id System</code><br>
<code>/dev/hda1 1 312 2506108+ c Win95 FAT32 (LBA)</code><br>
</FONT></TD></TR></TABLE><P>
In such a case, you can just start adding further partitions.
<P>
The exact same procedure applies in the case of SCSI drives. The
only difference is that <TT>
<FONT COLOR="#0000ff">/dev/hd</FONT></TT><I>?</I> changes to
<TT>
<FONT COLOR="#0000ff">/dev/sd</FONT></TT><I>?</I>. (See Chapter <A HREF="node45.html#chap:modules">42</A> for SCSI
device driver information.)
<P>
Here is a partitioning session with <TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT>:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>[root@cericon /root]# <font color="navy"><B>fdisk /dev/hda</B></font></code><br>
<code>Device contains neither a valid DOS partition table, nor Sun or SGI disklabel</code><br>
<code>Building a new DOS disklabel. Changes will remain in memory only,</code><br>
<code>until you decide to write them. After that, of course, the previous</code><br>
<code>content won't be recoverable.</code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
First, we use the <TT>
<FONT COLOR="#0000ff">p</FONT></TT> option to print current partitions--
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>p</B></font></code><br>
<code> </code><br>
<code>Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders</code><br>
<code>Units = cylinders of 16065 * 512 bytes</code><br>
<code> </code><br>
<code> Device Boot Start End Blocks Id System</code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
--of which there are clearly none. Now <TT>
<FONT COLOR="#0000ff">n</FONT></TT> lets us add a new partition:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> e extended</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>p</B></font></code><br>
</FONT></TD></TR></TABLE><P>
<P>
We want to define the first physical partition starting at the first cylinder:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Partition number (1-4): <font color="navy"><B>1</B></font></code><br>
<code>First cylinder (1-788, default 1): <font color="navy"><B>1</B></font></code><br>
</FONT></TD></TR></TABLE><P>
<P>
We would like an 80-megabyte partition. <TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT> calculates the
last cylinder automatically with:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Last cylinder or +size or +sizeM or +sizeK (1-788, default 788): <font color="navy"><B>+80M</B></font></code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
Our next <TT>
<FONT COLOR="#0000ff">n</FONT></TT>ew partition will span the rest of the disk
and will be an <TT>
<FONT COLOR="#0000ff">e</FONT></TT>xtended partition:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> e extended</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>e</B></font></code><br>
<code>Partition number (1-4): <font color="navy"><B>2</B></font></code><br>
<code>First cylinder (12-788, default 12): <font color="navy"><B>12</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (12-788, default 788): <font color="navy"><B>788</B></font></code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
Our remaining <TT>
<FONT COLOR="#0000ff">l</FONT></TT>ogical partitions fit within
the extended partition:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>10</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>15</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>20</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>25</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>30</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>35</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>40</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> l logical (5 or over)</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>l</B></font></code><br>
<code>First cylinder (12-788, default 12): <font color="navy"><B>12</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (12-788, default 788): <font color="navy"><B>+64M</B></font></code><br>
<code> </code><br>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> l logical (5 or over)</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>l</B></font></code><br>
<code>First cylinder (21-788, default 21): <font color="navy"><B>21</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (21-788, default 788): <font color="navy"><B>+100M</B></font></code><br>
<code> </code><br>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> l logical (5 or over)</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>l</B></font></code><br>
<code>First cylinder (34-788, default 34): <font color="navy"><B>34</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (34-788, default 788): <font color="navy"><B>+200M</B></font></code><br>
<code> </code><br>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> l logical (5 or over)</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>l</B></font></code><br>
<code>First cylinder (60-788, default 60): <font color="navy"><B>60</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (60-788, default 788): <font color="navy"><B>+1500M</B></font></code><br>
<code> </code><br>
<code>Command (m for help): <font color="navy"><B>n</B></font></code><br>
<code>Command action</code><br>
<code> l logical (5 or over)</code><br>
<code> p primary partition (1-4)</code><br>
<code><font color="navy"><B>l</B></font></code><br>
<code>First cylinder (252-788, default 252): <font color="navy"><B>252</B></font></code><br>
<code>Last cylinder or +size or +sizeM or +sizeK (252-788, default 788): <font color="navy"><B>788</B></font></code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
The default <I>partition type</I> is a single byte that
the operating system will look at to determine what kind of file
system is stored there. Entering <TT>
<FONT COLOR="#0000ff">l</FONT></TT> lists all known types:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>10</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>l</B></font></code><br>
<code> </code><br>
<code> 0 Empty 16 Hidden FAT16 61 SpeedStor a6 OpenBSD </code><br>
<code> [...]</code><br>
<code> 8 AIX 4d QNX4.x 82 Linux swap db CP/M / CTOS / .</code><br>
<code> 9 AIX bootable 4e QNX4.x 2nd part 83 Linux e1 DOS access </code><br>
<code> [...]</code><br>
<code>12 Compaq diagnost 56 Golden Bow a5 BSD/386 ff BBT </code><br>
<code>14 Hidden FAT16 <3 5c Priam Edisk </code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
<TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT> will set the type to <TT>
<FONT COLOR="#0000ff">Linux</FONT></TT> by default.
We only need to explicitly set the type of the swap partition:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>t</B></font></code><br>
<code>Partition number (1-9): <font color="navy"><B>5</B></font></code><br>
<code>Hex code (type L to list codes): <font color="navy"><B>82</B></font></code><br>
<code>Changed system type of partition 5 to 82 (Linux swap)</code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
Now we need to set the boot<TT>
<FONT COLOR="#0000ff">a</FONT></TT>ble flag on the first partition,
since BIOS's will not boot a disk without at least one bootable partition:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>a</B></font></code><br>
<code>Partition number (1-10): <font color="navy"><B>1</B></font></code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
Displaying our results gives:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>10</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>p</B></font></code><br>
<code> </code><br>
<code>Disk /dev/hda: 255 heads, 63 sectors, 788 cylinders</code><br>
<code>Units = cylinders of 16065 * 512 bytes</code><br>
<code> </code><br>
<code> Device Boot Start End Blocks Id System</code><br>
<code>/dev/hda1 * 1 11 88326 83 Linux</code><br>
<code>/dev/hda2 12 788 6241252+ 5 Extended</code><br>
<code>/dev/hda5 12 20 72261 82 Linux swap</code><br>
<code>/dev/hda6 21 33 104391 83 Linux</code><br>
<code>/dev/hda7 34 59 208813+ 83 Linux</code><br>
<code>/dev/hda8 60 251 1542208+ 83 Linux</code><br>
<code>/dev/hda9 252 788 4313421 83 Linux</code><br>
<code> </code><br>
</FONT></TD></TR></TABLE><P>
<P>
At this point, nothing has been committed to disk.
We <TT>
<FONT COLOR="#0000ff">w</FONT></TT>rite it as follows (<B>Note:</B> this step is irreversible):
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Command (m for help): <font color="navy"><B>w</B></font></code><br>
<code>The partition table has been altered!</code><br>
<code> </code><br>
<code>Calling ioctl() to re-read partition table.</code><br>
<code>Syncing disks.</code><br>
<code> </code><br>
<code>WARNING: If you have created or modified any DOS 6.x</code><br>
<code>partitions, please see the fdisk manual page for additional</code><br>
<code>information.</code><br>
</FONT></TD></TR></TABLE><P>
<P>
Even having <TT>
<FONT COLOR="#0000ff">w</FONT></TT>ritten the partition, <TT>
<FONT COLOR="#0000ff">fdisk</FONT></TT> may give a warning
that the kernel does not know about the new partitions. This happens if
the disk is already in use. In this case, you will need to reboot. For
the above partition, the kernel will give the following information at
boot time:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>Partition check:</code><br>
<code> hda: hda1 hda2 < hda5 hda6 hda7 hda8 hda9 ></code><br>
</FONT></TD></TR></TABLE><P>
The <TT>
<FONT COLOR="#0000ff"><</FONT></TT> ...<TT>
<FONT COLOR="#0000ff">></FONT></TT> shows that partition
<TT>
<FONT COLOR="#0000ff">hda2</FONT></TT> is extended and is subdivided into five smaller
partitions.
<P>
<H1><A NAME="SECTION002230000000000000000">
19.3 Formatting Devices</A>
</H1>
<P>
<H2><A NAME="SECTION002231000000000000000">
19.3.1 File systems</A>
</H2>
<P>
Disk drives are usually read in blocks of 1024 bytes (two
sectors). From the point of view of anyone accessing the device,
blocks are stored consecutively--there is no need to think
about cylinders or heads--so that any program can read the
disk as though it were a linear tape. Try
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>less /dev/hda1</code><br>
<code>less -f /dev/hda1</code><br>
</FONT></TD></TR></TABLE><P>
<P>
Now a complex directory structure with many files of arbitrary size needs to be
stored in this contiguous partition. This poses the problem of
what to do with a file that gets deleted and leaves a data ``hole''
in the partition, or a file that has to be split into parts
because there is no single contiguous space big enough to hold
it. Files also have to be indexed in such a way that they can be
found quickly (consider that there can easily be 10,000 files on
a system). U<SMALL>NIX</SMALL>'s symbolic/hard links and devices files
also have to be stored.
<P>
To cope with this complexity, operating systems have a format
for storing files called the <I>file system</I> (<TT>
<FONT COLOR="#0000ff">fs</FONT></TT>).
Like MS-DOS with its FAT file system or Windows with its FAT32 file system,
L<SMALL>INUX</SMALL> has a file system called the <I>2nd extended file system</I>, or <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT>.
<P>
Whereas <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT> is the traditional native L<SMALL>INUX</SMALL> file system, three
other native file systems have recently become available: SGI's XFS file
system, the ext3fs file system, and the reiserfs file system. These three
support fast and reliable recovery in the event of a power failure,
using a feature called <I>journaling</I>. A journaling file system prewrites
disk alterations to a separate log to facilitate recovery if the
file system reaches an incoherent state. (See Section <A HREF="node22.html#sec:repfs">19.5</A>.)
<P>
<H2><A NAME="SECTION002232000000000000000">
19.3.2 <TT>
<FONT COLOR="#0000ff">mke2fs</FONT></TT></A>
</H2>
<P>
To create a file system on a blank partition, use the command
<TT>
<FONT COLOR="#0000ff">mkfs</FONT></TT> (or one of its variants). To create a
L<SMALL>INUX</SMALL> <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT> file system on the first partition of
the primary master run:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mkfs -t ext2 -c /dev/hda1</code><br>
</FONT></TD></TR></TABLE><P>
or, alternatively
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mke2fs -c /dev/hda1</code><br>
</FONT></TD></TR></TABLE><P>
The <TT>
<FONT COLOR="#0000ff">-c</FONT></TT> option means to check for bad blocks by reading
through the entire disk first. This is a <I>read-only</I> check
and causes unreadable blocks to be flagged as such and not
be used. To do a full <I>read-write</I> check, use the
<TT>
<FONT COLOR="#0000ff">badblocks</FONT></TT> command. This command writes to and verifies every
bit in that partition. Although the <TT>
<FONT COLOR="#0000ff">-c</FONT></TT> option should
always be used on a new disk, doing a full read-write test is
probably pedantic. For the above partition, this test would be:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>badblocks -o blocks-list.txt -s -w /dev/hda1 88326</code><br>
<code>mke2fs -l blocks-list.txt /dev/hda1</code><br>
</FONT></TD></TR></TABLE><P>
<P>
After running <TT>
<FONT COLOR="#0000ff">mke2fs</FONT></TT>, we will find that
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=/dev/hda1 count=8 bs=1024 | file -</code><br>
</FONT></TD></TR></TABLE><P>
gives <TT>
<FONT COLOR="#0000ff">Linux/i386 ext2 filesystem</FONT></TT>.
<P>
<H2><A NAME="SECTION002233000000000000000">
19.3.3 Formatting floppies and removable drives</A>
</H2>
<P>
New kinds of removable devices are being released all the time.
Whatever the device, the same formatting procedure is used.
Most are IDE compatible, which means you can access them through
<TT>
<FONT COLOR="#0000ff">/dev/hd</FONT></TT><I>?</I>.
<P>
The following examples are a parallel port IDE disk drive, a
parallel port ATAPI CD-ROM drive, a parallel port ATAPI disk
drive, and your ``A:'' floppy drive, respectively:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mke2fs -c /dev/pda1</code><br>
<code>mke2fs -c /dev/pcd0</code><br>
<code>mke2fs -c /dev/pf0</code><br>
<code>mke2fs -c /dev/fd0</code><br>
</FONT></TD></TR></TABLE><P>
<P>
Actually, using an <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT> file system on a floppy drive
wastes a lot of space. Rather, use an MS-DOS file system, which has
less overhead and can be read by anyone (see
Section <A HREF="node22.html#sec:floppyformat">19.3.4</A>).
<P>
You often will not want to be bothered with partitioning a
device that is only going to have one partition anyway. In this
case, you can use the whole disk as one partition. An example is
a removable IDE drive as a primary slave <FONT COLOR="#ffa500">[<I>LS120</I>
disks and <I>Jazz</I> drives as well as removable IDE brackets
are commercial examples.]</FONT>:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mke2fs -c /dev/hdb</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H2><A NAME="SECTION002234000000000000000">
19.3.4 Creating MS-DOS floppies</A>
</H2>
<P>
Accessing files on MS-DOS/Windows floppies is explained in
Section <A HREF="node7.html#sec:mtools">4.16</A>. The command <TT>
<FONT COLOR="#0000ff">mformat A:</FONT></TT> will
format a floppy, but this command merely initializes the
file system; it does not check for bad blocks or do the low-level
formatting necessary to reformat floppies to odd storage
sizes.
<P>
<A NAME="sec:floppyformat"></A>
<P>
A command, called <TT>
<FONT COLOR="#0000ff">superformat</FONT></TT>, from the
<TT>
<FONT COLOR="#0000ff">fdutils</FONT></TT> package <FONT COLOR="#ffa500">[You may have to find this
package on the Internet. See Chapter <A HREF="node27.html#chap:packages">24</A> for how
to compile and install source packages.]</FONT> formats a floppy
in any way that you like. A more common (but less thorough) command
is <TT>
<FONT COLOR="#0000ff">fdformat</FONT></TT> from the <TT>
<FONT COLOR="#0000ff">util-linux</FONT></TT> package.
It verifies that each track is working
properly and compensates for variations between the mechanics of
different floppy drives. To format a 3.5-inch 1440-KB, 1680-KB, or
1920-KB floppy, respectively, run:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>cd /dev</code><br>
<code>./MAKEDEV -v fd0</code><br>
<code>superformat /dev/fd0H1440</code><br>
<code>superformat /dev/fd0H1690</code><br>
<code>superformat /dev/fd0H1920</code><br>
</FONT></TD></TR></TABLE><P>
<P>
Note that these are ``long file name'' floppies (VFAT), not old
13-character-filename MS-DOS floppies.
<P>
Most users would have only ever used a 3.5-inch floppy as a ``1.44 MB''
floppy. In fact, the disk media and magnetic head can write much
more densely than this specification, allowing 24 sectors per
track to be stored instead of the usual 18. This is why there is
more than one device file for the same drive. Some inferior
disks will, however, give errors when trying to format that
densely--<TT>
<FONT COLOR="#0000ff">superformat</FONT></TT> will show errors when this
happens.
<P>
See Table <A HREF="node21.html#tab:floppydevicenaming">18.1</A> on page <A HREF="node21.html#page:floppydevice"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A> for
the naming conventions of floppy devices, and their many respective formats.
<P>
<H2><A NAME="SECTION002235000000000000000">
19.3.5 <TT>
<FONT COLOR="#0000ff">mkswap</FONT></TT>, <TT>
<FONT COLOR="#0000ff">swapon</FONT></TT>, and <TT>
<FONT COLOR="#0000ff">swapoff</FONT></TT></A>
</H2>
<P>
The <TT>
<FONT COLOR="#0000ff">mkswap</FONT></TT> command formats a partition to be used as a
swap device. For our disk,
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mkswap -c /dev/hda5</code><br>
</FONT></TD></TR></TABLE><P>
<TT>
<FONT COLOR="#0000ff">-c</FONT></TT> has the same meaning as previously--to check for
bad blocks.
<P>
Once the partition is formatted, the kernel can be signalled to use that
partition as a swap partition with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>swapon /dev/hda5</code><br>
</FONT></TD></TR></TABLE><P>
and to stop usage,
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>swapoff /dev/hda5</code><br>
</FONT></TD></TR></TABLE><P>
Swap partitions cannot be larger than 128 MB, although you can
have as many of them as you like. You can <TT>
<FONT COLOR="#0000ff">swapon</FONT></TT> many
different partitions simultaneously.
<P>
<H1><A NAME="SECTION002240000000000000000">
19.4 Device Mounting</A>
</H1>
<P>
<A NAME="sec:mount"></A>
<P>
The question of how to access files on an arbitrary disk
(without <TT>
<FONT COLOR="#0000ff">C:</FONT></TT>, <TT>
<FONT COLOR="#0000ff">D:</FONT></TT>, etc., notation, of course)
is answered here.
<P>
In U<SMALL>NIX</SMALL>, there is only one root file system that spans many
disks. Different directories may actually exist on a different
physical disk.
<P>
<DIV ALIGN="CENTER">
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<TR><TD bgcolor="#FFE0FF">
<I>To bind a directory to a physical
device (like a partition or a CD-ROM) so that the device's
file system can be read is called <I>mounting</I> the device.</I>
</TD></TR>
</TABLE>
</DIV>
<P>
The <TT>
<FONT COLOR="#0000ff">mount</FONT></TT> command is used as follows:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mount [-t <fstype>] [-o <option>] <device> <directory></code><br>
<code>umount [-f] [<device>|<directory>]</code><br>
</FONT></TD></TR></TABLE><P>
The <TT>
<FONT COLOR="#0000ff">-t</FONT></TT> option specifies the kind of file system, and
can often be omitted since L<SMALL>INUX</SMALL> can autodetect most
file systems. <TT>
<FONT COLOR="#0000ff"><fstype></FONT></TT> can be one of
<TT>
<FONT COLOR="#0000ff">adfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">affs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">autofs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">coda</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">coherent</FONT></TT>, <TT>
<FONT COLOR="#0000ff">devpts</FONT></TT>, <TT>
<FONT COLOR="#0000ff">efs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">hfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">hpfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">iso9660</FONT></TT>, <TT>
<FONT COLOR="#0000ff">minix</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">msdos</FONT></TT>, <TT>
<FONT COLOR="#0000ff">ncpfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">nfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">ntfs</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">proc</FONT></TT>, <TT>
<FONT COLOR="#0000ff">qnx4</FONT></TT>, <TT>
<FONT COLOR="#0000ff">romfs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">smbfs</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">sysv</FONT></TT>, <TT>
<FONT COLOR="#0000ff">ufs</FONT></TT>, <TT>
<FONT COLOR="#0000ff">umsdos</FONT></TT>, <TT>
<FONT COLOR="#0000ff">vfat</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">xenix</FONT></TT>, or <TT>
<FONT COLOR="#0000ff">xiafs</FONT></TT>. The most common file systems are
discussed below. The <TT>
<FONT COLOR="#0000ff">-o</FONT></TT> option is not usually used. See
<TT>
<FONT COLOR="#0000ff">mount</FONT></TT>(8) for all possible options.
<P>
<H2><A NAME="SECTION002241000000000000000">
19.4.1 Mounting CD-ROMs</A>
</H2>
<P>
Put your distribution CD-ROM disk into your CD-ROM drive and mount
it with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>ls /mnt/cdrom</code><br>
<code>mount -t iso9660 -o ro /dev/hdb /mnt/cdrom</code><br>
</FONT></TD></TR></TABLE><P>
(Your CD-ROM might be <TT>
<FONT COLOR="#0000ff">/dev/hdc</FONT></TT> or <TT>
<FONT COLOR="#0000ff">/dev/hdd</FONT></TT>,
however--in this case you should make a soft link
<TT>
<FONT COLOR="#0000ff">/dev/cdrom</FONT></TT> pointing to the correct device.
Your distribution may also prefer <TT>
<FONT COLOR="#0000ff">/cdrom</FONT></TT> over <TT>
<FONT COLOR="#0000ff">/mnt/cdrom</FONT></TT>.)
Now <TT>
<FONT COLOR="#0000ff">cd</FONT></TT> to your <TT>
<FONT COLOR="#0000ff">/mnt/cdrom</FONT></TT> directory. You will
notice that it is no longer empty, but ``contains'' the CD-ROM's
files. What is happening is that the kernel is redirecting all
lookups from the directory <TT>
<FONT COLOR="#0000ff">/mnt/cdrom</FONT></TT> to read from the
CD-ROM disk. You can browse around these files as though they
were already copied onto your hard drive. This is one of the
things that makes U<SMALL>NIX</SMALL> cool.
<P>
When you are finished with the CD-ROM <I>unmount</I> it with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>umount /dev/hdb</code><br>
<code>eject /dev/hdb</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H2><A NAME="SECTION002242000000000000000">
19.4.2 Mounting floppy disks</A>
</H2>
<P>
Instead of using <TT>
<FONT COLOR="#0000ff">mtools</FONT></TT>, you could mount the floppy disk
with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mkdir /mnt/floppy</code><br>
<code>mount -t vfat /dev/fd0 /mnt/floppy</code><br>
</FONT></TD></TR></TABLE><P>
or, for older MS-DOS floppies, use
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mkdir /mnt/floppy</code><br>
<code>mount -t msdos /dev/fd0 /mnt/floppy</code><br>
</FONT></TD></TR></TABLE><P>
Before you eject the floppy, it is essential to run
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>umount /dev/fd0</code><br>
</FONT></TD></TR></TABLE><P>
in order that cached data is committed to the disk. Failing to
<TT>
<FONT COLOR="#0000ff">umount</FONT></TT> a floppy before ejecting will probably corrupt
its file system.
<P>
<H2><A NAME="SECTION002243000000000000000">
19.4.3 Mounting Windows and NT partitions</A>
</H2>
<P>
Mounting a Windows partition can also be done with the
<TT>
<FONT COLOR="#0000ff">vfat</FONT></TT> file system, and NT partitions (read-only) with
the <TT>
<FONT COLOR="#0000ff">ntfs</FONT></TT> file system. VAT32 is also supported (and autodetected).
For example,
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mkdir /windows</code><br>
<code>mount -t vfat /dev/hda1 /windows</code><br>
<code>mkdir /nt</code><br>
<code>mount -t ntfs /dev/hda2 /nt</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H1><A NAME="SECTION002250000000000000000">
19.5 File System Repair: <TT>
<FONT COLOR="#0000ff">fsck</FONT></TT></A>
</H1>
<P>
<A NAME="sec:repfs"></A>
<P>
<TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> stands for <I>file system check</I>.
<TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> scans the file system, reporting and fixing
errors. Errors would normally occur only if the kernel halted
before the file system was <TT>
<FONT COLOR="#0000ff">umount</FONT></TT>ed.
In this case, it may have been in the middle of a write operation which left the
file system in an <I>incoherent</I> state. This usually happens
because of a power failure. The file system is then
said to be <I>unclean</I>.
<P>
<TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> is used as follows:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>fsck [-V] [-a] [-t <fstype>] <device></code><br>
</FONT></TD></TR></TABLE><P>
<TT>
<FONT COLOR="#0000ff">-V</FONT></TT> means to produce verbose output. <TT>
<FONT COLOR="#0000ff">-a</FONT></TT> means to
check the file system noninteractively--meaning to not ask
the user before trying to make any repairs.
<P>
Here is what you would normally do with L<SMALL>INUX</SMALL> if you don't
know a whole lot about the <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT> file system:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>fsck -a -t ext2 /dev/hda1</code><br>
</FONT></TD></TR></TABLE><P>
although you can omit the <TT>
<FONT COLOR="#0000ff">-t</FONT></TT> option because L<SMALL>INUX</SMALL>
autodetects the file system. Note that you should not run
<TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> on a mounted file system. In exceptional circumstances
it is permissible to run <TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> on a file system that has been
mounted read-only.
<P>
<TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> actually just runs a program specific to that
file system. In the case of <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT>, the command
<TT>
<FONT COLOR="#0000ff">e2fsck</FONT></TT> (also known as <TT>
<FONT COLOR="#0000ff">fsck.ext2</FONT></TT>) is run. See
<TT>
<FONT COLOR="#0000ff">e2fsck</FONT></TT>(8) for exhaustive details.
<P>
During an interactive check (without the <TT>
<FONT COLOR="#0000ff">-a</FONT></TT> option,
or with the <TT>
<FONT COLOR="#0000ff">-r</FONT></TT> option--the default), various questions
may be asked of you, as regards fixing and saving things.
It's best to save stuff if you aren't sure; it will be placed in
the <TT>
<FONT COLOR="#0000ff">lost+found</FONT></TT> directory below the root directory of the
particular device. In the example system further below, there would exist the directories
<TT>
<FONT COLOR="#0000ff">/lost+found</FONT></TT>, <TT>
<FONT COLOR="#0000ff">/home/lost+found</FONT></TT>, <TT>
<FONT COLOR="#0000ff">/var/lost+found</FONT></TT>,
<TT>
<FONT COLOR="#0000ff">/usr/lost+found</FONT></TT>, etc. After doing a check on, say, <TT>
<FONT COLOR="#0000ff">/dev/hda9</FONT></TT>,
list the <TT>
<FONT COLOR="#0000ff">/home/lost+found</FONT></TT> directory and delete what you
think you don't need. These will usually be temporary files and log
files (files that change often). It's rare to lose
important files because of an unclean shutdown.
<P>
<H1><A NAME="SECTION002260000000000000000">
19.6 File System Errors on Boot</A>
</H1>
<P>
Just read Section <A HREF="node22.html#sec:repfs">19.5</A> again and run <TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> on the
file system that reported the error.
<P>
<H1><A NAME="SECTION002270000000000000000">
19.7 Automatic Mounts: <TT>
<FONT COLOR="#0000ff">fstab</FONT></TT></A>
</H1>
<P>
Manual mounts are explained above for new and removable disks. It is,
of course necessary for file systems to be automatically mounted
at boot time. What gets mounted and how is specified in the
configuration file <TT>
<FONT COLOR="#0000ff">/etc/fstab</FONT></TT>.
<P>
<TT>
<FONT COLOR="#0000ff">/etc/fstab</FONT></TT> will usually look something like this for the disk we
partitioned above:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>10</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>/dev/hda1 / ext2 defaults 1 1</code><br>
<code>/dev/hda6 /tmp ext2 defaults 1 2</code><br>
<code>/dev/hda7 /var ext2 defaults 1 2</code><br>
<code>/dev/hda8 /usr ext2 defaults 1 2</code><br>
<code>/dev/hda9 /home ext2 defaults 1 2</code><br>
<code>/dev/hda5 swap swap defaults 0 0</code><br>
<code>/dev/fd0 /mnt/floppy auto noauto,user 0 0</code><br>
<code>/dev/cdrom /mnt/cdrom iso9660 noauto,ro,user 0 0</code><br>
<code>none /proc proc defaults 0 0</code><br>
<code>none /dev/pts devpts mode=0622 0 0</code><br>
</FONT></TD></TR></TABLE><P>
<P>
For the moment we are interested in the first six lines only.
The first three fields (columns) dictate the partition, the
directory where it is to be mounted, and the file system type,
respectively. The fourth field gives options (the
<TT>
<FONT COLOR="#0000ff">-o</FONT></TT> option to <TT>
<FONT COLOR="#0000ff">mount</FONT></TT>).
<P>
The fifth field tells whether the file system contains real
files. The field is used by the <TT>
<FONT COLOR="#0000ff">dump</FONT></TT> command to decide if it
should be backed up. This is not commonly used.
<P>
The last field tells the order in which an <TT>
<FONT COLOR="#0000ff">fsck</FONT></TT> should
be done on the partitions. The <TT>
<FONT COLOR="#0000ff">/</FONT></TT> partition should come
first with a <TT>
<FONT COLOR="#0000ff">1</FONT></TT>, and all other partitions should come
directly after. Placing <TT>
<FONT COLOR="#0000ff">2</FONT></TT>'s everywhere else
ensures that partitions on different disks can be checked in
parallel, which speeds things up slightly at boot time.
<P>
The <TT>
<FONT COLOR="#0000ff">floppy</FONT></TT> and <TT>
<FONT COLOR="#0000ff">cdrom</FONT></TT> entries enable you to use
an abbreviated form of the <TT>
<FONT COLOR="#0000ff">mount</FONT></TT> command.
<TT>
<FONT COLOR="#0000ff">mount</FONT></TT> will just look up the corresponding directory and
file system type from <TT>
<FONT COLOR="#0000ff">/etc/fstab</FONT></TT>. Try
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mount /dev/cdrom</code><br>
</FONT></TD></TR></TABLE><P>
These entries also have the <TT>
<FONT COLOR="#0000ff">user</FONT></TT> option, which
allows ordinary users to mount these devices. The <TT>
<FONT COLOR="#0000ff">ro</FONT></TT> option
once again tells to <TT>
<FONT COLOR="#0000ff">mount</FONT></TT> the CD-ROM read only, and the
<TT>
<FONT COLOR="#0000ff">noauto</FONT></TT> command tells <TT>
<FONT COLOR="#0000ff">mount</FONT></TT> <I>not</I> to mount
these file systems at boot time. (More comes further below.)
<P>
<TT>
<FONT COLOR="#0000ff">proc</FONT></TT> is a kernel information database that looks
like a file system. For example <TT>
<FONT COLOR="#0000ff">/proc/cpuinfo</FONT></TT> is not
any kind of file that actually exists on a disk somewhere. Try
<TT>
<FONT COLOR="#0000ff">cat /proc/cpuinfo</FONT></TT>.
<P>
Many programs use <TT>
<FONT COLOR="#0000ff">/proc</FONT></TT> to get dynamic information on the
status and configuration of your machine. More on this is
discussed in Section <A HREF="node45.html#sec:proc">42.4</A>.
<P>
The <TT>
<FONT COLOR="#0000ff">devpts</FONT></TT> file system is another pseudo file system
that generates terminal master/slave pairs for programs. This is
mostly of concern to developers.
<P>
<H1><A NAME="SECTION002280000000000000000">
19.8 Manually Mounting <TT>
<FONT COLOR="#0000ff">/proc</FONT></TT></A>
</H1>
<P>
<A NAME="page:mountproc"></A>
<P>
You can mount the <TT>
<FONT COLOR="#0000ff">proc</FONT></TT> file system with the command
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mount -t proc /proc /proc</code><br>
</FONT></TD></TR></TABLE><P>
This is an exception to the normal <TT>
<FONT COLOR="#0000ff">mount</FONT></TT> usage.
Note that all common L<SMALL>INUX</SMALL> installations require <TT>
<FONT COLOR="#0000ff">/proc</FONT></TT>
to be mounted at boot time. The only times you will need this
command are for manual startup or when doing a <TT>
<FONT COLOR="#0000ff">chroot</FONT></TT>.
(See page <A HREF="node23.html#page:useingchroot"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A>.)
<P>
<H1><A NAME="SECTION002290000000000000000">
19.9 RAM and Loopback Devices</A>
</H1>
<P>
<A NAME="sec:ramloop"></A>
<P>
A <I>RAM device</I> is a block device that can be used as a
disk but really points to a physical area of RAM.
<P>
A <I>loopback device</I> is a block device that can be used as a
disk but really points to an ordinary file somewhere.
<P>
If your imagination isn't already running wild, consider
creating a floppy disk with file system, files and all,
<I>without actually having a floppy disk</I>, and being able to dump this creation to floppy
at any time with <TT>
<FONT COLOR="#0000ff">dd</FONT></TT>. You can also have a whole
other L<SMALL>INUX</SMALL> system
inside a 500 MB file on a Windows partition <I>and</I> boot into it--thus
obviating having to repartition a Windows machine just to run L<SMALL>INUX</SMALL>.
All this can be done with loopback and RAM devices.
<P>
<H2><A NAME="SECTION002291000000000000000">
19.9.1 Formatting a floppy inside a file</A>
</H2>
<P>
The operations are quite trivial. To create an <TT>
<FONT COLOR="#0000ff">ext2</FONT></TT> floppy inside
a 1440 KB <I>file</I>, run:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=/dev/zero of=~/file-floppy count=1440 bs=1024</code><br>
<code>losetup /dev/loop0 ~/file-floppy</code><br>
<code>mke2fs /dev/loop0</code><br>
<code>mkdir ~/mnt</code><br>
<code>mount /dev/loop0 ~/mnt</code><br>
<code>ls -al ~/mnt</code><br>
</FONT></TD></TR></TABLE><P>
<P>
When you are finished copying the files that you want into <TT>
<FONT COLOR="#0000ff">~/mnt</FONT></TT>, merely run
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>umount ~/mnt</code><br>
<code>losetup -d /dev/loop0</code><br>
</FONT></TD></TR></TABLE><P>
<P>
To dump the file system to a floppy, run
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=~/file-floppy of=/dev/fd0 count=1440 bs=1024</code><br>
</FONT></TD></TR></TABLE><P>
A similar procedure for RAM devices is
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<code> </code><br>
<font size="-1"><code>5</code></font><code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=/dev/zero of=/dev/ram0 count=1440 bs=1024</code><br>
<code>mke2fs /dev/ram0</code><br>
<code>mkdir ~/mnt</code><br>
<code>mount /dev/ram0 ~/mnt</code><br>
<code>ls -al ~/mnt</code><br>
</FONT></TD></TR></TABLE><P>
<P>
When you are finished copying the files that you want into <TT>
<FONT COLOR="#0000ff">~/mnt</FONT></TT>, merely run
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>umount ~/mnt</code><br>
</FONT></TD></TR></TABLE><P>
To dump the file system to a floppy or file, respectively, run:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=/dev/ram0 of=/dev/fd0 count=1440 bs=1024</code><br>
<code>dd if=/dev/ram0 of=~/file-floppy count=1440 bs=1024</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H2><A NAME="SECTION002292000000000000000">
19.9.2 CD-ROM files</A>
</H2>
<P>
Another trick is to move your CD-ROM to a file for high-speed
access. Here, we use a shortcut instead of the <TT>
<FONT COLOR="#0000ff">losetup</FONT></TT> command:
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>dd if=/dev/cdrom of=some_name.iso</code><br>
<code>mount -t iso9660 -o ro,loop=/dev/loop0 some_name.iso /cdrom</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<H1><A NAME="SECTION0022100000000000000000">
19.10 Remounting from Read-Only to Read-Write</A>
</H1>
<P>
A file system that is already mounted as <TT>
<FONT COLOR="#0000ff">r</FONT></TT>ead-<TT>
<FONT COLOR="#0000ff">o</FONT></TT>nly can be
remounted as <TT>
<FONT COLOR="#0000ff">r</FONT></TT>ead-<TT>
<FONT COLOR="#0000ff">w</FONT></TT>rite, for example, with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>mount -o rw,remount /dev/hda1 /</code><br>
</FONT></TD></TR></TABLE><P>
This command is useful when you log in in single-user mode
with no write access to your root partition.
<P>
<H1><A NAME="SECTION0022110000000000000000">
19.11 Disk <TT>
<FONT COLOR="#0000ff">sync</FONT></TT></A>
</H1>
<P>
The kernel caches write operations in memory for performance reasons.
These <I>flush</I> (physically commit to the magnetic media)
every so often, but you sometimes want to force a flush.
This is done simply with
<P><TABLE nowrap="1" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD valign="top" class="source" width="2%"><FONT color=red>
<code> </code><br>
</FONT></TD><TD valign="top" class="source" bgcolor="#FFE0C0"><FONT color=blue>
<code>sync</code><br>
</FONT></TD></TR></TABLE><P>
<P>
<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html2087"
HREF="node23.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2083"
HREF="rute.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2077"
HREF="node21.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2085"
HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2088"
HREF="node23.html">20. Advanced Shell Scripting</A>
<B> Up:</B> <A NAME="tex2html2084"
HREF="rute.html">rute</A>
<B> Previous:</B> <A NAME="tex2html2078"
HREF="node21.html">18. UNIX Devices</A>
  <B> <A NAME="tex2html2086"
HREF="node1.html">Contents</A></B>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|