Ubuntu 无法识别系统可用空间

Ubuntu 无法识别系统可用空间

我最初创建了一个虚拟磁盘(使用虚拟盒),其存储空间为 10 GB。我已经在其上安装了 ubuntu。它开始显示存储空间不足的警告,所以我将虚拟磁盘容量更改为 25 GB。但是当我运行 ubuntu 时,它一直显示相同的警告,似乎 ubuntu 无法识别新的可用空间。

如何解决这个问题?


运行此命令后:

lsblk -o name,size,type,fstype,mountpoint

我懂了:

NAME     SIZE TYPE FSTYPE   MOUNTPOINT
loop0    4.9M loop squashfs /snap/canonical-livepatch/41
loop1   29.5M loop squashfs /snap/sublime-text/18
loop2   86.6M loop squashfs /snap/core/4486
loop3  139.4M loop squashfs /snap/chromium/343
loop4   86.6M loop squashfs /snap/core/4650
loop5  139.8M loop squashfs /snap/chromium/353
sda       25G disk          
├─sda1     1M part          
└─sda2    10G part ext4     /
sr0     55.3M rom  iso9660  /media/dk/VBox_GAs_5.2.12

sudo parted /dev/sda resizepart 2 -1s
[sudo] password for dk: 
parted: invalid option -- '1'
Usage: parted [-hlmsv] [-a<align>] [DEVICE [COMMAND [PARAMETERS]]...]
dk@dkserver:/opt$ sudo resize2fs /dev/sda2
resize2fs 1.44.1 (24-Mar-2018)
The filesystem is already 2620672 (4k) blocks long.  Nothing to do!

(它没起作用)


结果 3:

sudo parted /dev/sda -- resizepart 2 -1s
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to
use all of the space (an extra 31457280 blocks) or continue with the current setting? 
parted: invalid token: 2                                                  
Fix/Ignore? y                                                             
parted: invalid token: y
Fix/Ignore? f                                                             
Partition number?     

我应该放哪个分​​区号?


我应该输入什么值?25 GB(或者以兆字节为单位?)还是应该输入更少的值(与其他系统/分区空间一起计算)?

sudo parted /dev/sda                                    
[sudo] password for dk: 
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free
        space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information
        of GNU Parted
(parted) resizepart 2
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
Yes/No? y                                                                 
End?  [10.7GB]? 

结果 4:

lsblk -o name,size,type,fstype,mountpoint
NAME     SIZE TYPE FSTYPE   MOUNTPOINT
loop0    4.9M loop squashfs /snap/canonical-livepatch/41
loop1   86.6M loop squashfs /snap/core/4650
loop2  139.8M loop squashfs /snap/chromium/353
loop3   86.6M loop squashfs /snap/core/4486
loop4   29.5M loop squashfs /snap/sublime-text/18
loop5  139.4M loop squashfs /snap/chromium/343
sda       25G disk          
├─sda1     1M part          
└─sda2    25G part ext4     /
sr0     55.3M rom  iso9660  /media/dk/VBox_GAs_5.2.12
dk@dkserver:~$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       9.8G  9.1G  230M  98% /

答案1

您需要扩展分区/dev/sda2以覆盖新添加的空间,然后需要调整文件系统的大小以填充分区。

  1. 延伸/dev/sda2至磁盘末端。

    如果磁盘使用 MBR 分区方案,那么就很容易:

    sudo parted /dev/sda -- resizepart 2 -1s
    

    如果磁盘使用 GPT 分区方案,则运行

    sudo parted /dev/sda
    

    并手动扩展分区号2

  2. 调整文件系统大小以填充分区:

    sudo resize2fs /dev/sda2
    

相关内容