Windows下Linux虚拟机磁盘分区扩容

场景说明:我的主机是Windows 7, 虚拟机是Wmware,里面装的是Linux。Windows下的Linux虚拟机, 磁盘分区不够,想扩容。

1) 首先进入vm中的Linux,sudo fdisk -l 列出磁盘的情况Disk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylinders #可以看出sda硬盘共10G,1306个磁道, 如果你有多个硬盘,应该会有sdb, sdc等Units = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00087bbc

Device Boot Start End Blocks Id System/dev/sda1 * 1 618 4959232 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 618 653 280577 5 ExtendedPartition 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 -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 4.7G 4.1G 410M 91% /none 119M 248K 119M 1% /devnone 123M 164K 123M 1% /dev/shmnone 123M 296K 123M 1% /var/runnone 123M 0 123M 0% /var/locknone 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): mCommand 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 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00087bbc

Device Boot Start End Blocks Id System/dev/sda1 * 1 618 4959232 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 618 653 280577 5 ExtendedPartition 2 does not end on cylinder boundary./dev/sda5 618 653 280576 82 Linux swap / Solaris

Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)lNo free sectors available #上面的扩展分区已经被用完。

Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)primary partition #需要输入全称:primary partition,直接输入 p 变成了打印的命令Partition number (1-4): 2Partition 2 is already defined. Delete it before re-adding it.

Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)primary partition 3Partition number (1-4): 3First cylinder (653-1305, default 653): Using default value 653Last cylinder, +cylinders or +size{K,M,G} (653-1305, default 1305): Using default value 1305 #一路回车 九八剩余的未使用的分区全利用了。

Command (m for help): p

Disk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00087bbc

Device Boot Start End Blocks Id System/dev/sda1 * 1 618 4959232 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 618 653 280577 5 ExtendedPartition 2 does not end on cylinder boundary./dev/sda3 653 1305 5240556+ 83 Linux/dev/sda5 618 653 280576 82 Linux swap / Solaris

Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.root@ubuntu:/home/nemo#

注意,1)这里虽然通过fdisk -l能看到新增的分区,但是要重启后才能写入分区表,比如这时要创建一个PV(物理卷)会提示找不到分区:重启系统后,新的分区就能正常使用了:root@ubuntu:/home/nemo# reboot #

2)新的分区必须经过格式化之后才能挂载,否则提示mount: you must specify the filesystem typeroot@ubuntu:/# mkfs.ext4 /dev/sda3

3)可以将分区挂接到一个已存在的不为空的目录上。但挂载后这个目录下以前的内容将不可用。我们想挂到/home下,所以先备份下/home, 再挂载,挂完后再copy回来。cd /mv /home /home2mkdir /homemount /dev/sda3 /homecp /home2/* /home/ok..

4)查看战果 查看各个分区的挂载目录以及分区的磁盘占用情况root@ubuntu:/home# df -ThFilesystem Type Size Used Avail Use% Mounted on/dev/sda1 ext4 4.7G 4.1G 410M 91% /none devtmpfs 119M 252K 119M 1% /devnone tmpfs 123M 88K 123M 1% /dev/shmnone tmpfs 123M 296K 123M 1% /var/runnone tmpfs 123M 0 123M 0% /var/locknone tmpfs 123M 0 123M 0% /lib/init/rw/dev/sda3 ext4 5.0G 138M 4.6G 3% /home #=========> 剩余4.6G, 可以放心玩啦!

2、一个分区挂载在一个已存在的目录上,这个目录可以不为空,但挂载后这个目录下以前的内容将不可用。对于其他操作系统建立的文件系统的挂载也是这样。

附:1)参考如下文章: Linux下的分区工具)root@ubuntu:/# du –max-depth=1 -h查看当前目录的磁盘占用情况

,旅游时最好的习惯:找个舒适的小店,挑张雅致的明信片,

Windows下Linux虚拟机磁盘分区扩容

相关文章:

你感兴趣的文章:

标签云: