VirtualBox 扩展虚拟硬盘
the Extension of the Virtual Disk of theVirtualBox
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.
$ df -h
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/controller--vg-root2.6G2.5G272M 1% /
udev 992M4.0K992M 1% /dev
tmpfs 201M388K200M 1% /run
none 5.0M 05.0M 0% /run/lock
none 1001M4.0K 1001M 1% /run/shm
/dev/sda1 236M 59M165M27% /boot
/dev/sdb1 100G 33M100G 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 modifyhdub_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 IdSystem
/dev/sda1 * 2048 499711 248832 83Linux
/dev/sda2 501758 10483711 4990977 5Extended
/dev/sda5 501760 10483711 4990976 8eLinux 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/sda
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f20e5
Device Boot Start End Blocks IdSystem
/dev/sda1 * 2048 499711 248832 83Linux
/dev/sda2 501758 10483711 4990977 5Extended
/dev/sda3 10483712 20971519 5243904 83Linux
/dev/sda5 501760 10483711 4990976 8eLinux LVM
And then use the command sudo fdisk -l to get the information of the whole disks.
cloud@controller:/var/log/mongodb$ sudo fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f20e5
Device Boot Start End Blocks IdSystem
/dev/sda1 * 2048 499711 248832 83Linux
/dev/sda2 501758 10483711 4990977 5Extended
/dev/sda3 10483712 20971519 5243904 83Linux
/dev/sda5 501760 10483711 4990976 8eLinux LVM
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
43 heads, 44 sectors/track, 110843 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x60e30023
Device Boot Start End Blocks IdSystem
/dev/sdb1 2048 209715199 104856576 83Linux
Disk /dev/mapper/controller--vg-root: 7247 MB, 7247757312 bytes
255 heads, 63 sectors/track, 881 cylinders, total 14155776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/controller--vg-root doesn't contain a valid partition table
Disk /dev/mapper/controller--vg-swap_1: 2143 MB, 2143289344 bytes
255 heads, 63 sectors/track, 260 cylinders, total 4186112 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /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
$ df -h
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/controller--vg-root6.6G2.6G3.7G41% /
udev 992M4.0K992M 1% /dev
tmpfs 201M388K200M 1% /run
none 5.0M 05.0M 0% /run/lock
none 1001M4.0K 1001M 1% /run/shm
/dev/sda1 236M 59M165M27% /boot
/dev/sdb1 100G 33M100G 1% /srv/node/sdb1
generated by
haroopad
版权声明:本文为博主原创文章,未经博主允许不得转载。
页:
[1]