GCE 实例 - 无法增加磁盘空间?

GCE 实例 - 无法增加磁盘空间?

我有一个带有 9000GB 磁盘的 GCE VM 实例:

$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0 19.5T  0 disk 
├─sda1    8:1    0  8.8T  0 part /
├─sda14   8:14   0    3M  0 part 
└─sda15   8:15   0  124M  0 part /boot/efi
~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  372K  3.2G   1% /run
/dev/sda1       8.7T  8.3T  105M 100% /
tmpfs            16G     0   16G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/sda15      124M  7.9M  116M   7% /boot/efi
tmpfs           3.2G     0  3.2G   0% /run/user/1000

我只是按照这里的步骤操作(https://cloud.google.com/compute/docs/disks/add-persistent-disk) 尝试增加磁盘大小。我已将磁盘编辑为 20000GB。

不过,我似乎无法扩大机器上的分区表以利用增加的尺寸。

当我尝试运行指南中的命令时,我得到:

$ sudo growpart /dev/sda 1
NOCHANGE: partition 1 could only be grown by -14579398752 [fudge=2048]

这是否意味着它不起作用?

resize2fs 也不起作用:

$ sudo resize2fs /dev/sda1
resize2fs 1.44.5 (15-Dec-2018)
The filesystem is already 2359262988 (4k) blocks long.  Nothing to do!

答案1

我尝试遵循相同的文档调整区域永久性磁盘的大小并没有发现任何问题:

  1. 创建虚拟机实例:

    $ gcloud compute instances create disk-resize --zone=us-central1-a --machine-type=n1-standard-1 --image=ubuntu-1804-bionic-v20200414 --image-project=ubuntu-os-cloud --boot-disk-size=9000GB --boot-disk-device-name=disk-resize
    
    Created [https://www.googleapis.com/compute/v1/projects/test-prj/zones/us-central1-a/instances/disk-resize].
    WARNING: Some requests generated warnings:
    - Disk size: '9000 GB' is larger than image size: '10 GB'. You might need 
    to resize the root repartition manually if the operating system does not 
    support automatic resizing. See https://cloud.google.com/compute/docs/disks/add-persistent-disk#resize_pd for details.
    
    NAME         ZONE           MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP    EXTERNAL_IP    STATUS
    disk-resize  us-central1-a  n1-standard-1               YY.128.15.YY  XX.222.86.XX  RUNNING
    
  2. 在任何更改之前检查磁盘空间:

    disk-resize:~$ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            1.8G     0  1.8G   0% /dev
    tmpfs           369M  884K  369M   1% /run
    /dev/sda1       8.6T  1.3G  8.6T   1% /
    tmpfs           1.9G     0  1.9G   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda15      105M  3.6M  101M   4% /boot/efi
    /dev/loop0       94M   94M     0 100% /snap/core/8935
    /dev/loop1       55M   55M     0 100% /snap/core18/1705
    /dev/loop2       98M   98M     0 100% /snap/google-cloud-sdk/126
    tmpfs           369M     0  369M   0% /run/user/1001
    
  3. 将磁盘大小增加到 20000GB:

    $ gcloud compute disks resize disk-resize --size 20000GB --zone us-central1-a
    
    ...
    Updated [https://www.googleapis.com/compute/v1/projects/test-prj/zones/us-central1-a/disks/disk-resize].
    ...
    sizeGb: '20000'
    ...
    status: READY
    

    ...

  4. 安装growpart

    $ sudo apt -y install cloud-guest-utils 
    
  5. 扩大分区:

    disk-resize:~$ lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    loop0     7:0    0 93.8M  1 loop /snap/core/8935
    loop1     7:1    0   55M  1 loop /snap/core18/1705
    loop2     7:2    0 97.1M  1 loop /snap/google-cloud-sdk/126
    sda       8:0    0 19.5T  0 disk 
    ├─sda1    8:1    0  8.8T  0 part /
    ├─sda14   8:14   0    4M  0 part 
    └─sda15   8:15   0  106M  0 part /boot/efi
    

    disk-resize:~$ sudo growpart /dev/sda 1
    CHANGED: partition=1 start=227328 old: size=18874140639 end=18874367967 new: size=41942812639,end=41943039967
    

    disk-resize:~$ lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    loop0     7:0    0 93.8M  1 loop /snap/core/8935
    loop1     7:1    0   55M  1 loop /snap/core18/1705
    loop2     7:2    0 97.1M  1 loop /snap/google-cloud-sdk/126
    sda       8:0    0 19.5T  0 disk 
    ├─sda1    8:1    0 19.5T  0 part /
    ├─sda14   8:14   0    4M  0 part 
    └─sda15   8:15   0  106M  0 part /boot/efi
    
  6. 扩展磁盘上的文件系统(ext4)以使用增加的空间:

    disk-resize:~$ sudo resize2fs /dev/sda1
    resize2fs 1.44.1 (24-Mar-2018)
    Filesystem at /dev/sda1 is mounted on /; on-line resizing required
    old_desc_blocks = 1125, new_desc_blocks = 2500
    The filesystem on /dev/sda1 is now 5242851579 (4k) blocks long.
    
  7. 检查可用磁盘空间:

    disk-resize:~$ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            1.8G     0  1.8G   0% /dev
    tmpfs           369M  884K  369M   1% /run
    /dev/sda1        19T  1.4G   19T   1% /
    tmpfs           1.9G     0  1.9G   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/sda15      105M  3.6M  101M   4% /boot/efi
    /dev/loop0       94M   94M     0 100% /snap/core/8935
    /dev/loop1       55M   55M     0 100% /snap/core18/1705
    /dev/loop2       98M   98M     0 100% /snap/google-cloud-sdk/126
    tmpfs           369M     0  369M   0% /run/user/1001          
    

让我们比较一下:

  • 前:

    /dev/sda1       8.6T  1.3G  8.6T   1% /
    
  • 后:

    /dev/sda1        19T  1.4G   19T   1% /
    

解决您的问题

  • 比较你的步骤和我的
  • 检查你是否有所需权限
  • 检查是否在步骤 5 之前通过控制台调整了步骤 3 中的虚拟机磁盘大小

    $ gcloud compute disks list
    NAME         LOCATION       LOCATION_SCOPE  SIZE_GB  TYPE         STATUS
    disk-resize  us-central1-a  zone            20000    pd-standard  READY
    
  • 检查磁盘配额的当前使用情况IAM&Admin-> Quotas-> 设置Quota typeAll quotas-> 设置ServiceCompute engine API-> 设置MetricPersistent disk standard (GB)-> 设置LocationNAME_OF_YOUR_ZONE

如果您仍然有问题,请使用您的步骤、命令和输出更新您的问题

此外,看看这个例子

相关内容