Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use llinux fdisk Partition tool

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the use of llinux fdisk partitioning tools". In daily operation, I believe many people have doubts about the use of llinux fdisk partitioning tools. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "the use of llinux fdisk partitioning tools". Next, please follow the editor to study!

I. introduction of fdisk

Fdisk-Partition table manipulator for Linux, translated into Chinese, means disk partition table operation tool; my translation is not very good, and I did not read the Chinese document; it is actually a partition tool; fdsik can divide a disk into several partitions, and at the same time, it can also specify a partition file system for each partition, such as linux, fat32, linux, linux swap, fat16 and file systems similar to Unix operating systems. Of course, when we use fdisk to partition the disk, it is not an end point, but we also need to format the file system needed for the partition; so that a partition can be used; this is similar to fdisk in DOS

Second, plan your hard disk partition reasonably

Before operating the partition, we need to understand a little theory of hard disk partition, such as the calculation of hard disk capacity and partition size; how to plan the partition of a hard disk, please refer to the following documents, thank you; "reasonable planning of your hard disk partition"

3. Fdisk-l to 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 surround the extended partitions between the main partitions; according to this principle, it is much easier for us to divide hard disk partitions; it can also reduce unnecessary trouble in the future.

1. Check the number of hard drives and partitions attached to the machine through fdisk-l

[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

From the above information, we know that two hard drives (or removable hard drives) are mounted in this machine, one of which is hda and the other is sda. If we want to check the condition of a single hard disk, we can operate it through fdisk-l / dev/hda1 or fdisk-l / dev/sda1; it is based on the hard disk ID of fdisk-l output. Hda has three primary partitions (including extended partitions), which are hda1 hda2 and hda3 (extended partitions). Logical partitions are hda5 to hda10

Sda has two primary partitions (including extended partitions), namely hda1 and hda2 (extended partitions); logical partitions are sda5 hda6; and total hard disk capacity = total capacity of primary partitions (including extended partitions)

Extended partition capacity = total logical partition capacity through the above example, we can know that hda=hda1+hda2+hda3, where hda3=hda5+hda6+hda7+hda8+hda9+hda10.

2. Explanation of some numerical values of fdisk-l

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 80g, with 255magnetic planes, 63 sectors, 9729 magnetic columns, and the capacity of each cylinder is 8225280 bytes=8225.280 K (approx.) = 8.225280m (approx.)

Partition sequence Boot starts terminating 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

Description: the representation of hard disk partition: in Linux, it is represented by hd*x or sd*x, where * represents a, b, c. The numbers 1, 2, 3 represented by x. Hd is mostly IDE hard disk; sd is mostly SCSI or removable storage.

Boot: indicates the boot partition. In the above example, hda1 is the boot partition.

Start (start): represents a partition that starts with X cylinder (magnetic column)

End (end): indicates a partition to the end of Y cylinder (magnetic column)

Id and System mean the same thing. Id doesn't look very intuitive. We need to confirm the partition type by specifying id when we fdisk a partition; for example, 7 means NTFS partition; this should be specified through the t function in fdisk. The following section will mention

Blocks (capacity): this is my translation, but it is not accurate. It does mean capacity, and its unit is K; the value of a partition capacity is derived from the following formula. Blocks= (corresponding partition End value-corresponding partition Start value) x unit cylinder (magnetic column) capacity, so let's calculate the Blocks size of hda1: hda1 Blocks= (765-1) x8225.2806284113.92 K = 6284.113.92m Note: the conversion unit is calculated from the decimal provided by the hard disk manufacturer, this partition capacity should be less in operating system binary terms. The resulting value is roughly the same as the value of / dev/hda1 we see through fdisk-l, because the conversion method is different, so it is impossible to be as accurate as possible. In addition, there is a little loss in partition, sometimes big or small; when we look at partition size or file, it is more intuitive to use decimal system to calculate; the method of calculation is that byte pushes forward three decimal places is K, and the value of K unit pushes forward three decimal places is M, M pushes forward three decimal places is G. ... It's usually not much different; that's all it takes.

3. Estimate whether a storage device is completely divided

We estimate whether a hard disk is completely partitioned. We only need to see whether the End of one partition and the Start of the next partition in the output of fdisk-l are a continuous number. In addition, we need to look at the beginning of fdisk-l of each hard disk device to see the value of his cylinders. For example, for hda devices, what we see is 9729 cylinders. We can see from the partition table of hda that the value of End of the previous partition + 1 is the value of Start of the next partition; for example, the value of Start of hda2 is the value of End of hda1, which proves that there is no blank partition between hda1 and hda2, which is continuous, and so on; in hda10, we see that the value of End is 9729, and there is also 9729 cylinders in the fdisk-l header information, which proves that the hard disk has been completely partitioned.

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 completely partitioned. Sda has 125 cylinders (columns), which is composed of a primary partition and an extended partition. In the extended partition, we see that the value of End is 125, and the cylinder of this mobile hard disk is 125, which means that it is impossible to add any more primary partitions to the hard disk. According to what we have mentioned above, there is no undivided space between sda1 sda2 sda5 sda6, but the end value of sda6's cylinders (cylinder) is 76, while the total cylinders of sda (cylinder) is 125. therefore, it seems that sda has undivided areas behind sda6. As for how much undivided space there is in sda, we will know by calculation. The total capacity of the extended partition is 806400 K, which is about 806.400m, while the logical partition sda5 and sda6 add up to about 400m, so there is still about 400m undivided space and can only be divided into chain logical partitions.

4. The operation of fdisk to hard disk and partition, enter the operation stage of fdisk to hard disk

We can partition the hard disk as long as you understand fdisk-l; through fdisk-l, we can find out the number of hard drives and device names in the machine; for example, in the example above, we will see two devices, one is / dev/hda, the other is / dev/sda

The command format for fdisk to operate the hard disk is as follows:

[root@localhost beinan] # fdisk device

For example, we know about / dev/hda or / dev/sda devices through fdisk-l; if we want to add or delete some more partitions, we can use

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

Or

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

Note in future examples, we will take the / dev/sda device as an example to show how to use fdisk to add, delete partitions, and so on.

1. Description of fdisk

When we enter the operation of the corresponding device through the fdisk device, we will find the following prompt; take the fdisk / dev/sda device as an example, the following is the same

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

Command (m for help): press m here and help will be output

Command action

A toggle a bootable flag

B edit bsd disklabel

C toggle the dos compatibility flag

D delete a partition Note: this is the action to delete a partition

L list known partition types Note: l lists the partition types so that we can set the corresponding partition type

M print this menu Note: M is to list 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 exit

S create a new empty Sun disklabel

T change a partition's system id Note: t change partition type

U change display/entry units

V verify the partition table

W write table to disk and exit note: write the partition table to the hard disk and exit

X extra functionality (experts only) Note: extended applications, expert functions

In fact, we only use Chinese notes, and we don't use other functions (Oh, mainly because I don't know how to use them, otherwise I would have shown it a long time ago); x extension functions are not commonly used; in general, as long as you know d l m p q t w; the following is detailed with examples, there is no way to do it, and beginners can't understand it.

2. List the partitions of the current operating hard disk, and use p

Command (m for help): P

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

3. Delete a partition through the d instruction of fdisk

Command (m for help): P Note: list the partitions

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

Command (m for help): d Note: delete partition assignment

Partition number (1-6): 6 Note: I want to delete sda6, just enter 6 here

Command (m for help): P Note: check the hard disk partition again to see if it has been deleted.

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

Command (m for help):

Warning: be careful when deleting partitions, please keep an eye on the sequence number of partitions. If you delete the extended partition, all logical partitions under the extended partition will be deleted; so be careful when operating; if you know that you have made a mistake, please do not panic. Do not save exit with Q; remember! When the partition operation is wrong, do not enter w to save exit!

4. Add a partition through the n instruction of fdisk

Command (m for help): P

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

Command (m for help): n Note: add a partition

Command action

L logical (5 or over) Note: add logical partition, the partition number should be greater than 5; why should it be greater than 5, because there is already sda5

P primary partition (1-4) Note: add a primary partition; the number is 1-4; but both sda1 and sda2 are occupied, so you can only start with 3.

P

Partition number (1-4): 3

No free sectors available Note: why did you fail when you failed?

Note: I tried to add a primary partition, which seems to have failed. Why did I fail? Because we see that the main partition + extended partition has used up the whole disk, look at the value of the End of the extended partition, and then look at the 125cylinders; in the p output information. It is better to look at the previous section; it is mentioned there; so we can only add logical partitions.

Command (m for help): n

Command action

L logical (5 or over)

P primary partition (1-4)

L Note: enter l here and you will enter the stage of logical partition.

First cylinder (51-125, default 51): note: this is the Start value of the partition. It is best to press enter directly here. If you enter a non-default number, it will cause a waste of space.

Using default value 51

Last cylinder or + size or + sizeM or + sizeK (51-125m, default 125m): + 200m Note: this defines the partition size. + 200m means the size is 200m. Of course, you can also calculate according to the size of the unit cylinder prompted by p, and then specify the value of End. Look back to see how it is calculated; or add it with the method of + 200m, which is more intuitive. If you want to add a partition of about 10G size, please enter + 10000m

Command (m for help):

5. Specify the partition type through the t instruction of fdisk

Command (m for help): t Note: specify the partition type through t

Partition number (1-6): 6 Note: which partition type should be changed? I designated 6, which is actually sda6.

Hex code (type L to list codes): l Note: enter L here to view the id of the partition type.

Hex code (type L to list codes): B Note: if I want this partition to be of type W95 FAT32, I can see from the L view that b means yes, so I enter b

Changed system type of partition 6 to b (W95 FAT32) Note: system information, changed successfully; whether it has changed, please check it with p

Command (m for help): P

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 75 201568 + b W95 FAT32

6. For fdisk exit, use Q or w

Where Q is not saved to exit, w is to save exit

Command (m for help): W

Or

Command (m for help): Q

7. an example of adding a partition

In this example, we will add two 200m primary partitions, the others are extended partitions, and we will add two 200m logical partitions to the extended partition.

Command (m for help): P Note: list partition tables

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

Command (m for help): n Note: add partition

Command action

E extended

P primary partition (1-4)

P Note: add primary partition

Partition number (1-4): 1 Note: add primary partition 1

First cylinder (1-125, default 1): note: enter directly, the starting position of main partition 1; default is 1, default is fine

Using default value 1

Last cylinder or + size or + sizeM or + sizeK (1-125m, default 125m): + 200m Note: specify the partition size, specify the size of 200m with + 200m

Command (m for help): n Note: add a new partition

Command action

E extended

P primary partition (1-4)

P Note: add primary partition

Partition number (1-4): 2 Note: add primary partition 2

First cylinder (26-125, default 26):

Using default value 26

Last cylinder or + size or + sizeM or + sizeK (26-125m, default 125m): + 200m Note: specify the partition size, specify the size of 200m with + 200m

Command (m for help): n

Command action

E extended

P primary partition (1-4)

E Note: add extended Partition

Partition number (1-4): 3 Note: specify 3, because the primary partition has already been divided into two, this is also the primary partition, starting from 3

First cylinder (51-125, default 51): note: enter directly

Using default value 51

Last cylinder or + size or + sizeM or + sizeK (51-125, default 125): note: enter directly and assign all the remaining space to the extended partition.

Using default value 125

Command (m for help): P

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 + 83 Linux

/ dev/sda2 26 50 201600 83 Linux

/ dev/sda3 51 125 604800 5 Extended

Command (m for help): n

Command action

L logical (5 or over)

P primary partition (1-4)

L note: add logical partitions

First cylinder (51-125, default 51):

Using default value 51

Last cylinder or + size or + sizeM or + sizeK (51-125m, default 125m): + 200m Note: add a partition of 200m size

Command (m for help): n

Command action

L logical (5 or over)

P primary partition (1-4)

L note: add a logical partition

First cylinder (76-125, default 76):

Using default value 76

Last cylinder or + size or + sizeM or + sizeK (76-125m, default 125m): + 200m Note: add a partition of 200m size

Command (m for help): P lists partition tables

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 + 83 Linux

/ dev/sda2 26 50 201600 83 Linux

/ dev/sda3 51 125 604800 5 Extended

/ dev/sda5 51 75 201568 + 83 Linux

/ dev/sda6 76 100 201568 + 83 Linux

Then we change the partition type through the t instruction as mentioned earlier; finally, don't forget to save and exit.

Fifth, format the partition and load

First prompt; use commands such as mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs to format partitions. For example, if I want to format sda6 to the ext3 file system, type

[root@localhost beinan] # mkfs.ext3 / dev/sda6

If I want to load sda6 into the current system to access files, there should be a mount command, but first you have to create a mount directory; for example, / mnt/sda6

[root@localhost beinan] # mkdir / mnt/sda6

[root@localhost beinan] # mount / dev/sda6 / mnt/sda6

[root@localhost beinan] # df-lh

Filesystem capacity used available used mount point

/ dev/hda8 11G 8.4G 2.0G 81% /

/ dev/shm 236M 0 236m 0% / dev/shm

/ dev/hda10 16G 6.9G 8.3G 46% / mnt/hda10

/ dev/sda6 191M 5.6m 176m 4% / mnt/sda6

So we can go to the / mnt/sda6 directory and access the files.

At this point, the study on "how to use the llinux fdisk Partition tool" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report