生产环境服务器磁盘扩容记录

磁盘已占用80%,对磁盘进行扩容

[root@JT-T-KEYAN-001 ~]# df -h
文件系统              容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_rhlinux1-lv_root
                       34G   25G  6.7G  79% /
tmpfs                 3.9G  224K  3.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
//172.16.239.6/KYGL    76T   15T   62T  19% /www/files
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]#

加上120G的磁盘之后,使用fdisk -l查看磁盘信息

[root@JT-T-KEYAN-001 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
64 heads, 32 sectors/track, 61440 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       40960    41430016   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_rhlinux1-lv_root: 36.1 GB, 36146511872 bytes
255 heads, 63 sectors/track, 4394 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


Disk /dev/mapper/vg_rhlinux1-lv_swap: 6274 MB, 6274678784 bytes
255 heads, 63 sectors/track, 762 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

[root@JT-T-KEYAN-001 ~]#

Disk 显示为 Disk /dev/sda: 64.4 GB,新添加的 120G 磁盘并未检测到。找到下述方式,查看 /sys/class/scsi_host 下的目录结构,添加 - - - 标志到目录下文件中的 scan文件

驱动程序读取到此标识后,会触发重新识别磁盘的操作

[root@JT-T-KEYAN-001 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@JT-T-KEYAN-001 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@JT-T-KEYAN-001 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
64 heads, 32 sectors/track, 61440 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       40960    41430016   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_rhlinux1-lv_root: 36.1 GB, 36146511872 bytes
255 heads, 63 sectors/track, 4394 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


Disk /dev/mapper/vg_rhlinux1-lv_swap: 6274 MB, 6274678784 bytes
255 heads, 63 sectors/track, 762 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

[root@JT-T-KEYAN-001 ~]#

通过上述方式,执行后并未生效,最后在凌晨重启了服务器(需要甚重考虑,不能影响生产业务),再通过 fdisk -l 查看磁盘信息

[root@JT-T-KEYAN-001 ~]# fdisk -l

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Disk /dev/mapper/vg_rhlinux1-lv_root: 36.1 GB, 36146511872 bytes
255 heads, 63 sectors/track, 4394 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


Disk /dev/mapper/vg_rhlinux1-lv_swap: 6274 MB, 6274678784 bytes
255 heads, 63 sectors/track, 762 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

[root@JT-T-KEYAN-001 ~]#

创建新的分区 fdisk /dev/sda

/dev/sda 取自 fdisk -l中的Disk /dev/sda: 171.8 GB, 171798691840 bytes

[root@JT-T-KEYAN-001 ~]# fdisk /dev/sda

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): 
Command (m for help): m
Command action
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): 

p查看当前分区信息

Command (m for help): p

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Command (m for help):

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Command (m for help):

Device显示已经存在 /dev/sda1/dev/sda2
n创建新的分区

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p # 选择主分区
Partition number (1-4):
Value out of range.
Partition number (1-4): 3 # 分区序号
First cylinder (5222-20886, default 5222):
Using default value 5222
Last cylinder, +cylinders or +size{K,M,G} (5222-20886, default 20886):
Using default value 20886

Command (m for help): 

再次查看分区信息

Command (m for help): p

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM
/dev/sda3            5222       20886   125823755   83  Linux # 新创建的分区

Command (m for help):

t修改分区的格式为 8e

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): 

查看调整后的分区信息

Command (m for help): p

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM
/dev/sda3            5222       20886   125823755   8e  Linux LVM

Command (m for help):

w保存信息

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@JT-T-KEYAN-001 ~]#

fdisk -l查看磁盘信息,Device下的 /dev/sda3为新创建的分区

[root@JT-T-KEYAN-001 ~]# fdisk -l

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x00013041

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM
/dev/sda3            5222       20886   125823755   8e  Linux LVM

Disk /dev/mapper/vg_rhlinux1-lv_root: 36.1 GB, 36146511872 bytes
255 heads, 63 sectors/track, 4394 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


Disk /dev/mapper/vg_rhlinux1-lv_swap: 6274 MB, 6274678784 bytes
255 heads, 63 sectors/track, 762 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

[root@JT-T-KEYAN-001 ~]#

reboot重启服务器,创建物理卷:

[root@JT-T-KEYAN-001 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]#

查看物理卷信息,此时分为两部分:

[root@JT-T-KEYAN-001 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_rhlinux1
  PV Size               39.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10114
  Free PE               0
  Allocated PE          10114
  PV UUID               qYY7GZ-7xaq-qneQ-uvpX-4XcJ-JmwR-B1GX5E

  "/dev/sda3" is a new physical volume of "119.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name
  PV Size               119.99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               iZiQu4-rkxI-N2aB-Isan-3m8z-Gd4C-5ZHLGh

[root@JT-T-KEYAN-001 ~]#

将新创建的物理卷,添加到卷组 vg_rhlinux1

vg_rhlinux1 取自于 pvdisplay 中的 VG Name

[root@JT-T-KEYAN-001 ~]# vgextend vg_rhlinux1 /dev/sda3
  Volume group "vg_rhlinux1" successfully extended
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]#

添加到卷组中后,再查看卷组信息:

[root@JT-T-KEYAN-001 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhlinux1
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               159.50 GiB
  PE Size               4.00 MiB
  Total PE              40832
  Alloc PE / Size       10114 / 39.51 GiB
  Free  PE / Size       30718 / 119.99 GiB
  VG UUID               O1n5g2-qwJZ-Vib0-D947-2H6R-ikoC-drQDuF

[root@JT-T-KEYAN-001 ~]#

卷组 vg_rhlinux1 已分配空间 39.51 GiB:Alloc PE / Size 10114 / 39.51 GiB
可分配空间 119.99 GiB: Free PE / Size 30718 / 119.99 GiB

增加文件系统 /dev/mapper/vg_rhlinux1-lv_root 的空间(119.99G):

/dev/mapper/vg_rhlinux1-lv_root 取自于 df -h

[root@JT-T-KEYAN-001 ~]# lvresize -L +119.99G /dev/mapper/vg_rhlinux1-lv_root
  Rounding size to boundary between physical extents: 119.99 GiB
  Extending logical volume lv_root to 153.66 GiB
  Logical volume lv_root successfully resized
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]#

resize2fs 增大未被加载的文件系统大小:

[root@JT-T-KEYAN-001 ~]# resize2fs /dev/mapper/vg_rhlinux1-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_rhlinux1-lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 10
Performing an on-line resize of /dev/mapper/vg_rhlinux1-lv_root to 40280064 (4k) blocks.
The filesystem on /dev/mapper/vg_rhlinux1-lv_root is now 40280064 blocks long.

[root@JT-T-KEYAN-001 ~]#

重新查看磁盘空间使用情况

[root@JT-T-KEYAN-001 ~]# df -h
文件系统              容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_rhlinux1-lv_root
                      152G   25G  119G  18% /
tmpfs                 3.9G   72K  3.9G   1% /dev/shm
/dev/sda1             485M   38M  423M   9% /boot
//172.16.239.6/KYGL    76T   15T   62T  19% /www/files
[root@JT-T-KEYAN-001 ~]#

结束!

问题:在虚拟机上进行添加测试时,还遇到显示可用空间为 32G,实际添加时并没有32G

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  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               95.50 GiB
  PE Size               4.00 MiB
  Total PE              24449
  Alloc PE / Size       16258 / <63.51 GiB
  Free  PE / Size       8191 / <32.00 GiB
  VG UUID               Y7eTgz-cYoH-r3gT-5BZw-3JTm-7hXg-TgjxRZ

[root@localhost ~]#
[root@localhost ~]# lvresize -L +32G /dev/mapper/VolGroup-lv_root
  Insufficient free space: 8192 extents needed, but only 8191 available
[root@localhost ~]#

只有 8191 可用,每个 PE Size 为 4MiB,可扩增空间为:8191 x 4 / 1024

[root@localhost ~]# lvresize -L +31.99G /dev/mapper/VolGroup-lv_root
  Rounding size to boundary between physical extents: 31.99 GiB.
  Size of logical volume VolGroup/lv_root changed from 50.00 GiB (12800 extents) to 81.99 GiB (20990 extents).
  Logical volume VolGroup/lv_root successfully resized.
[root@localhost ~]#

发表评论

您的电子邮箱地址不会被公开。