68.Linux: Disk partitioning, mounting

table of Contents

One, linux partition

(1) Principle introduction

(2) Hard disk description

(3) View the mounting status of all devices

2. The whole process of mounting the partition (important)

(1) Add a hard disk to the virtual machine

(2) Partition the hard disk

(3) Format the newly added partition

(4) Mount the partition

(5) Cancel the association between the partition and the directory

(6) Permanently mount

Third, the disk situation query

(1) Query the overall disk usage of the system

(2) Query the disk occupancy of the specified directory

Fourth, the disk situation-work instructions

(1) Count the number of files in the /home folder

(2) Count the number of directories in the /home folder

(3) Count the number of files in the /home folder, including those in subfolders

(4) Count the number of directories in the /home folder, including those in subfolders

(5) Display the /home file structure as a tree


One, linux partition

(1) Principle introduction

Regardless of the number of partitions in Linux , which directory is allocated to, it is just a root directory in the final analysis , which is an independent and unique file structure. Each partition in Linux is used to form a part of the entire file system.

 

Linux uses a processing method called "loading" , which allows multiple partitions in the hard disk to correspond one-to-one with each file directory in the linux system.

Let's take a look at our own partition situation:

We mount one partition to the root directory, one partition to the boot directory, and one partition to the swap directory.

The so-called mount, take boot as an example, the contents of the boot directory will be recorded in this partition of the hard disk sda1. We set this partition size when we created the virtual machine. Do you remember?

 

(2) Hard disk description

Linux hard disks are divided into IDE hard disks and SCSI hard disks. At present, they are basically SCSI hard disks.

For IDE hard disks, the drive identifier is "hdx~", where "hd" represents the type of device where the partition is located, "x" represents the disk number, and "~" represents the partition.

For SCSI hard disks, the drive identifier is "sdx~", where "sd" represents the type of device where the partition is located, "x" represents the disk number, and "~" represents the partition.

Let's take a look at our screenshot above, we start with sd, which means it is a SCSI hard disk. a represents the plate number. 123 represents the partition.

 

(3) View the mounting status of all devices

lsblk 或者 lsblk -f

 

2. The whole process of mounting the partition (important)

(1) Add a hard disk to the virtual machine

Right-click the virtual machine and click Settings

Create a new hard disk:

(2) Partition the hard disk

Restart the virtual machine and reconnect:

At this point we see a hard disk, but it has not been partitioned yet.

Partition instructions:

fdisk /dev/sdb

After entering the command, it will display as follows:

After saving, there are partitions, but at this time we still need to format, because he does not have uuid yet:

(3) Format the newly added partition

#格式化磁盘
mkfs -t ext4 /dev/sdb1

注:其中ext4是分区类型

So far, we have formatted the partition

(4) Mount the partition

mount 分区 目录

We first create a directory, and then mount the partition to the newly created directory, you can see where I framed it: 

Then, we enter the newly created directory and create a new file. The file is actually saved in the new partition.

(5) Cancel the association between the partition and the directory

If the partitions on the hard disk do not want to bind to the previous directory, but want to bind to other directories, you need to cancel the association first. (Of course, the files saved during the association period will always exist)

#取消关联,这两者效果相同
umount 分区

#取消关联,这两者效果相同
umount 目录

Note: After mounting with the command line, after restarting the system, the mounting relationship disappears. In other words, their mounting relationship is temporary

(6) Permanently mount

Permanently mount by modifying /etc/fstab

#挂载完成后执行如下,实现永久挂载
mount -a

Let's modify the contents of fstab first:

 

If you remember uuid, you can write uuid through the following. If you can’t remember, you can mount it as follows:

Restart after completion:

 

Third, the disk situation query

(1) Query the overall disk usage of the system

df -h

 

(2) Query the disk occupancy of the specified directory

#默认查询当前目录
du [选项] /目录

-h:带计量单位
-s:制定目录占用大小汇总
-a:含文件
--max-depth=1:子目录深度
-c:列出明细的同时,增加汇总值

 

Fourth, the disk situation-work instructions

(1) Count the number of files in the /home folder

ls -l /home | grep "^-" | wc -l

(2) Count the number of directories in the /home folder

ls -l /home | grep "^d" |wc -l

(3) Count the number of files in the /home folder, including those in subfolders

ls -lR /home | grep "^-" | wc -l

(4) Count the number of directories in the /home folder, including those in subfolders

ls -lR /home | grep "^d" |wc -l

(5) Display the /home file structure as a tree

tree /home
#如果没有tree指令,先安装
yum install tree

 

Guess you like

Origin blog.csdn.net/qq_40594696/article/details/113986714