Airzero Cloud

Next Generation Cloud !

Extending Linux Disk VMware Hyper-V CentOS/Redhat on the Fly Live

- Posted in Server Administration by

In this blog, we are looking at how to extend Linux disk VMware hyper-v centos/Redhat on the fly live.

Check if you can expand the current disk or require to add a new one.

This is rather a significant step because a disk that has been partitioned into 4 primary divisions already can not be raised anymore. To prevent this, log into your server and run fdisk -l at the command line.

# fdisk -l

Disk /dev/sda: 187.9 GB, 187904819200 bytes
255 heads, 63 sectors/track, 22844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot     Start       End     Blocks   Id  System
/dev/sda1   *           1       25      200781   83  Linux
/dev/sda2              26       2636    20972857+  8e  Linux LVM

If it examines like that, with only 2 sections, you can safely open the current hard disk in the Virtual Machine.

However, if it displays like this:

~# fdisk -l

Disk /dev/sda: 187.9 GB, 187904819200 bytes
255 heads, 63 sectors/track, 22844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot     Start       End     Blocks   Id  System
/dev/sda1   *           1       25      200781   83  Linux
/dev/sda2              26       2636    20972857+  8e  Linux LVM
/dev/sda3            2637       19581   136110712+  8e  Linux LVM
/dev/sda4           19582       22844   26210047+  8e  Linux LVM

It will offer you that there are already 4 primary sections on the system, and you ought to count a new Virtual Disk to your Virtual Machine. You can always use that extra Virtual Disk to improve your LVM size, so don’t worry.

The “hardware” part, “physically” adding disk space to your VM

Do that in your VMWare / esx / hyper-v console. If the option is greyed out to expand? Add a new disk or shut down the VM and extend the disk as such.

Partitioning the unallocated area: if you’ve raised the disk size

Once you’ve modified the disk’s size in VMware, bounce up your VM too if you had to shut it down to expand the disk size in vSphere. If you’ve rebooted the server, you won’t have to rescan your SCSI machines as that occurs on boot. If you did not reboot your server, rescan your SCSI systems as such.

First, check the name of your scsi devices.

$ ls /sys/class/scsi_device/
0:0:0:0 1:0:0:0  2:0:0:0

Then rescan the scsi bus. Beneath you can replace the ‘0:0:0:0’ with the actual scsi bus word found with the last command. Each colon is prefixed with a slash, which is what creates it looks weird.

$ echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan

Partitioning the unallocated space: if you’ve included a new disk

If you’ve included a new disk on the server, the activities are the same to those described above. Either of rescanning an already existing scsi bus like shown earlier, you have to rescan the server to detect the new scsi bus as you’ve included a new disk.

$ ls  /sys/class/scsi_host/
total 0
drwxr-xr-x  3 root root 0 Feb 13 02:55 .
drwxr-xr-x 39 root root 0 Feb 13 02:57 ..
drwxr-xr-x  2 root root 0 Feb 13 02:57 host0

Your host machine is called ‘host0’

$ echo "- - -" > /sys/class/scsi_host/host0/scan

It won’t show any output, but running ‘fdisk -l’ will display the new disk.

Create the new partition

Once the rescan is done, you can identify if the space can be seen on the disk.

~$  fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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      391     3036285   8e  Linux LVM

So the host can now visualize the 10GB hard disk.

~$  fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with:
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n

Now type ‘n’, to build a new partition.

Command action
e   extended
p   primary partition (1-4)
 p

Now select “p” to create a further direct partition.

Partition number (1-4): 3

Select your partition number. Since it already had /dev/sda1 and /dev/sda2, the logical number would be 3.

First cylinder (392-1305, default 392): 
Using default value 392
Last cylinder or +size or +sizeM or +sizeK (392-1305, default 1305): 
Using default value 1305

The cylinder matters will vary depending on your plan. It should be secure to just hint enter, as fdisk will give you a default value for the first and last cylinder.

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): w

Once you get around to the major command within fdisk, type w to report your partitions to the disk. You’ll get a notification about the kernel still utilizing the old partition table, and to reboot to utilize the new table. The reboot is not required as you can even rescan for those partitions using partprobe. Execute the below to scan for the recently created partition.

~$ partprobe -s

If that does not function for you, you can attempt to use “partx” to rescan the machine and add the latest partitions. In the command below, difference /dev/sda to the disk on which you’ve just included a new partition.

~$ partx -v -a /dev/sda

If that even does not offer you the recently completed partition for you to operate, you have to reboot the server.

~$  fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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      391     3036285   8e  Linux LVM
/dev/sda3           392     1305    7341705   8e  Linux LVM

Extend your Logical Volume with the new partition.

Now, assemble the physical volume as a cause for your LVM. Please return /dev/sda3 with the newly built partition.

~$  pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created

Now identify how your Volume Group is called.

~$  vgdisplay
--- Volume group ---
VG Name             VolGroup00
...

Let’s give that Volume Group by including the newly built physical volume to it.

$  vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
~$  pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [2.88 GB / 0    free]
PV /dev/sda3   VG VolGroup00   lvm2 [7.00 GB / 7.00 GB free]
Total: 2 [9.88 GB] / in use: 2 [9.88 GB] / in no VG: 0 [0   ]

Now we can extend Logical Volume .

~$  lvextend /dev/VolGroup00/LogVol00 /dev/sda3
Extending logical volume LogVol00 to 9.38 GB
Logical volume LogVol00 successfully resized

If you’re executing this on Ubuntu, use the following.

~$  lvextend /dev/mapper/vg-name /dev/sda3

All that remains now, is to resize the file system to the volume group, so we can utilize the space. Substitute the path to the correct /dev device if you’re on ubuntu/debian systems.

~$  resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2457600 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2457600 blocks long.
$ resize2fs /dev/mapper/centos_sql01-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos_sql01-root
Couldn't find valid filesystem superblock.

In that case, you’ll require to improve the XFS partition.

~$  df -h
Filesystem          Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 9.1G 1.8G  6.9G  21% /
/dev/sda1           99M   18M   77M  19% /boot
tmpfs               125M    0  125M   0% /dev/shm

If you have any doubt about the above topic. Don’t hesitate to contact us. Airzero cloud will be your digital partner.

Airzero Cloud is an excellent web hosting service that offers an array of powerful tools. We will help you to enhance your business.

Email id: [email protected]

enter image description here Author - Johnson Augustine
Cloud Architect, Ethical hacker
Founder: Airo Global Software Inc
LinkedIn Profile: www.linkedin.com/in/johnsontaugustine/