创建虚拟机实例后如何扩展默认分区? [英] How to extend default partition after creating an VM instance?

查看:154
本文介绍了创建虚拟机实例后如何扩展默认分区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FI-WARE云创建了一个具有12GB磁盘的Centos x64 VM实例.我可以毫无问题地访问它,并且我已经开始安装软件.但是,默认创建的分区/dev/vda1只有5GB,我已经填满了.我想知道如何扩展分区以使用完整的磁盘.

I created a Centos x64 VM instance with a 12GB disk using the FI-WARE cloud. I can access it with not problem and I have started installing software. However, the default created partition /dev/vda1 is only 5GB and I have already filled it. I would like to know how to extend the partition to use the full disk.

谢谢

推荐答案

我会说你有两种方法.第一个是安全的,第二个是危险的.因此,让我们从安全的角度开始: 您可以使用fdisk/dev/vda(或分开的/dev/vda)来创建新分区.由于该分区将在创建和装载'/'的同一虚拟磁盘中创建,因此在使用新分区之前,您必须重新引导VM.

I would say you have two ways. The first one which is safe and the second one which is risky. So, let's start by the safe one: You could use fdisk /dev/vda (or parted /dev/vda) in order to create a new partition. As the partition will be created in the same virtual disk where your '/' is created and mounted, you'll have to reboot your VM before using your new partition.

重新启动VM时,您将能够格式化新分区:

When you reboot your VM, you'll be able to format your new partition:

 mkfs -t ext4 /dev/vda2

然后将新分区挂载到您想要的任何位置:

And mount your new partition wherever you want:

 mount /dev/vda2 /mnt

为了使这种安装持续进行,您可以在/etc/fstab中添加新行:

In order to make this mounting persistent, you could add a new line to /etc/fstab:

 /dev/vda2      /mnt                       ext4    defaults        1 1

第二种方法是扩展/dev/vda1分区.这是有风险的,如果您犯了任何错误,则您的VM可能无法再次(单独)启动,请自行承担风险.无论如何-

The second way is extending your /dev/vda1 partition. This is risky and if you make any mistake, it is possible that your VM won't be able to boot again (alone), use this at your own risk. Anyway here it goes --

使用fdisk(parted会拒绝这样做),您可以更改分区-

Using fdisk (parted will refuse to do this) you can change the partition --

# fdisk /dev/vda

删除dos分区标志并将单位更改为扇区":

Remove the dos partition flag and change units to 'sectors':

Command (m for help): c
DOS Compatibility flag is not set

Command (m for help): u
Changing display/entry units to sectors

让我们看一下分区表:

Command (m for help): p

Disk /dev/vda: 10.7 GB, 10737418240 bytes
181 heads, 40 sectors/track, 2896 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: 0x000c897f

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    10485759     5241856   83  Linux

删除第一个分区

Command (m for help): d
Selected partition 1

然后使用整个磁盘再次创建它:

And create it again using the whole disk:

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519

接下来,您应该将启动标志设置为第一个分区:

Next, you should set the boot flag to your first partition:

Command (m for help): a
Partition number (1-4): 1

您退出fdisk,并使用"w"命令写入更改,然后重新启动VM.

You quit fdisk writing your changes with 'w' command and reboot the VM.

重新启动后,您应该调整文件系统的大小:

Once it reboots, you shoud resize your filesystem:

# resize2fs  /dev/vda1

这篇关于创建虚拟机实例后如何扩展默认分区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆