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.
Fdisk-l viewing hard disk and partition information
The total number of primary partitions (including extended partitions) cannot be more than four, nor can the extended partition be surrounded by the primary partition; According to this principle, we divide the hard disk partition is more easy, but also can reduce unnecessary trouble in the future
1, through the fdisk-l to see the number of hard drive and partition of the machine
Fdisk-l
disk/dev/sda:18.9 GB, 18874368000 bytes
255 heads, Sectors/track, 2294 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk IDENTIFIER:0X0007AA11
Device Boot Start End Blocks Id System
/DEV/SDA1 * 1 2040 16382976 Linux
/dev/sda2 2040 2295 2048000, Linux Swap/solaris
Through the above information, we know that this machine mounts a hard drive (or a removable hard disk) SDA; if we want to see a single hard drive, it can be operated by Fdisk-l/DEV/HDA1 or fdisk-l/dev/sda1;
2, about fdisk-l Some values of the 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)
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): The meaning of the expression is indeed the meaning of the volume, 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 fully partitioned
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;
Fdisk operation of the hard disk and partition, enter FDISK on the hard drive 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:
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
Fdisk/dev/hda
Or
Fdisk/dev/sdb
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;
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 use, 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): 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 by using Fdisk's n command
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 add logical partitions.
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 by using 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 save exit
Command (M for help): W
Or
Command (M for help): Q
Format the partition, and load the
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 sdb1 for EXT4 file system, then input;
Mkfs.ext4/dev/sdb1
If I want to load sda1 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/DATA/BK;
Manual mount (System restart failure)
Mkdir/data/bk
Mount/dev/sda1/data/bk
Write Mount Table/etc/fstab
Check the UUID value of the SDB1 first
Execution: BLKID/DEV/SDB1
Display:/dev/sdb1:uuid= "0d5c78da-db47-48be-b9d5-d92444345b3c" type= "Ext4"
Vi/etc/fstab
Add the following line to permanently mount the
Uuid=0d5c78da-db47-48be-b9d5-d92444345b3c/data EXT4 Defaults 0 0
Requires a reboot to take effect
So we can get into the/DATA/BK directory and access the files.