虚拟机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)
上一篇 2022年6月20日 上午9:46
下一篇 2022年6月20日 上午10:00


相关推荐

  • webstorm2021.1激活码(注册激活)

    (webstorm2021.1激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/ide…

    2022年3月29日
    570
  • 🌟《从一到二:基于Trae的多智能体合作Prompt自动生成迭代指南》

    🌟《从一到二:基于Trae的多智能体合作Prompt自动生成迭代指南》

    2026年3月15日
    3
  • 图解原型和原型链

    图解原型和原型链前言知识 结论 原型 把一个函数称为类的话 原型就是每个类都有的属性 作用 给这类添加属性 分为两类 显式原型 prototype 和隐式原型 proto 所有函数对象 Function 都有显式原型 所有对象 如 Object Function Array 等对象 都有隐式原型原型链 本质是链表 proto 相当于链表的指针 指向下一个对象 每个对象都有 proto 属性 它指向构造函数的 prototype 属性 构造函数的 prototype 属性的 proto 属性

    2025年9月27日
    4
  • Linux netstat命令详解

    Linux netstat命令详解简介Netstat命令用于显示各种网络相关信息,如网络连接,路由表,接口状态(InterfaceStatistics),masquerade连接,多播成员(MulticastMemberships)等等。输出信息含义执行netstat后,其输出结果为ActiveInternetconnections(w/oservers)ProtoRecv-QSend-QLocalAddressForeignAddressStatetcp02210.34.6.

    2022年5月30日
    34
  • 后台管理系统 – 权限设计

    后台管理系统 – 权限设计一、前言对于前端项目特别是中后台管理系统项目,权限设计是最复杂的点之一。一般来说权限设计需要后端来把关,毕竟相对来说前端是无法保证安全的,前端的代码和数据请求都可以伪造。而前端的权限设计更多是为了用户体验的考虑。前端保证体验,后端保证安全。由于前后端的开发差异和侧重点不同,在权限设计上也不一样。后端更多的是根据功能对象划分不同的权限模块,针对接口相应进行权限判断;而前端更多是针对页面路由进行模块划分,针对页面可访问进行判断。接下来将以后台管理系统为例,分享个人对前端权限设计的见解。(具体内容尽量做

    2022年7月16日
    15
  • 崇州上线“政务小龙虾”智能助手 “人工智能+政务服务”迈入“分钟级”时代

    崇州上线“政务小龙虾”智能助手 “人工智能+政务服务”迈入“分钟级”时代

    2026年3月12日
    3

发表回复

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

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