背景
[root@localhost gitlab-kas]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <99.00g 4.00m
[root@localhost gitlab-kas]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <99.00g 4.00m
[root@localhost gitlab-kas]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- <41.12g
root centos -wi-ao---- 50.00g
swap centos -wi-a----- <7.88g
/dev/sda: 2199.0 GB 还有剩余的空间,我先分到/dev/sda2,再进行扩展root
/dev/sda2 2099200 209715199 103808000 8e Linux LVM在 fdisk
中执行以下操作:
操作步骤
调整分区大小
复制代码
fdisk /dev/sda
- 在
fdisk
中执行以下操作:p
打印当前分区表。d
删除/dev/sda2
分区。n
创建一个新的分区,选择与原来相同的起始扇区,新的结束扇区为剩余磁盘的末尾。t
设置新的分区类型为8e
(Linux LVM)。w
保存并退出。
重读分区表
复制代码
partprobe
重新扫描物理卷
复制代码
pvresize /dev/sda2
查看物理卷状态
复制代码
pvs
扩展逻辑卷
复制代码
lvextend -l +100%FREE /dev/centos/root
扩展文件系统
- 对于
xfs
文件系统: - 复制代码
xfs_growfs /dev/centos/root
- 对于
ext4
文件系统:
- 复制代码
resize2fs /dev/centos/root
通过以上步骤,你可以成功地将剩余的空间从 /dev/sda
分配到 /dev/sda2
并扩展 root
逻辑卷。请确保在执行这些操作之前备份重要数据。
磁盘是MBR(不能超过2T)转 GPT (不丢失数据)
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart primary ext4 0% 100%
(parted) quit
Information: You may need to update /etc/fstab.
[root@localhost ~]# resize2fs /dev/sdb1
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/sdb1' first.
[root@localhost ~]# e2fsck -f /dev/sdb1
e2fsck 1.42.9 (28-Dec-2013)
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/sdb1: 251932/134217728 files (0.1% non-contiguous), 355092564/536870655 blocks
[root@localhost ~]# resize2fs /dev/sdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sdb1 to 805305856 (4k) blocks.
The filesystem on /dev/sdb1 is now 805305856 blocks long.
[root@localhost ~]# mount /dev/sdb1 /data
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 28K 7.8G 1% /dev/shm
tmpfs 7.8G 16M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 2.0T 318G 1.7T 16% /
/dev/sda1 1014M 152M 863M 15% /boot
/dev/mapper/centos-home 42G 33M 42G 1% /home
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/sdb1 3.0T 1.3T 1.6T 47% /data
Comments | NOTHING