RHEL: Extending a vmdk (Virtual Machine disk)

# Tested on RHEL 5, 6 & 7


# This procedure may be carried out to make visible the new size of a disk that is already
# presented and used by the OS and that has been extended at virtual server level.

# Whenever possible I recommend to create a new disk instead of doing
an extension. In
# some situations we may experience some trouble when trying to read the new size of the
# disk so a reboot may be needed.

# For RHEL under 5.3, if disk is being used by LVM and if it's already assigned to a
Volume
# Group, a reboot of the server may be required in order to make visible the new size of the
# disk. Otherwise, as a workaround, one can add a new disk to the Volume Group and, then,
# 'pvmove' the physical extends to the new disk in order to free the old one.


# For RHEL 5.3 and higher

# Rescan device

SD=<sdc>

echo 1 > /sys/block/$SD/device/rescan
 
# At this point, physical volume and disk sizes shown by 'pvdisplay' and 'fdisk' should be
# different.


# If existing physical volume was created directly on the whole disk, without partition,
# a 'pvresize' should be enough for the new size to be taken into account

pvresize /dev/$SD

# If, on the other hand, disk is already partitioned, this is, we are using devices in the
# form /dev/sdx1, /dev/sdx2, we have to create a new partition with 'fdisk' tool

fdisk /dev/$SD

   The number of cylinders for this disk is set to 2480.
   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): p
 
   Disk /dev/sdc: 20.4 GB, 20401094656 bytes
   255 heads, 63 sectors/track, 2480 cylinders
   Units = cylinders of 16065 * 512 = 8225280 bytes   
 
   Device Boot      Start         End      Blocks   Id  System
   /dev/sdc1   *           1          33      265041   83  Linux
   /dev/sdc2              34        1958    15462562+  8e  Linux LVM


# Let's create a new partition. In our case, we'll create partition # 3
# (primary Linux LVM partition). For the first and last cylinder usually default values
# will be ok; if not, choose carefully the beginning and the end of the new partition

   Command (m for help): n
   Command action   
   e   extended   
   p   primary partition (1-4)
   p
   Partition number (1-4): 3
   First cylinder (1959-2480, default 1959):
   Using default value 1959
   Last cylinder or +size or +sizeM or +sizeK (1959-2480, default 2480):
   Using default value 2480 
 
   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
   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.

# Rescan disks

partprobe -s

# We may have an error like following one:

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdc (Device or resource busy).
As a result, it may not reflect all of your changes until after reboot.


# Then, use following command instead:

partx -a /dev/$SD
 

# New partition is ready to be used ('pvcreate', etc)

brw-r----- 1 root disk 8, 33 Nov  3 15:15 /dev/sdc1
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples
Viewed 4496 times since Fri, Nov 30, 2018
Watchdog script to keep an application running
Viewed 17632 times since Tue, Jul 31, 2018
linux aix Killing a process and all of its descendants
Viewed 3296 times since Tue, May 5, 2020
How to Configure ‘FirewallD’ in RHEL/CentOS 7 and Fedora 21
Viewed 10013 times since Wed, Oct 9, 2019
Index » Community Contributions » System encryption using LUKS and GPG encrypted keys for arch linux
Viewed 2579 times since Fri, Jul 13, 2018
rabbitmq Troubleshooting TLS-enabled Connections
Viewed 2005 times since Sun, Dec 6, 2020
RHEL: Manually encrypting a filesystem with LUKS
Viewed 3440 times since Sun, May 27, 2018
RHEL: Services basic management - systemd
Viewed 18101 times since Sat, Jun 2, 2018
Linux Cluster Tutorial
Viewed 1720 times since Sat, Sep 29, 2018
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 8943 times since Sun, Nov 22, 2020