📄 lsg03.htm
字号:
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>As mentioned earlier, Linux's fdisk commands are different than the FDISK commands for DOS. The following list explains the commands you need to run Linux's fdisk utility:
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Command
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Action
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
d
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Deletes an existing partition
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
l
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Lists all known partition types
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
n
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a new partition
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
p
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Displays the current partition table
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
q
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Quits fdisk without saving changes
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
t
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Changes a partition's type code
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
v
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Verifies the partition table
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
w
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Writes current partition table to disk and exits</FONT>
</TABLE><P>Linux's fdisk utility offers quite a few more commands, as Figure 3.3 shows. This screen is the output from the Linux fdisk help (m) command. Note the warning at the top of the screen. This warning is issued whenever your hard drive has more than 1024 cylinders, which early versions of Linux (pre 1.0 kernels mostly) couldn't support. Later versions of Linux, including the version provided on this book's CD-ROM, all support much larger hard drives. The warning is a holdover from the earlier system and should really be taken out.
<BR>
<P><B> <A HREF="03LSG03.gif">Figure 3.3.</B>
<BR><B>Linux's </B><B>fdisk</B><B> utility offers these commands.</A></B>
<BR>
<P>The process for setting up a partition is to first examine the partition table to make sure any existing partitions are correct. If you have a DOS partition on your drive, it should show in the partition table. If you created Linux swap and filesystem partitions when you were in DOS' fdisk, they should appear in the partition table too, although the partitions' types will be incorrect.
<BR>
<BR>
<A NAME="E69E33"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting Up Linux Partitions</B></FONT></CENTER></H4>
<BR>
<P>To create the Linux swap space partition, use the n command and give the starting sector number. Usually, this number will be immediately after any existing DOS partition (or other operating systems you have installed). Linux's fdisk lets you specify the size of the partition either by supplying an end sector number or by giving a size in megabytes (remember the swap space size has a practical maximum of 16M). If you give the size in megabytes, the format is usually +XXM, where XX is the number of megabytes (such as +16M). You can also specify kilobytes, but you don't want to create a swap partition that is less than 1M.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Most PC BIOSs cannot handle more than 1024 cylinders on a disk drive. You may not be able to create DOS or Linux partitions or filesystems that go beyond the 1,023th cylinder (numbering starts at zero). Some other operating systems, such as SCO UNIX, allow you to use anything beyond the 1,024 limit. Linux can use partitions beyond the 1,024 limit, but it can't boot from them. If you have a disk drive that has more than 1023 cylinders, make sure your primary Linux partition ends before 1023. You can create extra partitions following that cylinder and mount them as second filesystems. Alternatively, you can create a single large Linux filesystem that extends or starts beyond the 1,023rd cylinder and use a LILO boot floppy disk.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The fdisk program asks you whether you want to create a primary or an extended partition. If you are creating a primary partition, the program wants the number (one to four—remember a DOS partition has to be number one to boot). In most cases, you should create only primary partitions, unless you have a large disk drive. You can use extended partitions to add logical drives inside primary partitions, which is similar to the way DOS creates logical drives. In Linux, extended partitions are not the same as extended filesystems!
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Some distributions of Linux issue the message Warning: Linux can't currently use X sectors of this partition. This warning was in early versions of Linux that couldn't handle filesystems larger than 64K and can be ignored.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>After you have created the Linux partition, assign it a type. Some versions of fdisk prompt for this information right away, and others let you select the option to assign filesystem types from the fdisk menu. In either case, the letter l will display all known filesystem types. Choose the one that designates a Linux swap space (number 82), and check the partition table. Figure 3.4 shows the filesystem types supported by the version of Linux included with this book. As you can see, many filesystem types are allowed, although most users will only use the DOS, Linux swap, and Linux data types. The other filesystem types were included in earlier versions of Linux for compatibility with other operating systems.
<BR>
<P><B> <A HREF="03LSG04.gif">Figure 3.4.</B>
<BR><B>The filesystem types supported by Linux, identified by type number and </B><B>description.</A></B>
<BR>
<P>Your Linux swap space partition should have the correct size and partition type when you display the partition table with the p command. Although Linux doesn't care about the partition type numbers, some other operating systems do note them, so it's a good practice to label them correctly in order to prevent future problems. This practice also helps you keep the partition table organized.
<BR>
<P>Next, create your primary Linux filesystem partition in the same manner. If you want to use the rest of the disk drive for that partition, you can enter the end sector number of your drive (Linux's fdisk will tell you the range you can use). This number would be the usual default if your hard drive has a DOS, Linux swap space, and Linux filesystem partition on it. After you have created the Linux filesystem partition, identify its filetype as 82, which is a Linux native type. You can display the partition table at any time with the p command (inside fdisk only). Figure 3.5 shows a partition table set up on a 2.4G SCSI hard drive (/dev/sda), which has 500M for DOS (/dev/sda1), a 16M Linux swap space partition (/dev/sda2), and the rest of the drive for Linux data (/dev/sda3).
<BR>
<P><B> <A HREF="03LSG05.gif">Figure 3.5.</B>
<BR><B>A completed partition table with DOS and Linux sharing a large (2.4G) </B><B>drive.</A></B>
<BR>
<P>Make a note of the size of the swap space and filesystem partitions, in blocks, as you will need this information later. You can read this information straight from the partition table. After you create the Linux partitions and are satisfied with the partition table layout, save and exit fdisk. Make sure you write the table to disk with the w command. If you don't save the information, you will have to repeat the process again.
<BR>
<BR>
<A NAME="E69E34"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Enabling the Swap Space for Installation</B></FONT></CENTER></H4>
<BR>
<P>Linux's installation routine requires a good chunk of RAM to proceed. If you have 4M of RAM or less, you will have problems installing Linux unless you have the kernel use the swap space partition. (If you have only 4M or less of RAM in your system, you should have a swap space of at least 8M, preferably 16M.) If you try to install Linux and get memory error messages, you system doesn't have enough RAM and the kernel needs to use the swap space. Even if you have lots of RAM, there's no reason not to enable the swap space now. To enable the swap space, issue the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">mkswap -c partition size</FONT></PRE>
<P>where partition is the name of the partition and size is the size of the partition in blocks. If you didn't make a note of this number earlier when setting up the partition table, you can start fdisk again and read the size in blocks from the partition table display.
<BR>
<P>For example, if you have set up the Linux swap space on partition /dev/hda2 (the second primary partition on the first non-SCSI drive) and it has a size of 13,565 blocks you would issue the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">mkswap -c /dev/hda2 13565</FONT></PRE>
<P>The -c option in the command line tells the mkswap utility to format the partition and check it for bad blocks. This option slows down the creation of the swap partition a little, but a bad block in the swap partition can cause your entire system to crash. If mkswap finds any errors in the swap space, it will generate an error message and mark the block as unusable by the operating system (the block is removed from the total available for swap space). Because mkswap flags bad blocks to be left alone, you can ignore the bad block messages unless there is a considerable number of them (ten or more is a good limit in a 16M partition), in which case your hard drive has too many bad blocks and you should consider either low-level formatting it or replacing it with a new drive.
<BR>
<P>After you set up the swap partition, you enable the Linux swap space partition with the swapon command. Usually, you have to specify the partition, although some versions use the partition table to figure out the partition automatically. It never hurts to be explicit, though. To enable the swap partition set up in the preceding example, you would enter the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">swapon /dev/hda2</FONT></PRE>
<P>You have to repeat the mkswap and swapon commands for each swap partition, if you created more than one. As soon as you execute the swapon command, the Linux kernel starts to use the new swap space as an extension of the physical RAM. Figure 3.6 shows a swap partition called /dev/sda2 (second partition on the first SCSI drive) being set up and activated. Note that you need to know the size of the partition in blocks. You get this number from the fdisk utility.
<BR>
<P><B> <A HREF="03LSG06.gif">Figure 3.6.</B>
<BR><B>Setting up and activating a swap partition on /dev/sda2.</A></B>
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -