cenots 调整分区大小和lv的扩容

[root@node-1 ~]# fdisk /dev/vda
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/vda: 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: 0x000d4405

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    20971519     9436160   8e  Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-83886079, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-83886079, default 83886079):
Using default value 83886079
Partition 2 of type Linux and of size 39 GiB is set

Command (m for help): p

Disk /dev/vda: 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: 0x000d4405

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    83886079    40893440   83  Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/vda: 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: 0x000d4405

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    83886079    40893440   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@node-1 ~]# lvextend -l +100%FREE  /dev/mapper/centos-root
  New size (2047 extents) matches existing size (2047 extents).
[root@node-1 ~]# lvextend -l +100%FREE  /dev/mapper/centos-root
  New size (2047 extents) matches existing size (2047 extents).
[root@node-1 ~]# lsblk
NAME            MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda             252:0    0  40G  0 disk
├─vda1          252:1    0   1G  0 part /boot
└─vda2          252:2    0  39G  0 part
  ├─centos-root 253:0    0   8G  0 lvm  /
  └─centos-swap 253:1    0   1G  0 lvm  [SWAP]
[root@node-1 ~]# pvs
  PV         VG     Fmt  Attr PSize  PFree
  /dev/vda2  centos lvm2 a--  <9.00g    0
[root@node-1 ~]# pvresize /dev/vda2
  Physical volume "/dev/vda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
[root@node-1 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/vda2  centos lvm2 a--  <39.00g 30.00g
[root@node-1 ~]# lvextend -l +100%FREE  /dev/mapper/centos-root
  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to <38.00 GiB (9727 extents).
  Logical volume centos/root successfully resized.
[root@node-1 ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <38.00g
  swap centos -wi-ao----   1.00g
[root@node-1 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2096128, 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 2096128 to 9960448
[root@node-1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   38G  1.1G   37G   3% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   17M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1               1014M  143M  872M  15% /boot
tmpfs                    380M     0  380M   0% /run/user/0
12-30 05:49