【问题标题】:How to extend default partition after creating an VM instance? [closed]创建虚拟机实例后如何扩展默认分区? [关闭]
【发布时间】:2014-05-08 06:24:59
【问题描述】:

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

谢谢,

【问题讨论】:

    标签: virtual-machine fiware


    【解决方案1】:

    我会说你有两种方法。第一个是安全的,第二个是有风险的。所以,让我们从安全的开始: 您可以使用 fdisk /dev/vda(或 parted /dev/vda)来创建新分区。由于分区将在创建和挂载“/”的同一虚拟磁盘中创建,因此您必须在使用新分区之前重新启动 VM。

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

     mkfs -t ext4 /dev/vda2
    

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

     mount /dev/vda2 /mnt
    

    为了使这种挂载持久化,您可以在 /etc/fstab 中添加一个新行:

     /dev/vda2      /mnt                       ext4    defaults        1 1
    

    第二种方法是扩展您的 /dev/vda1 分区。这是有风险的,如果您犯了任何错误,您的虚拟机可能无法(单独)再次启动,使用此操作需您自担风险。反正就是这样——

    使用 fdisk(parted 会拒绝这样做)你可以改变分区 --

    # fdisk /dev/vda
    

    删除dos分区标志并将单位更改为'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
    

    然后使用整个磁盘重新创建它:

    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
    

    接下来,您应该将引导标志设置为您的第一个分区:

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

    您使用 'w' 命令退出 fdisk 写入更改并重新启动 VM。

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

    # resize2fs  /dev/vda1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多