如何扩大虚拟机安装ubuntu教程ubuntu系统的硬盘容量

Linux系统扩容根目录磁盘空间的操作方法
&更新时间:日 14:21:46 & 作者:非法小恋
这篇文章主要介绍了Linux系统扩容根目录磁盘空间的操作方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
一、使用背景
Linux根目录磁盘空间不够用了,当修改了虚拟机模版增加磁盘大小或者插入了一块新硬盘,但是发现系统里的大小还是没改变。
产生的原因是没有给磁盘格式化,没有增加分区。
二、操作方法
1. 查看磁盘空间大小,使用df -h 命令,发现挂载根目录节点的/dev/mapper/ubuntu14--vg-root 只有28G容量。
root@ubuntu14:/opt# df -h
容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu14--vg-root
0% /sys/fs/cgroup
3.9G 4.0K 3.9G
799M 384K 799M
0% /run/lock
0% /run/shm
0% /run/user
2. 增加磁盘空间,例如下图使用VM虚拟机增加的方式。
3.使用fdisk -l命令查看磁盘信息。当看到第一行Disk /dev/vda: 161.1 GB与实际df -h显示内容不符时,说明增加磁盘成功了。
root@ubuntu14:/opt# fdisk -l
Disk /dev/vda: 161.1 GB,
16 heads, 63 sectors/track, 312076 cylinders, total
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x
e Linux LVM
Disk /dev/mapper/ubuntu14--vg-root: 29.8 GB,
255 heads, 63 sectors/track, 3623 cylinders, total
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x
Disk /dev/mapper/ubuntu14--vg-root doesn't contain a valid partition table
Disk /dev/mapper/ubuntu14--vg-swap_1: 2147 MB,
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x
Disk /dev/mapper/ubuntu14--vg-swap_1 doesn't contain a valid partition table
4.使用fdisk /dev/vda, 创建新分区。
注意:不同操作系统的磁盘命名方式不同,有些是/dev/sda。具体使用方式参考第三步中fdisk -l首行显示Disk。如笔者在该系统中首行显示为Disk /dev/vda: 161.1 GB,
bytes ,故使用命令fdisk /dev/vda)
按照下面Linux操作进行分区。
root@ubuntu14:/opt# fdisk /dev/vda
命令(输入 m 获取帮助): m
toggle a bootable flag
edit bsd disklabel
toggle the dos compatibility flag
delete a partition
list known partition types
print this menu
add a new partition
create a new empty DOS partition table
print the partition table
quit without saving changes
create a new empty Sun disklabel
change a partition's system id
change display/entry units
verify the partition table
write table to disk and exit
extra functionality (experts only)
命令(输入 m 获取帮助): n #new 新分区
Partition type:
primary (1 primary, 1 extended, 2 free)
logical (numbered from 5)
Select (default p): p
#选择主分区
分区号 (1-4,默认为 3): 3 #分区序号
起始 sector (572799,默认为 499712): #分区开始回车默认
将使用默认值 499712
Last sector, +扇区 or +size{K,M,G} (757,默认为 501757):
将使用默认值 501757
命令(输入 m 获取帮助): n #new 新分区
Partition type:
primary (2 primary, 1 extended, 1 free)
logical (numbered from 5)
Select (default p): p #选择主分区
Selected partition 4
起始 sector (572799,默认为 ): #分区开始回车默认
将使用默认值
Last sector, +扇区 or +size{K,M,G} (572799,默认为 ):
将使用默认值
命令(输入 m 获取帮助): t
#修改分区格式
分区号 (1-5): 4
#修改分区号
Hex code (type L to list codes): 8e #格式选择8e
Changed system type of partition 4 to 8e (Linux LVM)
命令(输入 m 获取帮助): p #显示分区信息
Disk /dev/vda: 161.1 GB,
16 heads, 63 sectors/track, 312076 cylinders, total
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x
e Linux LVM
e Linux LVM
Partition table entries are not in disk order
命令(输入 m 获取帮助): w #保存信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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.
5. 重启Linux操作系统,使用reboot命令。
6. 创建物理卷,使用pvcreate /dev/vda4命令。
root@ubuntu14:~# pvcreate /dev/vda4
Physical volume "/dev/vda4" successfully created
7.查看新建的物理卷和大小,使用pvdisplay命令。
root@ubuntu14:~# pvdisplay
--- Physical volume ---
ubuntu14-vg
29.76 GiB / not usable 2.00 MiB
Allocatable
yes (but full)
Allocated PE
XR32TY-aRQC-IQC6-oCx7-aa9X-KdJe-bHmaBd
"/dev/vda4"
VG Name is a new physical volume of "120.00 GiB"
--- NEW Physical volume ---
120.00 GiB
Allocatable
Allocated PE
MVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk122
8. 将添加新的物理卷,加载到ubuntu14-vg卷组,使用vgextend ubuntu14-vg /dev/vda4命令。
root@ubuntu14:~# vgextend ubuntu14-vg /dev/vda4
Volume group "ubuntu14-vg" successfully extended
9. 查看卷组信息,使用vgdisplay命令。
root@ubuntu14:~# vgdisplay
--- Volume group ---
ubuntu14-vg
Metadata Areas
Metadata Sequence No 4
read/write
149.76 GiB
Alloc PE / Size
7618 / 29.76 GiB
Free PE / Size
30720 / 120.00 GiB
cq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D
10.增加ubuntu14-vg大小,增加120G。使用lvresize -L +120G /dev/mapper/ubuntu14--vg-root命令。
root@ubuntu14:~# lvresize -L +120G /dev/mapper/ubuntu14--vg-root
Extending logical volume root to 147.76 GiB
Logical volume root successfully resized
11. 重新识别ubuntu14-vg大小,使用resize2fs /dev/mapper/ubuntu14--vg-root命令。
root@ubuntu14:~# resize2fs /dev/mapper/ubuntu14--vg-root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/ubuntu14--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 10
The filesystem on /dev/mapper/ubuntu14--vg-root is now
blocks long.
12.查看扩容后的大小 ,使用df -h命令。
root@ubuntu14:~# df -h
容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu14--vg-root 146G
0% /sys/fs/cgroup
3.9G 4.0K 3.9G
799M 388K 799M
0% /run/lock
0% /run/shm
0% /run/user
当看到/dev/mapper/ubuntu14--vg-root 已经更新到新的大小时,则表示增加成功。
以上所述是小编给大家介绍的Linux系统扩容根目录磁盘空间的操作方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具今天用虚拟机的时候,发现虚拟机快满了,提示磁盘空间小,不得不扩充虚拟机空间。经过百度搜索,终于搞定了,记录如下
平台: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:
– 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.
– 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.
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
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.
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.
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
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.
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.
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).
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.
You will then be prompted to select a language, pressing enter defaults to English.
Next we select the default option 0 by pressing enter as we will be working with the GUI.
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.
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.
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.
After doing this, you should see /dev/sda2 (represented by the blue box) spread out over the unallocated space.
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.
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.
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.
Select the /dev/sda2 extended partition and click Resize/Move.
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.
Once this is complete the disk will look like this.
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.
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.
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.
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.
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.
vmware中ubuntu虚拟机扩容
vmware ubuntu硬盘空间不够用,空间扩展
Ubuntu 扩展磁盘空间
亲测解决Vmware12中Ubuntu14.04占用空间大的问题
虚拟机ubuntu磁盘空间不足,如何扩容
VMware下Ubuntu系统扩展硬盘方法(全图解)
vmware中的linux虚拟机如何增加磁盘容量
VM虚拟机下给Ubuntu 目录分区增加容量的方法
给vmware的ubuntu虚拟机增加硬盘、增加新的分区并自动挂载
没有更多推荐了,
(window.slotbydup=window.slotbydup || []).push({
id: "5865577",
container: s,
size: "300,250",
display: "inlay-fix"虚拟机Ubuntu需要多大磁盘空间【windows7吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:470,799贴子:
虚拟机Ubuntu需要多大磁盘空间收藏
默认好像是8G,如果除去Swap分区,那么7G也可以,虽然实际占用只有3~4G。
你妹还没安装完。。。
虚拟机设置成动态分配磁盘空间,大一点没关系,用不到不会占用实体磁盘,实际上安装完ubuntu大约占用4个多G,我虚拟机分配20个G给ubuntu。
安装ubuntu都是断网装的 5分钟解决 那语言包不换源下载蛋疼的要死 我硬盘装的40G
大神们,我想问下,在虚拟机上装好后的ubuntu还可以在修改起初设定的硬盘空间大小吗?假如:我安装时,把20G改成了200G怎么将这200G缩小点,新手,急求
登录百度帐号VMware11下对虚拟机Ubuntu14.10系统所在分区sda1进行磁盘扩容_Linux教程_Linux公社-Linux系统门户网站
你好,游客
VMware11下对虚拟机Ubuntu14.10系统所在分区sda1进行磁盘扩容
来源:Linux社区&
作者:cryhelyxx
1. Gparted简介
GParted (Gnome Partition Editor)是一种非常小巧自启动运行光盘,采用X org,轻量级的Fluxbox窗口管理器,以及最新的2.6 Linux内核建构。其中包含的GParted硬盘分区工具,作为系统维护盘非常有用。
GParted是一款Linux下的功能非常强大的分区工具,和windows下的&分区魔术师&类似,操作和显示上也很相似。GParted可以方便的创建、删除分区,也可以调整分区的大小和移动分区的位置。
GParted支持多种Linux下常见的分区格式,包括ext2、ext4、fat、hfs、jfs、reiser4、reiserfs、xfs,甚至ntfs。另外官方还提供了 LiveCD 和 LiveUSB 版本的 GParted,方便在没有主系统的情况下对硬盘进行分区!
2. Gparted iso镜像下载
Gparted的iso镜像下载地址:
当前最新版本是: 0.21.0-1, 即要下载& gparted-live-0.21.0-1-amd64.iso 或 gparted-live-0.21.0-1-i586.iso
3. 虚拟机硬盘扩容
1. 通过vmware-vdiskmanager.exe进行扩容
本文目的是: 对sda1分区即根文件系统所有分区进行扩容
进入VMware11软件的安装目录下, 找到vmware-vdiskmanager.exe
进入DOS下, 执行以下命令
vmware-vdiskmanager -x 200GB xxxx.vmdk
本人操作如下:
vmware-vdiskmanager -x 200GB "D:\vms\_14_10\ubuntu_14_10.vmdk"
其中, 参数-x 表示 扩容到200GB(这里根据自己的需要按量扩容), xxx.vmdk表示虚拟机的硬盘。
(p.s. 如果路径存在空格, 请将路径用双引号括起来)
至此, 虚拟机硬盘扩容完毕。
2. 通过vmware的图形界面进行扩容
首先虚拟机是关闭状态, 才可以使用 &磁盘实用工具&, 点击&扩展&, 调整虚拟机的硬盘容量, 点击确定保存退出。
4. 在虚拟机的CD/DVD(SATA)里加载Gparted的ISO镜像
在虚拟机设置--CD/DVD(SATA)里, 在"启动时连接"前打钩 并选择 上面下载好的 gparted-live-0.21.0-1-amd64.iso 镜像, 如下图:
然后开启虚拟机, 在提示按ESC进入Boot启动菜单时快速按下& ESC键, 出现boot菜单列表, 选择从CD-ROM Driver 项作为第一启动设备进行启动, 如下图:
直接& 回车
选择26, 即中文简体
然后进入Gparted的界面会自动弹出Gparted的分区界面。
5. 用Gparted进行合并分区到sda1
进入Gparted的启动界面后,
从上面看, 依次删除 linux-swap项, extended项, 最后剩下sda1和未分配, 然后右键"sda1"项进行调整大小, 将磁盘容量调整到合适的大小并预留2G作交换区
再右键"未分配"进行逻辑分区, 再格式化出linux-swap, 最后点击打钩提交生效。 如下:
OK, 退出Gparted 启动界面, 即关机。将CD/DVD(SATA)的项设置为不启动连接, 并移除Gparted镜像, 恢复为如下即可:
6. 检测系统所有分区sda1是否扩容成功
开启虚拟机,在终端执行:
如下图, 如果系统所有分区即sda1磁盘的容量达到目的, 则表示成功!
OK, Enjoy it!!!
更多Ubuntu相关信息见 专题页面
本文永久更新链接地址:
相关资讯 & & &
& (08/10/:56)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款

我要回帖

更多关于 ubuntu虚拟机 的文章

 

随机推荐