Home  >  Article  >  System Tutorial  >  Master Linux must-learn commands: how to use fidsk and practical examples

Master Linux must-learn commands: how to use fidsk and practical examples

WBOY
WBOYOriginal
2024-06-12 19:02:411057browse

掌握 Linux 必学命令:fidsk 的使用方法及实例演示

Preface

Write an article to share with you a command that must be learned under Linux: fidsk

If you don’t have a Linux environment at hand, you can refer to my previous article: Oops, I suddenly want to get a Linux centos8 system to play with, what should I do?

Introduction

Linuxfdisk is a program that creates and maintains partition tables. It is compatible with DOS-type partition tables, BSD or SUN-type c drive lists.

Usually we use it to manage Linux c drive, partition View Linux 64-bit system, low format and other operations.

is one of the must-learn commands for contacting Linux.

Sentence pattern

fdisk [必要参数][选择参数]

Required parameters:

Select parameters:

Menu operation instructions

Running environment

Before demonstrating the example, let me explain that the environment I am running this time is CentOS864

Example demonstration

1. Display the current partition situation

The most commonly used one here is fdisk-l, as follows:

As you can see from the picture, I only have a c drive /dev/sdaView linux 64-bit system, the size is 20G. There are two partitions in this disk, namely /dev/sda1 and /dev/sda2, with sizes of 1G and 19G respectively, as well as other information such as starting point and sector.

The two /dev/mappers below the picture are logical volume devices. We will not discuss them in this chapter, just know that there is such a thing.

In addition, if there are multiple c drives, you can also use fdisk-l/dev/sda followed by the c drive name to view them individually.

Simply put, that’s all for viewing fdisk. In other words, it meets daily needs.

Let’s talk specifically about how to use fdisk to build a new partition and mount it to the directory.

fdisk build new partition

need:

Add a new hard drive and require building a new partition and mounting it to /root/study_video

accomplish:

1. Add c drive

If it is a cloud server, just go to the background and lower the c drive.

If it is a chemical server, shut down the server and power off, open the chassis, and lower the c drive.

查看linux操作系统位数_查看linux 64位系统_linux查看位置

I am using VMware here and it crashes first. Let me teach you a little method, you can use the command: shutdown-hnow to crash

linux查看位置_查看linux操作系统位数_查看linux 64位系统

After returning to VMware, you can see that it is also frozen here.

We double-click the c drive (SCSI) location in the picture on the right.

linux查看位置_查看linux 64位系统_查看linux操作系统位数

Click below to add a button

查看linux 64位系统_查看linux操作系统位数_linux查看位置

Select the c drive in the new panel that opens and click Next

查看linux 64位系统_查看linux操作系统位数_linux查看位置

Default, next step

linux查看位置_查看linux操作系统位数_查看linux 64位系统

Here you can choose to create the c drive mode, such as directly loading it using the one created before, or recreating it.

If not necessary, just continue with the default and next step.

linux查看位置_查看linux 64位系统_查看linux操作系统位数

Adjust the size, set other defaults, and continue to the next step (I have too few learning materials, so the capacity is set to 5G, you can use it as you like [silly laugh])

linux查看位置_查看linux 64位系统_查看linux操作系统位数

查看linux操作系统位数_查看linux 64位系统_linux查看位置

If there is no need to rename, just default and click Finish

查看linux 64位系统_查看linux操作系统位数_linux查看位置

Looking at the settings panel now, is there an extra hard drive?

ok, click OK to close the panel.

查看linux操作系统位数_查看linux 64位系统_linux查看位置

2. Create partition

Turn on the computer and connect to Xshell (if you don’t know how to connect, you can refer to my article: Let’s talk about the collision between VMware16’s centos8 and Win10’s Xshell).

Afterwards, fdisk-l is used again to view the c drive information. The results are as follows:

It is obvious that the new c drive has been downloaded successfully, and the partition operation is carried out below.

①After fdisk command + c drive device name

linux查看位置_查看linux 64位系统_查看linux操作系统位数

You can see the software prompts, pay attention to red hat linux, this is a high-risk operation. Be careful, careful, careful!

Enter m at this time to see the help information:

查看linux操作系统位数_linux查看位置_查看linux 64位系统

查看linux操作系统位数_查看linux 64位系统_linux查看位置

If you forget the specific command during temporary operation, you can check it at any time through this function.

Here we enter n to build a new partition:

查看linux 64位系统_linux查看位置_查看linux操作系统位数

Default directly and create a primary partition.

linux查看位置_查看linux操作系统位数_查看linux 64位系统

This is usually the direct default.

If you are interested in partitioning, you can refer to this article of mine: Briefly talk about the relationship and number restrictions between primary partitions/expanded partitions/logical partitions in Linux

After that comes the track settings. Here you will be asked to start and end, that is, select the capacity of the current partition. We directly default here, and the system will allocate all the capacity of the c drive to this partition.

Look, as shown in the picture above, the new partition has already been constructed.

Use the p command to query the newly built partition:

As you can see, /dev/sdb1 already exists. And you can't use it to check the disk space in Linux yet. At least before we mount it, we have to low-level it.

Enter w first to save changes:

linux查看位置_查看linux 64位系统_查看linux操作系统位数

After saving, you will find a prompt message, and then manually exit the operation command interactive mode.

After that, we use the mkfs command to low-format it, here it is formatted into an ext4 partition.

ok, partition construction and low formatting are completed. Next, mount to the directory.

Mount partition to directory

As mentioned in it, we need to mount this partition to the study material folder in the /home directory. Here we need to create the /home/study_video directory first, and then use the mount command to mount it.

Specific examples are as follows:

Get it done and call it a day!

Summarize

There are two functions of fdisk:

1. View the C drive overview

2. Operate the c drive, such as partition

Although it seems like a lot, it is not difficult after all. When you need to operate, just follow my steps one by one.

查看linux 64位系统_linux查看位置_查看linux操作系统位数

The above is the detailed content of Master Linux must-learn commands: how to use fidsk and practical examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn