This is the 9th day of my participation in Gwen Challenge

This article will discuss the use of the fdisk command, using fdisk can do partition management.

1. Command Overview:

Fdisk Is the most commonly used partition tool in Linux distributions. Usage: fdisk [Option] Device Common option: -l View the disk partition table

2. Partition experiment

Procedure: 1) Add a hard disk to the VM

  1. Use fdisk to partition the newly added hard disk

3) Format the partition for it to take effect

4) Mount partitions

Next, follow me step by step to learn:

1) Add a hard disk to the VM

Select the hard drive and click “Add” as shown in the picture: Select the hard drive and click “Add” below to add a hard drive:

Open the Add Hardware wizard: select the first hard drive and click Next

Select the recommended SCSI and click Next:

Here, we select create a new disk and click Next:

The maximum disk capacity is 20G. Note that:

If possible, do not choose the first option and use all disk space immediately. What this means is that the 20 GB disk capacity you allocate will immediately take up your hard disk capacity.

The following two items are the disk space that can be increased

That is, when you install the disk, it is 8 GB, it takes up 8 GB of disk space, and if it increases later, it will increase a little bit, it will not take up 20 GB of disk space immediately after installing the disk.

Select the default and click Finish

After adding the hard disk, you can see the new hard disk

Then start the VM:

Note when starting up whether your ISO image is mounted, as shown in the following figure:

2) Use fdisk to partition

What are the current partitions?You can see our new hard disk SDB, which is now partitioned

A) Use command partition

B) Enter m to view help. Let’s see what options are available for help:

Let’s take the meaning of each line argument separately:

C) Meaning of each line parameter:
parameter meaning
b edit bsd disklabel Edit the BSD disk label
c toggle the dos compatibility flag Toggle DOS compatibility flags
d delete a partition Deleted partitions
g create a new empty GPT partition table Create a new empty GPT partition table
G create an IRIX (SGI) partition table Create the IRIX(SGI) partition table
l list known partition types Display partition type
m print this menu Print help menu
n add a new partition Adding a new partition
o create a new empty DOS partition table Create a new empty DOS partition table
p print the partition table Display partition table
q quit without saving changes If no, exit
s create a new empty Sun disklabel Create a new empty Sun disk label
t change a partition’s system id Changing the partition type
u change display/entry units Change the display/input unit
v verify the partition table Verify partition table
w write table to disk and exit Write partition table information to hard disk, save operation and exit
x extra functionality (experts only) Additional features (experts only)
D) Create a partition, so type n to create a partition

Note: The extended primary partition(1-4) is generally a maximum of four primary partitions, and multiple logical partitions can be created.

However, if the primary partition is divided into four, the logical partition cannot be divided. We usually have three primary partitions and the rest are logical partitions

Here is the first fast hard disk, so directly select the primary partition can be:

E) Create a primary partition

Now that we have returned to the original position, we want to check the current partition status:

F) P Display partition information

G) After splitting, we save and exit W

Now that we have finished partitioning, we can check:

3) Let the new partition take effect

There are two ways to make a partition work: restart it or get a new partition table. The command used to get the new partition table is partx

[root@gaosh-1 ~]# partx -a /dev/sdb

4) Mount and use the new partition
A) Format partitions
[root@gaosh-1 ~]# mkfs.ext4 /dev/sdb1Mke2fs 1.41.12 (17-May-2010) File system label = OS :Linux block size =4096 (log=2) Block size =4096 (logStride=0 blocks, width=0 blocks 328656 inodes, 1313305 blocks 65665 blocks (5.00%) ReservedforThe super user =0 Maximum filesystem blocks=1346371584Copy the code

Note: To format to ext4, use the command mkfs.ext4. To format to an XFS system, use mkfs.xfs

B) Create and mount a mount directory

C) At this point, we can enter the new partition operation

Note: Enter the new partition from the mount directory, not from /dev/sdb1.

3. Other uses of fdisk

a) fdisk -l

Run the fdisk -l command to view the number and partitions of hard disks

As you can see in the figure above, the disk is 21.5 gigabytes, actually 20 gigabytes, with 255 magnetic faces, 63 sectors, and 2610 magnetic columns. Each magnetic column has a capacity of 8225280 bytes.

Conclusion:

So far, we have covered the usage of fdisk. This article covers disk-related information, such as the concepts of magnetic heads, magnetic columns, and sectors, which I will cover in a separate chapter later.

I am Internet old xin, Linux from bronze to king of the road, continue to update