How to use Fdisk in Linux systems

Source: Internet
Author: User

Fdsik partitions can be divided into several areas, but also for each partition to specify the partition of the file system, such as Linux, FAT32, Linux, Linux swap, FAT16 and its UNIX-like operating system file system, etc. of course, when we use FDISK to partition disk operations, is not an end point, we also need to format the partition of the file system required to use such a partition; This is similar to Fdisk in DOS.


The Fdisk feature under Linux is extremely powerful, and it can be used to divide the most complex partitions, with a brief introduction to its usage:

For IDE hard disks, each disk has a device name: Four IDE interfaces corresponding to the motherboard, and the device name is:/DEV/HDA,/DEV/HDB,/DEV/HDC,/DEV/HDD, etc.

If there are also IDE raid cards, then:/DEV/HDE,/DEV/HDF,/DEV/HDG,/DEV/HDH.

For SCSI hard drives, the device name is/DEV/SDA,/DEV/SDB ... Wait a minute

The command line usage for FDISK is: Fdisk hard drive device name

When you enter Fdisk, you first type ' m ' to display the Fdisk full menu.

And then type ' P ' to display the current partitioned table status.

Type ' n ', add a partition, and then prompt you to select the partition type (Basic or Extended), and then select the partition number (1-4).

Note: Each hard disk can be divided into up to four primary partitions (including basic and extended partitions).

Where: The basic partition can be divided up to four, the extended partition can be divided into one, but the extended partition can be divided into multiple logical partitions (up to a few I have not tried, in short, a lot).

Select the type of partition you want to create and the partition number, you will be prompted to enter the starting cylinder, starting from 1;

Then enter the end of the cylinder, you can enter the actual number of cylinders, but also can be "+ partition size" of the way to enter, such as: +1024m in the beginning of the cylinder after the addition of 1024M.

The device name for the primary partition is:/DEV/HDA1,/DEV/HDA2,/DEV/HDA3,/DEV/HDA4, and the logical partition's device name is:/dev/hda5,/dev/hda6,/dev/hda7 ... Wait a minute.

Type ' d ', delete the partition, and enter the partition number to remove it. Note that when you delete an extended partition, all logical partitions are deleted at the same time.

Type ' t ' to change the partition flag (this is the most essential part of Linux's Fdisk!)., the new partition default flag is EXT2 (Linux), which you can change to either the (Linux swap), or ' B ' (FAT32), ' F ' (FAT32 Extend, limited to extended partitions), ' 86′ (NTFS) ... And so on dozens of kinds of types.

This way, friends with multiple operating systems can use the Linux fdisk to divide all the partitions you want!

Type ' a ' to toggle the partition activation switch. Note: Each time you type, the selected partition changes between activation and deactivation, but you must ensure that only one partition is activated at the end. Then the ' P ' command is used, and the activated partition will have a ' * ' number.

In addition to the above several commands, there are several others, but not too often.

Finally, type ' W ', and the changes you make to the partition are written to the hard disk; type ' Q ' to discard all changes.

With the flexibility to use Fdisk, you can also fix some corrupted partition tables, provided you have an accurate memory of the initial and terminating cylinders for each partition.

Then attach a way to format the hard disk: To format the partition into a Linux Ext2 format, using: Mkext2fs/dev/hda? To format the partition into FAT32 format, use: Mkfs.vfat/dev/hda?

1, through the fdisk-l view machine situation;

Number of hard drives and partitions

[Root@localhost beinan]# Fdisk-l
disk/dev/hda:80.0 gb,80026361856bytes
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
/dev/hda2 766 2805 16386300 C W95 FAT32 (LBA)
/dev/hda3 2806 9729 55617030 5 Extended
/dev/hda5 2806 3825 8193118+ Linux
/dev/hda6 3826 5100 10241406 Linux
/dev/hda7 5101 5198 787153+ Linux Swap/solaris
/dev/hda8 5199 6657 11719386 Linux
/DEV/HDA9 6658 7751 8787523+ Linux
/DEV/HDA10 7752 9729 15888253+ Linux
disk/dev/sda:1035 MB, 1035730944 bytes
256 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 Wuyi 200781 Linux
With the information above, we know that two hard drives (or mobile drives) are mounted in this machine, 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 ID of the output is HDA, where there are three primary partitions (including extended partitions), primary partitions hda1 Hda2 and Hda3 (extended partitions), and logical partitions HDA5 to HDA10;
The SDA has two primary partitions (including extended partitions), SDA1 and Sda2 (extended partitions), logical partitions SDA5 HDA6, hard disk Total capacity = Total capacity of primary partitions (including extended partitions)
Extended partition capacity = logical partition Total capacity through the above example, we can learn Hda=hda1+hda2+hda3, where hda3=hda5+hda6+hda7+hda8+hda9+hda10 ...

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.