国产化改造之Anolis操作系统空间扩容
•虚拟化软件:VMware® Workstation 17 Pro•虚拟机:Anolis OS 23在VMware 中给Anolis虚拟机总共分了100GB空间,已经不够用。需要扩充,因为Anolis底层是Linux,而Linux是使用LVM(Logical Volume Manager)所以扩充磁盘非常方便。
环境信息
-
•
虚拟化软件:VMware® Workstation 17 Pro
-
•
虚拟机:Anolis OS 23
在VMware 中给Anolis虚拟机总共分了100GB空间,已经不够用。需要扩充,因为Anolis底层是Linux,而Linux是使用LVM(Logical Volume Manager)所以扩充磁盘非常方便。步骤如下
扩容前
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ao_anolis-root 96G 19G 78G 20% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.1M 1.6G 1% /run
tmpfs 3.9G 0 3.9G 0% /tmp
/dev/nvme0n1p2 960M 210M 751M 22% /boot
tmpfs 791M 12K 791M 1% /run/user/0
查看磁盘相关信息 fdisk -l
下面结果中/dev/nvme0n1、/dev/mapper/ao_anolis-root、/dev/mapper/ao_anolis-swap三个为磁盘信息。其中//dev/nvme0n1磁盘有四个分区/dev/nvme0n1p1和/dev/nvme0n1p2,/dev/nvme0n1p3,/dev/nvme0n1p4。
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# fdisk -l
GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
Disk /dev/nvme0n1: 200 GiB, 214748364800 bytes, 419430400 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: gpt
Disk identifier: 227AF57E-5B1C-4EE6-843B-DD60D78A92F2
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 4095 2048 1M BIOS boot
/dev/nvme0n1p2 4096 2101247 2097152 1G Linux filesystem
/dev/nvme0n1p3 2101248 41940991 39839744 19G Linux LVM
/dev/nvme0n1p4 41940992 209713151 167772160 80G Linux filesystem
Disk /dev/mapper/ao_anolis-root: 96 GiB, 103075020800 bytes, 201318400 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/ao_anolis-swap: 2 GiB, 2147483648 bytes, 4194304 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
注意:Disklabel type:
-
•
dos:表示使用的是MBR(Master Boot Record)分区表;分区空间不能超过2TB,fdisk命令可处理,也可使用parted
-
•
gpt表示使用的是GPT(GUID Partition Table)分区表;分区空间可支持更大,应使用parted命令或者gdisk命令。fdisk无法处理GPT,仅可查看!
查看磁盘空间,分区,文件系统,挂接点 lsblk -f
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sr0 iso9660 Joliet Extension anolis-23-x86_64-dvd 2024-05-30-22-03-11-00
nvme0n1
├─nvme0n1p1
├─nvme0n1p2 xfs c710639d-df1f-472f-8b87-42035e4a3d4b 750.3M 22% /boot
├─nvme0n1p3 LVM2_member LVM2 001 SSrbCU-CCr5-rKs5-o4GU-vB0i-dsea-e3EYTl
│ ├─ao_anolis-root xfs c033ff40-4827-4e87-a3f6-b427715e462d 77.4G 19% /
│ └─ao_anolis-swap swap 1 0e01bf08-d822-4249-9b91-c67a66ae34ba [SWAP]
└─nvme0n1p4 LVM2_member LVM2 001 Dv6Xfh-F8Vw-vGfF-zjg4-8AVm-cCoP-3BbMky
└─ao_anolis-root xfs c033ff40-4827-4e87-a3f6-b427715e462d 77.4G 19% /
扩容步骤
关闭虚拟机,在虚拟机设置中点击“硬盘”,点击“扩展”,进行扩展设置
磁盘创建 partition,通过命令fdisk进行创建,新增的partion为nvme0n1
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.39.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): h
h: unknown command
Command (m for help): m
Help:
GPT
M enter protective/hybrid MBR
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty MBR (DOS) partition table
s create a new empty Sun partition table
Command (m for help): n
Partition number (5-128, default 5):
First sector (209713152-419430366, default 209713152):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (209713152-419430366, default 419428351):
Created a new partition 5 of type 'Linux filesystem' and of size 100 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
新增以后再次查看磁盘空间 fdisk -l
多了一块/dev/nvme0n1p5
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# fdisk -l
Disk /dev/nvme0n1: 200 GiB, 214748364800 bytes, 419430400 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: gpt
Disk identifier: 227AF57E-5B1C-4EE6-843B-DD60D78A92F2
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 4095 2048 1M BIOS boot
/dev/nvme0n1p2 4096 2101247 2097152 1G Linux filesystem
/dev/nvme0n1p3 2101248 41940991 39839744 19G Linux LVM
/dev/nvme0n1p4 41940992 209713151 167772160 80G Linux filesystem
/dev/nvme0n1p5 209713152 419428351 209715200 100G Linux filesystem
Disk /dev/mapper/ao_anolis-root: 96 GiB, 103075020800 bytes, 201318400 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/ao_anolis-swap: 2 GiB, 2147483648 bytes, 4194304 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
创建PV并纳入VG
这个时候通过pvdisplay或vgdisplay命令还看不到刚才新增的Partition
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# pvdisplay
--- Physical volume ---
PV Name /dev/nvme0n1p3
VG Name ao_anolis
PV Size <19.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID SSrbCU-CCr5-rKs5-o4GU-vB0i-dsea-e3EYTl
--- Physical volume ---
PV Name /dev/nvme0n1p4
VG Name ao_anolis
PV Size 80.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20479
Free PE 255
Allocated PE 20224
PV UUID Dv6Xfh-F8Vw-vGfF-zjg4-8AVm-cCoP-3BbMky
[root@anolis ~]# vgdisplay
--- Volume group ---
VG Name ao_anolis
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 98.99 GiB
PE Size 4.00 MiB
Total PE 25342
Alloc PE / Size 25087 / <98.00 GiB
Free PE / Size 255 / 1020.00 MiB
VG UUID HBywpj-Igkz-nyH1-6zSf-ActB-Z9Qk-R6xVwr
通过pvcreate,创建pv,创建后通过pvdisplay就可以看到新增的Partition,通过vgdisplay命令可以看到此时并未纳入到vg中
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# pvcreate /dev/nvme0n1p5
Physical volume "/dev/nvme0n1p5" successfully created.
Not creating system devices file due to existing VGs.
[root@anolis ~]# pvdisplay
--- Physical volume ---
PV Name /dev/nvme0n1p3
VG Name ao_anolis
PV Size <19.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID SSrbCU-CCr5-rKs5-o4GU-vB0i-dsea-e3EYTl
--- Physical volume ---
PV Name /dev/nvme0n1p4
VG Name ao_anolis
PV Size 80.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20479
Free PE 255
Allocated PE 20224
PV UUID Dv6Xfh-F8Vw-vGfF-zjg4-8AVm-cCoP-3BbMky
"/dev/nvme0n1p5" is a new physical volume of "100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/nvme0n1p5
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 3gW52r-wx2Q-hZYf-n4jL-Vu8v-2ZYY-QZNlYu
[root@anolis ~]# vgdisplay
--- Volume group ---
VG Name ao_anolis
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 98.99 GiB
PE Size 4.00 MiB
Total PE 25342
Alloc PE / Size 25087 / <98.00 GiB
Free PE / Size 255 / 1020.00 MiB
VG UUID HBywpj-Igkz-nyH1-6zSf-ActB-Z9Qk-R6xVwr
最后用vgextend将新建的pv加入到vg中(本机上的vg名为“ao_anolis”),加入成功后再次使用vg命令可以看到已经纳入
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# vgextend ao_anolis /dev/nvme0n1p5
Volume group "ao_anolis" successfully extended
[root@anolis ~]# vgdisplay
--- Volume group ---
VG Name ao_anolis
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <198.99 GiB
PE Size 4.00 MiB
Total PE 50941
Alloc PE / Size 25087 / <98.00 GiB
Free PE / Size 25854 / 100.99 GiB
VG UUID HBywpj-Igkz-nyH1-6zSf-ActB-Z9Qk-R6xVwr
对原LV扩展容量
在扩LV之前,可以通过命令lvdisplay查看当前的LV情况。可以看到:
-
•
系统已存在两个LV,都是基于在名为“ao_anolis”的VG上分配的空间。
-
•
结合前面,我们正是要给LV Pathe是“/dev/ao_anolis/root” 的LV进行扩展
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# lvdisplay
--- Logical volume ---
LV Path /dev/ao_anolis/swap
LV Name swap
VG Name ao_anolis
LV UUID 4MregN-gLNt-lXQz-FSmr-HXVN-qCio-pJL04R
LV Write Access read/write
LV Creation host, time anolis, 2024-08-07 00:36:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
--- Logical volume ---
LV Path /dev/ao_anolis/root
LV Name root
VG Name ao_anolis
LV UUID tidop2-uxMA-dwbU-9DSw-4af7-1mfK-9NDKY3
LV Write Access read/write
LV Creation host, time anolis, 2024-08-07 00:36:42 +0800
LV Status available
# open 1
LV Size <96.00 GiB
Current LE 24575
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
因此,我们将新增的100GB空闲空间,全部分配给LV Path为“/dev/ao_anolis/root” 的LV。 命令格式为:
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# lvextend -L +100G /dev/ao_anolis/root
Size of logical volume ao_anolis/root changed from <96.00 GiB (24575 extents) to <196.00 GiB (50175 extents).
Logical volume ao_anolis/root successfully resized.
[root@anolis ~]# lvdisplay
--- Logical volume ---
LV Path /dev/ao_anolis/swap
LV Name swap
VG Name ao_anolis
LV UUID 4MregN-gLNt-lXQz-FSmr-HXVN-qCio-pJL04R
LV Write Access read/write
LV Creation host, time anolis, 2024-08-07 00:36:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
--- Logical volume ---
LV Path /dev/ao_anolis/root
LV Name root
VG Name ao_anolis
LV UUID tidop2-uxMA-dwbU-9DSw-4af7-1mfK-9NDKY3
LV Write Access read/write
LV Creation host, time anolis, 2024-08-07 00:36:42 +0800
LV Status available
# open 1
LV Size <196.00 GiB
Current LE 50175
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
扩大文件系统 xfs_growfs
这时通过df查看当前文件系统,仍未变化。这是因为尽管LV容量扩大了,但文件系统还未扩大。
通过df -T命令查看当前文件系统的类型。如果是ext4等文件系统可以通过命令resize2fs扩大, 因为我们是xfs文件系统,所以需要使用命令xfs_growfs来完成文件系统扩大。
然后再次通过df查看文件系统空间情况,可以看到空间已经扩大。
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ao_anolis-root 96G 19G 78G 20% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.1M 1.6G 1% /run
tmpfs 3.9G 0 3.9G 0% /tmp
/dev/nvme0n1p2 960M 210M 751M 22% /boot
tmpfs 791M 12K 791M 1% /run/user/0
[root@anolis ~]# xfs_growfs /dev/mapper/ao_anolis-root
meta-data=/dev/mapper/ao_anolis-root isize=512 agcount=23, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=1
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
data = bsize=4096 blocks=25164800, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25164800 to 51379200
最后再次使用df命令查看空间,可以看到/dev/mapper/ao_anolis-root已经成功增加了100G
--javascripttypescriptshellbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
[root@anolis ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ao_anolis-root 196G 21G 176G 11% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.1M 1.6G 1% /run
tmpfs 3.9G 0 3.9G 0% /tmp
/dev/nvme0n1p2 960M 210M 751M 22% /boot
tmpfs 791M 12K 791M 1% /run/user/0
更多推荐
所有评论(0)