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

Introduction to partitioning, formatting and mounting of linux fdisk

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

Share

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

This article introduces the relevant knowledge of "introduction of linux fdisk partitioning, formatting and mounting". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

About hard disk partitions: primary partition (including extended partition), logical partition, up to 4 primary partition (including extended partition).

Therefore, when we partition the hard disk, it is best to divide the main partition continuously, for example: primary partition 1, main partition 2, extended partition.

This article takes the fdisk tool as an example to partition a hard disk.

1. Fdisk-l look at the hard disk on the system and find the hard disk that needs to be partitioned, for example: / dev/sdb.

Then, fdisk / dev/sdb

Access to the device. The following appears:

Command (m for help):

View help information: enter m and see the following information

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

Please read the meaning of each parameter carefully. What is commonly used is: d l m p q t w

2. List the partitions of the hard disk currently in operation, 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

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.

If it is the disk where the system is located, it will prompt to restart, and the restart will be OK. Then proceed to step 5.

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-t ext3-c / dev/sda6 specific parameter description, please man mkfs.

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

This is the end of the introduction to linux fdisk partitioning, formatting, and mounting. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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