How to use fdisk partitions in Linux

Source: Internet
Author: User
I. fdisk introduction fdisk-PartitiontablemanipulatorforLinux, which means the disk partition table operation tool in Chinese. I did not translate very well and did not read Chinese documents; in fact, the partition tool fdsik can divide disks into several partitions, and can also specify partitions for each partition.

I. INTRODUCTION to fdisk

Fdisk-Partition table manipulator for Linux, translated into Chinese means the disk Partition table operation tool; I did not translate very well and did not read the Chinese documentation; in fact, it is actually a Partition tool

Fdsik can divide disks into several partitions and specify the partition file system for each partition, for example, linux, fat32, linux, linux swap, fat16, and file systems of Unix-like operating systems. of course, when we use fdisk to operate partitions on disks, it is not an end point, we need to format the required file system for the partition so that a partition can be used. This is similar to fdisk in DOS.

2. reasonably plan your hard disk partition

Before partitioning, we need to understand the theory of hard disk partitioning, such as the calculation of hard disk capacity and partition size; for how to plan partitions for a hard disk, please refer to the following documents. thank you

Rational planning of your hard disk partition

III. fdisk-l view hard disk and partition information

Through rational planning of your hard disk partitions, we know that the total number of primary partitions (including extended partitions) cannot exceed four, nor can we enclose extended partitions between primary partitions. According to this principle, it is easier for us to divide hard disk partitions. It can also reduce unnecessary troubles in the future.

1. use fdisk-l to view the number of hard disks mounted to the machine and the partition information.

[Root @ localhost beinan] # fdisk-l
Disk/dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device Boot Start End Blocks Id System
/Dev/hda1*1 765 6144831 7 HPFS/NTFS
/Dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/Dev/hda3 2806 9729 55617030 5 Extended
/Dev/hda5 2806 3825 8193118 + 83 Linux
/Dev/hda6 3826 5100 10241406 83 Linux
/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris
/Dev/hda8 5199 6657 11719386 83 Linux
/Dev/hda9 6658 7751 8787523 + 83 Linux
/Dev/hda10 7752 9729 15888253 + 83 Linux
Disk/dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128*512 = 8257536 bytes
Device Boot Start End Blocks Id System
/Dev/sda1 1 25 201568 + c W95 FAT32 (LBA)
/Dev/sda2 26 125 806400 5 Extended
/Dev/sda5 26 50 201568 + 83 Linux
/Dev/sda6 51 76 200781 83 Linux

Based on the above information, we know that two hard disks (or mobile hard disks) are attached to this machine, one of which is hda and the other is sda. if we want to view the status of a single hard disk, you can use fdisk-l/dev/hda1 or fdisk-l/dev/sda1. take the hard disk ID output by fdisk-l as the standard.

Hda has three primary partitions (including extended partitions): hda1 hda2 and hda3 (extended partitions), and hda5 to hda10.

Sda has two primary partitions (including extended partitions): hda1 and hda2. the logical partition is sda5 hda6.

Total disk capacity = total capacity of the primary partition (including extended partitions)

Extended partition capacity = total capacity of logical partitions

Through the above example, we can know that hda = hda1 + hda2 + hda3, where hda3 = hda5 + hda6 + hda7 + hda8 + hda9 + hda10 ...... ......
2. description of some fdisk-l values

Disk/dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

The hard disk is 80 GB, with 255 magnetic surfaces; 63 sectors; 9729 Magnetic columns; the capacity of each cylinder (magnetic column) is 8225280 bytes = 8225.280 K (about) = 8.225280 M (about );
Partition sequence boot starts to terminate capacity partition type ID partition type
Device Boot Start End Blocks Id System
/Dev/hda1*1 765 6144831 7 HPFS/NTFS
/Dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/Dev/hda3 2806 9729 55617030 5 Extended
/Dev/hda5 2806 3825 8193118 + 83 Linux
/Dev/hda6 3826 5100 10241406 83 Linux
/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris
/Dev/hda8 5199 6657 11719386 83 Linux
/Dev/hda9 6658 7751 8787523 + 83 Linux
/Dev/hda10 7752 9729 15888253 + 83 Linux

Note:

Hard disk partition representation: In Linux, hd * x or sd * x is used, where * represents a, B, c ...... ...... Numbers 1, 2, 3, and so on ...... ...... HDDs are mostly IDE hard disks; sd is mostly SCSI or mobile storage;

Boot: indicates the Boot partition. in the preceding example, hda1 is the Boot partition;

Start (Start): indicates that a partition starts from X cylinder (magnetic column;

End: indicates that a partition ends with Y cylinder (magnetic column;

Id and System indicate the same meaning. id does not seem intuitive. we need to specify the id to confirm the partition type when fdisk is a partition. for example, if the id is 7, NTFS is used; this must be specified through the t function in fdisk. The following parts will be mentioned;

Blocks; the value of a partition capacity comes from the following formula;

Blocks = (End value of the corresponding partition-Start value of the corresponding partition) capacity of x unit cylinder (magnetic column)

So let's calculate the size of the Blocks in hda1:

Hda1 Blocks = (765-1) x8225.280 = 6284113.92 K = 6284.113.92M

Note: The conversion unit is counted from the 10th digit provided by the hard disk manufacturer. if the unit is measured in binary format of the operating system, the partition capacity should be less, the obtained value is roughly the same as the value of/dev/hda1 we can see through fdisk-l. because the conversion method is different, it is impossible to be as accurate as possible; in addition, some loss occurs during partitioning, and sometimes large or small;

When we look at the partition size or file, we still use decimal to calculate it more intuitively. the calculation method is that byte pushes the three decimal places forward to K, and the value in K units pushes the three decimal places forward to M, M is pushed forward to the decimal point ...... ...... Generally, it cannot be much worse;

3. estimate whether a storage device is fully divided

To estimate whether a hard disk is fully divided, we only need to check whether the End of the last partition and the Start of the next partition are a continuous number in the cylinders (column) output by fdisk-l, in addition, let's take a look at the starting part of fdisk-l for each hard disk device and its cylinders value;

For example, for the hda device, we see 9729 cylinders. through the hda partition table, we can see that the End value of the previous partition + 1 is the Start value of the next partition; for example, the Start value of hda2 is the End value of hda1 + 1, which proves that there is no blank partition between hda1 and hda2, which is continuous, and so on; in hda10, we can see that the End value is 9729, and the fdisk-l header information also contains 9729 cylinders, which proves that the hard disk has been fully divided;

Disk/dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128*512 = 8257536 bytes
Device Boot Start End Blocks Id System
/Dev/sda1 1 25 201568 + c W95 FAT32 (LBA)
/Dev/sda2 26 125 806400 5 Extended
/Dev/sda5 26 50 201568 + 83 Linux
/Dev/sda6 51 76 200781 83 Linux

Let's see if the sda mobile storage is fully divided. sda has 125 cylinders (bars) and a primary partition and an extended partition. in the extended partition, we can see that the End value is 125, and the cylinder of the mobile hard disk is 125, which indicates that it is impossible to add any primary partition to the hard disk; according to the above-mentioned sda1 sda2 sda5 sda6, there is no undivided space between them, but the End value of cylinders (column) of sda6 is 76, while the total cylinders (column) of sda has 125, as a result, sda has unpartitioned areas behind sda6;

As to the number of unpartitioned spaces of sda, we will know it. The total capacity of the extended partition is 806400 K, which is about M, and the size of the logical partition sda5 and sda6 is about M, so there is still about MB of unpartitioned space, and can only be divided into chain logical partitions;

4. fdisk operations on hard disks and partitions go to the fdisk operation phase

We can partition the hard disk on the premise that you have understood fdisk-l; through fdisk-l, we can find the number of all hard disks and device names on the machine; for example, in the above example, we can see two devices:/dev/hda and/dev/sda;

The command format for fdisk hard disk operation is as follows:

[Root @ localhost beinan] # fdisk device

For example, we know the/dev/hda or/dev/sda device through fdisk-l. if we want to add or delete some partitions, we can use

[Root @ localhost beinan] # fdisk/dev/hda

Or

[Root @ localhost beinan] # fdisk/dev/sda

Note: In the following example, we will use the/dev/sda device as an example to explain how to use fdisk to add or delete partitions;

 

[NextPage]

 

1. description of fdisk;

When you access the corresponding device through the fdisk device, you will find the following prompt: Take the fdisk/dev/sda device as an example, the same as below;

[Root @ localhost beinan] # fdisk/dev/sda
Command (m for help): Press m here to output help;
Command action
A toggle a bootable flag
B edit bsd disklabel
C toggle the dos compatibility flag
D delete a partition note: this operation deletes a partition;
L list known partition types note: l lists the partition types for us to set the corresponding partition types;
M print this menu note: m lists help information;
N add a new partition note: add a partition;
O create a new empty DOS partition table
P print the partition table note: p lists partition tables;
Q quit without saving changes note: Do not save and exit;
S create a new empty Sun disklabel
T change a partitions s

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.