surroundings
name | Attributes |
---|---|
CPU | x5650 |
RAM | 4G |
Disk | 20G+4TB |
At this time, we assume that the server has the following things:
-
Installed the Parted (yum install parted)
-
Partition size has been victory, the company server and adding a hard disk to increase the capacity of 4T!
-
In addition to / boot partition, and the rest are extended LVM logical partition mode
Software Installation and View
First check whether the software is installed:
[root@Candy ~]# rpm -qa | grep lvm
lvm2-libs-2.02.118-2.el6.x86_64
lvm2-2.02.118-2.el6.x86_64
[root@Candy ~]# lv
lvchange lvextend lvmdiskscan lvmsar lvresize
lvconvert lvm lvmdump lvreduce lvs
lvcreate lvmchange lvmetad lvremove lvscan
lvdisplay lvmconf lvmsadc lvrename
[root@Candy ~]# rpm -qa | grep parted
parted-2.1-29.el6.x86_64
When you're ready to see the way the software under VM Hardware:
[root@Candy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root
7.3G 231M 6.7G 4% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/mapper/vg_candy-home
3.9G 8.0M 3.7G 1% /home
/dev/mapper/vg_candy-usr
3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var
3.9G 63M 3.6G 2% /var
[root@Candy ~]# fdisk -l
Disk /dev/sda: 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: 0x0006e71c
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 2611 20458496 8e Linux LVM
Disk /dev/sdb: 4398.0 GB, 4398046511104 bytes
255 heads, 63 sectors/track, 534698 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_candy-root: 8061 MB, 8061452288 bytes
255 heads, 63 sectors/track, 980 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_candy-usr: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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_candy-var: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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_candy-home: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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@Candy ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
At this time we have seen, Centos already know a sdb disk, but did not mount the partition.
Parted partitioning using pre-expansion
Now suppose that in addition to / boot partition the rest are full! We need to partition the hard disk to spend 4T (/ dev / sdb).
[root@Candy ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
新的磁盘标签类型? gpt
(parted) mkpart
分区名称? []?
文件系统类型? [ext2]? ext4
起始点? 0T
结束点? 4T
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 4398GB 4398GB
(parted)set 1 lvm on
(parted)p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 4398GB 4398GB lvm
(parted)q
[root@Candy ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
Now let us explain the operation:
-
mklabel convert to gpt disk partition, because MBR partition can not support TB-level hard disk (please refer to their own specific, parted course, also supports the following operating level TB)
-
mkpart convert good gpt partition the disk, you need to provide file system type, start point, end point.
-
Enter p to print out just before doing generated after partition.
-
set 1 lvm on partition is num 1, tager set to LVM, so as to add to the volume group in vm
Next, we see what our LVM group named:
[root@Candy ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_candy 1 4 0 wz--n- 19.51g 0
[root@Candy ~]# vgdisplay
--- Volume group ---
VG Name vg_candy
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
[root@Candy ~]# lvscan
ACTIVE '/dev/vg_candy/usr' [4.00 GiB] inherit
ACTIVE '/dev/vg_candy/var' [4.00 GiB] inherit
ACTIVE '/dev/vg_candy/home' [4.00 GiB] inherit
ACTIVE '/dev/vg_candy/root' [7.51 GiB] inherit
[root@Candy ~]#
Know lvm volume group called 'vg_candy', we will use vgextend to add a member to the lvm 'vg_candy' roll group.
[root@Candy ~]# vgextend vag_candy /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Volume group "vg_candy" successfully extended
Now we vgs command and then look at the number of pv:
[root@Candy ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_candy 2 4 0 wz--n- 4.02t 4.00t
When we compare whether vgs is not added to see the number of PV from 1 to 2 up!
Let us now look at the capacity vgdisplay now partition.
[root@Candy ~]# vgdisplay
--- Volume group ---
VG Name vg_candy
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 4.02 TiB
PE Size 4.00 MiB
Total PE 1053569
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 1048575 / 4.00 TiB
VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
Contrast command is not added again vgdiplay found, FreePE a value from 0/0 to 1048575 / 4.00 TiB. Such instructions Candy has been successfully added into vg_candy lvm logical volume group in the partition of 4TB.
Now before we carry out the expansion of all logical partitions, df -h to see what partitions.
[root@Candy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root 7.3G 231M 6.7G 4% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/mapper/vg_candy-home 3.9G 8.0M 3.7G 1% /home
/dev/mapper/vg_candy-usr 3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var 3.9G 63M 3.6G 2% /var
Now troublesome thing has been done, then the rest for expansion for the partition.
For expansion as disk
假设:我们需要向 这些分区都添加500G容量: /
、/home
、/usr
、/var
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-root
Size of logical volume vg_candy/root changed from 7.51 GiB (1922 extents) to 507.51 GiB (129922 extents).
Logical volume root successfully resized
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-home
Size of logical volume vg_candy/home changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
Logical volume home successfully resized
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-usr
Size of logical volume vg_candy/usr changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
Logical volume usr successfully resized
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-var
Size of logical volume vg_candy/var changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
Logical volume var successfully resized
大家注意,这一步操作时不可逆的!
如果输入了错误的分区名字还好! 如果添加到其它分区了,就得重复N遍来缩容,比较麻烦哦! 建议大家注仔细核对上面的FileSystem.
切记切记…
提示扩容成功! 让我们再次用上述命令查看LVM信息:
[root@Candy ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_candy 2 4 0 wz--n- 4.02t 2.05t
[root@Candy ~]# lvscan
ACTIVE '/dev/vg_candy/usr' [504.00 GiB] inherit
ACTIVE '/dev/vg_candy/var' [504.00 GiB] inherit
ACTIVE '/dev/vg_candy/home' [504.00 GiB] inherit
ACTIVE '/dev/vg_candy/root' [507.51 GiB] inherit
[root@Candy ~]# vgdisplay
--- Volume group ---
VG Name vg_candy
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 10
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 4.02 TiB
PE Size 4.00 MiB
Total PE 1053569
Alloc PE / Size 516994 / 1.97 TiB
Free PE / Size 536575 / 2.05 TiB
VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
[root@Candy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root 7.3G 231M 6.7G 4% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/mapper/vg_candy-home 3.9G 8.0M 3.7G 1% /home
/dev/mapper/vg_candy-usr 3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var 3.9G 63M 3.6G 2% /var
看到这里大家可能奇怪! 为什么df -h 还没变呢?
刷新磁盘信息与写入
我们需要用resize2fs 重设分区大小, 这样才能使df -h 也能生效.
而resize2fs 需要的时间与你给予的容量线性叠加. 也就是说你给的容量越多,resize2fs 的需要的时间就越多。
[root@Candy ~]# resize2fs /dev//mapper/vg_candy-root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-root to 133040128 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-root is now 133040128 blocks long.
[root@Candy ~]# resize2fs /dev//mapper/vg_candy-usr
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-usr is mounted on /usr; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-usr to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-usr is now 132120576 blocks long.
[root@Candy ~]# resize2fs /dev//mapper/vg_candy-var
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-var is mounted on /var; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-var to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-var is now 132120576 blocks long.
[root@Candy ~]# resize2fs /dev//mapper/vg_candy-home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-home is mounted on /home; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-home to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-home is now 132120576 blocks long.
[root@Candy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root 500G 245M 474G 1% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/mapper/vg_candy-home 496G 16M 471G 1% /home
/dev/mapper/vg_candy-usr 496G 390M 471G 1% /usr
/dev/mapper/vg_candy-var 496G 71M 471G 1% /var
结束语
顺便给大家晒一张重启后系统自动挂载的图!
Centos 系统还是比较聪明的. 其实重启与不重启都能使用, 只是为大家演示重启后的效果.
希望此文章能帮助大家平滑的进行水平扩容!