热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

VMware下对Ubuntu进行扩充磁盘大小

今天用虚拟机的时候,发现虚拟机快满了,提示磁盘空间小,不得不扩充虚拟机空间。经过百度搜索,终于搞定了,记录如下平台:VMware(10.0.3)+Ubuntu14.04(32bi

今天用虚拟机的时候,发现虚拟机快满了,提示磁盘空间小,不得不扩充虚拟机空间。经过百度搜索,终于搞定了,记录如下

平台:VMware(10.0.3)+Ubuntu 14.04(32bit)

1. 选择VMware的虚拟机->设置->硬盘->实用工具->扩展 
这里写图片描述

2.在扩展磁盘容量对话框中,选择你要扩充的最大磁盘大小,我这里填的是25GB 
这里写图片描述

3.扩充完毕后,打开Ubuntu,然后安装一个工具Gparted 
sudo apt-get install Gparted

4.安装完毕后,然后在你的应用里搜索这个应用,打开 
这里写图片描述

5.打开Gparted应用,你可以看到已分配分区状况和新增未分配的分区 
这里写图片描述

Use GParted to increase disk size of a Linux native partition

In this post we will cover how to increase disk space for a VMware virtual machine that is using a Linux native partition rather than logical volume manager (LVM). Firstly we will increase the size of the virtual disk on the virtual machine at the hardware level and then once this is complete we will boot into a GParted live CD and perform the changes required to make use of the additional disk space so that the operating system is able to use it.

As there are a number of different ways to increase disk space I have also posted some different methods here:

  • How to Increase the size of a Linux LVM by expanding the virtual machine disk – In this article the virtual disk that is using LVM is expanded, whereas in this current article we are instead increasing the virtual disk and expanding the Linux native partition.
  • How to Increase the size of a Linux LVM by adding a new disk – In this article a new virtual disk is added to the virtual machine, a new partition is created, the volume group and logical volume are both expanded and then the filesystem is resized.
  • How to Decrease the size of a Linux LVM – In this article the file system is shrunk followed by the LVM, allowing you to reclaim space in the volume group.

Important Notes: During the time that the GParted ISO is mounted you will be booted into this live CD rather than your normal operating system, basically meaning that during this process there will be down time from normal server operations.

Be very careful when following this article as this process has the potential to cause a lot of damage to your data. If you are working with virtual machines make sure you take a snapshot of your virtual machine beforehand, or otherwise have some other form of up to date backup before proceeding. Note that a snapshot must not be taken until after the virtual disk has been increased in the first step below, otherwise you will not be able to increase the disk until it has been removed. It could also be worth cloning the virtual machine first and testing out this method on the clone.

Prerequisites: You will need to download the GParted live CD ISO file so that you can use it later, you can get this here.

Throughout my examples I will be working with a VMware virtual machine running Debian 6, this was set up with a 20gb disk and we will be increasing it by 10gb for a total final size of 30gb.

Below is an image displaying disk information on the server before we begin.
disk free and fdisk
It is important to identify that you are actually using a Linux native partition – as this is what we are extending. As you can see in the above image /dev/sda1 is listed as “Linux” and it has the ID of 83. The 83 hex code shows that it is a Linux native partition, while 8e shows a Linux LVM. For information on increasing a LVM please see the linked posts above.

Note that /dev/sda1 is the partition we will be expanding.

Increasing the virtual hard disk

First off we increase the allocated disk space on the virtual machine itself. This is done by right clicking the virtual machine in vSphere, selecting edit settings, and then selecting the hard disk. In the below image I have changed the previously set hard disk of 20gb to 30gb while the virtual machine is up and running. Once complete click OK, this is all that needs to be done in VMware for this process.

VMware virtual disk increase

If you are not able to modify the size of the disk, the provisioned size setting is greyed out. This can happen if the virtual machine has a snapshot in place, these will need to be removed prior to making the changes to the disk. Alternatively you may need to shut down the virtual machine if it does not allow you to add or increase disks on the fly, if this is the case shut down and make the change, do not power the virtual machine back on at this stage as next we mount the GParted ISO.

Booting into the GParted Live CD

Now that we have increased the hard disk space of the virtual machines, we need to boot into the GParted live CD to continue, you can download this here.

Right click on the virtual machine in vSphere and select “Edit Settings” to bring up the properties.

Select the CD/DVD Drive and then select your GParted ISO, in this instance I have already uploaded this file to the datastore so I have just clicked the browse button to select it. Make sure that connect at power on is ticked.

Mount GParted live CD

I have also selected for the boot options to be presented on the next boot so that I can select to boot into the ISO easier. You can also adjust the time to delay the boot so that you have appropriate time to select that you want to boot from CD, in the below image this is set to 5 seconds, and force to boot into bios is enabled so that I can select to boot from CD on next boot.

VMware boot options

Now we are ready to power on the virtual machine (if your virtual machine was still on, shut down and power on), I have done this using some older versions of GParted in the past and it is worth noting that over time the GUI has changed so the following images may look a little different for you. I am using the current latest version of the live CD, version 0.14.1-1.

Once the virtual machine has powered on and you have booted to the CD, you will be presented with the following menu, just press enter to boot into GParted Live (Default Settings).

GParted

After some time you will then arrive at the following screen, for this I did not change anything and just accepted the defaults by pressing enter.

GParted

You will then be prompted to select a language, pressing enter defaults to English.

GParted

Next we select the default option 0 by pressing enter as we will be working with the GUI.

GParted

Once complete you will be presented with the GUI with GParted already open, if it is not already open you can select it from the Desktop icon.

GParted

As you can see the original /dev/sda1 partition that is making use of the 20gb disk is there, as well as the new unallocated 10gb from when we increased the size of the virtual hard disk earlier. The space between the two is the swap space. The total /dev/sda disk size of 30gb is also shown.

What needs to be done now is get /dev/sda1 to take up that unallocated space, this is not currently possible because swap is in the way so we need to move things around. If you do not have swap in between the partition to be extended and the unallocated space then you will be able to skip down a few steps until you arrive at the image where /dev/sda1 and the unallocated space are next to each other.

First we select /dev/sda2 which is the extended partition containing the swap, we want to expand this to include the 10gb of unallocated space.

Select /dev/sda2 and click “Resize/Move” and you will be presented with the following.

GParted

Basically you just need to drag the black arrow of /dev/sda2 all the way to the end of the unallocated space and click the Resize/Move button.

GParted

After doing this, you should see /dev/sda2 (represented by the blue box) spread out over the unallocated space.

GParted

This change and all further changes will not yet be applied, you can see the tasks down the bottom of the GParted interface and these will be applied only once you click the Apply button. Alternatively you can click the Undo button to remove a pending change.

This time we want to select /dev/sda5 which is the swap partition and select Resize/Move, this will result in the following.

GParted

This time rather than expanding the partition, we want to just move swap all the way to the end of the /dev/sda2 space that it is in, this is done by just dragging the box to the end which will then look like this.

GParted

Click the Resize/Move button and then a warning may appear informing you that moving a partition might cause your operating system to fail to boot. It also warns that performing this move may take a long time to apply, read the warning then click OK to continue.

The GUI should now look something like the below image, where /dev/sda1 is located right next to /dev/sda2 which contains the unallocated space.

GParted

Select the /dev/sda2 extended partition and click Resize/Move.

GParted

Drag this to the right so that only the swap space is contained and the grey unallocated space is freed, click Resize/Move once complete.

GParted

Once this is complete the disk will look like this.

GParted

Now we have /dev/sda1 next to the unallocated space so we are finally ready to expand /dev/sda1. Select /dev/sda1 and click the Resize/Move button.

GParted

You will be able to perform this action straight away if you did not have swap in between /dev/sda1 and the unallocated space, the previous steps were to get swap out of the way in GParted.

Drag the arrow over so that the unallocated space is then consumed by /dev/sda1 as shown below, then click Resize/Move.

GParted

Once this is done the /dev/sda1 partition will now be using the unallocated space that was previously there. All that is left to do is click the apply button which will apply the changes – you will be prompted to confirm with a warning that data loss may occur.

Note that this may take a while depending on how much of the disk is currently in use and the amount of disk space you are increasing, because a file system check (fsck) is run before the expansion and after it to ensure that there are no issues. I have performed this method on a 400gb server in the past and to increase it 100gb took approximately 5 hours. In this example I am only increasing by 10gb and there is only about 1gb of data on the disk so this took approximately 2 minutes to finish applying.

Once complete you will see something similar to the below image, you will be able to click close once finished.

GParted

Everything is now finished, you just need to reboot the virtual machine and then boot from disk rather than CD, alternatively shut down the virtual machine and unmount the live CD and then power it back on.

Once the operating system has booted you can confirm that the disk space has expanded correctly. Below you can see that /dev/sda1 is now 30gb in size.

GParted

Summary

With this method we have increased the virtual hard disk drive through VMware, booted into a GParted live CD ISO and expanded the primary Linux native partition over the unallocated space, resulting in overall disk space being increased successfully.



推荐阅读
  • 本文探讨了如何在 PHP 的 Eloquent ORM 中实现数据表之间的关联查询,并通过具体示例详细解释了如何将关联数据嵌入到查询结果中。这不仅提高了数据查询的效率,还简化了代码逻辑。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • golang常用库:配置文件解析库/管理工具viper使用
    golang常用库:配置文件解析库管理工具-viper使用-一、viper简介viper配置管理解析库,是由大神SteveFrancia开发,他在google领导着golang的 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • Python自动化处理:从Word文档提取内容并生成带水印的PDF
    本文介绍如何利用Python实现从特定网站下载Word文档,去除水印并添加自定义水印,最终将文档转换为PDF格式。该方法适用于批量处理和自动化需求。 ... [详细]
  • 360SRC安全应急响应:从漏洞提交到修复的全过程
    本文详细介绍了360SRC平台处理一起关键安全事件的过程,涵盖从漏洞提交、验证、排查到最终修复的各个环节。通过这一案例,展示了360在安全应急响应方面的专业能力和严谨态度。 ... [详细]
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 百度服务再次遭遇技术问题,疑似DNS解析故障
    近日晚间,百度多项在线服务出现加载异常,包括移动端搜索在内的多个功能受到影响。初步迹象表明,问题可能与DNS服务器解析有关。 ... [详细]
  • 本文详细介绍了MicroATX(也称Mini ATX)和MATX主板规格,探讨了它们的结构特点、应用场景及对电脑系统成本和性能的影响。同时,文章还涵盖了相关操作系统的实用技巧,如蓝牙设备图标删除、磁盘管理等。 ... [详细]
  • 本文将深入探讨PHP编程语言的基本概念,并解释PHP概念股的含义。通过详细解析,帮助读者理解PHP在Web开发和股票市场中的重要性。 ... [详细]
  • 爱奇艺视频下载指南
    随着百度在视频领域的不断扩展,爱奇艺的内容库日益丰富,涵盖了大量新番动画、电影、电视剧和综艺节目。本文将详细介绍如何通过爱奇艺客户端下载视频,帮助用户轻松实现离线观看。 ... [详细]
  • 脑机接口(BCI)技术正逐步将科幻变为现实,从帮助听障人士恢复听力到使瘫痪者重新站立,甚至可能将多年的学习过程压缩至瞬间。本文探讨了这一前沿技术的现状、挑战及其未来前景。 ... [详细]
  • 百度搜索结果链接提取工具 UrlGetter V1.43
    该工具专为获取百度搜索引擎的结果页面中的网址链接而设计,能够解析并转换为原始URL。通过正则表达式匹配技术,精准提取网页链接,并提供详细的使用说明和下载资源。 ... [详细]
author-avatar
vfjgjgv
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有