Openstack实例不使用整个硬盘 [英] Openstack Instance does not use the entire hard disk
问题描述
我使用"Ubuntu Server 10.04 LTS(Lucid Lynx)-32位"映像和具有20 GB磁盘(OpenStack Icehouse)的m1.small falvour创建了新的虚拟机实例.当我登录到vm并运行df -h时,我发现VM不会使用整个分配的HD.命令结果如下所示:
I created new vm instance using "Ubuntu Server 10.04 LTS (Lucid Lynx) - 32 bits" image and m1.small falvour which has 20 GB Disk (OpenStack Icehouse). When i logging to the vm and run df -h , I found that the VM does not use the entire assigned HD. The command results are shown as the following:
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 1.4G 595M 721M 46% /
none 1005M 144K 1005M 1% /dev
none 1007M 0 1007M 0% /dev/shm
none 1007M 36K 1007M 1% /var/run
none 1007M 0 1007M 0% /var/lock
none 1007M 0 1007M 0% /lib/init/rw
"fdisk -l"显示DH大小为20 GB:
The "fdisk -l" shows the DH size is 20 GB:
Disk /dev/vda: 21.5 GB, 21474836480 bytes
4 heads, 32 sectors/track, 327680 cylinders
Units = cylinders of 128 * 512 = 65536 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb9da
Device Boot Start End Blocks Id System
/dev/vda1 * 17 32768 2096128 83 Linux
我需要虚拟机占用分配给它的全部空间.知道我该如何解决吗?我希望将解决方案应用于创建的每个虚拟机,因此,我不想在实例化后手动更新虚拟机.我还必须使用10.04图片(不能升级到14.04)
I need the vm to take the full space assigned to it. Any idea how could I fix it? I want the solution to be applied on each vm I create, so I do not want to manually update the VM after instantiation. I also must use 10.04 image ( can not upgrdate to 14.04)
推荐答案
这里的问题是图像.我抓起那一个然后跑起来,运行
The problem here is the image. I grabbed that one and ran it up, it's pretty simple to run a
sudo resize2fs /dev/vda1
,它将把文件系统的大小调整为分区的大小,似乎是2GB.除此之外,您还必须增加分区大小.为此,我认为您最好使用virt-resize
,那里有一些很好的方法,例如 askubuntu ,本质上是:
which will resize the filesystem to the size of the partition, which seems to be 2GB. Beyond that, you have to increase the partition size. For that I think you're probably best off using virt-resize
, there are some good howto's out there e.g. askubuntu, in essence:
- SSH进入您的openstack控制器节点
-
source keystonerc_admin
(或任何可能被称为的人) -
nova list --all-tenants | grep <instance_name>
或只是从地平线上获取服务器guid -
nova show <server_guid>
并记下您的机器正在运行的新主机.还要注意实例名称(例如instance-00000adb) - SSH进入该新星节点
-
virsh dumpxml instance-00000adb
并查找图像文件.就我而言,这是/var/lib/nova/instances/<server_guid>/disk
,但并非总是如此吗? -
yum install libguestfs-tools
-
truncate -r /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
-
truncate -s +2G /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
-
virt-resize --expand /dev/sda1 /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
-
mv disk disk.old ; mv disk.new disk
- SSH into your openstack controller node
source keystonerc_admin
(or whatever yours may be called)nova list --all-tenants | grep <instance_name>
or just grab the server guid from horizonnova show <server_guid>
and note which nova host your machine is running on. Also note the instance name (e.g. instance-00000adb)- SSH into that nova node
virsh dumpxml instance-00000adb
and look for the image file. On mine, this is/var/lib/nova/instances/<server_guid>/disk
but that may not always be the case?yum install libguestfs-tools
truncate -r /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
truncate -s +2G /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
virt-resize --expand /dev/sda1 /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk /var/lib/nova/instances/d887249a-0d95-473e-b4f2-41f71df4dbb5/disk.new
mv disk disk.old ; mv disk.new disk
NB-当我再次启动它时,我的工作还不够,还没有时间进行调查,但相差不远,希望这会有所帮助.
NB - mine didn't quite work when I booted that up again, not got time to investigate yet but it can't be far off that, and hopefully this helps.
一旦设法再次启动它,则可以将其关闭并从地平线创建快照.然后,您可以像使用其他任何映像一样使用该快照,并直接从那里启动所有后续VM.
Once you've managed to boot that up again, then you can shut it down and create a snapshot from horizon. You can then use that snapshot just like any other image, and launch all subsequent VMs directly from there.
HTH.
这篇关于Openstack实例不使用整个硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!