虚拟机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

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 卡尔曼滤波原理详解及系统模型建立(simulink)

    卡尔曼滤波原理详解及系统模型建立(simulink)卡尔曼滤波原理详解及系统模型建立(simulink)卡尔曼滤波器卡尔曼滤波器是在上个世界五六十年代的时候提出的,到今天已经有六十年左右的时间,但卡尔曼滤波算法不管在控制、制导、导航或者通讯方面对数据的预测能力依然处在一个不可撼动的位置上,但是很多人对于其算法内部的工作原理究竟是怎么运作的依然不理解,所以在工程上很多人都只是把卡尔曼滤波当成是一种“黑箱”预测算法,并不清楚内部原理。但实际上没有任…

    2022年6月16日
    28
  • 内部类与静态内部类的区别_禁止序列化非静态类的内部类

    内部类与静态内部类的区别_禁止序列化非静态类的内部类&nbsp;&nbsp;&nbsp;&nbsp;如果一个类中定义了静态成员变量和静态方法,那么静态方法可以访问静态成员变量,而无法访问非静态成员变量,并且静态成员变量和静态方法是随着类的加载而加载、非静态成员变量和方法的声明周期是由对象的声明周期控制的。&nbsp;&nbsp;&nbsp;&nbsp;静态内部类和非静态内部类同静态方法和非静态方法类似。为什么要使用内部类&nbsp;&n…

    2022年10月11日
    5
  • vim查找关键字「建议收藏」

    vim查找关键字「建议收藏」当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢?在vi里可没有菜单-〉查找不过没关系,你在命令模式下敲斜杆(/)这时在状态栏(也就是屏幕左下脚)就出现了“/”然后输入你要查找的关键字敲回车就可以了。如果你要继续查找此关键字,敲字符n就可以继续查找了。敲字符N(大写N)就会向前查询;…

    2022年6月16日
    44
  • Idea激活码永久有效Idea2017.3.6激活码教程-持续更新,一步到位

    Idea激活码永久有效Idea2017.3.6激活码教程-持续更新,一步到位Idea激活码永久有效2017.3.6激活码教程-Windows版永久激活-持续更新,Idea激活码2017.3.6成功激活

    2022年6月17日
    30
  • mysql 慢查询日志分析[通俗易懂]

    mysql 慢查询日志分析[通俗易懂]1.查找mysqlmy.ini文件C:\ProgramData\MySQL\MySQLServer5.72.查看mysql慢查询日志位置showvariableslike’%slow_query_log%’;3.查看mysql慢查询时间showvariableslike’long_query_time’;4.修改mysql修改慢查询时间找到my.ini文件修改long_query_time设置值,重启服务mysql…

    2022年10月11日
    4
  • mysql float double区别_mysql float和double类型的区别

    mysql float double区别_mysql float和double类型的区别2017-11-04回答1.float类型float列类型默认长度查不到结果,必须指定精度,比如numfloat,insertintotable(num)values(0.12);select*fromtablewherenum=0.12的话,emptyset。numfloat(9,7),insertintotable(num)values(0.12);…

    2025年7月14日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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