Linux_fdisk command Detail, about the division of the detailed

Source: Internet
Author: User
Tags hex code

This article is written in very detailed, particularly good

Fdisk-l
You can list all partitions, including partitions and USB devices that are not hung. I usually use this to find the location of the partitions that need to be mounted, such as hanging a U-disk.
Example of how to use Fdisk partitioning in Linux: http://linux.chinaitlab.com/set/39459.html
Note: fdisk-l lists all the partitions
First, the introduction of Fdisk;
Fdisk-partition table manipulator for Linux, translated into Chinese means the Disk partition table Operation tool, I translated not very good, also did not read the Chinese document; in fact, the partitioning tool;
Fdsik can partition the disk into several zones, but also can specify partitions for each partition of the file system, such as Linux, FAT32, Linux, Linux swap, FAT16 and in fact, Unix-like operating system of the file system, etc., of course, when we use Fdisk partition disk operations , is not an end point, we also need to format the partition of the required file system, such a partition to use; This is similar to Fdisk in DOS;
Note: Use the Fdisk tool to make a logical partition of a physical hard disk first. The logical partition is then assigned the appropriate file system. Such partitions are only available for use. Gee, I'll tell you what the filesystem is after I use the DF command.
Second, reasonable planning of your hard disk partition;
Before operating the partition, we must understand the hard disk partition theory, such as hard disk capacity and partition size calculation, for a hard disk how to plan partition, etc., please refer to the following documents, thank you;
"Reasonable planning your hard disk partition"-------deep feeling!
Third, fdisk-l view hard disk and partition information;
Through the rational planning of your hard disk partition, we know that the total number of primary partitions (including extended partitions) can not exceed four, nor can the extended partition be surrounded by the main partition, according to this principle, we divide the hard disk partition is more easy, but also for the future to reduce unnecessary trouble;
1, through the fdisk-l to see the number of hard disk and partition of the machine;
[Email protected] beinan]# fdisk-l
The following is the first hard disk that is HDA
disk/dev/hda:80.0 GB, 80026361856 bytes
255 heads, Sectors/track, 9729 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Device Boot Start End Blocks Id System
/DEV/HDA1 * 1 765 6144831 7 Hpfs/ntfs Primary partition
/dev/hda2 766 2805 16386300 C W95 FAT32 (LBA) Primary partition
/dev/hda3 2806 9729 55617030 5 Extended Extended partition
/dev/hda5 2806 3825 8193118+ the Linux logical partition
/dev/hda6 3826 5100 10241406 the Linux logical partition
/DEV/HDA7 5101 5198 787153+ the Linux swap/solaris logical partition
/dev/hda8 5199 6657 11719386 the Linux logical partition
/DEV/HDA9 6658 7751 8787523+ the Linux logical partition
/DEV/HDA10 7752 9729 15888253+ the Linux logical partition
The following is an indication of the second hard drive SDA
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA) Primary partition
/dev/sda2 806400 5 Extended Extended partition
/dev/sda5 201568+ Linux
/dev/sda6 200781 Linux
With the information above, we know that this machine mounts two hard drives (or removable hard disks), one of which is HDA and the other is SDA; if we want to see a single hard drive, we can do it by fdisk-l/dev/hda1 or fdisk-l/dev/sda1; fdisk-l The hard drive identification of the output is accurate;
HDA has three primary partitions (including extended partitions), the primary partition hda1 Hda2 and Hda3 (extended partition), and the logical partition is HDA5 to hda10;
SDA has two primary partitions (including extended partitions), respectively hda1 and HDA2 (extended partition); logical partition is SDA5 Hda6;
Total hard disk capacity = Total capacity of primary partition (including extended partition)
Extended partition capacity = Total logical partition capacity
Through the above example, we can learn that Hda=hda1+hda2+hda3, which hda3=hda5+hda6+hda7+hda8+hda9+hda10 ...
What is the role of logical partitioning?
2, about the fdisk-l some numerical description;
disk/dev/hda:80.0 GB, 80026361856 bytes
255 heads, Sectors/track, 9729 cylinders
Units = Cylinders of 16065 * 8225280 bytes
This hard drive is 80G, has 255 magnetic surface, 63 sectors, 9,729 magnetic columns, each cylinder (magnetic column) capacity is 8225280 bytes=8225.280 K (about) =8.225280m (about); partition sequence boot start 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+-up Linux
/dev/hda6 3826 5100 10241406-Up Linux
/dev/hda7 5101 5198 787153+, Linux Swap/solaris
/dev/hda8 5199 6657 11719386-up Linux
/DEV/HDA9 6658 7751 8787523+-up Linux
/DEV/HDA10 7752 9729 15888253+-up Linux
Description
The representation of a hard disk partition: In Linux is represented by hd*x or sd*x, where * denotes a, B, c .... The number 1, 2, 3 ... x indicates that the HD is mostly IDE hard disk; SD is mostly SCSI or removable storage;;;
Boot: Represents the boot partition, in the example above hda1 is the boot partition;
Start (start): Represents a partition starting from X cylinder (magnetic column);
End: Represents the end of a partition to Y cylinder (magnetic column);
The ID and system represent a meaning, the ID looks less intuitive, we want to specify the ID to confirm the partition type when fdisk a partition, such as 7 for NTFS partition; This is specified by the T function in Fdisk. The following section will refer to;
Blocks (capacity): This is my translation, in fact, not accurate, meaning is indeed the meaning of capacity, 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 count the size of the HDA1 Blocks:
HDA1 blocks= (765-1) x8225.280=6284113.92 K = 6284.113.92M
Note: The conversion unit from the hard disk manufacturers to provide 10 of the calculation, if the operating system binary to calculate, this partition capacity should be less, this value and we see through the fdisk-l/dev/hda1 value is roughly equivalent, because the conversion method is not the same, so it is impossible to be as accurate as possible , plus a bit of loss in partitioning, sometimes large or small, is present;
We look at the size of the partition or file, or use the decimal to calculate the more intuitive, the calculation method is a byte forward to push the decimal point three is K, the value of K-unit forward push the decimal point three is m,m forward to push the decimal point three is g ... Generally not much, so the count is OK;
3, estimate whether a storage device is completely divided;
We estimate whether a hard disk is completely divided, we just look at the contents of the fdisk-l output of cylinders (cylinder) The end of the previous partition and the next partition start is not a continuous number, in addition to look at the beginning of the fdisk-l of each hard disk device, Look at the value of his cylinders (cylinder);
For example, the HDA device, we see is 9729 cylinders; we can see that the value of end of the previous partition is +1 of the start value of the next partition through HDA's partition table, i.e. the value of Hda2 start is the value of HDA1 end +1, which proves that HDA1 and HD There is no blank partition in the middle of the A2, it is continuous, and so on; in hda10, we see that the value of End is 9729, and there is 9729 cylinders in fdisk-l header information, proving that the hard disk has been completely partitioned;
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
/dev/sda6 200781 Linux
Let's look at the SDA mobile storage is not completely divided, SDA has 125 cylinders (cylinder), there is a primary partition and an extended partition structure, in the extended partition, we see the value of end is 125, and this mobile hard disk cylinder is 125, This means that the hard drive cannot add any more primary partitions, and according to what we said above, there is no space between the sda1 sda2 Sda5 Sda6, but Sda6 's cylinders (cylinder) End value is 76, and SDA total cylinders (cylinder) has 125 , it appears that SDA has an sda6 in the back of the area;
As for the number of SDA there is no space, we know that the total capacity of the extended partition is 806400 K, about 806.400M, and the logical partition SDA5 and sda6 the size of the added up is about 400M, so there is still no space around 400M, And can only be divided into chain logical partition;
Four, fdisk on the hard disk and partition operation, into FDISK on the hard disk operation phase;
We can partition the hard drive, if you understand the fdisk-l; through fdisk-l, we can find out the number of drives and the name of the device, such as the above example, we will see two devices one is/dev/hda, the other is/DEV/SDA;
The command format for Fdisk to manipulate the hard disk is as follows:
[[email protected] beinan]# fdisk device
For example, we know through fdisk-l/dev/hda or/DEV/SDA device; If we want to add or delete some partitions, we can use
[Email protected] beinan]# Fdisk/dev/hda
Or
[Email protected] beinan]# FDISK/DEV/SDA
Note In the future example, we should take the/DEV/SDA equipment as an example, to explain how to use Fdisk to manipulate the addition, delete the partition and other actions;
1, the description of Fdisk;
When we go through the FDISK device, into the operation of the corresponding device, we will find the following prompt, taking FDISK/DEV/SDA equipment as an example to the same;
[Email protected] beinan]# FDISK/DEV/SDA
Command (M for help): pressing m here will output the aid;
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 of deleting a partition;
L list Known partition types Note: L is a list of partition types for us to set the corresponding partition type;
M Print this menu note: M is a list of 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 the partition table;
Q Quit without saving changes Note: Do not save the exit;
s create a new empty Sun Disklabel
t change a partition ' s system ID Note: T changes the 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 application, expert function;
In fact, we commonly use only the note has the Chinese, other functions we do not commonly used (ah, mainly I will not use, otherwise will show off); X expansion function, is not commonly used, in general, as long as the understanding of D l m p Q t w on the line;
The following example operation to detail, no examples no way, novice also can not understand;
2, list the current operation of the partition of the hard disk, with P;
Command (M for help): P
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
/dev/sda6 200781 Linux
3. Delete a partition by using the D command of Fdisk;
Command (M for help): P Note: Lists the partitioning situation;
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
/dev/sda6 200781 Linux
Command (M for help): D Note: perform delete partition designation;
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 was deleted?
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
Command (M for help):
Caution: Be careful when deleting partitions, please watch the serial number of the partition, if you delete the extended partition, the logical partition under the extended partition will be deleted; If you know that you are wrong, please do not panic, do not use Q to save the exit; Remember! When the partition operation is wrong, do not enter W Save exit!!!
4. Add a partition via the n command of Fdisk;
Command (M for help): P
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
Command (M for help): N Note: add a partition;
Command Action
L logical (5 or over) Note: Increase the logical partition, the partition number is greater than 5, why is greater than 5, because there are already sda5;
P primary partition (1-4) Note: Add a primary partition, numbering from 1-4, but sda1 and sda2 are occupied, so only starting from 3;
P
Partition number (1-4): 3
No Free Sectors Available Note: Why failed in the failure?
Note: I tried to add a primary partition, which seems to be a failure, why failed? Because we see the main partition + extended partition of the entire disk is exhausted, look at the value of the end of the extended partition, and then see the P output message has the cylinders; it's better to look at the front part;
So we can only increase the logical partition;
Command (M for help): N
Command Action
L logical (5 or over)
P primary partition (1-4)
L Note: Enter the "L" here, enter the division of logical partition stage;
First cylinder (51-125, default 51): Note: This is the start value of the partition, it is best to press ENTER directly, if you enter a non-default number, will cause space waste;
Using Default Value 51
Last cylinder or +size or +sizem or +sizek (51-125, default): +200m Note: This is the definition of partition size, +200m is the size of 200M, of course, you can also according to the unit of P prompt Cylind The size of the ER to calculate, and then to specify the value of end. Look back to see how it is, or use +200m this method to add, this can be intuitive. If you want to add a 10G or so size partition, 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 by T;
Partition number (1-6): 6 Note: Which partition type do you want to change? I've assigned 6, which is actually sda6.
Hex code (Type L to list codes): L Note: Enter the L here to see the ID of the partition type;
Hex code (type L to list codes): B Note: If I want this partition to be W95 FAT32 type, by L view I know B is, so I entered B;
Changed system type of partition 6 to B (W95 FAT32) Note: Systematic information, change success, whether it is changed, please use P to view;
Command (M for help): P
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ C W95 FAT32 (LBA)
/dev/sda2 806400 5 Extended
/dev/sda5 201568+ Linux
/dev/sda6 201568+ b W95 FAT32
6, the exit of Fdisk, with Q or W;
Where q is not saved exit, W is saved to 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 partition, the other is extended partition, in the extended partition we add two 200M size logical partition;
Command (M for help): P Note: Lists the partition table;
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 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: Direct carriage return, starting position of primary partition 1; default is 1, default is good; Using defaults value 1
Last cylinder or +size or +sizem or +sizek (1-125, default): +200m Note: Specify the partition size and +200m to specify a size of 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-125, default): +200m Note: Specify the partition size and +200m to specify a size of 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: specified as 3, because the primary partition has been divided by two, this is also the primary partition, starting from 3;
First cylinder (51-125, default 51): Note: direct carriage return;
Using Default Value 51
Last cylinder or +size or +sizem or +sizek (51-125, default 125): Note: Direct carriage return, all the rest of the space to the extended partition;
Using Default Value 125
Command (M for help): P
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ Linux
/dev/sda2 201600 Linux
/dev/sda3 604800 5 Extended
Command (M for help): N
Command Action
L logical (5 or over)
P primary partition (1-4)
L Note: Add logical partition;
First cylinder (51-125, default 51):
Using Default Value 51
Last cylinder or +size or +sizem or +sizek (51-125, default): +200m Note: Add a partition with a size of 200M;
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-125, default): +200m Note: Add a partition with a size of 200M;
Command (M for help): p lists the partition table;
disk/dev/sda:1035 MB, 1035730944 bytes
Heads, Sectors/track, cylinders
Units = Cylinders of 16128 * 8257536 bytes
Device Boot Start End Blocks Id System
/DEV/SDA1 1 201568+ Linux
/dev/sda2 201600 Linux
/dev/sda3 604800 5 Extended
/dev/sda5 201568+ Linux
/dev/sda6 201568+ Linux
Then we change the partition type by the T-command according to the previous.
Finally do not forget w save exit;
The partition is formatted and loaded;
First hint; with Mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 Mkfs.minix mkfs.reiserfs mkfs.xfs such as the command to format the partition, such as I want to format Sda6 for ext3 file system, then input;
[Email protected] beinan]# Mkfs.ext3/dev/sda6
If I want to load Sda6 to the current system to access the file, there should be a mount command, but first you have to build a mount directory, such as/mnt/sda6;
[Email protected] beinan]# Mkdir/mnt/sda6
[Email protected] beinan]# Mount/dev/sda6/mnt/sda6
[Email protected] beinan]# DF-LH
Filesystem capacity used% mount point available
/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 into the/mnt/sda6 directory and then access the file;
Specific permission methods, as well as more detailed usage of mount, in the future I will write a special post; it's a bit embarrassing to drop all the content in one.

Linux_fdisk command Detail, about the division of the detailed

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.