vmware虚拟机拓展磁盘容量

刚开始用虚拟机,本着试用的原则装机时只分配了20G硬盘,后来……

就没有后来了?

……反正就是硬盘不够用了,于是想到拓展硬盘~倒腾倒腾,总结如下:

首先虚拟机处于关闭状态

点击“虚拟机”->“设置”->选择“硬盘”->“实用工具”->“拓展”


想再加40G(原来有20G,所以此处填60G),点击“拓展”然后“确定”。

开启虚拟机,查看磁盘情况

$ sudo fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832cylinders, total 125829120 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x000e0659

 

  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/sda5        39847936    41940991    1046528   82  Linux swap / Solaris

从上可看到磁盘容量为64.4G(60G磁盘+1G内存),说明磁盘已经扩展到60G。

但是此时拓展的空间还没有真正用起来,需要重新分区挂载,下面详细说明。

新增分区:

$ sudo fdisk /dev/sda

 

Command (m for help): m         /*输入m查看详细帮助*/

Command action

  a   toggle a bootable flag

  b   edit bsd disklabel

  c   toggle the dos compatibilityflag

  d   delete a partition

  l   list known partition types

  m   print this menu

  n   add a new partition

  o   create a new empty DOSpartition table

  p   print the partition table

  q   quit without saving changes

  s   create a new empty Sundisklabel

  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 (expertsonly)

 

Command (m for help): p                   /*输入p打印当前分区信息*/

 

Disk /dev/sda: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832cylinders, total 125829120 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x000e0659

 

  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/sda5        39847936    41940991    1046528   82  Linux swap / Solaris

 

Partition table entries are not in diskorder

 

Command (m for help): n                   /*输入新建分区*/

Partition type:

  p   primary (2 primary, 1extended, 1 free)

  l   logical (numbered from 5)

Select (default p):                                /*默认回车*/

Using default response p

Selected partition 4                             /*默认回车,如有其它未被占用值可选,也可选其它值 */

First sector (41940992-125829119, default41940992):

Using default value 41940992          /*默认回车*/

Last sector, +sectors or +size{K,M,G}(41940992-125829119, default 125829119): +40G    /*输入+40G,注意大写*/

 

Command (m for help): p                   /*输入p打印当前分区信息*/

 

Disk /dev/sda: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832cylinders, total 125829120 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x000e0659

 

  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   125827071   41943040   83  Linux

/dev/sda5        39847936    41940991    1046528   82  Linux swap / Solaris

 

/*可以看到已经新增分区/dev/sda4 */

 

Partition table entries are not in diskorder

 

Command (m for help): w                  /*输入保存*/

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy.

The kernel still uses the old table. Thenew table will be used at

the next reboot or after you runpartprobe(8) or kpartx(8)

Syncing disks.

 

重启ubantu系统使分区生效。

接下来要格式化分区

$ sudo mkfs -t ext4 /dev/sda4

mke2fs 1.42.9 (4-Feb-2014)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

2621440 inodes, 10485760 blocks

524288 blocks (5.00%) reserved for thesuper user

First data block=0

Maximum filesystem blocks=4294967296

320 block groups

32768 blocks per group, 32768 fragments pergroup

8192 inodes per group

Superblock backups stored on blocks:

       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

       4096000, 7962624

 

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystemaccounting information: done

然后将磁盘分区挂载到文件夹下:

$ sudo mount /dev/sda4/home/dpcai/workspace

(/home/dpcai/workspace为自定义的目录)

再查看磁盘阵列信息:

$ df -h

Filesystem      Size Used Avail Use% Mounted on

/dev/sda1        19G 2.8G   15G  16% /

none            4.0K     0 4.0K   0% /sys/fs/cgroup

udev            483M  4.0K 483M   1% /dev

tmpfs            99M 780K   98M   1% /run

none            5.0M     0 5.0M   0% /run/lock

none            494M     0 494M   0% /run/shm

none            100M     0 100M   0% /run/user

.host:/         318G 137G  182G  43% /mnt/hgfs

/dev/sda4        40G  48M   38G   1% /home/dpcai/workspace

 

发现新分区/dev/sda4 已经挂载到/home/dpcai/workspace目录下。

最后,要使分区挂载永久生效,需要将/dev/sda4与/home/dpcai/workspace目录的对应关系写到/etc/fstab文件中:

$ sudo vi /etc/fstab

在文件中添加以下内容

/dev/sda4 /home/dpcai/workspace   ext4    defaults   1 2

保存退出:wq

这样就完成啦!再重启系统依然可以看到/dev/sda4 挂载到/home/dpcai/workspace目录下~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值