centos6 LVM分区容量扩充

centos6 LVM分区容量扩充

王忘杰
2021-03-17 / 0 评论 / 346 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年03月17日,已超过1346天没有更新,若内容或图片失效,请留言反馈。
[root@cloud ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-lv_root
                      7.4G  3.0G  4.1G  43% /

如果你买的VPS分区是10G+xxG=xxG这种,你肯定会遇到一个问题,根目录太小,空白磁盘不知道怎么利用

2种方案
把分区单独挂载一个目录,把网站放到里面
网安互联VPS挂载另一块硬盘 http://tntsec.com/index.php/archives/238.html
缺点,没啥缺点,自定义的目录,要说缺点,只能说不方便吧。

用LVM扩充直接把根扩展到最大
我看的教程
http://www.aips.me/vps-linux-fen-qu.html
我这里实际做一遍,然后补充下即可

首先列出磁盘
fdisk -l
我的之前分过区,所以有东西
如果你挂载这个磁盘,别忘了卸载,umount

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb3               1       10443    83883366    5  Extended
/dev/sdb5               1       10443    83883334+  83  Linux

所以我肯定要删除分区
fdisk /dev/sdb

查看分区结构
Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb3               1       10443    83883366    5  Extended
/dev/sdb5               1       10443    83883334+  83  Linux

h可以获得帮助,可以看到,d delete a partition
删干净
Command (m for help): d
Partition number (1-5): 5

Command (m for help): d
Selected partition 3

查看下,空了
Command (m for help): p

   Device Boot      Start         End      Blocks   Id  System

保存下
Command (m for help): w

The partition table has been altered!

重新进入
fdisk /dev/sdb
看下p
空了

新建分区
Command (m for help): n

Command action
   e   extended
   p   primary partition (1-4)

新建主分区,分区号1,大小默认
p
Partition number (1-4): 1

First cylinder (1-10443, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): 
Using default value 10443

设置分区格式为LVM 8e就是LVM
Command (m for help): t

Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

保存
Command (m for help): w

The partition table has been altered!

查看下,妥妥的
fdisk -l

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       10443    83883366   8e  Linux LVM

查看下当前的卷组情况
vgs

  VG       #PV #LV #SN Attr   VSize VFree
  vg_cloud   1   2   0 wz--n- 9.51g    0 

创建物理卷,然后加入卷组
pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created  #创建成功

vgextend vg_cloud /dev/sdb1

  Volume group "vg_cloud" successfully extended    #加入成功

查看卷组
vgdisplay

  Free  PE / Size       20479 / 80.00 GiB

查看当前正在工作的卷组,这个肯定是根
lvdisplay

  --- Logical volume ---
  LV Path                /dev/vg_cloud/lv_root
  LV Size                7.57 GiB

加入
lvresize -L +79.00G /dev/vg_cloud/lv_root

  Size of logical volume vg_cloud/lv_root changed from 7.57 GiB (1938 extents) to 86.57 GiB (22162.
  Logical volume lv_root successfully resized #成功

调整容量,大概需要5分钟
resize2fs /dev/vg_cloud/lv_root

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_cloud/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 6
Performing an on-line resize of /dev/vg_cloud/lv_root to 22693888 (4k) blocks.
 
The filesystem on /dev/vg_cloud/lv_root is now 22693888 blocks long.

完成

df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-lv_root
                       86G  3.0G   78G   4% /



0

评论

博主关闭了所有页面的评论