在线扩容LVM硬盘容量

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://navyaijm.blog.51cto.com/4647068/821329

上次东莞的机器都是通过网络批量安装的系统,有几台HP的一拖四的服务器没有RAID卡,所以只用到了一块硬盘,还有两块硬盘没有用上,现在我要把剩下的两块硬盘扩容到/data下面,我们分区都是做了LVM,下面是具体如何在线扩容的过程:

一.看以下现在的分区情况:

[root@localhost ~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3837    30716280   8e  Linux LVM
/dev/sda3            3838        5367    12289725   82  Linux swap / Solaris
/dev/sda4            5368      121601   933649605   8e  Linux LVM

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

 

二、在线扩容容量主要分5给步骤

   1.用fdisk设置新的具有8e systenID的分区;

   2.利用pvcreate构建PV;

   3.利用vgextend将PV加入VG(/dev/VolGroupData);

   4.利用lvresize将新加入的PV内的PE加入/dev/VolGroupData中;

   5.通过resize2fs将文件系统的容量确实增加!

三、具体实施步骤:

   1.新建分区,一块盘一分区

[root@localhost ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n(新建分区)
Command action
   e   extended
   p   primary partition (1-4)
p(主分区)
Partition number (1-4): 1(回车)
First cylinder (1-121601, default 1): (回车)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601): 
Using default value 121601

Command (m for help): wq(保存退出)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

[root@localhost ~]# fdisk /dev/sdc

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n(新建分区)
Command action
   e   extended
   p   primary partition (1-4)
p(主分区)
Partition number (1-4): 1(回车)
First cylinder (1-121601, default 1): (回车)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601): 
Using default value 121601

Command (m for help): wq(保存退出)
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.
Syncing disks.
[root@localhost ~]#

2.更改systenID号

[root@localhost ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t(更改systemID)
Selected partition 1
Hex code (type L to list codes): 8e(LVM的systemID)
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): wq(保存退出)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

[root@localhost ~]# fdisk /dev/sdc

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t(更改systemID)
Selected partition 1
Hex code (type L to list codes): 8e(LVM的systemID)
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): wq(保存退出)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3.看一下现在的分区情况

[root@localhost ~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3837    30716280   8e  Linux LVM
/dev/sda3            3838        5367    12289725   82  Linux swap / Solaris
/dev/sda4            5368      121601   933649605   8e  Linux LVM

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001   8e  Linux LVM

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      121601   976760001   8e  Linux LVM

 

4.新建新的PV /dev/sdb1、/dev/sdc1

[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# 

5.看一下PV

[root@localhost ~]# pvscan 
  PV /dev/sda4   VG VolGroupData    lvm2 [890.38 GB / 0    free]
  PV /dev/sda2   VG VolGroupRoot    lvm2 [29.28 GB / 0    free]
  PV /dev/sdb1                      lvm2 [931.51 GB]
  PV /dev/sdc1                      lvm2 [931.51 GB]
  Total: 4 [2.72 TB] / in use: 2 [919.66 GB] / in no VG: 2 [1.82 TB]

可以看到/dev/sdb1、/dev/sdc1是新加入并且尚未被使用的

6.加大VG,利用vgextend功能

[root@localhost ~]# vgextend /dev/VolGroupData /dev/sdb1 /dev/sdc1
  Volume group "VolGroupData" successfully extended
[root@localhost ~]# 

7.看一下VG是否加大

[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroupData
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               2.69 TB
  PE Size               32.00 MB
  Total PE              88108
  Alloc PE / Size       28492 / 890.38 GB
  Free  PE / Size       59616 / 1.82 TB
  VG UUID               6uvOR7-Pe9I-3fxK-CI3D-Yoqm-1nQv-D7MorV

确实加大了,剩余的PE共有59616个,容量为1.82T

8.放大LV,利用lvresize的功能

[root@localhost ~]# lvresize -l +59616 /dev/VolGroupData/LogVolData 
  Extending logical volume LogVolData to 2.68 TB
  Logical volume LogVolData successfully resized

注意:如果文件系统是xfs的那么就用xfs_growf命令

9.看一下LV是否增加

[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/VolGroupData/LogVolData
  VG Name                VolGroupData
  LV UUID                6kAmNU-pX1J-hbx6-bKQ4-Iu1L-uC4M-W9GFQa
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.68 TB
  Current LE             87796
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

10.虽然LV已经增加了,但是文件系统却没有相对增加,现在我们就在线增加,不需要umount,很人性化,

[root@localhost ~]# resize2fs /dev/VolGroupData/LogVolData 
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroupData/LogVolData is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/VolGroupData/LogVolData to 719224832 (4k) blocks.
The filesystem on /dev/VolGroupData/LogVolData is now 719224832 blocks long.

因为是磁盘比较打2个T,所以这个时间比较长写,大概半个小时左右。

A.看一下扩容前的情况

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroupRoot-LogVolRoot
                       29G  1.9G   26G   7% /
/dev/mapper/VolGroupData-LogVolData
                      854G  201M  809G   1% /data
/dev/mapper/VolGroupData-LogVolLogs
                      9.5G  151M  8.9G   2% /data/logs
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 3.0G     0  3.0G   0% /dev/shm

B.看一下扩容后的情况

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroupRoot-LogVolRoot
                       29G  1.9G   26G   7% /
/dev/mapper/VolGroupData-LogVolData
                      2.6T  202M  2.5T   1% /data
/dev/mapper/VolGroupData-LogVolLogs
                      9.5G  151M  8.9G   2% /data/logs
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 3.0G     0  3.0G   0% /dev/shm

 

OK,整个过程就是这样子的,绝对是产出环境中的。

 

本文出自 “屌丝运维男” 博客,请务必保留此出处http://navyaijm.blog.51cto.com/4647068/821329

时间: 2024-08-24 06:10:42

在线扩容LVM硬盘容量的相关文章

固态硬盘容量小 ? 360云盘免费扩容36T

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断淘宝客 站长团购 云主机 技术大厅 几年以前,碍于厂商对成本的限制,一块同容量的固态硬盘比机械硬盘贵了很多,曾经装机配上一块固态硬盘,也是标准发烧友的配置.现如今固态硬盘市场日趋成熟,普及率也比前两年大幅提高,不过固态硬盘容量仍以128GB和256GB为主,价位也并没有降低多少,许多用户想要给自己的电脑扩容,只能继续选购昂贵的产品,今天就教您完美扩容并且不花费一分钱.

固态硬盘容量小?360云盘免费扩容36T(图)

几年以前,碍于厂商对成本的限制,一块同容量的http://www.aliyun.com/zixun/aggregation/15579.html">固态硬盘比机械硬盘贵了很多,曾经装机配上一块固态硬盘,也是标准发烧友的配置.现如今固态硬盘市场日趋成熟,普及率也比前两年大幅提高, 不过固态硬盘容量仍以128GB和256GB为主,价位也并没有降低 多少,许多用户想要给自己的电脑扩容,只能继续选购昂贵的产品,今天就教您完美扩容并且不花费一分钱. 微博网友"谈笑皆鸿儒6316"

linux中XenServer虚拟机扩容LVM磁盘分区

说明:XenServer里面安装的虚拟机,分区的时候采用的是LVM磁盘分区 需求:现在需要扩容虚拟机根分区/ 具体操作: 一.使用XenCenter增大虚拟机磁盘容量,如下图所示 增大当前磁盘到50GB 注意:必须在虚拟机关机状态下进行 二.查看硬盘容量 df -h #可以看到此时根分区还是12G,没有变化 fdisk -l #已经可以看到整个磁盘容量变为53.6GB了 三.创建新的磁盘分区 fdisk /dev/xvda #对磁盘/dev/xvda进行操作 p #查看当前分区 n #创建新分区

XenServer 虚拟机扩容LVM磁盘分区的方法_XenServer

说明:XenServer里面安装的虚拟机,分区的时候采用的是LVM磁盘分区 需求:现在需要扩容虚拟机根分区/ 具体操作: 一.使用XenCenter增大虚拟机磁盘容量,如下图所示 增大当前磁盘到50GB 注意:必须在虚拟机关机状态下进行 二.查看硬盘容量 df -h #可以看到此时根分区还是12G,没有变化 fdisk -l #已经可以看到整个磁盘容量变为53.6GB了 三.创建新的磁盘分区 fdisk /dev/xvda #对磁盘/dev/xvda进行操作 p #查看当前分区 n #创建新分区

oracle 11g ASM 磁盘组在线扩容实验:

oracle 11g ASM磁盘组扩容实验: 该主机为我经常用的测试机,因为为了顺便学习ASM,底层存储使用的是ASM的方式,但是以前规划的时候磁盘组只有4G,由于数据文件增加,导致没有可用的空间.所以,模拟生产环境做了ASM在线扩容的实验. 建议在做之前,对数据库进行备份. ---------------------------------------1.主机和数据库环境--------------------------------------- SQL> select * from v$v

VirtualBox如何扩展虚拟机Ubuntu的硬盘容量?

一.问题描述 刚刚在VirtualBox中使用Ubuntu虚拟机中,出现了虚拟硬盘不够用的情况. 乖乖,查了一下磁盘空间,如下所示: df -H 原来是上午安装Ubuntu虚拟机的时候,选择了动态分配存储,想当然的以为硬盘不够用的时候,它会自动扩展,没想到上限是默认的8G.这就悲剧了,才用了一下子就占了96%的磁盘空间了,因此只能进行虚拟硬盘容量的扩容操作. 二.扩展虚拟硬盘容量 第1步.查看硬盘镜像文件 1.虚拟机关机,关机后如下所示,显示硬盘大小上限为8G. 2.启动CMD命令行,进入Vir

Win8.1系统怎么查看硬盘容量大小?

  Win8.1系统怎么查看硬盘容量大小? 1.首先我们需要找到"这台电脑"图标,找到之后单击该图标,然后就会进入到如图面板,在这个面板的上方会有一个"管理"按钮,我们选择该按钮. 2.接下来就会进入到计算机管理面板,在这个面板的存储下方就会有一个"磁盘管理"功能,我们选择该功能. 3.然后就会进入到磁盘管理控制面板,在这个面板的左下角我们就可以看到硬盘的容量是多大了.

Win8.1系统查看硬盘容量的方法

  我们平常在购买电脑的时候都会考虑电脑硬盘容量的大小,虽然商家一般都会标注是多大,但是为了安全起见,我们还是需要自己手动去核实电脑的实际容量是多少以防被骗.但是很多童鞋可能都不知道怎么查看电脑硬盘容量的大小,下面小编就来说说怎么操作. 首先我们需要找到"这台电脑"图标,找到之后单击该图标,然后就会进入到如图面板,在这个面板的上方会有一个"管理"按钮,我们选择该按钮. 接下来就会进入到计算机管理面板,在这个面板的存储下方就会有一个"磁盘管理"功能

如何查看win8电脑的硬盘容量大小?

  在之前的win7 旗舰版中,咱们要查看电脑中的磁盘容量大小是很方便的,大家只需要直接双击进入计算机中,然后分别右键点击每一个win7旗舰版电脑中的磁盘,然后选择属性,然后在打开的属性窗口中,咱们就可以看到每一个磁盘的容量大小了.但是升级到win8系统之后,似乎很多用户都不知道该如何对电脑中的磁盘大小进行查询了.下面,就让小编来具体介绍一下,如何查看win8电脑的硬盘容量大小吧! 推荐系统:win7旗舰版32位下载 1.首先,咱们需要将win8系统从新式的metro界面中返回到传统界面中,之后