用运营商的镜像安装云服务器,选择Linux系统的发行版 CentOS8.1, 云盘500G,内存16G; 但是安装好系统会发现根目录 很小只有8G 需要调整到50G. 现在讲调整的过程记录下来。
基本概念
PV(Physical Volume)- 物理卷
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备。
VG(Volumne Group)- 卷组
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。
LV(Logical Volume)- 逻辑卷
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组。
CentOS8.1 中文语言改为英文语言
#vim /etc/locale.conf
LANG="zh_CN.UTF-8"
修改为
LANG=en_US.UTF-8
#reboot
重启动生效
CentOS8.1 图像化启动改为字符多用户
[root@centos8 etc]# more inittab
# inittab is no longer used.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
[root@centos8 etc]# systemctl set-default multi-user.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.
[root@centos8 etc]# reboot
重启动生效
CentOS8.1 系统盘/根目录扩容
1. 查看磁盘大小及剩余空间
[root@centos8 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 8.0G 4.1G 3.9G 52% /
/dev/vda1 ext4 976M 143M 766M 16% /boot
tmpfs tmpfs 1.6G 4.0K 1.6G 1% /run/user/0
2. 查看硬盘数量和分区情况
[root@centos8 ~]# fdisk -l
Disk /dev/vda: 540 GiB, 579820584960 bytes, 1132462080 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
Disk identifier: 0x1cdf0571
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 20971519 18872320 9G 8e Linux LVM
Disk /dev/mapper/cl-root: 8 GiB, 8585740288 bytes, 16769024 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/cl-swap: 1 GiB, 1073741824 bytes, 2097152 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
3. 对未分配的磁盘分区
[root@centos8 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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):
First sector (20971520-1132462079, default 20971520):
Last sector, +sectors or +size{
K,M,G,T,P} (20971520-1132462079, default 1132462079): +42GB
Created a new partition 3 of type 'Linux' and of size 39.1 GiB.
Command (m for help): P
P: unknown command
Command (m for help): p
Disk /dev/vda: 540 GiB, 579820584960 bytes, 1132462080 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
Disk identifier: 0x1cdf0571
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 20971519 18872320 9G 8e Linux LVM
/dev/vda3 20971520 103002111 82030592 39.1G 83 Linux
Command (m for help): w
The partition table has been altered.
Syncing disks.
4. 将磁盘分区表变化信息通知内核,系统重新加载分区表
[root@centos8 ~]# partprobe -s
/dev/vda: msdos partitions 1 2 3
5. 创建物理卷
[root@centos8 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
6. 查看lvm卷
[root@centos8 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name cl
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID bJ39om-je2X-7eVI-99cr-ieNt-Qlkm-LfqOBM
"/dev/vda3" is a new physical volume of "<39.12 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size <39.12 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID fhAswC-ab3g-qgdN-5hoW-iIFE-rzKI-FFg9GC
7. 查看卷组 ,卷组名为 “cl”(有的系统默认为“centos”,注意修改)
vgdisplay
8. 将新卷扩展进原有的“cl”卷组里
[root@centos8 ~]# vgextend cl /dev/vda3
Volume group "cl" successfully extended
9. 扩展逻辑卷
[root@centos8 ~]# lvextend -l +100%free /dev/mapper/cl-root
Size of logical volume cl/root changed from <8.00 GiB (2047 extents) to <47.11 GiB (12060 extents).
Logical volume cl/root successfully resized.
### 查看逻辑卷文件系统类型
[root@centos8 ~]# blkid /dev/mapper/cl-root
/dev/mapper/cl-root: UUID="b67bbb1c-3845-4fe5-9906-9902394816e2" TYPE="xfs"
10. 扩展文件系统,如果是ext类型分区,使用resize2fs命
[root@centos8 ~]# xfs_growfs /
meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2096128, 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
data blocks changed from 2096128 to 12349440
[root@centos8 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 48G 4.4G 43G 10% /
/dev/vda1 ext4 976M 143M 766M 16% /boot
tmpfs tmpfs 1.6G 4.0K 1.6G 1% /run/user/0