【问题标题】:vagrant no space left on devicevagrant 设备上没有剩余空间
【发布时间】:2015-07-31 13:04:23
【问题描述】:

今天我开始在简单的操作上遇到错误,例如在vim 中创建小文件,bash 完成也开始报错。

这是df -h 的结果:

vagrant@machine:/vagrant$ df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/sda1                             40G   38G  249M 100% /
none                                 4.0K     0  4.0K   0% /sys/fs/cgroup
udev                                 2.0G   12K  2.0G   1% /dev
tmpfs                                396M  396K  395M   1% /run
none                                 5.0M     0  5.0M   0% /run/lock
none                                 2.0G     0  2.0G   0% /run/shm
none                                 100M     0  100M   0% /run/user
overflow                             1.0M  148K  876K  15% /tmp
192.168.50.1:/Users/nha/repo/assets  233G  141G   93G  61% /var/www/assets
vagrant                              233G  141G   93G  61% /vagrant

显然/ 没有空间了?是不是很奇怪,因为我在其他文件系统中有空间(或者我误读了什么)?

如何在我的虚拟机上获得更多空间?

【问题讨论】:

  • ncdu 显示大约使用了 6GB,所以我现在很困惑。

标签: vagrant virtualbox


【解决方案1】:

即使您的来宾操作系统上有空间,VM 也是有限的。为了增加磁盘的大小需要几个步骤:

首先,vagrant halt关闭你的虚拟机

调整磁盘大小

VBoxManage clonehd box-disk1.vmdk box-disk1.vdi --format vdi
VBoxManage modifyhd box-disk1.vdi --resize 50000

启动虚拟机并更改虚拟机的配置以关联新磁盘

使用 fdisk 调整磁盘大小

你需要用新空间创建一个新分区并分配它,所以首先启动VM并以超级用户身份登录

vagrant up && vagrant ssh
su -

命令(如我的实例所示)是

[root@oracle ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 52.4 GB, 52428800000 bytes
255 heads, 63 sectors/track, 6374 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00041a53

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2611    20663296   8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-6374, default 2611):
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-6374, default 6374):
Using default value 6374

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.
[root@oracle ~]#

注意您可能需要将 /dev/sda 与您的配置进行比较

新建分区(再次以超级用户su -登录)

su -
[root@oracle ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/sda2  linux lvm2 a--  19.70g    0
[root@oracle ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@oracle ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/sda2  linux lvm2 a--  19.70g     0
  /dev/sda3        lvm2 a--  28.83g 28.83g

[root@oracle ~]# vgextend linux /dev/sda3
  Volume group "linux" successfully extended
[root@oracle ~]# lvextend -l +100%FREE /dev/linux/root
[root@oracle ~]# resize2fs /dev/linux/home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/linux/home is mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/linux/home to 7347200 (4k) blocks.
The filesystem on /dev/linux/home is now 7347200 blocks long.

【讨论】:

  • 抱歉我接受的太快了。我销毁/重建了我的机器,但它不起作用,但我现在在 virtualbox gui 中注意到虚拟大小为 40GB,但实际大小为 1.33GB。 (?)
  • @nha,在构建 vm 时,vagrant 不会保留您为磁盘分配的所有空间 - 在您的情况下,您定义了具有 40 GB 硬盘驱动器的 VM,但您只使用1GB 左右,所以 vagrant/VirtualBox 将保留 1.33 GB 并且会增长。它们可以增长直到达到 40GB,这是您在 VM 上为该硬盘分配的大小限制(如果您想要它,如果 VM 的物理 HD 为 40GB)当您达到此限制时,您需要扩展大小限制连接到 VM 的 HD(我给你的方法)或连接另一个硬盘
  • 谢谢,我明白了。但是我现在收到与空间相关的错误(例如在启动 mongo 时,我得到“请在 /data/db/journal 中提供至少 3379MB 或使用 --smallfiles”)
  • 但是,在我的欢迎登录消息中,我有类似“/的使用:39.34GB 的 96.6%”之类的内容......有问题不是吗?
  • 确实,有些奇怪。 /tmp 中有什么东西正在占用你的空间吗?
【解决方案2】:

您可以增加盒子中的空间,而不会丢失数据或创建新分区。

  1. 暂停您的虚拟机;

  2. 转到/home_dir/VirtualBox VMs

  3. 将文件格式从 .vmdk 更改为 .vdi。然后使用上面答案中的命令来增加空间。

  4. 改回文件扩展名并更改文件名。

  5. 将扩展磁盘附加到您的虚拟机。

    VBoxManage storageattach <your_box_name> --storagectl "IDE Controller" --
    port 0 --device 0 --type hdd --medium new_extended_file.vmdk
    
  6. 在您的 VirtualBox 应用程序中,转到 Your_VM -> 设置 -> 存储。单击控制器并选择下面的“添加新磁盘”。从现有磁盘中选择您刚刚扩展的磁盘。

Here's a step by step instruction how to expand the space in your vagrant box or virtual machine.

【讨论】:

  • 完美 - 看起来很棒!干得好!
【解决方案3】:

增加 vagrant box 大小的最简单方法是使用vagrant-disksize 插件。

在您的 vagrant 根文件夹中,运行 vagrant plugin install vagrant-disksize

然后将新的大小添加到 Vagrantfile:

Vagrant.configure('2') do |config|
  ...
  config.disksize.size = '60GB'
end

那么vagrant haltvagrant up
vagrant reload 将不起作用。

我了解到,如果您超调,该插件会出现缩小磁盘大小的问题。

编辑:
在 Mac 上,这个插件还调整了来宾操作系统(在我的例子中是 Ubuntu)中的分区大小。
在 Windows 上,Vagrant 会在主机操作系统上保留空间(它会扩大磁盘),但在从客户操作系统内调整分区大小之前,您无法使用该空间。
我用的是GParted,但是其他的方案看起来更简单,比如:https://nguyenhoa93.github.io/Increase-VM-Partition

【讨论】:

    【解决方案4】:

    我有时不得不破坏机器并重新构建它,这在我的情况下释放了相当多的空间,你可以通过运行来做到这一点

    vagrant destroy
    
    vagrant up
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2012-01-14
      • 2012-05-15
      • 2018-11-22
      • 2015-07-21
      • 2020-12-16
      • 2014-11-20
      相关资源
      最近更新 更多