操作系统的存储管理

发布时间:2024年01月23日

一、文件系统概述

? 文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构;即在存储设备上组织文件的方法。操作系统中负责管理和存储文件信息的软件机构称为文件管理系统,简称文件系统。

二、常见的文件类型

注意:拷的文件比较大时,需要格式化为NTFS

三、系统交换分区

四、磁盘基础

4.1 Linux系统如何查看磁盘信息

[root@openEuler1 ~]# fdisk -l        #fdisk -l 命令用于查看系统所有的磁盘信息,包括已挂载和未挂载磁盘
Disk /dev/nvme0n1: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: VMware Virtual NVMe Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb6d0d4f5

Device         Boot   Start      End  Sectors Size Id Type
/dev/nvme0n1p1 *       2048  2099199  2097152   1G 83 Linux
/dev/nvme0n1p2      2099200 83886079 81786880  39G 8e Linux LVM


Disk /dev/mapper/openeuler-root: 35.07 GiB, 37656461312 bytes, 73547776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/openeuler-swap: 3.93 GiB, 4215275520 bytes, 8232960 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@openEuler1 ~]# df -h        #df -h 命令查看系统挂载、磁盘空间大小和利用率
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    4.0M     0  4.0M   0% /dev
tmpfs                       1.7G     0  1.7G   0% /dev/shm
tmpfs                       676M  9.0M  667M   2% /run
tmpfs                       4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/mapper/openeuler-root   35G  1.4G   32G   5% /
tmpfs                       1.7G     0  1.7G   0% /tmp
/dev/nvme0n1p1              974M  151M  756M  17% /boot

4.2 查看根分区剩余的百分比是多少

[root@openEuler1 ~]# df -h | awk '/\/$/ {print $5}'
5%
[root@openEuler1 ~]# df -h | awk '/\/$/ {print $(NF-1)}'
5%
[root@openEuler1 ~]# df -h | awk '/\/$/ {print 100-$(NF-1)}'
95
[root@openEuler1 ~]# df -h | awk '/\/$/ {print 100-$(NF-1), "%"}'
95 %

4.3 磁盘分区?

注意:一个硬盘只有一个扩展分区,除去主分区,其他空间都分配给扩展分区

①添加磁盘

②查看是否添加成功

[root@openEuler1 ~]# lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0                 11:0    1  3.5G  0 rom
nvme0n1            259:0    0   40G  0 disk
├─nvme0n1p1        259:1    0    1G  0 part /boot
└─nvme0n1p2        259:2    0   39G  0 part
  ├─openeuler-root 253:0    0 35.1G  0 lvm  /
  └─openeuler-swap 253:1    0  3.9G  0 lvm  [SWAP]
nvme0n2            259:3    0   20G  0 disk

③分区

[root@openEuler1 ~]# fdisk /dev/nvme0n2

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x545fe70a.

Command (m for help): m        #查看帮助手册        

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

Command (m for help): n    #创建分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):        #直接回车默认是主分区

Using default response p.
Partition number (1-4, default 1):        #直接回车默认编号为1
First sector (2048-41943039, default 2048):        #起始扇区可以直接回车
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): +1G        #创建主分区的大小  
                                                 
Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): p        #打印
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual NVMe Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x545fe70a

Device         Boot Start     End Sectors Size Id Type
/dev/nvme0n2p1       2048 2099199 2097152   1G 83 Linux

Command (m for help): n        #创建分区
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e        #创建扩展分区
Partition number (2-4, default 2):        #直接回车默认编号为2
First sector (2099200-41943039, default 2099200):        #起始扇区可以直接回车
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-41943039, default 4194303                                                                          9):        #直接回车,意味着将剩下的分区全部给扩展分区,但是扩展分区不能直接用,要用还要进一步划分逻辑分区

Created a new partition 2 of type 'Extended' and of size 19 GiB.

Command (m for help): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual NVMe Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x545fe70a

Device         Boot   Start      End  Sectors Size Id Type
/dev/nvme0n2p1         2048  2099199  2097152   1G 83 Linux
/dev/nvme0n2p2      2099200 41943039 39843840  19G  5 Extended

Command (m for help): n        #创建分区
All space for primary partitions is in use.
Adding logical partition 5        #逻辑分区编号从5开始
First sector (2101248-41943039, default 2101248):        #默认
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2101248-41943039, default 4194303                                                                          9): +1G        #1G大小

Created a new partition 5 of type 'Linux' and of size 1 GiB.

Command (m for help): p
Disk /dev/nvme0n2: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual NVMe Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x545fe70a

Device         Boot   Start      End  Sectors Size Id Type
/dev/nvme0n2p1         2048  2099199  2097152   1G 83 Linux
/dev/nvme0n2p2      2099200 41943039 39843840  19G  5 Extended
/dev/nvme0n2p5      2101248  4198399  2097152   1G 83 Linux

Command (m for help): w        #保存退出,分区完毕
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

?4.4 格式化分区

[root@openEuler1 ~]# mkfs.xfs /dev/nvme0n2p5
meta-data=/dev/nvme0n2p5         isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4.5 挂载

#配置开机自动挂载
[root@openEuler1 ~]# vim /etc/fstab

五、逻辑卷

5.1 逻辑卷概念

一般先PV再VG最后LV,格式化挂载后使用

文章来源:https://blog.csdn.net/2201_75581284/article/details/135787840
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。