赞
踩
目录
(1)是传统的分区机制,使用BIOS引导PC设备,寻址空间只有 32bit,分区空间最大支持2.2TB
支持的分区数量: 4个主分区或者3个主分区1个扩展分区(分区表占据64个字节,其中每个分区的信息占用16个字节,分区表里面可以记录四个分区信 息描述)
(2)MBR分区类型:
主分区(primary partition)(系统分区)
用来启动操作系统,必须是主分区
一块硬盘最多4个主分区或3主分区+1扩展分区(含多个逻辑分区),主分区不可以再进行二次分区。
主分区可以直接建立文件系统,存放数据
可以用来引导、启动操作系统
扩展分区(extended partition)(活动分区)
一块硬盘最多一个扩展分区,加主分区最多4个
不能创建文件系统
可以划分多个逻辑分区
逻辑分区(logical partition)(启动分区)
安装操作系统的分区,可以是主分区也可以是逻辑分区
能创建文件系统,存放数据
逻辑分区的数量没有限制
(1)全局唯一标识分区表)是一种比MBR分区更先进、更灵活的磁盘分区模式
(2)GPT分区优点:
在默认情况下,GPT最多可支持128个分区
支持大于2.2TB的总容量及大于2.2TB的分区,最大支持
18EB(1EB=1024PB,1PB=1024TB,1TB=1024GB)
GPT分区表自带备份
向后兼容MBR ,GPT分区表上包含保护性的MBR
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom #光盘
- /run/media/root/RHEL-9-1-0-BaseOS-x86_64
- nvme0n1 259:0 0 50G 0 disk #nvme类型硬盘
- ├─nvme0n1p1 259:1 0 1G 0 part /boot #主分区1
- └─nvme0n1p2 259:2 0 49G 0 part #主分区2
- ├─rhel-root 253:0 0 44G 0 lvm / #主分区2的第一个逻辑分区
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP] #主分区2的第二个逻辑分区
虚拟机关机状态,设置虚拟机,添加磁盘设备,设置大小,确定保存,开机查看
添加完20G之后必须要确定虚拟机主页出现新磁盘信息
开机查看磁盘信息
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
创建主分区
- [root@SLB ~]# fdisk /dev/nvme0n2
-
- Welcome to fdisk (util-linux 2.37.4).
- 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 0x6ee58e65.
-
-
- Command (m for help): n
- Partition type
- p primary (0 primary, 0 extended, 4 free)
- e extended (container for logical partitions)
- Select (default p): 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): +5G
- #指定分配大小
- Created a new partition 1 of type 'Linux' and of size 5 GiB.
-
- Command (m for help): n
- Partition type
- p primary (1 primary, 0 extended, 3 free)
- e extended (container for logical partitions)
- Select (default p): p
- Partition number (2-4, default 2): 2
- First sector (10487808-41943039, default 10487808):
- Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-41943039, default 41943039): +5G
-
- Created a new partition 2 of type 'Linux' and of size 5 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: 0x6ee58e65
-
- Device Boot Start End Sectors Size Id Type
- /dev/nvme0n2p1 2048 10487807 10485760 5G 83 Linux
- /dev/nvme0n2p2 10487808 20973567 10485760 5G 83 Linux
-
- Command (m for help): n
- Partition type
- p primary (2 primary, 0 extended, 2 free)
- e extended (container for logical partitions)
- Select (default p): p
- Partition number (3,4, default 3): 3
- First sector (20973568-41943039, default 20973568):
- Last sector, +/-sectors or +/-size{K,M,G,T,P} (20973568-41943039, default 41943039): +5G
-
- Created a new partition 3 of type 'Linux' and of size 5 GiB.
-
- Command (m for help): n
- Partition type
- p primary (3 primary, 0 extended, 1 free)
- e extended (container for logical partitions)
- Select (default e): e #创建扩展分区
-
- Selected partition 4
- First sector (31459328-41943039, default 31459328):
- Last sector, +/-sectors or +/-size{K,M,G,T,P} (31459328-41943039, default 41943039):
- #不填写默认就将剩余空间都分配给它
- Created a new partition 4 of type 'Extended' and of size 5 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: 0x6ee58e65
-
- Device Boot Start End Sectors Size Id Type
- /dev/nvme0n2p1 2048 10487807 10485760 5G 83 Linux
- /dev/nvme0n2p2 10487808 20973567 10485760 5G 83 Linux
- /dev/nvme0n2p3 20973568 31459327 10485760 5G 83 Linux
- /dev/nvme0n2p4 31459328 41943039 10483712 5G 5 Extended
-
- Command (m for help): w #保存退出
- The partition table has been altered.
- Calling ioctl() to re-read partition table.
- Syncing disks.
-
- [root@SLB ~]#
部分参数
指令 | 作用 |
a | 调整磁盘的启动分区 |
d | 删除磁盘分区 |
l | 显示所有支持的分区类型 |
m | 查看所有指令的帮助信息 |
q | 不保存更改,退出fdisk命令 |
g | 新建一个空的GPT分区表 |
p | 显示当前磁盘的分区信息 |
t | 更改分区类型 |
u | 切换所显示的分区大小单位 |
n | 创建新分区 |
w | 把修改写入磁盘分区表,然后退出fdisk命令 |
o | 新建一个空的DOS分区表 |
在上面的基础上再加两块磁盘
查看磁盘信息
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- nvme0n4 259:9 0 10G 0 disk
使用gdisk创建分区
- [root@SLB ~]# gdisk /dev/nvme0n3
- GPT fdisk (gdisk) version 1.0.7
-
- Partition table scan:
- MBR: not present
- BSD: not present
- APM: not present
- GPT: not present
-
- Creating new GPT entries in memory.
-
- Command (? for help): ?
- b back up GPT data to a file #备份GPT数据到文件中
- c change a partition's name #更改分区的名称
- d delete a partition #删除分区
- i show detailed information on a partition #列出分区的详细信息
- l list known partition types #列出已知的分区类型
- n add a new partition #新增分区
- o create a new empty GUID partition table (GPT) #创建一个新的空GUID分区表
- p print the partition table #打印分区表
- q quit without saving changes #退出并保存
- r recovery and transformation options (experts only) #恢复和转型
- s sort partitions #排序分区
- t change a partition's type code #更改分区的类型代码
- v verify disk #验证磁盘
- w write table to disk and exit #将表写入磁盘并退出
- x extra functionality (experts only) #额外功能
- ? print this menu #帮助信息
-
- Command (? for help): n
- Partition number (1-128, default 1): 1
- First sector (34-20971486, default = 2048) or {+-}size{KMGTP}:
- Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +3G
- Current type is 8300 (Linux filesystem)
- Hex code or GUID (L to show codes, Enter = 8300):
- Changed type of partition to 'Linux filesystem'
-
- Command (? for help): p
- Disk /dev/nvme0n3: 20971520 sectors, 10.0 GiB
- Model: VMware Virtual NVMe Disk
- Sector size (logical/physical): 512/512 bytes
- Disk identifier (GUID): 25FB5AC0-32CF-46C3-B496-292B1FABDFA3
- Partition table holds up to 128 entries
- Main partition table begins at sector 2 and ends at sector 33
- First usable sector is 34, last usable sector is 20971486
- Partitions will be aligned on 2048-sector boundaries
- Total free space is 14679997 sectors (7.0 GiB)
-
- Number Start (sector) End (sector) Size Code Name
- 1 2048 6293503 3.0 GiB 8300 Linux filesystem
-
- Command (? for help): n
- Partition number (2-128, default 2): 2
- First sector (34-20971486, default = 6293504) or {+-}size{KMGTP}:
- Last sector (6293504-20971486, default = 20971486) or {+-}size{KMGTP}: +5G
- Current type is 8300 (Linux filesystem)
- Hex code or GUID (L to show codes, Enter = 8300):
- Changed type of partition to 'Linux filesystem'
-
- Command (? for help): p
- Disk /dev/nvme0n3: 20971520 sectors, 10.0 GiB
- Model: VMware Virtual NVMe Disk
- Sector size (logical/physical): 512/512 bytes
- Disk identifier (GUID): 25FB5AC0-32CF-46C3-B496-292B1FABDFA3
- Partition table holds up to 128 entries
- Main partition table begins at sector 2 and ends at sector 33
- First usable sector is 34, last usable sector is 20971486
- Partitions will be aligned on 2048-sector boundaries
- Total free space is 4194237 sectors (2.0 GiB)
-
- Number Start (sector) End (sector) Size Code Name
- 1 2048 6293503 3.0 GiB 8300 Linux filesystem
- 2 6293504 16779263 5.0 GiB 8300 Linux filesystem
-
- Command (? for help): w
-
- Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
- PARTITIONS!!
-
- Do you want to proceed? (Y/N): y
- OK; writing new GUID partition table (GPT) to /dev/nvme0n3.
- The operation has completed successfully.
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- nvme0n4 259:9 0 10G 0 disk
交互模式下
- [root@SLB ~]# parted /dev/nvme0n4
- GNU Parted 3.5
- Using /dev/nvme0n4
- Welcome to GNU Parted! Type 'help' to view a list of commands.
-
- (parted) help
- align-check TYPE N 检查分区 N 的类型(最小|选择)对齐方式
- help [COMMAND] 打印常规帮助,或命令上的帮助
- mklabel,mktable LABEL-TYPE 创建新的磁盘标签(分区表)
- mkpart PART-TYPE [FS-TYPE] START END 添加新分区
- name NUMBER NAME 将分区编号命名为名称
- print [devices|free|list,all] 显示分区表、可用设备、可用空间或所有找到的分区
- quit 退出
- rescue START END 拯救在开始和结束附近丢失的分区
- resizepart NUMBER END 调整分区编号的大小
- rm NUMBER 删除分区号
- select DEVICE 选择要编辑的设备
- disk_set FLAG STATE 更改所选设备上的标志
- disk_toggle [FLAG] 切换所选设备上的标志状态
- set NUMBER FLAG STATE 更改分区号上的标志
- toggle [NUMBER [FLAG]] 切换分区号上的标志状态
- type NUMBER TYPE-ID or TYPE-UUID 分区号的类型集 TYPE-ID 或 TYPE-UUID
- unit UNIT 将默认单位设置为单位
- version 显示 GNU Parted 的版本号和版权信息
-
- (parted) mklabel
- New disk label type? gpt #指定分区表类型
- Warning: The existing disk label on /dev/nvme0n4 will be destroyed
- and all data on this disk will be lost. Do you want to continue?
- Yes/No? yes
- (parted) mkpart
- Partition name? []? dpart1
- File system type? [ext2]? ext4 #指定分区文件系统
- Start? 0%
- End? 20%
- (parted) p
- Model: VMware Virtual NVMe Disk (nvme)
- Disk /dev/nvme0n4: 10.7GB
- Sector size (logical/physical): 512B/512B
- Partition Table: gpt
- Disk Flags:
-
- Number Start End Size File system Name Flags
- 1 1049kB 2147MB 2146MB ext4 dpart1
-
- (parted) q
- Information: You may need to update /etc/fstab.
-
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- nvme0n4 259:9 0 10G 0 disk
- └─nvme0n4p1 259:11 0 2G 0 part
命令行模式下
这里的分区类型可以写primary、logical、extended
- [root@SLB ~]# parted /dev/nvme0n4 mklabel gpt
- Warning: The existing disk label on /dev/nvme0n4 will be destroyed
- and all data on this disk will be lost. Do you want to continue?
- Yes/No? yes
- Information: You may need to update /etc/fstab.
-
- [root@SLB ~]# parted /dev/nvme0n4 mkpart primary 0% 5G
- Information: You may need to update /etc/fstab.
-
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- nvme0n4 259:9 0 10G 0 disk
- └─nvme0n4p1 259:11 0 4.7G 0 part
-
- [root@SLB ~]# parted /dev/nvme0n4 rm 1 #命令行通过编号删除分区
- Information: You may need to update /etc/fstab.
-
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- nvme0n4 259:9 0 10G 0 disk
主要用到 LVM,将若干个磁盘或者磁盘分区连接为一个整块的卷组,形成一个存储池,管理员可以在卷组上任意创建逻辑卷,并进一步在逻辑卷上创建文件系统。 管理员通过LVM可以方便的调整存储卷组的大小,并且可以对磁盘存储按照组的方式进行命名、管理和分配。
指系统的存储设备文件,如: /dev/hda1、/dev/sda,磁盘
PV,物理卷可以是整个硬盘、硬盘分区或从逻辑上与磁盘分区具有同样功能的设备,是LVM的基本存储逻辑块,但包含有与LVM相关的管理参数。
VG,可以看成单独的逻辑磁盘,建立在PV之上,一个卷组中至少要包括一个PV,在卷组建立之后可以自定义名称,动态地添加PV到卷组中。
物理区域是物理卷中可用于分配的最小存储单元,物理区域的大小默认为4MB。物理区域大小一旦确定将不能更改,同一卷组中的所有物理卷的物理区域大小需要一致。
LV,相当于物理分区。逻辑卷建立在卷组之上,卷组中的未分配 空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态的扩展或缩小空间。系统中的多个逻辑卷,可以属于同一个卷组,也可以属于不同的多个卷组。
逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在卷组中的物理区域大小,LE的大小和PE的大小相同。
逻辑卷以及卷组相关的元数据也是保存在位于物理卷起始处的卷组描述符区域中, 包括PV描述符、VG描述符、LV描述符和PE描述符等。
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- nvme0n4 259:9 0 10G 0 disk
- [root@SLB ~]# pvcreate /dev/nvme0n3p2
- Physical volume "/dev/nvme0n3p2" successfully created.
- [root@SLB ~]# pvs #查看pv,详细查看使用pcdisplay
- PV VG Fmt Attr PSize PFree
- /dev/nvme0n1p2 rhel lvm2 a-- <49.00g 0
- /dev/nvme0n3p2 lvm2 --- 5.00g 5.00g
- [root@SLB ~]# parted /dev/nvme0n3 set 2 lvm on
- Information: You may need to update /etc/fstab.
vgcreate -s 卷组大小 卷组名称
- [root@SLB ~]# vgcreate -s 4M SLB /dev/nvme0n3p2
- Volume group "SLB" successfully created
- [root@SLB ~]# vgs
- VG #PV #LV #SN Attr VSize VFree
- SLB 1 0 0 wz--n- <5.00g <5.00g
- rhel 1 2 0 wz--n- <49.00g 0
lvcreate -n 逻辑卷名称 -L 指定逻辑卷大小 位于哪个卷组,-l指的是指定逻辑区域数量,一个区域4M,以此来计算
- [root@SLB ~]# lvcreate -n LSLB -L 500M SLB
- Logical volume "LSLB" created.
- [root@SLB ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log C
- LSLB SLB -wi-a----- 500.00m
- root rhel -wi-ao---- <44.00g
- swap rhel -wi-ao---- 5.00g
- [root@SLB ~]# lvcreate -n LSLB1 -l 20 SLB
- Logical volume "LSLB1" created.
- [root@SLB ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- LSLB SLB -wi-a----- 500.00m
- LSLB1 SLB -wi-a----- 80.00m
- root rhel -wi-ao---- <44.00g
- swap rhel -wi-ao---- 5.00g
- [root@SLB ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:4 0 5G 0 part
- ├─nvme0n2p2 259:5 0 5G 0 part
- ├─nvme0n2p3 259:6 0 5G 0 part
- └─nvme0n2p4 259:7 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- ├─SLB-LSLB 253:2 0 500M 0 lvm
- └─SLB-LSLB1 253:3 0 80M 0 lvm
- nvme0n4 259:9 0 10G 0 disk
- [root@SLB ~]# mkfs.xfs /dev/SLB/LSLB #格式化的是你的卷组下的逻辑卷,LSLB格式化后挂载后就能使用了,而LSLB1并没有执行则不能使用
- meta-data=/dev/SLB/LSLB isize=512 agcount=4, agsize=32000 blks
- = sectsz=512 attr=2, projid32bit=1
- = crc=1 finobt=1, sparse=1, rmapbt=0
- = reflink=1 bigtime=1 inobtcount=1
- data = bsize=4096 blocks=128000, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0, ftype=1
- log =internal log bsize=4096 blocks=1368, version=2
- = sectsz=512 sunit=0 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- [root@SLB ~]# mkfs. #有以下类型
- mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.fat mkfs.minix mkfs.msdos mkfs.vfat mkfs.xfs
- [root@SLB ~]# mkdir /mnt/SLB
- [root@SLB ~]# mount /dev/SLB/LSLB /mnt/SLB/
- [root@SLB ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- devtmpfs 4.0M 0 4.0M 0% /dev
- tmpfs 5.0G 0 5.0G 0% /dev/shm
- tmpfs 2.0G 9.7M 2.0G 1% /run
- /dev/mapper/rhel-root 44G 4.6G 40G 11% /
- /dev/nvme0n1p1 1014M 286M 729M 29% /boot
- /dev/sr0 8.5G 8.5G 0 100% /cdrom
- tmpfs 1022M 56K 1022M 1% /run/user/42
- tmpfs 1022M 40K 1022M 1% /run/user/0
- /dev/mapper/SLB-LSLB 495M 29M 466M 6% /mnt/SLB
- #验证可以正常使用
- [root@SLB SLB]# rz
-
- [root@SLB SLB]# ll
- total 15508
- -rw-r--r-- 1 root root 15878040 Jul 22 09:36 percona-xtrabackup-80-8.0.27-19.1.el8.x86_64.rpm
- [root@SLB SLB]# df -h
- Filesystem Size Used Avail Use% Mounted on
- devtmpfs 4.0M 0 4.0M 0% /dev
- tmpfs 5.0G 0 5.0G 0% /dev/shm
- tmpfs 2.0G 9.7M 2.0G 1% /run
- /dev/mapper/rhel-root 44G 4.6G 40G 11% /
- /dev/nvme0n1p1 1014M 286M 729M 29% /boot
- /dev/sr0 8.5G 8.5G 0 100% /cdrom
- tmpfs 1022M 56K 1022M 1% /run/user/42
- tmpfs 1022M 40K 1022M 1% /run/user/0
- /dev/mapper/SLB-LSLB 495M 44M 451M 9% /mnt/SLB
- [root@SLB SLB]# pvcreate /dev/nvme0n3p1
- Physical volume "/dev/nvme0n3p1" successfully created.
- [root@SLB SLB]# parted /dev/nvme0n3 set 1 lvm on
- Information: You may need to update /etc/fstab.
-
- [root@SLB SLB]# vgextend SLB /dev/nvme0n2p1
- Volume group "SLB" successfully extended
- [root@SLB SLB]# vgs SLB
- VG #PV #LV #SN Attr VSize VFree
- SLB 2 2 0 wz--n- 9.99g <9.43g
不同文件系统类型的扩/减容方式不同
- [root@SLB SLB]# lsblk -f |grep SLB
- ├─SLB-LSLB xfs 9491d05a-8b9d-4b11-a49a-2c88716c9805 450.8M 9% /mnt/SLB
- └─SLB-LSLB1 ext4 1.0 38cef6a3-5bf5-4f1f-8ae4-a5f80e851f2d
-
- #查看文件系统类型
对于xfs类型,不支持减容
- [root@SLB SLB]# lvs /dev/SLB/LSLB
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- LSLB SLB -wi-ao---- 500.00m
- [root@SLB SLB]# lvextend -L +100M /dev/SLB/LSLB #也可以使用lvresize
- Size of logical volume SLB/LSLB changed from 500.00 MiB (125 extents) to 600.00 MiB (150 extents).
- Logical volume SLB/LSLB successfully resized.
- [root@SLB SLB]# lvs /dev/SLB/LSLB
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- LSLB SLB -wi-ao---- 600.00m
- [root@SLB SLB]# lsblk | grep LSLB
- ├─SLB-LSLB 253:2 0 600M 0 lvm /mnt/SLB
- └─SLB-LSLB1 253:3 0 580M 0 lvm
-
-
- #-L +100M表示在原有基础上增加100M,-L 100M表示增加到100M
-
- [root@SLB SLB]# df -h | grep /mnt/SLB
- #挂载的目录显示并没有扩容,使用xfs_growfs命令后再查看已经扩容成功
- /dev/mapper/SLB-LSLB 495M 44M 451M 9% /mnt/SLB
- [root@SLB SLB]# xfs_growfs /mnt/SLB
- meta-data=/dev/mapper/SLB-LSLB isize=512 agcount=4, agsize=32000 blks
- = sectsz=512 attr=2, projid32bit=1
- = crc=1 finobt=1, sparse=1, rmapbt=0
- = reflink=1 bigtime=1 inobtcount=1
- data = bsize=4096 blocks=128000, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0, ftype=1
- log =internal log bsize=4096 blocks=1368, version=2
- = sectsz=512 sunit=0 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- data blocks changed from 128000 to 153600
- [root@SLB SLB]# df -h | grep /mnt/SLB
- /dev/mapper/SLB-LSLB 595M 45M 551M 8% /mnt/SLB
对于ext类型,支持扩容和减容
- Please run 'e2fsck -f /dev/SLB/LSLB1' first.
- [root@SLB SLB]# e2fsck -f /dev/SLB/LSLB1 #进行系统检查
- e2fsck 1.46.5 (30-Dec-2021)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/SLB/LSLB1: 11/37120 files (0.0% non-contiguous), 6654/148480 b
- [root@SLB SLB]# lsblk | grep SLB1
- └─SLB-LSLB1 253:3 0 580M 0 lvm
-
- [root@SLB SLB]# lvresize -L +200M /dev/SLB/LSLB1 #增加200M
- Size of logical volume SLB/LSLB1 changed from 580.00 MiB (145 extents) to 780.00 MiB (195 extents).
- Logical volume SLB/LSLB1 successfully resized.
- [root@SLB SLB]# lsblk | grep SLB1
- └─SLB-LSLB1 253:3 0 780M 0 lvm
-
- [root@SLB SLB]# lvreduce -L 100M /dev/SLB/LSLB1 #减少到100M
- WARNING: Reducing active logical volume to 100.00 MiB.
- THIS MAY DESTROY YOUR DATA (filesystem etc.)
- Do you really want to reduce SLB/LSLB1? [y/n]: y
- Size of logical volume SLB/LSLB1 changed from 780.00 MiB (195 extents) to 100.00 MiB (25 extents).
- Logical volume SLB/LSLB1 successfully resized.
- [root@SLB SLB]# lsblk | grep SLB1
- └─SLB-LSLB1 253:3 0 100M 0 lvm
-
-
- resize2fs命令可以重置文件系统大小
在Linux系统中, swap交换分区的作用类似于Windows系统中“虚拟内存”。当有程序被调入内存后,但 是该程序又不是常被CPU所取用时,那么这些不常被使用的程序将会被放到硬盘的swap交换分区当中, 而将速度较快的内存空间释放给真正需要的程序使用,以避免由于物理内存不足而造成的系统效能低的 问题。如果系统没有swap交换分区,或者现有交换分区的容量不够用时,可扩展swap交换分区。
Linux必须创建/和swap分区,一般需要创建/、/boot、swap分区,又分以磁盘分区的方式扩展swap交换分区和以镜像文件的方式扩展swap交换分区
- [root@SLB SLB]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- sr0 11:0 1 8.4G 0 rom /cdrom
- nvme0n1 259:0 0 50G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 49G 0 part
- ├─rhel-root 253:0 0 44G 0 lvm /
- └─rhel-swap 253:1 0 5G 0 lvm [SWAP]
- nvme0n2 259:3 0 20G 0 disk
- ├─nvme0n2p1 259:10 0 5G 0 part
- ├─nvme0n2p2 259:11 0 5G 0 part
- ├─nvme0n2p3 259:14 0 5G 0 part
- └─nvme0n2p4 259:15 0 1K 0 part
- nvme0n3 259:8 0 10G 0 disk
- ├─nvme0n3p1 259:12 0 3G 0 part
- └─nvme0n3p2 259:13 0 5G 0 part
- ├─SLB-LSLB 253:2 0 600M 0 lvm /mnt/SLB
- └─SLB-LSLB1 253:3 0 100M 0 lvm
- nvme0n4 259:9 0 10G 0 disk
- [root@SLB SLB]# mkswap /dev/nvme0n4
- mkswap: /dev/nvme0n4: warning: don't erase bootbits sectors
- (gpt partition table detected). Use -f to force.
- Setting up swapspace version 1, size = 10 GiB (10737414144 bytes)
- no label, UUID=b95da1f0-eb78-4cce-82ec-eaf12c96d851
- [root@SLB SLB]# swapon /dev/nvme0n4 #激活使用swapon,禁用使用swapoff
- [root@SLB SLB]# swapon -s #查看激活,两种方式
- Filename Type Size Used Priority
- /dev/dm-1 partition 5242876 -2
- /dev/nvme0n4 partition 10485756 -3
- [root@SLB SLB]# cat /proc/swaps
- Filename Type Size Used Priority
- /dev/dm-1 partition 5242876 -2
- /dev/nvme0n4 partition 10485756 -3
- [root@SLB SLB]# dd if=/dev/zero of=/swap bs=1M count=1024
- #从无限零资源去读,每块大小为1M,共1024块 这个文件不建议使用cat去查看
- 1024+0 records in
- 1024+0 records out
- 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 4.6908 s, 229 MB/s
-
- [root@SLB SLB]# mkswap /swap
- mkswap: /swap: insecure permissions 0644, fix with: chmod 0600 /swap
- Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
- no label, UUID=2627f925-1694-42aa-a7ab-3d23ef569371
- [root@SLB SLB]# swapon /swap
- swapon: /swap: insecure permissions 0644, 0600 suggested.
- [root@SLB SLB]# chmod 0600 /swap
- [root@SLB SLB]# swapon -s
- Filename Type Size Used Priority
- /dev/dm-1 partition 5242876 -2
- /dev/nvme0n4 partition 10485756 -3
- /swap file 1048572 -4
- [root@SLB SLB]# swapon -s
- Filename Type Size Used Priority
- /dev/dm-1 partition 5242876 0 -2
- /dev/nvme0n4 partition 10485756 0 -3
- /swap file 1048572 0 -4
- [root@SLB SLB]#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。