Saltar al final de los metadatos
Version
This article was written for version 6 of OP5 Appliance System, it could work on both lower and higher version if nothing else is stated.
Articles in community space is not covered by OP5 Support
When running virtual machines there might be a need to add space your virtual machine when it’s running low, in this example we will add 10GB to the root filesystem of a virtual instance of OP5 Appliance System 6.5.
Prerequisites
To follow this article the following will be needed:
- OP5 Appliance System 6 or CentOS 6
- As always when working with storage, make sure you have a recent backup of the virtual machine to be safe if anything should go wrong.
- No snapshots can be present on the VM when resizing the disk
- Basic knowledge about Linux and LVM2
-
Shut down your virtual machine
-
Change the setting «Provisioned Size» in VMware to the total size that you want to have available in the operating system of your virtual server:
-
Start the virtual machine and log in as root to check that size on your disk has changed:
# fdisk -l /dev/sdaDisk/dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000076f1Device Boot Start End Blocks Id System/dev/sda1* 1 17 131072 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda217 8355 66976768 8e Linux LVMIn this example, the disk /dev/sda has been extended to 107.4 GB and there are only two primary partitions currently in use, this is good because there are room for two more primary partitions.
-
What you need to do now is to create the new partition sda3 that disk size can be taken from when extending the logical volume later on. This will be done with fdiskThe default values here should be sane, just press enter after the command input.
# fdisk /dev/sdaWARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command'c') and change displayunitstosectors (command'u').Command (mforhelp): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 3First cylinder (8355-13054, default 8355):Using default value 8355Last cylinder, +cylinders or +size{K,M,G} (8355-13054, default 13054):Using default value 13054 - In the previous step, a new partition was created from the space that was added from VMware, and now we need to set the correct partition type before writing the partition table and saving the changes:
Command (mforhelp): tPartition number (1-4): 3Hex code (typeL to list codes): 8eChanged systemtypeof partition 3 to 8e (Linux LVM)Command (mforhelp): wThe partition table has been altered!Calling ioctl() to re-readpartition 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.The warning message above can be addressed in two ways: 1) Reboot the system, 2) Re-scan the device and add the new partition.
We will do the latter:
# partx -v -a /dev/sdadevice/dev/sda: start 0 size 209715200gpt: 0 slicesdos: 4 slices# 1: 2048- 264191 ( 262144 sectors, 134 MB)# 2: 264192-134217727 (133953536 sectors, 68584 MB)# 3: 134217728-209712509 ( 75494782 sectors, 38653 MB)# 4: 0- -1 ( 0 sectors, 0 MB)BLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2added partition 3The partx application will give some errors for the existing partitions, but that’s nothing to worry about. The important part is that partition 3 was successfully added.
If partition 3 isn’t added you need to reboot the machine to make the changes take effect. - Now we need to create a new physical volume that can be used for adding space to the volume group
# pvcreate /dev/sda3Physical volume"/dev/sda3"successfully created - Check what name your volume group your root filesystem uses:
# vgdisplay--- Volume group ---VG Name 1System IDFormat lvm2[..]In this case the Volume group is called 1
-
Now, lets extend the volume group with the space we added with vgextend:
# vgextend 1 /dev/sda3Volume group"1"successfully extended - With the utility pvscan you can see what physical volumes are available, and how much free space there is within them. The free space can be used to extend your root partion, or other volumes that are short on space.
# pvscanPV/dev/sda2VG 1 lvm2 [63,87 GiB / 29,87 GiBfree]PV/dev/sda3VG 1 lvm2 [36,00 GiB / 36,00 GiBfree]Total: 2 [99,87 GiB] /inuse: 2 [99,87 GiB] /inno VG: 0 [0 ] - Now in this step we will at 10G to the root partition. First find out what logical volume that the root partition belongs to:
# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/1-sys7,8G 1,4G 6,0G 20% /tmpfs 246M 0 246M 0%/dev/shm/dev/sda1120M 27M 88M 24%/boot/dev/mapper/1-opt7,8G 181M 7,2G 3%/opt/dev/mapper/1-tmp7,8G 19M 7,4G 1%/tmp/dev/mapper/1-var7,8G 475M 6,9G 7%/varIn this case, the root partition originates from the logical volume «sys», and the total size is 7.8 GB.
- The following command will add 10 GB to the Logical Volume «sys» in the Volume Group «1» and the disk area will be taken from the Physical Volume sda3.
# lvextend -l +100%FREE /dev/mapper/centos-root /dev/sda3Size of logical volume 1/syschanged from 8,00 GiB (2048 extents) to 18,00 GiB (4608 extents).Logical volume sys successfully resized. - Run the following command to expand the ext4 filesystem inside of the Logical Volume:
# xfs_growfs /dev/mapper/centos-rootAnd volià! Now your root partition is extended with 10 GB:
# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/1-sys18G 1,5G 16G 9% /tmpfs 246M 0 246M 0%/dev/shm/dev/sda1120M 27M 88M 24%/boot/dev/mapper/1-opt7,8G 181M 7,2G 3%/opt/dev/mapper/1-tmp7,8G 19M 7,4G 1%/tmp/dev/mapper/1-var7,8G 475M 6,9G 7%/varOP5 Monitor: Open Source Network Monitoring
OP5 is the preferred Open Source Networking & Server Monitoring tool for large multi-national companies in over 60 markets. If you would like to experience OP5 Monitor you can get started here, alternatively, if you prefer to get more hands on you can Download OP5 Monitor for free.
