VirtualBox 扩展虚拟硬盘

来源:互联网 发布:mac onedrive 打不开 编辑:程序博客网 时间:2024/05/19 04:27

the Extension of the Virtual Disk of the VirtualBox

Background:

I created a virtual disk of which the size is 5 GB for the cloud controller server. When I installed the mongodb, there is not enough space left.

Firstly, I will use the ‘df -h’ to check the usage of disk.

[cloud@controller ~(keystone_admin)]$ df -hFilesystem                       Size  Used Avail Use% Mounted on/dev/mapper/controller--vg-root  2.6G  2.5G  272M   1% /udev                             992M  4.0K  992M   1% /devtmpfs                            201M  388K  200M   1% /runnone                             5.0M     0  5.0M   0% /run/locknone                            1001M  4.0K 1001M   1% /run/shm/dev/sda1                        236M   59M  165M  27% /boot/dev/sdb1                        100G   33M  100G   1% /srv/node/sdb1

In the situation, I have to extend the space of the hard disk. It is lucky that the ‘/dev/mapper/controller—vg-root’ is the LVM. the LVM can be extended easily. Now we have 2 ways to extend it. One way is to create a new virtual disk and add it into the volume group to extend it. Another way is to resize the original virtual disk and then create a new partition and add it into the volume group. the first way is easier than the other. So I select the more complicated way because I can learn more.

Step 1: extend the virtual diske size

Before you run the command, please close the related VM.
The format of the command: VBoxManage modifyhd <VirtualDiskFileName> --resize <final_disk_size_megabytes>

C:\Users\ezonghu\VirtualBox VMs\ub_ctrl>VBoxManage modifyhd  ub_ctrl.vdi --resize 10240

the command means to change the ‘ub_ctrl.vdi’ virtual disk to 10GB.

Step 2: add partition

Use ‘fdisk’ to add a partition.
The format of the command: fdisk <device_path>
The original partitions:

   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048      499711      248832   83  Linux/dev/sda2          501758    10483711     4990977    5  Extended/dev/sda5          501760    10483711     4990976   8e  Linux LVM

Check the information of the partitions, you can see the size of the disk has been 10.7 GB. And then use the ‘n’ to add a new partition and the partition is primary and the start is 10483712 and the end is 20971519. At last use the ‘w’ to write the partition table. And use sudo partprobe to activate the configuration.

cloud@controller:/var/log/mongodb$ sudo fdisk /dev/sdaCommand (m for help): pDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000f20e5   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048      499711      248832   83  Linux/dev/sda2          501758    10483711     4990977    5  Extended/dev/sda3        10483712    20971519     5243904   83  Linux/dev/sda5          501760    10483711     4990976   8e  Linux LVM

And then use the command sudo fdisk -l to get the information of the whole disks.

cloud@controller:/var/log/mongodb$ sudo fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000f20e5   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048      499711      248832   83  Linux/dev/sda2          501758    10483711     4990977    5  Extended/dev/sda3        10483712    20971519     5243904   83  Linux/dev/sda5          501760    10483711     4990976   8e  Linux LVMDisk /dev/sdb: 107.4 GB, 107374182400 bytes43 heads, 44 sectors/track, 110843 cylinders, total 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x60e30023   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048   209715199   104856576   83  LinuxDisk /dev/mapper/controller--vg-root: 7247 MB, 7247757312 bytes255 heads, 63 sectors/track, 881 cylinders, total 14155776 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/controller--vg-root doesn't contain a valid partition tableDisk /dev/mapper/controller--vg-swap_1: 2143 MB, 2143289344 bytes255 heads, 63 sectors/track, 260 cylinders, total 4186112 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/controller--vg-swap_1 doesn't contain a valid partition table

Use the command sudo mkfs.ext4 /dev/sda3 to make the ext4 filesystem.

Step3: create physical volume

use the command sudo pvcreate /dev/sda3 to create the physical volume
use the command sudo pvdisplay to get the information of the physical volumes.

Step4: add a new physical volume to the volume group

use the command sudo vgdisplay to get the information of the volume group.
use the command sudo vgextend controller-vg /dev/sda3 to extend the ‘contrller-vg’ volume group.

Step5: extend the logical volume

use the command sudo lvdisplay to get the information of the logical volume.
use the command sudo lvextend -L +2048M /dev/controller-vg/root to extend the 2GB space in the ‘/dev/controller-vg/root’ logical volume.

Step6: resize the file system

use the command sudo resize2fs -p /dev/controller-vg/root to resize.

Step7: check the result of the actions

[cloud@controller ~(keystone_admin)]$ df -hFilesystem                       Size  Used Avail Use% Mounted on/dev/mapper/controller--vg-root  6.6G  2.6G  3.7G  41% /udev                             992M  4.0K  992M   1% /devtmpfs                            201M  388K  200M   1% /runnone                             5.0M     0  5.0M   0% /run/locknone                            1001M  4.0K 1001M   1% /run/shm/dev/sda1                        236M   59M  165M  27% /boot/dev/sdb1                        100G   33M  100G   1% /srv/node/sdb1
generated by haroopad
0 0
原创粉丝点击