设为首页 收藏本站
查看: 1023|回复: 0

[经验分享] VirtualBox 扩展虚拟硬盘

[复制链接]
累计签到:8 天
连续签到:1 天
发表于 2015-10-12 13:42:16 | 显示全部楼层 |阅读模式
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 -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/controller--vg-root  2.6G  2.5G  272M   1% /
udev                             992M  4.0K  992M   1% /dev
tmpfs                            201M  388K  200M   1% /run
none                             5.0M     0  5.0M   0% /run/lock
none                            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/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   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 -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   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
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   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux
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 &#43;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 -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/controller--vg-root  6.6G  2.6G  3.7G  41% /
udev                             992M  4.0K  992M   1% /dev
tmpfs                            201M  388K  200M   1% /run
none                             5.0M     0  5.0M   0% /run/lock
none                            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
版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-125938-1-1.html 上篇帖子: LINUX内核升级后virtualbox无法使… 下篇帖子: [Linux]Fedora 20 虚拟机VirtualBox安装笔记
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表