VMware虚拟机中扩大Ubuntu系统磁盘空间

在安装软件的时候,很多人都是习惯性地连续点击“下一步”,一直到安装完成。这样的安装过程比较快,但有时留下首尾。好比VMware 新建Linux虚拟机的时候,默认的最大磁盘大小是20GB,这个初看觉得够用,等你要做一个Android播放机的源码编译时就发现空间远远不够用了,这时除了重装之外,您还可以选择扩大系统磁盘空间。

VMware版本: VMware Workstation 10.0.0 build-1295980

操作系统版本:Ubuntu 14.04.1 LTS
一、在VMware系统中扩展磁盘空间,注意要在虚拟机未开启的状态下操作,具体见下图:



<!--more-->



二、在Ubuntu 操作系统中增加分区(我的虚拟机Ubuntu默认安装下磁盘有3个分区,由于分区Linux和Extended之间有空闲空间,再加上扩展的磁盘空间,因 此用fdisk的'n'自动增加分区时,需要做2次新增分区动作,增加2个不连续的分区。当然这里也可以用gparted 分区工具进行分区,该工具需要在图形桌面环境下运行
root@ubuntu:sudo apt-get install gparted
root@ubuntu:/home/laozhu# gparted(gpartedbin:3324): Gtk-WARNING **: cannot open display:   #我的没有安装图形桌面环境,提示出错了
root@ubuntu:/home/laozhu#root@ubuntu:/home/work# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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: 0x000490e6
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda3        39847934    41940991     1046529    5  Extended
/dev/sda5        39847936    41940991     1046528   82  Linux swap/ 
Solaris
Command (m for help): n
Partition type:
p   primary (1 primary, 1 extended, 2 free)
l   logical (numbered from 5)
Select (default p): p
Partition number (1-4, default 2):
Using default value 2
First sector (39845888-62914559, default 39845888):
Using default value 39845888
Last sector, +sectors or +size{K,M,G} (39845888-39847933, default 39847933):
Using default value 39847933
Command (m for help): n
Partition type:
p   primary (2 primary, 1 extended, 1 free)
l   logical (numbered from 5)
Select (default p): p
Selected partition 4
First sector (41940992-62914559, default 41940992):
Using default value 41940992
Last sector, +sectors or +size{K,M,G} (41940992-62914559, default 62914559):
Using default value 62914559
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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: 0x000490e6
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39845888    39847933        1023   83  Linux
/dev/sda3        39847934    41940991     1046529    5  Extended
/dev/sda4        41940992    62914559    10486784   83  Linux
/dev/sda5        39847936    41940991     1046528   82  Linux swap/ 
Solaris
Command (m for help): w
Command (m for help): q
root@ubuntu:/home/work# partprobe            #重启操作系统
root@ubuntu:/home/work#<div></div>
三、格式化新建分区并设置挂载点
格式化:
root@ubuntu:/#mkfs.ext4 /dev/sda4
建立目录:
root@ubuntu:/#mkdir /home/work
创建挂载点:
root@ubuntu:/# mount -t ext4 /dev/sda4 /home/work
把新建的分区挂载到/home/work目录。
这时你就可以查看到home/work里面有个lost+found目录。

四、让系统开机自动挂载
在/etc/fstab中添加以下内容:
/dev/sda4       /home/work  ext4    defaults    1   0
重启下就可以见效了。

五、重启之后看分区表,发现存在 Partition table entries are not in disk order (意思是分区表条目未按物理扇区起始、结束顺序排序),解决方法:
root@ubuntu:/home/work# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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: 0x000490e6
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39847934    41940991     1046529    5  Extended
/dev/sda3        39845888    39847933        1023   83  Linux
/dev/sda4        41940992    62914559    10486784   83  Linux
/dev/sda5        39847936    41940991     1046528   82  Linux swap / Solaris
Partition table entries are not in disk order
root@ubuntu:/home/work#
root@ubuntu:/home/work# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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: 0x000490e6
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39847934    41940991     1046529    5  Extended
/dev/sda3        39845888    39847933        1023   83  Linux
/dev/sda4        41940992    62914559    10486784   83  Linux
/dev/sda5        39847936    41940991     1046528   82  Linux swap / Solaris
Partition table entries are not in disk order
root@ubuntu:/home/work# fdisk /dev/sda
Command (m for help): x
Expert command (m for help): m
Command action
b   move beginning of data in a partition
c   change number of cylinders
d   print the raw data in the partition table
e   list extended partitions
f   fix partition order
g   create an IRIX (SGI) partition table
h   change number of heads
i   change the disk identifier
m   print this menu
p   print the partition table
q   quit without saving changes
r   return to main menu
s   change number of sectors/track
v   verify the partition table
w   write table to disk and exit
Expert command (m for help): f
Done.
Expert command (m for help): p
Disk /dev/sda: 255 heads, 63 sectors, 3916 cylinders
Nr AF  Hd Sec  Cyl  Hd Sec  Cyl     Start      Size ID
1 80  32  33    0 254  63 1023       2048   39843840 83
2 00  74  27  432 106  56  432   39845888       2046 83
3 00 254  63 1023 254  63 1023   39847934    2093058 05
4 00 180   3  562  63  51  844   41940992   20973568 83
5 00 254  63 1023 254  63 1023          2    2093056 82
Expert command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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.
root@ubuntu:/home/work# partprobe
root@ubuntu:/home/work#
root@ubuntu:/home/work#
root@ubuntu:/home/work# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       19478204  16171136   2294588  88% /
none               4       0       4   0% /sys/fs/cgroup
udev            494384       4   494380   1% /dev
tmpfs           101048      612   100436   1% /run
none             5120       0     5120   0% /run/lock
none           505228       16    505212   1% /run/shm
none           102400       0    102400   0% /run/user
/dev/sda4       10189816    23028   9626120   1% /home/work
root@ubuntu:/home/work#

喜欢:
0
标签:
去到顶部