Centos7 LVM扩容实例

来源:互联网 发布:产品原型软件 编辑:程序博客网 时间:2024/06/13 20:19
Centos7 lvm 扩容与以往版本有所不同

1.插入硬盘,我是在虚拟机上做的测试  直接添加一块5G的硬盘

2.系统读取硬盘信息
    # echo "- - -" > /sys/class/scsi_host/host0/scan

  查看结果 (红字为新加硬盘)
       # fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000524cf

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 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/centos-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


Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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.新加硬盘创建为 pv
      # pvcreate /dev/sdb 
  Physical volume "/dev/sdb" successfully created

[root@localhost host0]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               10
  Allocated PE          4984
  PV UUID               z5e55H-j5bT-F1Op-cnpF-BPZQ-MQBS-OCZ9mK
   
  "/dev/sdb" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               5.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               31hT9s-0YJG-io43-hcla-TPMq-2R5N-TOZexF


4.扩容vg
# vgextend centos /dev/sdb 
   Volume group "centos" successfully extended

[root@localhost host0]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               24.50 GiB
  PE Size               4.00 MiB
  Total PE              6273
  Alloc PE / Size       4984 / 19.47 GiB
  Free  PE / Size       1289 / 5.04 GiB
  VG UUID               eD4mco-Sn0A-xt13-2g5h-Jttn-z1BZ-ZeHbJN


5.扩容lv
     # lvextend -L +5G /dev/centos/root 
             Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 22.47 GiB (5752 extents).
             Logical volume root successfully resized.
[root@localhost host0]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 22.47g                                                    
  swap centos -wi-ao----  2.00g              


6.扩容文件系统 (注意!!!)
   # resize2fs /dev/centos/root      报错
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.


以往的centos使用的文件系统是  ext2/ext3/ext4  
其对应的的调整命令是resize2fs

CentOS7.0的默认文件系统类型是 Xfs 其对应的调整命令是 xfs_growfs 不同文件系统类型对应的创建、检查、调整命令不同,要注意区分。


看下系统文件类型# df -hTFilesystem              Type      Size  Used Avail Use% Mounted on/dev/mapper/centos-root xfs        23G  1.4G   22G   6% /devtmpfs                devtmpfs  1.9G     0  1.9G   0% /devtmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shmtmpfs                   tmpfs     1.9G  8.6M  1.9G   1% /runtmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup/dev/sda1               xfs       497M  125M  373M  26% /boottmpfs                   tmpfs     379M     0  379M   0% /run/user/0
使用新命令
# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1144832 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=0        finobt=0data     =                       bsize=4096   blocks=4579328, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=0log      =internal               bsize=4096   blocks=2560, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 4579328 to 5890048[root@localhost host0]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   23G  1.4G   22G   6% /devtmpfs                 1.9G     0  1.9G   0% /devtmpfs                    1.9G     0  1.9G   0% /dev/shmtmpfs                    1.9G  8.6M  1.9G   1% /runtmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup/dev/sda1                497M  125M  373M  26% /boottmpfs                    379M     0  379M   0% /run/user/0
扩容成功!
原创粉丝点击