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

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

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

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
primary partition 3
Partition number (1-4): 3
First cylinder (653-1305, default 653):
Using default value 653
Last 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 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/sda3             653        1305     5240556+  83  Linux
/dev/sda5             618         653      280576   82  Linux swap / Solaris

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/nemo#


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

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

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

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/25618.html