📄 readme.fdisk
字号:
`fdisk': the Linux partition table editor=========================================`fdisk' is the Linux partition table editor. In this section weexamine this utility and try to describe it thoroughly enough so thatanyone can use it.* Contents:* Disks and how they are described.* Dividing up your disk.* The `fdisk' command.* Deleting and adding partitions.* Active flags and system types.* Extra commands for experts.* Warnings for `fdisk' users.Disks and how they are described--------------------------------A typical disk consists physically of one or more circular objectscalled "platters", which rotate about a central axis. Devices called"heads" move to specified places on the disk surface to read or writeinformation. There is usually one head on each side of every platter,and all these heads are attached to a comb-like controller arm whichmoves all of them at the same time, either closer to the centre of thedisk, or closer to the outer edge.Suppose the arm is in one position, putting an area of the disksurface within reach of one or another of the heads. This total area,everything that is accessible without moving the arm, is called a"cylinder". (A cylinder is a barrel-shaped cross section of a disk,consisting of a circular strip from each side of each platter.) Thepart of a cylinder that one head can read or write without moving iscalled a "track".Each track is divided into several pie-shaped slices called"sectors", which are the smallest parts of the disk which can be reador written at a time. The sectors on one disk are usually all the samesize.In fact, there are not always two heads to every platter, there aresome disks which do not have the same amount of data in every cylinder,and there may be disks which do not have the same amount of data inevery sector. These features are usually hidden on PCs by thecontroller card or the BIOS, which map the physical geometry of a diskonto a logical geometry, which is what is actually used to access thedisk.The numbers which describe the "geometry" of a disk are 1. The number of cylinders it contains. 2. The number of tracks per cylinder, which is the number of heads. 3. The number of sectors per track. 4. The number of bytes per sector.These numbers vary from disk to disk, but a typical PC disk mighthave about 1000 cylinders, half a dozen heads, and 15 or 20 sectors pertrack, with each sector containing 512 bytes or characters; such a diskcontains 40 to 60 megabytes of data. A "double density" floppy diskcontains 40 cylinders, with 2 heads (2 tracks per cylinder), and with 9sectors per track; such a disk contains 360 kilobytes, or 360 * 1024characters. A "high density" 3.5 inch floppy contains 80 cylinders,with 2 heads and 18 sectors per track, or 1.44 megabytes, or 1440 *1024 characters.The exact size of a track or cylinder in bytes varies from one diskto another. This `fdisk' for Linux deals mainly with cylinders, sincethis is the best unit to use when allocating space for partitions. Itreports partition sizes in "blocks" of 1024 bytes, or 2 sectors, since`mkswap' and the various `mkfs' programs require this number. A blockis the smallest amount of space which can be set aside for a file inthe current file systems.An operating system, such as Linux or DOS or OS/2, may use a disk inany way that it wishes, but if two operating systems share the samedisk, they must agree on who owns what, or else one will interfere withthe other (that is, by damaging the other's files). A "partition" is asection of a hard disk which is handled as a unit by all operatingsystems which can access the disk. The standard way to definepartitions (for the moment) is the "partition table", a list ofinformation which is stored in parts of the disk that don't belong toany of the systems using the disk. The beginning of the partitiontable is stored in the disk's primary boot sector, and the rest isstored in a chain of sectors scattered throughout the disk.The first sector on the disk is called the "primary boot block" or"primary boot sector" because (1) it comes first, before other, similarsectors; (2) it tells where the other, similar sectors are found, sothat it is logically `prior' to them; and (3) it usually contains codewhich is executed when the system boots up. This sector contains atable describing at most four partitions. These areas are called"primary partitions".The partition table in the primary boot sector may also describe atmost one "extended partition". This is a large area of the disk,usually containing all the space which is not in any primary partition.Within this space we can set aside other areas which are called"logical partitions", because they look almost exactly like primarypartitions. In fact, the main difference between them is that we canboot from primary partitions, while we cannot boot from logicalpartitions. This happens because the address of a primary partition isin a fixed place, whereas the address of a secondary partition is not,so we require a more complicated process to discover it, one which istoo difficult for most primary boot programs.Dividing up your disk---------------------It is a good idea to plan ahead before you start creating partitionson your disk. If you set aside a partition for some purpose, it is noteasy to change its size: you must backup all the data from the partition,whether to floppies, to another partition, to another hard disk, orsomewhere else; then you must edit the table which describes thispartition, so changing its size; then you must reboot and initialisethe new partition, formatting it, for example, under DOS, or running`mkfs' under Linux; finally you can copy all the data back. It ispossible, if you have several partitions, to copy data back and forthbetween them while you change their sizes, but this is a bit risky andtime consuming. It is better to plan ahead what you will need, sinceit is hard to change it afterwards.Many people with large disks and recent versions of DOS have theirentire file system on one large partition. They usually ask, `Isn'tthere any way I can reformat my disk without copying everything off?'There is no way to do it using standard DOS utilities, and there is notruly safe way to do it using commercial software, because, if you makea mistake, you will lose the entire contents of your disk. If you aregoing to back up your disk anyway, you might as well copy the data backsafely. The Linux FAQ contains references to tools and procedureswhich will allow you to do this, if you dare.DOS and Linux both allow you to access several partitions on asingle disk; on DOS these are treated as if they were separate disks ordrives, and under Linux they are treated as different "devices".You can have up to 64 partitions on a single IDE disk, or up to 16partitions on a single SCSI disk, at least as far as Linux isconcerned; in practice you will rarely want so many. The maximum sizeof a Linux file system on a single partition depends on the type offile system you use. Minix file systems are limited to 64 megabytes.You may have all of your Linux files in a single partition, or you mayhave two, three, or more Linux file systems. Similarly you may haveone or more DOS partitions. If you have several small partitions, yourun much less risk of losing all your files if your disk getscorrupted. On the other hand, you may run out of space on a smallpartition more easily.Under DOS, you must refer to each partition by a separate driveletter, but all partitions are automatically accessible. Under Linuxonly the root partition is automatically accessible, but once we mountanother partition, it is indistinguishable from the rest of the filesystem. Disks are usually mounted by a command in one of the systemstartup files, `/etc/rc', so you need not worry about having to do ityourself whenever you boot the system. But even ordinary users maybe allowed to mount removable hard disks and floppy disks.Linux requires at least one partition, which is the `root' of thefile system. You may prefer to have a separate partition for `/usr',which contains most of the executable files, or for `/home', whichcontains most of your private files. You may also wish to set aside apartition to use for swap space, depending on the amount of memory yourPC has. You will certainly need swap space if you have less than 4 MBof RAM and wish to compile anything substantial. You can reserve swapspace in a file, but you need a partition big enough to hold it, andthis will probably be less efficient than having a partition devoted toswap.The disk space you need for Linux is discussed in README.prepare.Are you going to boot Linux from the hard disk, or will you bootfrom a floppy? Some boot programs place severe restrictions on wherethe boot partition can be. LILO is more relaxed about this, but doesrequire either the Master Boot Record on your first hard disk, or theboot record on one of the first four partitions on your first hard disk.If you have an extended partition with logical partitions in it, youcan have only three primary partitions containing data.The `fdisk' command-------------------Every operating system, whether DOS, OS/2, or Linux, should provideits own utility for editing hard disk partition tables. At least fourof these utilities have been called `fdisk', for `Fixed DISK setupprogram', where `fixed' means `not removable'. I believe the first PCprogram named `fdisk' came from Microsoft in about 1985; before thattime disks were too small to divide into separate sections.Every operating system has its own peculiarities. Normally youshould set up a partition for the use of one operating system by usingits own `fdisk' program. Do not use the Linux `fdisk' to createpartitions for DOS or for any system other than Linux; otherwise youmay have problems.An `fdisk' program performs two functions: it reports how the disk isconfigured, and it changes that configuration by adding or deletingpartitions. Most `fdisk' programs can also change other information inpartition tables.This `fdisk' for Linux operates on one hard disk at a time. If yougive the command fdiskit reports on, and is able to change, `/dev/hda', the first harddisk. (If you have no `/dev/hda', `fdisk' uses `/dev/sda' as thedefault device.) To look at or change the second hard disk, `/dev/hdb',give the command fdisk /dev/hdbTo look at or change the first SCSI disk, give the command fdisk /dev/sdaThere are some special forms of the `fdisk' command. One of them,suggested by Jim Winstead, simply lists all partitions on all availabledisks: fdisk -l (where `l' is a letter, not the digit `1')The option `-v' is provided to list the current version of the`fdisk' command. Finally, there is an option `-s' which is not reallyintended for interactive use. It causes fdisk to print the size of apartition in blocks of 1024 bytes as follows: fdisk -s /dev/hda7 39934Because this is intended to be used by `mkfs' and `mkswap' programs,it does not return the size of extended partitions or of partitionswhose system type code is less than 10 (hexadecimal a). If you start`fdisk' without using one of these special options, it responds byasking for a command: Command (m for help): _Each `fdisk' command consists of a single letter, which must befollowed by <RETURN> before it is obeyed. Upper and lower case are notdistinguished. Anything you type after the first character is ignored.Give the command `m', and you should see this menu: Command action a toggle a bootable flag d delete a partition l list known partition types m print this menu n add a new partition p print the partition table q quit without saving changes t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): _The simplest commands are Print, Verify, and Quit. On a small disk, thePrint command might produce a display like this one: Disk /dev/hda: 5 heads, 17 sectors, 977 cylinders Units = cylinders of 85 * 512 bytes Device Boot Begin Start End Blocks Id System /dev/hda1 * 1 1 236 10021+ 1 DOS 12-bit FAT /dev/hda2 837 837 977 5992+ 5 Extended /dev/hda3 * 237 237 836 25500 83 Linux native /dev/hda5 837 837 936 4249+ 82 Linux swap /dev/hda6 942 942 977 1522 1 DOS 12-bit FATThere are 5 partitions reported; `/dev/hda4' does not appear becauseit is not allocated. Partitions 1 and 3 are flagged as bootable. Thesize of each partition is reported in 1 kilobyte blocks; hence theprimary Linux partition, partition 3, is 25 1/2 megabytes in size. The`+' after three of the sizes warns that these partitions contain an oddnumber of sectors: Linux normally allocates filespace in 1 kilobyteblocks, so the extra sector in partition 5 is wasted. Id numbers arereported in hexadecimal and explained in English.The display/entry units may be either cylinders or sectors. Thedefault is cylinders, but changing the units makes the print commanddisplay the following table for the system reported above: Disk /dev/hda: 5 heads, 17 sectors, 977 cylinders Units = sectors of 1 * 512 bytes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -