📄 283-286.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Managing File Systems</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=14//-->
<!--PAGES=283-286//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="280-283.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="286-288.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The following sections show how to use <TT>fdisk</TT>. Here is an example of how to use <TT>fdisk</TT> to set up the partitions on a hard disk for use by Linux. Assume that you want to configure the first IDE drive in your system for Linux. Make sure that you have a backup of your data. All data on your hard disk is destroyed in the process. The name of the first IDE hard disk is /dev/hda, which is the default device for Linux.</P>
<P><FONT SIZE="+1"><B>Running <I>fdisk</I>
</B></FONT></P>
<P>You run <TT>fdisk</TT> with this command</P>
<!-- CODE SNIP //-->
<PRE>
# fdisk
</PRE>
<!-- END CODE SNIP //-->
<P>and <TT>fdisk</TT> responds with the following:</P>
<!-- CODE SNIP //-->
<PRE>
Using /dev/hda as default device!
Command (m for help):
</PRE>
<!-- END CODE SNIP //-->
<P>This tells you that <TT>fdisk</TT> is using disk /dev/hda as the device that you’re working with. Because this is what you wanted, you’re fine. You should always check to make sure that you’re really on the disk that you think you’re on. Linux then displays the <TT>fdisk</TT> command prompt.</P>
<P><FONT SIZE="+1"><B>Displaying the Current Partition Table</B></FONT></P>
<P>The first thing you want to do is display the current partition table. This is done with the <TT>p</TT> command:</P>
<!-- CODE SNIP //-->
<PRE>
Command (m for help): <B>p</B>
Disk /dev/hda: 14 heads, 17 sectors, 1024 cylinders
Units = cylinders of 238 * 512 bytes
</PRE>
<!-- END CODE SNIP //-->
<!-- CODE SNIP //-->
<PRE>
Device Boot Begin Start End Blocks Id System
</PRE>
<!-- END CODE SNIP //-->
<!-- CODE SNIP //-->
<PRE>
Command (m for help):
</PRE>
<!-- END CODE SNIP //-->
<P>This listing shows that the current disk, /dev/hda, has a geometry of 14 heads, 17 sectors, and 1,024 cylinders. The display units are in cylinders of 238 * 512 (121,856) bytes each. Because there are 1,024 cylinders and each cylinder is 121,856 bytes, you can deduce that the disk can hold 1,0244×121,856 = 124,780,544 bytes, or about 120MB. You can also see that /dev/hda has no partitions.
</P>
<P><FONT SIZE="+1"><B>Creating a New Partition</B></FONT></P>
<P>Assume that you want to create a 100MB Linux file partition for user home directories and a 20MB swap partition. Your next step is to use the <TT>n</TT> command to create a new partition:</P>
<!-- CODE SNIP //-->
<PRE>
Command (m for help): <B>n</B>
Command action
e extended
p primary partition (1-4)
<B>p</B>
Partition number (1-4): <B>1</B>
First cylinder (1-1023): <B>1</B>
Last cylinder or +size or +sizeM or +sizeK (1-1023): <B>+100M</B>
</PRE>
<!-- END CODE SNIP //-->
<P>Using the <TT>n</TT> command to create a new partition displays another menu. You must choose whether you want to create an extended partition or a primary partition. You typically want to create a primary partition unless you have more than four partitions on a disk. <TT>fdisk</TT> then asks you for the partition number that you want to create. Because this is the first partition on the disk, you answer <TT><B>1</B></TT>. You’re then prompted for the first cylinder for the partition. This determines where on the disk the data area starts. Again, because this will be the first partition on the disk, you can start the partition at cylinder 1.</P>
<P>The next line asks you how large you want the partition to be. You have several options as to how to answer this question. <TT>fdisk</TT> accepts either a number, which it interprets as the size in cylinders, or the size in bytes, kilobytes, or megabytes. The size in bytes is specified as <TT><I>+bytes</I></TT>, where <TT>bytes</TT> is the size of the partition. Similarly, <TT><I>+size</I>K</TT> and <TT><I>+size</I>M</TT> set the partition size to size kilobytes or size megabytes, respectively. You know that you want a 100MB partition, so the easiest answer to the prompt is <TT><B>+100M</B></TT>.</P>
<P><FONT SIZE="+1"><B>Rechecking the Partition Table</B></FONT></P>
<P>Now you should check the partition table again to see what <TT>fdisk</TT> has done:</P>
<!-- CODE SNIP //-->
<PRE>
Command (m for help): <B>p</B>
Disk /dev/hda: 14 heads, 17 sectors, 1024 cylinders
Units = cylinders of 238 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 1 1 861 102400 81 Linux/MINIX
Command (m for help):
</PRE>
<!-- END CODE SNIP //-->
<P>The partition table shows that you have 1 partition, /dev/hda1, that goes from cylinder 1 to cylinder 861 and uses 102,400 blocks. It’s listed as being type 81, Linux/MINIX.
</P>
<P><FONT SIZE="+1"><B>Creating the Swap Partition</B></FONT></P>
<P>Now you need to create the 20MB swap partition by using the remaining disk space. This is just like creating the first partition:
</P>
<!-- CODE SNIP //-->
<PRE>
Command (m for help): <B>n</B>
Command action
e extended
p primary partition (1-4)
<B>p</B>
Partition number (1-4): <B>2</B>
First cylinder (862-1023): <B>862</B>
Last cylinder or +size or +sizeM or +sizeK (862-1023): <B>1023</B>
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>TIP: </B>It’s usually better to go ahead and enter the size of the last partition in cylinders to make sure that you use all the disk space.<HR></FONT>
</BLOCKQUOTE>
<P>Here you specified partition number 2 for the second partition. When <TT>fdisk</TT> prompts for the first cylinder, notice that it gives a range of 862 to 1023. This is because the first partition takes up everything before cylinder 862. So enter <TT><B>862</B></TT> as the starting cylinder for the second partition. You want to use all the remaining space on the disk for the swap partition. You should have about 20MB left, but if you specify the size in megabytes, the internal <TT>fdisk</TT> calculations could leave you with a couple of unused cylinders. So you enter <TT><B>1023</B></TT> for the last cylinder on the size prompt.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>You might see an error similar to this<!-- CODE SNIP //-->
<PRE>
Warning: Linux cannot currently use the last xxx sectors of this partition.
</PRE>
<!-- END CODE SNIP //-->
<P>where <TT>xxx</TT> is some number. Such an error can be ignored. It’s left over from the days when Linux couldn’t access file systems larger than 64MB.<HR></FONT>
</BLOCKQUOTE>
</P>
<P><FONT SIZE="+1"><B>Making Sure the Sizes Are Correct</B></FONT></P>
<P>At this point, you’ve created both partitions that you wanted to create. You should take a look at the partition table one more time to check that the sizes are correct:
</P>
<!-- CODE SNIP //-->
<PRE>
Command (m for help): <B>p</B>
Disk /dev/hda: 14 heads, 17 sectors, 1024 cylinders
Units = cylinders of 238 * 512 bytes
Device Boot Begin Start End Blocks Id System
/dev/hda1 1 1 861 102400 81 Linux/MINIX
/dev/hda2 862 862 1023 19159 81 Linux/MINIX
Command (m for help):
</PRE>
<!-- END CODE SNIP //-->
<P>As you can see, /dev/hda1 uses cylinder 1 through cylinder 861 with a size of 102,400 blocks, which is approximately 100MB. Partition /dev/hda2 goes from cylinder 862 to cylinder 1023 with a size of 19,156 blocks, or almost 20MB.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="280-283.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="286-288.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -