访问Google Compute Engine VM实例中的整个磁盘

时间:2015-08-02 07:57:35

标签: linux google-compute-engine mount centos7 disk-partitioning

Google控制台显示磁盘大小为100 GB

enter image description here

df -h显示:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        10G  2.4G  7.7G  24% /           ---> why does it show only 10 GB
devtmpfs        3.7G     0  3.7G   0% /dev
tmpfs           3.7G     0  3.7G   0% /dev/shm
tmpfs           3.7G   89M  3.6G   3% /run
tmpfs           3.7G     0  3.7G   0% /sys/fs/cgroup

fdisk -l显示:(它显示磁盘/ dev / sda和设备启动为/ dev / sda1)
我有两个磁盘......这告诉我什么?

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000917b9
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    20969472    10483712+  83  Linux

谷歌搜索告诉我运行resize2fs并显示:

resize2fs /dev/sda
    resize2fs 1.42.9 (28-Dec-2013)
    resize2fs: Device or resource busy while trying to open /dev/sda
    Couldn't find valid filesystem superblock.
resize2fs /dev/sda1
   resize2fs 1.42.9 (28-Dec-2013)
   resize2fs: Bad magic number in super-block while trying to open /dev/sda1
   Couldn't find valid filesystem superblock.

如何访问完整的100GB?

环境:使用谷歌提供的图像创建的centos 7

1 个答案:

答案 0 :(得分:2)

正如Zachary Newman在评论中指出的那样,CentOS不会自动将根分区的大小调整为磁盘的完整大小,因此您必须执行一些手动步骤才能重新分区磁盘,然后调整根文件系统的大小。 / p>

为了帮助您,我写了this script来自动完成这个过程。最好将其作为启动脚本运行,或者对于已经运行的VM,您可以按如下方式运行它:

$ curl -o /tmp/fdisk.sh https://raw.githubusercontent.com/mbrukman/cloud-launcher/master/apps/common/fdisk.sh
$ sudo bash /tmp/fdisk.sh

脚本将自动重新分区并重新启动VM。启动后,通过SSH重新连接到它并再次运行脚本:

$ sudo bash /tmp/fdisk.sh

脚本将根据磁盘的当前状态自动选择正确的步骤,无论是(重新分区+重启)还是调整大小。