The Linux fdisk command uses

Source: Internet
Author: User
Tags hex code

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:

[[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;

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
DDelete a partition note: This is the action of deleting a partition;
LList known partition types Note: L is a list of partition types for us to set the corresponding partition type;
mPrint this menu Note: M is a list of help information;
NAdd a new partition note: Adds a partition;
o Create a new empty DOS partition table
PPrint the partition table Note: P lists the partition table;
QQuit without saving changes Note: Do not save the exit;
s create a new empty Sun Disklabel
TChange a partition ' s system ID Note: T changes the partition type;
U Change display/entry units
V Verify the partition table
WWrite table to disk and exit Note: Write the partition table to the hard disk and exit;
xExtra 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;

lists the partitions of the current operating hard drive, using the 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

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!!! add a partition by using Fdisk's n instruction

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 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):

specifying a 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

Four, an example of adding a partition

In this example we will add two 200M primary partitions, the others are extended partitions, we add two 200M-size logical partitions in the extended 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, primary partition 1 start position, default is 1, default is good;
Using Default 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 don't forget W save exitformat the partition and load

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 get into the/mnt/sda6 directory and access the files.

The Linux fdisk command uses

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.