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


相关推荐

  • PHP中heredoc和nowdoc的用法

    PHP中heredoc和nowdoc的用法

    2022年2月23日
    47
  • leetcode-138. 复制带随机指针的链表(链表)

    leetcode-138. 复制带随机指针的链表(链表)给你一个长度为 n 的链表,每个节点包含一个额外增加的随机指针 random ,该指针可以指向链表中的任何节点或空节点。构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节点的 next 指针和 random 指针也都应指向复制链表中的新节点,并使原链表和复制链表中的这些指针能够表示相同的链表状态。复制链表中的指针都不应指向原链表中的节点 。例如,如果原链表中有 X 和 Y 两个节点,其中 X.random –> Y 。那么在复制链

    2022年8月9日
    9
  • 树莓派搭建个人网站_树莓派 freenas

    树莓派搭建个人网站_树莓派 freenas必要的设置如下:#在树莓派上设置手机上网的接口ifconfig#查看网络接口sudosrsepc_if_masq.sheth0#选择能上网的接口,此处为eth0#在电脑1上设置路由信息使得电脑1能ping到测试手机sudorouteadd-host172.16.0.2gw192.168.2.104#临时添加路由信息,其中172.16.0.2为测试手机的IP地址,192.168.2.104为树莓派的IP地址route-n#查看路由信息#在测试手机上SIM卡信.

    2022年10月6日
    2
  • MySQL自增主键值回溯问题

    MySQL自增主键值回溯问题平时我们使用MySQL时,通常每一个表都会有一个自增主键ID,每新增一条数据,ID值就会自增1。但在8.0之前版本的MySQL中,这个自增值会存在一个回溯的问题。例如,在一个新表中插入三条主键为1、2、3的数据行,这时候用SHOWCREATETABLE命令查看该表的AUTO_INCREMENT的值是4,这是没问题的。然后把ID=3的数据行删掉,再次查询AUTO_INCREMENT的值,依然是4,这也是没问题的。但如果重启一下MySQL,这个值就会变回3,而不是4,发生了回溯。这是因为AUTO_I

    2022年6月16日
    77
  • 初识 GTK

    初识 GTKGTK+是一种函数库是用来帮助制作图形交互界面的。整个函数库都是由C语言来编写的。GTK+函数库通常也叫做GIMP工具包。

    2025年5月24日
    2
  • 剖析RT-Thread中console与finsh组件实现(2)[通俗易懂]

    剖析RT-Thread中console与finsh组件实现(2)[通俗易懂]接上一章剖析RT-Thread中finsh组件实现(1),rt_device具体定义如下:其中内核基类定义如下:所以刚才串口1初始化后名称被初始化为了“usart1”,与刚才设置终端时入参刚好可以匹配。而这个标志是类型标志,串口类型即为RT_Object_Class_Device,同时也是一个静态类,所以会或上0x80其实rt_device中最重要的是传入了设备回调与操作函数指针,这些指针此时指向的是串口1的一系列操作函数。这些函数被初始化在串口1初始化的rt_hw_serial

    2022年5月12日
    37

发表回复

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

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