美文网首页
VirtualBox磁盘扩容

VirtualBox磁盘扩容

作者: Lyudmilalala | 来源:发表于2023-12-27 15:03 被阅读0次

df -h获取当前文件系统的使用情况

$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              794M  1.2M  793M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  8.8G  488M  95% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.7G  251M  1.4G  16% /boot
shared                             439G  409G   31G  94% /opt/shared        
tmpfs                              794M  4.0K  794M   1% /run/user/1000  
shared                             439G  409G   31G  94% /media/sf_shared     

物理磁盘扩容

关闭虚拟机 -> 右上角【管理】 -> 虚拟介质管理,在页面上选择对应的虚拟机磁盘,拖动浮标修改大小

NOTICE:目前无法将大磁盘改小,暂未实现缩减功能

虚拟介质管理.png

查看新添加的磁盘,下图中的/dev/sda即为挂载的磁盘,同时我们可以看到对应Linux文件系统根目录的虚拟磁盘/dev/mapper/ubuntu--vg-ubuntu--lv的容量并没有增加

$ sudo fdisk -l
[sudo] password for spinq: 
Disk /dev/loop0: 63.46 MiB, 66547712 bytes, 129976 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 /dev/loop1: 63.91 MiB, 67014656 bytes, 130888 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 /dev/loop2: 79.95 MiB, 83832832 bytes, 163736 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 /dev/loop3: 111.95 MiB, 117387264 bytes, 229272 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 /dev/loop4: 40.86 MiB, 42840064 bytes, 83672 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
GPT PMBR size mismatch (31457279 != 104857599) will be corrected by write.  
The backup GPT table is not on the end of the device.


Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VBOX HARDDISK   
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: gpt
Disk identifier: 0F7F3C0E-834C-4462-AB38-63129ECAD7E6

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3674111  3670016  1.8G Linux filesystem
/dev/sda3  3674112 31455231 27781120 13.2G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 10 GiB, 10737418240 bytes, 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

此时df -h

$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              794M  1.2M  793M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  8.2G  1.2G  89% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.7G  251M  1.4G  16% /boot
shared                             439G  409G   30G  94% /opt/shared        
tmpfs                              794M  4.0K  794M   1% /run/user/1000

Q1: 为什么``变大了一点

Q2: 为什么第二个shared消失了

扩展物理分区

如果仔细看,我们可以发现/dev/sda的几个分区加起来并没有达到50G的大小

这说明在磁盘尾部还留有一大片未被分配的区域,为了使用它们,我们需要将这些空间划分到我们希望挂载的分区中去。我们使用parted来实现

sudo parted /dev/sda
(parted) resizepart 3
End? [31456.2MB]? 100%
(parted) quit

再次查看磁盘空间,发现分区/dev/sda3变大

$ sudo fdisk -l /dev/sda
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VBOX HARDDISK   
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: gpt
Disk identifier: 0F7F3C0E-834C-4462-AB38-63129ECAD7E6

Device       Start       End   Sectors  Size Type
/dev/sda1     2048      4095      2048    1M BIOS boot
/dev/sda2     4096   3674111   3670016  1.8G Linux filesystem
/dev/sda3  3674112 104857566 101183455 48.2G Linux filesystem

挂载物理卷轴到虚拟卷轴

若上一步修改了磁盘分区大小,需要同步更新物理卷轴大小

sudo pvresize /dev/sda3

查看可用的物理卷轴大小,Free PE即为可增加的空间,数据为卷轴数量,每个卷轴4MB

$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <48.25 GiB / not usable 16.50 KiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              12351
  Free PE               8960
  Allocated PE          3391
  PV UUID               NXUaFx-dgOz-nxvG-1Dlx-T6w6-9lte-Yyfh4a

将这些空间全部用来扩展 LVM 逻辑卷

$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <10.00 GiB (2560 extents) to <48.25 GiB (12351 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

命令文件系统重新分配空间

$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 7
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 12647424 (4k) blocks long.

再查看df -h,发现空间已经增加

$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              794M  1.2M  793M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   48G  8.2G   38G  18% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.7G  251M  1.4G  16% /boot
shared                             439G  409G   30G  94% /opt/shared        
tmpfs                              794M  4.0K  794M   1% /run/user/1000   

相关文章

  • 《Linux实践技能》学习笔记 day11

    Linux 虚拟机 virtualbox 磁盘扩容 首先在虚拟机中模拟磁盘挂载,先关机,扩容磁盘大小image.p...

  • VirtualBox磁盘扩容

    一般我们在设置虚拟磁盘时采用的是动态分配大小. 但是还是极有可能用着用着超出了最大容许容量. 此时就需要对虚拟磁盘...

  • VirtualBox下扩容磁盘过程记录

    磁盘原有空间21G,这次试着添加1G空间,并把它扩充到根目录下。 关闭虚拟机,在“设置”中定位磁盘文件位置并记录下...

  • VirtualBox下扩容磁盘过程记录

    工作中有些项目要用到windows里的IE浏览器,在Mac上安装了VirtualBox,不得不说VirtualBo...

  • ubuntu虚拟机系统磁盘扩容

    oracle VM virtualbox ubuntu虚拟机系统磁盘扩容 当初安装时,分配给了虚拟机25G空间,想...

  • LVM扩容

    扩容【virtualBox】虚拟硬盘 cmd 进入【virtualBox】主目录,输出以下命令扩容虚拟硬盘容量(P...

  • linux下virtualbox,扩容windows虚拟磁盘

    我使用的是ubuntu14,在birtualbox里装了一个win7。装完发现,当时创建虚拟磁盘时,空间分配小了(...

  • Virtualbox 扩容

    第二次经历了双系统的linux莫名其妙挂掉的惨痛经历,真的很痛恨改底层的bug,遂换回虚拟机……大不了每步操作之后...

  • VirtualBox 扩容

    VDI: VBoxManage modifyhd xxxx.vdi --resize 16000 51200 5...

  • Virtualbox扩容

    在Vagrant+Virtualbox 打造统一的部署环境中,基础容量只有8G,开发人员搭建各种开发环境的时,8G...

网友评论

      本文标题:VirtualBox磁盘扩容

      本文链接:https://www.haomeiwen.com/subject/rgirndtx.html