Minggu, 29 April 2018

Increasing Disk of VM Guest VM Ware ESXI

  Tidak ada komentar
Increasing disk spaces on the Linux servers is a daily routine work for very system administrator. So, in this article we are going to show you some simple simple steps that you can use to increase your disk spaces on Linux CentOS 7 on VmWare ESXi host without rebooting to your production server using Linux commands.

1) Increasing disk of VM guest:

Before increasing the disk volume inside your Linux system, you need to add a new disk or increase the one its has already attached with the system by editing its settings from your VMware vShere, Workstation or any other infrastructure environment that you are using.
Increase disk

2) Check Disk Space:

Run the following command to check the current size of your disk space.
[root@myhost]# df -h
[root@myhost]#
[root@myhost]# fdisk -l
[root@myhost]#
Fdisk check
Here we can see that the total disk size is still the same that is 10 GB while we have already increased it to 50 GB from the back end.

3) Expanding Space without Rebooting VM

Now run the following commands to expand the disk space in the physical volume of the Operating System without rebooting the virtual machine by Re-scanning the SCSI Bus and then adding SCSI Device.
[root@myhost]# ls /sys/class/scsi_host/
[root@myhost]#
[root@myhost]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@myhost]#
[root@myhost]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@myhost]#
[root@myhost]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@myhost]#
Check the names of your SCSI devices and then rescan the SCSI buses using below commands.
[root@myhost]# ls /sys/class/scsi_device/
[root@myhost]#
[root@myhost]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
[root@myhost]#
[root@myhost]# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
[root@myhost]#
That will rescan the current scsi bus and the disk size that we increased from the VM guest settings will be show up as you can see in the below image.

Rescan disk device

4) New Disk Partition:

Once you are able to see the increased disk space inside your system then the run the following command to format your disk for creating a new partition by following the steps to increase your physical disk volume.
[root@myhost]# fdisk /dev/sda
[root@myhost]#
Welcome to fdisk (util-linux 2.23.2) press the 'm' key for help
[root@myhost]# fdisk
[root@myhost]# Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
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
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
Type the 'p' to print the current partition table then create a new primary partition by typing the 'n' key and selecting the available sectors. Change the disk type to 'Linux LVM' by using 't' command and selecting the code to '8e' or leave as it to its default type that is '83'.
Now write the table to disk and exit by Entring 'w' key as shown.
[root@myhost]# fdisk
[root@myhost]# 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: Device or resource busy.
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)
New disk Volume

5)Creating Physical Volume:

As indicated above run the 'partprobe' or kpartx command so that the tables are ready to use and then create the new Physical Volume using the below commands.
[root@myhost]# partprobe
[root@myhost]#
[root@myhost]# pvcreate /dev/sda3
[root@myhost]#
To check the newly created volume run the following command to see if the new physical volume has been created and visible. After that we will extend the Volume Group 'centos' with the newly create Physical Volume as shown.
[root@myhost]# pvdisplay
[root@myhost]#
[root@myhost]# vgextend centos /dev/sda3
[root@myhost]#
Extend volume Group

6) Extending Logical Volume:

Now we will extend the Logical Volume to increase the disk space on it using the the below command.
[root@myhost]# lvextend -L +40G /dev/mapper/centos-root
[root@myhost]#
Once you get the successfully increased message, run the command as shown below to extend the size of your logical volume .

ext4 FS type
[root@myhost]# resize2fs /dev/mapper/centos-root
[root@myhost]#
xfs FS type
[root@myhost]# xfs_grows /dev/mapper/centos-root
[root@myhost]#
The size of the '/' partition has been increased successfully, you can check the size of your disk drives by using the 'df' command as shown.
Increase disk space
Youtube :