场景说明:我的主机是Windows 7, 虚拟机是Wmware,里面装的是Linux。
Windows下的Linux虚拟机, 磁盘分区不够,想扩容。
1) 首先进入vm中的Linux,sudo fdisk -l 列出磁盘的情况
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders #可以看出sda硬盘共10G,1306个磁道, 如果你有多个硬盘,应该会有sdb, sdc等
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00087bbc
Device Boot Start End Blocks Id System
/dev/sda1 * 1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 618 653 280577 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 618 653 280576 82 Linux swap / Solaris
#可以看出
1)已经用了 1~653磁道, 还有1306-653=653个磁道未用, 已经有5G已经分区,还有5G未分区。
和现实一致,我的虚拟机文件本来默认5G, 刚把磁盘扩容到10G,还有5G还为分区。
2)现有的5G被分为了3个区, 除了有一个是扩展分区(扩展分区是用来挂其他逻辑分区用的),也就两个分区 一个是 linux分区 一个是 linux swap(交换分区)
2)查看现有分区的磁盘使用情况以及挂载情况
root@Ubuntu:/home/nemo# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 4.7G 4.1G 410M 91% /
none 119M 248K 119M 1% /dev
none 123M 164K 123M 1% /dev/shm
none 123M 296K 123M 1% /var/run
none 123M 0 123M 0% /var/lock
none 123M 0 123M 0% /lib/init/rw
可以看到现有的5G分区已经基本上被使用玩。/dev/sda1分区是被挂载在了"/"根目录下, 还剩9%的剩余容量。
2)开始把剩余的为使用的5G磁盘也分区吧,并且给其挂载一个目录
root@ubuntu:/home/nemo# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00087bbc
Device Boot Start End Blocks Id System
/dev/sda1 * 1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 618 653 280577 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 618 653 280576 82 Linux swap / Solaris