lvm卷组管理之磁盘扩容

服务器使用的是阿里云的服务器,由于早期阿里云还不支持磁盘直接扩容,所以当时做了lvm卷组管理,以便后期磁盘不足时可以灵活的扩展,以下是我目前的环境:

[alex@iZ25noqnry1Z ~]$ df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/xvda1             20G  2.0G   17G  11% /

tmpfs                 1.9G     0  1.9G   0% /dev/shm

/dev/mapper/VolGroup-data

                      936G  820G   69G  93% /data

如上,磁盘已快不足了。现在在阿里云的控制台将磁盘扩展到1500GB,然后在控制台重启服务器(在系统中重启无效),重启前先将 /etc/fstab 中的磁盘挂载信息注释掉。

[root@iZ25noqnry1Z ~]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Thu Jul  3 10:43:14 2014

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=2a348234-4a73-491c-98e9-47900d88697b / ext4 defaults,barrier=0 1 1

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

none                  /proc/xen               xenfs   defaults        0 0

#/dev/VolGroup/data     /data                   ext4    defaults        0 0

重启后ssh登录系统,如下:

[root@iZ25noqnry1Z ~]# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00060953

    Device Boot      Start         End      Blocks   Id  System

/dev/xvda1   *           1        2611    20970496   83  LinuxDisk /dev/xvdb: 1610.6 GB, 1610612736000 bytes

255 heads, 63 sectors/track, 195812 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xe3ad639b

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1      130541  1048570551   8e  Linux LVM

Disk /dev/mapper/VolGroup-data: 1020.1 GB, 1020054732800 bytes

255 heads, 63 sectors/track, 124014 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

如上,磁盘扩容已生效。

接下来进行lvm扩容。

    

1. 将扩展的磁盘进行分区

[root@iZ25noqnry1Z ~]# fdisk /dev/xvdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').

Command (m for help): p

Disk /dev/xvdb: 1610.6 GB, 1610612736000 bytes

255 heads, 63 sectors/track, 195812 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xe3ad639b

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1      130541  1048570551   8e  Linux LVM

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (130542-195812, default 130542):

Using default value 130542

Last cylinder, +cylinders or +size{K,M,G} (130542-195812, default 195812):

Using default value 195812

Command (m for help): p

Disk /dev/xvdb: 1610.6 GB, 1610612736000 bytes

255 heads, 63 sectors/track, 195812 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xe3ad639b

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1      130541  1048570551   8e  Linux LVM

/dev/xvdb2          130542      195812   524289307+  83  Linux

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 8e

Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/xvdb: 1610.6 GB, 1610612736000 bytes

255 heads, 63 sectors/track, 195812 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xe3ad639b

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1      130541  1048570551   8e  Linux LVM

/dev/xvdb2          130542      195812   524289307+  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: 设备或资源忙.

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.

出现上面信息,root重启一下服务器。

    

重启后查看磁盘信息,如下:

[root@iZ25noqnry1Z ~]# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00060953

    Device Boot      Start         End      Blocks   Id  System

/dev/xvda1   *           1        2611    20970496   83  Linux

Disk /dev/xvdb: 1610.6 GB, 1610612736000 bytes

255 heads, 63 sectors/track, 195812 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xe3ad639b

    Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1               1      130541  1048570551   8e  Linux LVM

/dev/xvdb2          130542      195812   524289307+  8e  Linux LVM

Disk /dev/mapper/VolGroup-data: 1020.1 GB, 1020054732800 bytes

255 heads, 63 sectors/track, 124014 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

    

2. 创建PV物理卷

[root@iZ25noqnry1Z ~]# pvcreate /dev/xvdb2

  Physical volume "/dev/xvdb2" successfully created

    

3. 将pv加入现有的vg组中

[root@iZ25noqnry1Z ~]# vgextend VolGroup /dev/xvdb2

  Volume group "VolGroup" successfully extended

    

4. 扩展现有lv卷

[root@iZ25noqnry1Z ~]# lvextend -L +327200 /dev/VolGroup/data    

  Extending logical volume data to 1.24 TiB

  Logical volume data successfully resized

可以使用扩展所有剩余容量:

# lvextend  -l +100%FREE /dev/VolGroup/data

    

5. 刷新容量

[root@iZ25noqnry1Z ~]# lvextend -L +327200 /dev/VolGroup/data      

  Extending logical volume data to 1.24 TiB

  Logical volume data successfully resized

[root@iZ25noqnry1Z ~]# resize2fs /dev/VolGroup/data

resize2fs 1.41.12 (17-May-2010)请先运行 'e2fsck -f /dev/VolGroup/data'.

出现以上,那就执行一下吧。

[root@iZ25noqnry1Z ~]# e2fsck -f /dev/VolGroup/data

e2fsck 1.41.12 (17-May-2010)

第一步: 检查inode,块,和大小

第二步: 检查目录结构

第3步: 检查目录连接性

/lost+found未找到.创建<y>? 是

Pass 4: Checking reference counts

第5步: 检查簇概要信息

/dev/VolGroup/data: ***** 文件系统已修改 *****

/dev/VolGroup/data: 173081/62259200 files (1.8% non-contiguous), 218725658/249036800 blocks

[root@iZ25noqnry1Z ~]#

    

执行检查完成,再次执行刷新:

[root@iZ25noqnry1Z ~]# resize2fs /dev/VolGroup/data

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/VolGroup/data to 332800000 (4k) blocks.

The filesystem on /dev/VolGroup/data is now 332800000 blocks long.

    

6. 挂载磁盘

[root@iZ25noqnry1Z data]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/xvda1             20G  1.9G   17G  11% /

tmpfs                 1.9G     0  1.9G   0% /dev/shm

/dev/mapper/VolGroup-data

                      1.3T  820G  367G  70% /data

    

7. 将 /etc/fstab 文件中注释的磁盘挂载信息打开,可以重启一下服务器看是否依然正常挂载,成功挂载就OK了。

版权声明:
作者:admin
链接:https://www.chenxie.net/archives/1165.html
来源:蜀小陈
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>