虚拟机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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 行测题库图形推理_2021年考公务员

    行测题库图形推理_2021年考公务员事业单位考试中,判断推理是占据一定的地位的,其中图形推理是大家经常见到的。然而,有的考生会觉得这类题目有些难,像“相亲”一样,都是看眼缘。实则不然,图形推理有它自己的规律,大家需要根据图形特征去识别该题对应的规律。比如图形相似我们可以从位置变化或者是组合叠加角度上去考虑。如果相似度很高我们更建议大家考虑位置变化,那今天中公教育老师带大家来看一下何为位置变化。1.从所给的四个选项中,选择最合适的一个…

    2022年9月10日
    1
  • js call方法_recall

    js call方法_recallJacvaScript中的call()方法和apply()方法,1.每个函数都包含两个非继承而来的方法:call()方法和apply()方法。2.相同点:这两个方法的作用是一样的。都是在特定的作用域中调用函数,等于设置函数体内this对象的值,以扩充函数赖以运行的作用域。

    2022年10月23日
    0
  • Laravel5.5 支付宝手机网站支付的教程

    Laravel5.5 支付宝手机网站支付的教程

    2021年10月24日
    51
  • 电容是根据什么分类_电容的分类与识别图片

    电容是根据什么分类_电容的分类与识别图片一、瓷介电容器(CC)1.结构用陶瓷材料作介质,在陶瓷表面涂覆一层金属(银)薄膜,再经高温烧结后作为电极而成。瓷介电容器又分1类电介质(NPO、CCG));2类电介质(X7R、2X1)和3类电介质(Y5V、2F4)瓷介电容器。2.特点1类瓷介电容器具有温度系数小、稳定性高、损耗低、耐压高等优点。最大容量不超过1000pF,常用的有CC1、CC2、CC18A、CC11、CCG等系…

    2022年8月22日
    5
  • ICMP 协议「建议收藏」

    ICMP 协议「建议收藏」一、什么是ICMP协议?ICMP(InternetControlMessageProtocol)Internet控制报文协议。它是TCP/IP协议簇的一个子协议,用于在IP主机、路由器之间传递控制消息。控制消息是指网络通不通、主机是否可达、路由是否可用等网络本身的消息。这些控制消息虽然并不传输用户数据,但是对于用户数据的传递起着重要的作用。ICMP使用IP的基本支持,就像它是一个更高级别…

    2022年10月23日
    0
  • 【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃

    【iOS开发-22】navigationBar导航栏,navigationItem建立:获取导航栏中的基本文本和button以及各种跳跃

    2022年1月16日
    36

发表回复

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

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