Mac virtualbox虚拟机通过LVM扩容磁盘

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yunlilang/article/details/79979189

1、首先关闭虚拟机,查看硬盘分配的属性:为动态分配分配存储
硬盘属性
2、进入virtual box安装目录

#cd /Users/gds/VirtualBox VMs/gds
#VBoxManage list hdds
UUID:           2fb7b86c-64f7-467b-9d45-de6df399e325
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/gds/VirtualBox VMs/gds/gds.vdi
Storage format: VDI
Capacity:       32768 MBytes
Encryption:     disabled

可知硬盘UUID:2fb7b86c-64f7-467b-9d45-de6df399e325,大小为:32768 MBytes

3、调整磁盘空间->60G

#VBoxManage modifyhd 2fb7b86c-64f7-467b-9d45-de6df399e325 --resize 60000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

#VBoxManage list hdds
UUID:           2fb7b86c-64f7-467b-9d45-de6df399e325
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Users/gds/VirtualBox VMs/gds/gds.vdi
Storage format: VDI
Capacity:       60000 MBytes
Encryption:     disabled

4、重启虚拟机使之生效:

#fdisk -l /dev/sda
Disk /dev/sda: 58.6 GiB, 62914560000 bytes, 122880000 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
Disklabel type: dos
Disk identifier: 0xbbef9801

设备       启动    Start   末尾   扇区 Size Id 类型
/dev/sda1  *        2048 62914559 62912512  30G 83 Linux
/dev/sda2       62916606 67106815  4190210   2G  5 扩展
/dev/sda5       62916608 67106815  4190208   2G 82 Linux 交换 / Solaris

 #fdisk /dev/sda
 Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


命令(输入 m 获取帮助): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

:F
Unpartitioned space /dev/sda: 26.6 GiB, 28555870208 bytes, 55773184 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

   Start    末尾   扇区  Size
67106816 122879999 55773184 26.6G

这里需要注意不能采用默认的开始sector,要采用未分区的 start sector,这样才能加入想加的那个分区,否则是另外的一个分区

命令(输入 m 获取帮助): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
分区号 (3,4, default 3): 3
First sector (62914560-122879999, default 62914560): 67106816
Last sector, +sectors or +size{K,M,G,T,P} (67106816-122879999, default 122879999):

Created a new partition 3 of type 'Linux' and of size 26.6 GiB.
命令(输入 m 获取帮助): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 设备或资源忙

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).

5、重启

fdisk -l /dev/sda
Disk /dev/sda: 58.6 GiB, 62914560000 bytes, 122880000 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
Disklabel type: dos
Disk identifier: 0xbbef9801

设备       启动    Start    末尾   扇区  Size Id 类型
/dev/sda1  *        2048  62914559 62912512   30G 83 Linux
/dev/sda2       62916606  67106815  4190210    2G  5 扩展
/dev/sda3       67106816 122879999 55773184 26.6G 83 Linux
/dev/sda5       62916608  67106815  4190208    2G 82 Linux 交换 / Solaris

Partition table entries are not in disk order.

可见/dev/sda3已经加入进来。

6、扩展volume group, logical volume
安装lvm2,sudo apt-get install lvm2, 查看volume group:

vgdisplay
  /run/lvm/lvmetad.socket: connect failed: 没有那个文件或目录
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.

报错,执行下列操作:

root@gds$ systemctl enable lvm2-lvmetad.service
Synchronizing state of lvm2-lvmetad.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable lvm2-lvmetad
root@gds$ systemctl enable lvm2-lvmetad.socket
root@gds$ systemctl start lvm2-lvmetad.service
root@gds$ systemctl start lvm2-lvmetad.socket

创建物理卷(physical volume):

root@gds$ pvcreate /dev/sda3
Physical volume “/dev/sda3” successfully created

使用新的物理卷来扩展 LVM 的 VolGroup:
通过vgdisplay 来查看自己系统目录 / 的volume group,本文为:VolGroup-lv_root

通过vgextend命令扩展现有的vg: vgextend VolGroup-lv_root /dev/sda3
然后扩展 LVM 的逻辑卷 VolGroup-lv_root:
lvextend -L +26G /dev/mapper/VolGroup-lv_root

调整逻辑卷的大小: resize2fs /dev/mapper/VolGroup-lv_root

至此,OK。


如果扩容的分区没有采用LVM管理,则可以通过mount的方式,创建一个目录,然后把这个目录挂载到分区上,例如把mount /dev/sda3 /home/data,来达到扩容的目的。

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页