系统CentOS7
原有磁盘20G
先到VM客户端界面中扩展到40G,然后启动系统,进入系统后操作,操作记录如下:
Last login: Wed Dec 11 23:10:40 2019 from 192.168.1.47
[root@cib-server1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 17G 282M 99% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 9.0M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 379M 0 379M 0% /run/user/0
[root@cib-server1 ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos
Disk identifier: 0x000ef4fd
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/rhel-root: 18.2 GB, 18249416704 bytes, 35643392 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/rhel-swap: 2147 MB, 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
[root@cib-server1 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos
Disk identifier: 0x000ef4fd
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos
Disk identifier: 0x000ef4fd
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 83886079 20971520 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@cib-server1 ~]# ll /dev/sda*
brw-rw---- 1 root disk 8, 0 Dec 12 01:45 /dev/sda
brw-rw---- 1 root disk 8, 1 Dec 12 01:45 /dev/sda1
brw-rw---- 1 root disk 8, 2 Dec 12 01:45 /dev/sda2
[root@cib-server1 ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-2
[root@cib-server1 ~]# ll /dev/sda*
brw-rw---- 1 root disk 8, 0 Dec 12 01:45 /dev/sda
brw-rw---- 1 root disk 8, 1 Dec 12 01:45 /dev/sda1
brw-rw---- 1 root disk 8, 2 Dec 12 01:45 /dev/sda2
brw-rw---- 1 root disk 8, 3 Dec 12 01:45 /dev/sda3
[root@cib-server1 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@cib-server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <19.00g 0
/dev/sda3 lvm2 --- 20.00g 20.00g
[root@cib-server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <19.00g 0
[root@cib-server1 ~]# vgextend rhel /dev/sda3
Volume group "rhel" successfully extended
[root@cib-server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 2 2 0 wz--n- 38.99g <20.00g
[root@cib-server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <17.00g
swap rhel -wi-ao---- 2.00g
[root@cib-server1 ~]# lvextend -l +100%FREE /dev/sda
/dev/sda2 /dev/sda3
[root@cib-server1 ~]# ll /dev/mapper/
total 0
crw------- 1 root root 10, 236 Dec 12 01:44 control
lrwxrwxrwx 1 root root 7 Dec 12 01:44 rhel-root -> ../dm-0
lrwxrwxrwx 1 root root 7 Dec 12 01:44 rhel-swap -> ../dm-1
[root@cib-server1 ~]# lvextend -l +100%FREE /dev/mapper/rhel-root
Size of logical volume rhel/root changed from <17.00 GiB (4351 extents) to 36.99 GiB (9470 extents).
Logical volume rhel/root successfully resized.
[root@cib-server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 36.99g
swap rhel -wi-ao---- 2.00g
[root@cib-server1 ~]# xfs_growfs /
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal 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 4455424 to 9697280
[root@cib-server1 ~]# df -h
(END)