上次东莞的机器都是通过网络批量安装的系统,有几台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,整个过程就是这样子的,绝对是产出环境中的。