maintenance:general:centos_vmdisk_resize
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
maintenance:general:centos_vmdisk_resize [2019/12/23 12:16] – ↷ Page moved from internal:procedures:centos_vmdisk_resize to maintenance:general:centos_vmdisk_resize yspeerte | maintenance:general:centos_vmdisk_resize [2024/07/03 12:31] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Extend Centos VM disk ===== | ||
+ | This procedure describes the commands required to extend the disk size of a NetYCE VM based on RHEL/CentOS 6 or RHEL/CentOS 7. Both procedures are similar but differ in the details. | ||
+ | |||
+ | ==== RHEL/CentOS 7 ==== | ||
+ | |||
+ | === 1) Resize the virtual disk === | ||
+ | First, halt and power down the VM. Using the hypervisor resize the virtual disk of the VM. | ||
+ | In the example sessions the size is increased from 8 GB to 40 GB. | ||
+ | |||
+ | <WRAP indent> | ||
+ | VirtualBox cannot resize VMDK disks, you need to convert to VDI disk format first. After halting the VM, execute on the host cli while in the appropriate directory the command below. The example converts the “Genesis” disk from vmdk to vdi format | ||
+ | < | ||
+ | VBoxManage clonehd --format VDI Genesis.vmdk Genesis.vdi | ||
+ | </ | ||
+ | If the disk-filename or extension was changed, detach it from the Genesis storage controller using virtual box gui (machine - settings - storage) and attach the new image to the controller (add hard disk - choose existing) | ||
+ | |||
+ | Then you can resize the disk to desired value. | ||
+ | </ | ||
+ | |||
+ | Start the VM and login using ' | ||
+ | |||
+ | === 2) Recreate the disk partition === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | root@genesis7 ~ | ||
+ | # fdisk /dev/sda | ||
+ | |||
+ | Command (m for help): p | ||
+ | |||
+ | Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 sectors | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk label type: dos | ||
+ | Disk identifier: 0x000ae8d2 | ||
+ | |||
+ | | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Delete the second (LVM) partition | ||
+ | < | ||
+ | Command (m for help): d | ||
+ | Partition number (1,2, default 2): 2 | ||
+ | Partition 2 is deleted | ||
+ | </ | ||
+ | |||
+ | And recreate it. Use the default start and end blocks. Then set the partition type to LVM again (8e). | ||
+ | < | ||
+ | Command (m for help): n | ||
+ | Partition type: | ||
+ | | ||
+ | | ||
+ | Select (default p): p | ||
+ | Partition number (2-4, default 2): 2 | ||
+ | First sector (2099200-16777215, | ||
+ | Using default value 2099200 | ||
+ | Last sector, +sectors or +size{K, | ||
+ | Using default value 16777215 | ||
+ | Partition 2 of type Linux and of size 7 GiB is set | ||
+ | |||
+ | Command (m for help): t | ||
+ | Partition number (1,2, default 2): 2 | ||
+ | Hex code (type L to list all codes): 8e | ||
+ | Changed type of partition ' | ||
+ | </ | ||
+ | |||
+ | Verify the results and when satisfied write it to disk. Abort if incorrect, nothing will change until the ' | ||
+ | < | ||
+ | Command (m for help): p | ||
+ | |||
+ | Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 sectors | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk label type: dos | ||
+ | Disk identifier: 0x000ae8d2 | ||
+ | |||
+ | | ||
+ | / | ||
+ | / | ||
+ | |||
+ | Command (m for help): w | ||
+ | </ | ||
+ | |||
+ | === 3) Reboot the VM === | ||
+ | |||
+ | < | ||
+ | # reboot | ||
+ | </ | ||
+ | |||
+ | === 4) Verify the disk partitions === | ||
+ | Login as ' | ||
+ | |||
+ | < | ||
+ | # fdisk /dev/sda | ||
+ | |||
+ | Command (m for help): p | ||
+ | |||
+ | Disk /dev/sda: 43.4 GB, 43411046400 bytes, 84787200 sectors | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk label type: dos | ||
+ | Disk identifier: 0x000ae8d2 | ||
+ | |||
+ | | ||
+ | / | ||
+ | / | ||
+ | |||
+ | Command (m for help): q | ||
+ | </ | ||
+ | |||
+ | === 5) Resize the physical volume === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # pvresize /dev/sda2 | ||
+ | Physical volume "/ | ||
+ | 1 physical volume(s) resized or updated / 0 physical volume(s) not resized | ||
+ | </ | ||
+ | |||
+ | === 6) Resize the logical volume === | ||
+ | Using '' | ||
+ | The name of the /dev/mapper device may differ, use the <tab> for filename completion to find the reference for ' | ||
+ | |||
+ | < | ||
+ | # lvresize / | ||
+ | Size of logical volume centos_c7-2/ | ||
+ | Logical volume centos_c7-2/ | ||
+ | </ | ||
+ | |||
+ | === 7) Extend the xfs filesystem === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # xfs_growfs / | ||
+ | meta-data=/ | ||
+ | | ||
+ | | ||
+ | data | ||
+ | | ||
+ | naming | ||
+ | log =internal | ||
+ | | ||
+ | realtime =none | ||
+ | data blocks changed from 1624064 to 10125312 | ||
+ | </ | ||
+ | |||
+ | === 8) Verify the results === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # df -h / | ||
+ | Filesystem | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | === 9) Check filesystem === | ||
+ | |||
+ | < | ||
+ | # touch /forcefsck | ||
+ | # reboot | ||
+ | </ | ||
+ | |||
+ | When the system returns the extended disk is ready for use. | ||
+ | |||
+ | |||
+ | |||
+ | ==== RHEL/CentOS 6 ==== | ||
+ | |||
+ | === 1) Resize the virtual disk === | ||
+ | First, halt and power down the VM. Using the hypervisor resize the virtual disk of the VM. | ||
+ | <WRAP indent> | ||
+ | VirtualBox cannot resize VMDK disks, you need to convert to VDI disk format first. After halting the VM, execute on the host cli while in the appropriate directory the command below. The example converts the " | ||
+ | < | ||
+ | VBoxManage clonehd --format VDI Genesis.vmdk Genesis.vdi | ||
+ | </ | ||
+ | |||
+ | If the disk-filename or extension was changed, detach it from the Genesis storage controller using virtual box gui (machine - settings - storage) and attach the new image to the controller (add hard disk - choose existing) | ||
+ | |||
+ | Then you can resize the disk to desired value. | ||
+ | </ | ||
+ | |||
+ | Start the VM and login using ' | ||
+ | |||
+ | |||
+ | === 2) Recreate the disk partition === | ||
+ | The session samples show how a system using two LVM partitions is extended, not by adding a third partition by by extending the third partition. Look at the last section of this article how to extend the disk size of a RedHat/ | ||
+ | |||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # fdisk /dev/sda | ||
+ | |||
+ | WARNING: DOS-compatible mode is deprecated. It's strongly recommended to | ||
+ | switch off the mode (command ' | ||
+ | sectors (command ' | ||
+ | |||
+ | Command (m for help): c | ||
+ | DOS Compatibility flag is not set | ||
+ | |||
+ | Command (m for help): u | ||
+ | Changing display/ | ||
+ | |||
+ | Command (m for help): p | ||
+ | |||
+ | Disk /dev/sda: 107.4 GB, 107374182400 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk identifier: 0x00034ecd | ||
+ | |||
+ | Device Boot Start End Blocks Id System | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Delete the second (LVM) partition | ||
+ | < | ||
+ | Command (m for help): d | ||
+ | Partition number (1-4): 3 | ||
+ | </ | ||
+ | |||
+ | And recreate it. Use the default start and end blocks. Then set the partition type to LVM again (8e). | ||
+ | < | ||
+ | Command (m for help): n | ||
+ | Command action | ||
+ | e extended | ||
+ | p primary partition (1-4) | ||
+ | p | ||
+ | Partition number (1-4): 3 | ||
+ | First sector (8388608-209715199, | ||
+ | Using default value 8388608 | ||
+ | Last sector, +sectors or +size{K, | ||
+ | Using default value 209715199 | ||
+ | |||
+ | 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): p | ||
+ | |||
+ | Disk /dev/sda: 107.4 GB, 107374182400 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = sectors of 1 * 512 = 512 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk identifier: 0x00034ecd | ||
+ | |||
+ | Device Boot Start End Blocks Id System | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Verify the results and when satisfied write it to disk. Abort if incorrect, nothing will change until the ' | ||
+ | < | ||
+ | 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) | ||
+ | Syncing disks. | ||
+ | </ | ||
+ | |||
+ | === 3) Reboot the VM === | ||
+ | |||
+ | < | ||
+ | # reboot | ||
+ | </ | ||
+ | |||
+ | === 4) Verify the disk partitions === | ||
+ | Login as ' | ||
+ | |||
+ | |||
+ | === 5) Resize the physical volume === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # pvresize /dev/sda3 | ||
+ | Physical volume "/ | ||
+ | 1 physical volume(s) resized / 0 physical volume(s) not resized | ||
+ | </ | ||
+ | |||
+ | === 6) Resize the logical volume === | ||
+ | Using '' | ||
+ | The name of the /dev/mapper device may differ, use the <tab> for filename completion to find the reference for ' | ||
+ | |||
+ | < | ||
+ | # lvresize / | ||
+ | control VolGroup-lv_root VolGroup-lv_swap | ||
+ | |||
+ | # lvresize / | ||
+ | Size of logical volume VolGroup/ | ||
+ | Logical volume lv_root successfully resized. | ||
+ | </ | ||
+ | |||
+ | === 7) Extend the ext4 filesystem === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # resize2fs / | ||
+ | resize2fs 1.41.12 (17-May-2010) | ||
+ | Filesystem at / | ||
+ | old desc_blocks = 1, new_desc_blocks = 7 | ||
+ | Performing an on-line resize of / | ||
+ | </ | ||
+ | |||
+ | === 8) Verify the results === | ||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | # df -h / | ||
+ | Filesystem Size Used Avail Use% Mounted on | ||
+ | / | ||
+ | 98G 3.3G 90G 4% / | ||
+ | </ | ||
+ | |||
+ | === 9) Check filesystem === | ||
+ | |||
+ | < | ||
+ | # touch /forcefsck | ||
+ | # reboot | ||
+ | </ | ||
+ | |||
+ | When the system returns the extended disk is ready for use. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Adding a partition to RHEL/CentOS 6 ==== | ||
+ | |||
+ | locate filesystem to extend | ||
+ | # df -h | ||
+ | |||
+ | eg: / | ||
+ | we need the volgroup '' | ||
+ | |||
+ | halt vm | ||
+ | # halt | ||
+ | |||
+ | compact the VM disk using VirtualBox cli tool | ||
+ | cd VirtualBox-VMs/ | ||
+ | VBoxManage modifyhd yceone-disk1.vdi --compact | ||
+ | |||
+ | resize vm disk, eg to 8G | ||
+ | VBoxManage modifyhd yceone-disk1.vdi --resize 8192 | ||
+ | |||
+ | boot vm normally, login as root \\ | ||
+ | locate next free partition number on /dev/sda | ||
+ | # fdisk -l | ||
+ | |||
+ | create extra primary partition of desired size (the amount added) | ||
+ | # fdisk /dev/sda | ||
+ | fdisk> c | ||
+ | fdisk> u | ||
+ | fdisk> n (add partition) | ||
+ | fdisk> p (primary) | ||
+ | fdisk> 3 (partiton) | ||
+ | fdisk> < | ||
+ | fdisk> < | ||
+ | fdisk> t (type) | ||
+ | fdisk> 3 (partition) | ||
+ | fdisk> 8e (linux LVM) | ||
+ | fdisk> w | ||
+ | |||
+ | halt and reboot | ||
+ | # halt | ||
+ | | ||
+ | add partition as new physical volume and extend the volume group with it | ||
+ | # lvm | ||
+ | lvm> pvcreate /dev/sda3 | ||
+ | lvm> vgextend VolGroup /dev/sda3 | ||
+ | lvm> lvextend -L+10000 / | ||
+ | this reports the number of extends available. take that number, multiply by 4 and specify that instead | ||
+ | lvm> lvextend -L+4092 / | ||
+ | to be sure no other extends are available try to extend by one more | ||
+ | lvm> lvextend -L+1 / | ||
+ | lvm> quit (exit lvm) | ||
+ | |||
+ | resize the filesystem | ||
+ | # resize2fs -F / | ||
+ | |||
+ | Done! check free size | ||
+ | # df -h | ||
+ | |||
+ | |||
+ | // |