虚拟机lvm 扩容「建议收藏」

虚拟机lvm 扩容「建议收藏」1.先在Vmware上,把虚拟机硬盘做扩展,如果有快照存在,磁盘可能是不可编辑状态,先删除快照后再扩展。2.现在打开虚拟机发现系统的磁盘空间已经扩了,但是硬盘分区可用空间没变,还是原来的30G[root@masterhome]#fdisk-lDisk/dev/sda:64.4GB,64424509440bytes,125829120sectorsUnits=…

大家好,又见面了,我是你们的朋友全栈君。

1.先在Vmware上,把虚拟机硬盘做扩展,如果有快照存在,磁盘可能是不可编辑状态,先删除快照后再扩展。

2.现在打开虚拟机发现系统的磁盘空间已经扩了,但是硬盘分区可用空间没变,还是原来的30G

[root@master home]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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: 0x000e39fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM

3、使用fdisk 新建分区,为lvm扩容做准备

[root@master ~]# 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: 66.6 GB, 66571993088 bytes, 130023424 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: 0x000e39fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM

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

Command (m for help): p

Disk /dev/sda: 66.6 GB, 66571993088 bytes, 130023424 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: 0x000e39fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM
/dev/sda3       125829120   130023423     2097152   83  Linux

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: 66.6 GB, 66571993088 bytes, 130023424 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: 0x000e39fe

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM
/dev/sda3       125829120   130023423     2097152   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.

使分区表生效,无需重启:    partprobe

4、建立pv

[root@master ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@master ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               <59.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              15103
  Free PE               1
  Allocated PE          15102
  PV UUID               FIyz9f-hb3s-EfyI-jvlU-w3WW-B00f-h1YADj
   
  "/dev/sda3" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               otYU0U-Nti9-H9zz-D2h8-Gqys-f8wJ-Eqnkwd

5、扩展vg

[root@master ~]# vgextend cl /dev/sda3
  Volume group "cl" successfully extended
[root@master ~]# vgdisplay
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               60.99 GiB
  PE Size               4.00 MiB
  Total PE              15614
  Alloc PE / Size       15102 / 58.99 GiB
  Free  PE / Size       512 / 2.00 GiB
  VG UUID               yjbhCl-sZnU-wNh1-usz3-WP99-CGVU-OOyWie

6、扩展lv

输入扩展单元,这里就是上面的Free Pe 的大小。  

挂载到“/” 根目录下,将卷组下的卷cl 扩容2G。

[root@master ~]# lvextend -L  +2G  /dev/cl/home
  Size of logical volume cl/home changed from <18.70 GiB (4786 extents) to <20.70 GiB (5298 extents).
  Logical volume cl/home successfully resized.
[root@master ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                Yz5pFL-TNrc-WQrG-Ow07-xN78-MljW-CQeIKQ
  LV Write Access        read/write
  LV Creation host, time cent7-01, 2018-11-20 09:08:07 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                12FQnu-Eav4-0W1k-329H-QGkA-t8tB-vanNr0
  LV Write Access        read/write
  LV Creation host, time cent7-01, 2018-11-20 09:08:07 +0800
  LV Status              available
  # open                 1
  LV Size                <20.70 GiB
  Current LE             5298
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                QtcPGX-XC5Y-QmU1-8lGc-yInH-Nxbn-hbR45h
  LV Write Access        read/write
  LV Creation host, time cent7-01, 2018-11-20 09:08:07 +0800
  LV Status              available
  # open                 1
  LV Size                <38.30 GiB
  Current LE             9804
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

这个命令一般是新加分区的时候用到的。lvcreate -L  100M -n  lvdata   Vo1Group00

创建了一个名字为lvData,容量大小是100M的分区,其中:-L:指定LV的大小 -n:指定LV的名。Vo1Group00:表示从这个VG中划分LV;

7、调整文件系统

使用 resize2fs时,提示错误

[root@master ~]# resize2fs  /dev/cl/home
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/cl/home
Couldn't find valid filesystem superblock.

了解后发现,xfs格式的文件扩充需要使用 xfs_growfs

[root@master ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        39G  9.8G   29G  26% /
devtmpfs            devtmpfs  475M     0  475M   0% /dev
tmpfs               tmpfs     487M     0  487M   0% /dev/shm
tmpfs               tmpfs     487M  7.6M  479M   2% /run
tmpfs               tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  179M  836M  18% /boot
/dev/mapper/cl-home xfs        19G  2.8G   16G  15% /home
tmpfs               tmpfs      98M     0   98M   0% /run/user/0


[root@master ~]# xfs_growfs  /dev/mapper/cl-home
meta-data=/dev/mapper/cl-home    isize=512    agcount=4, agsize=1225216 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4900864, 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 4900864 to 5425152

8、收工

[root@master ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   39G  9.8G   29G  26% /
devtmpfs             475M     0  475M   0% /dev
tmpfs                487M     0  487M   0% /dev/shm
tmpfs                487M  7.6M  479M   2% /run
tmpfs                487M     0  487M   0% /sys/fs/cgroup
/dev/sda1           1014M  179M  836M  18% /boot
/dev/mapper/cl-home   21G  2.8G   18G  14% /home
tmpfs                 98M     0   98M   0% /run/user/0

参考文章:http://www.cnblogs.com/gaojun/archive/2012/08/22/2650229.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151505.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号