• VirtualBox Ubuntu系统硬盘扩容


    1、关闭虚拟机,找到需要扩容的硬盘,修改为新的容量80GB,应用保存。

    2、打开VM,进入系统,使用lsblk可以看到硬盘容量已经变为80GB,但硬盘根分区还没有扩容,使用df查看根文件系统也没有扩容。

    1. [192.168.2.108] alpha@mascot.x ~ $ lsblk
    2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    3. loop0 7:0 0 111.9M 1 loop /snap/lxd/24322
    4. loop1 7:1 0 53.3M 1 loop /snap/snapd/19457
    5. loop2 7:2 0 63.4M 1 loop /snap/core20/1974
    6. sda 8:0 0 80G 0 disk
    7. ├─sda1 8:1 0 1M 0 part
    8. └─sda2 8:2 0 25G 0 part /
    9. sr0 11:0 1 1024M 0 rom
    10. [192.168.2.108] alpha@mascot.x ~ $ df -h
    11. Filesystem Size Used Avail Use% Mounted on
    12. tmpfs 392M 1.1M 391M 1% /run
    13. /dev/sda2 25G 7.7G 16G 33% /
    14. tmpfs 2.0G 0 2.0G 0% /dev/shm
    15. tmpfs 5.0M 0 5.0M 0% /run/lock
    16. tmpfs 392M 4.0K 392M 1% /run/user/1000

    3、使用parted命令修改分区大小:

    sudo parted /dev/sda

    运行parted命令后,输入help查看命令列表。

    1. [192.168.2.108] alpha@mascot.x ~ $ sudo parted /dev/sda
    2. [sudo] password for alpha:
    3. GNU Parted 3.4
    4. Using /dev/sda
    5. Welcome to GNU Parted! Type 'help' to view a list of commands.
    6. (parted) help
    7. align-check TYPE N check partition N for TYPE(min|opt) alignment
    8. help [COMMAND] print general help, or help on COMMAND
    9. mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
    10. mkpart PART-TYPE [FS-TYPE] START END make a partition
    11. name NUMBER NAME name partition NUMBER as NAME
    12. print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular
    13. partition
    14. quit exit program
    15. rescue START END rescue a lost partition near START and END
    16. resizepart NUMBER END resize partition NUMBER
    17. rm NUMBER delete partition NUMBER
    18. select DEVICE choose the device to edit
    19. disk_set FLAG STATE change the FLAG on selected device
    20. disk_toggle [FLAG] toggle the state of FLAG on selected device
    21. set NUMBER FLAG STATE change the FLAG on partition NUMBER
    22. toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
    23. unit UNIT set the default unit to UNIT
    24. version display the version number and copyright information of GNU Parted
    25. (parted)

     输入print命令,打印当前分区表,会提示有可用空间,需要修复GPT,输入Fix修复:

    1. (parted) print
    2. 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 115343360
    3. blocks) or continue with the current setting?
    4. Fix/Ignore? Fix
    5. Model: ATA VBOX HARDDISK (scsi)
    6. Disk /dev/sda: 85.9GB
    7. Sector size (logical/physical): 512B/512B
    8. Partition Table: gpt
    9. Disk Flags:
    10. Number Start End Size File system Name Flags
    11. 1 1049kB 2097kB 1049kB bios_grub
    12. 2 2097kB 26.8GB 26.8GB ext4
    13. (parted)

     修复GPT之后,可以输入print free查看可用的空间:

    1. (parted) print free
    2. Model: ATA VBOX HARDDISK (scsi)
    3. Disk /dev/sda: 85.9GB
    4. Sector size (logical/physical): 512B/512B
    5. Partition Table: gpt
    6. Disk Flags:
    7. Number Start End Size File system Name Flags
    8. 17.4kB 1049kB 1031kB Free Space
    9. 1 1049kB 2097kB 1049kB bios_grub
    10. 2 2097kB 26.8GB 26.8GB ext4
    11. 26.8GB 85.9GB 59.1GB Free Space
    12. (parted)

    继续 输入resizepart 2 100%命令,将分区2扩容100%可用空间,输入Yes确认操作:

    1. (parted) resizepart 2 100%
    2. Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
    3. Yes/No? Yes
    4. (parted)

     输入q退出parted命令,再用lsblk查看,根分区大小已经变成80G,但使用df查看根文件系统,还是25G,没有扩容。

    1. (parted) q
    2. Information: You may need to update /etc/fstab.
    3. [192.168.2.108] alpha@mascot.x ~ $ lsblk
    4. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    5. loop0 7:0 0 63.4M 1 loop /snap/core20/1974
    6. loop1 7:1 0 111.9M 1 loop /snap/lxd/24322
    7. loop2 7:2 0 53.3M 1 loop /snap/snapd/19457
    8. loop3 7:3 0 38.8M 1 loop /snap/snapd/21759
    9. loop4 7:4 0 63.9M 1 loop /snap/core20/2318
    10. loop5 7:5 0 87M 1 loop /snap/lxd/28373
    11. sda 8:0 0 80G 0 disk
    12. ├─sda1 8:1 0 1M 0 part
    13. └─sda2 8:2 0 80G 0 part /
    14. sr0 11:0 1 1024M 0 rom
    15. [192.168.2.108] alpha@mascot.x ~ $ df -h
    16. Filesystem Size Used Avail Use% Mounted on
    17. tmpfs 392M 1.1M 391M 1% /run
    18. /dev/sda2 25G 7.9G 16G 35% /
    19. tmpfs 2.0G 0 2.0G 0% /dev/shm
    20. tmpfs 5.0M 0 5.0M 0% /run/lock
    21. tmpfs 392M 4.0K 392M 1% /run/user/1000

    4、使用resize2fs命令更新文件系统大小,再用df查看根文件系统大小已经更新:

    sudo resize2fs /dev/sda2

    1. [192.168.2.108] alpha@mascot.x ~ $ sudo resize2fs /dev/sda2
    2. resize2fs 1.46.5 (30-Dec-2021)
    3. Filesystem at /dev/sda2 is mounted on /; on-line resizing required
    4. old_desc_blocks = 4, new_desc_blocks = 10
    5. The filesystem on /dev/sda2 is now 20971003 (4k) blocks long.
    6. [192.168.2.108] alpha@mascot.x ~ $ df -h
    7. Filesystem Size Used Avail Use% Mounted on
    8. tmpfs 392M 1.1M 391M 1% /run
    9. /dev/sda2 79G 8.1G 68G 11% /
    10. tmpfs 2.0G 0 2.0G 0% /dev/shm
    11. tmpfs 5.0M 0 5.0M 0% /run/lock
    12. tmpfs 392M 4.0K 392M 1% /run/user/1000

    结束。

    参考:

    ubuntu 扩展分区并将剩余空间添加到现有逻辑卷中_ubuntu扩展分区大小 将一个磁盘加到另一个当中-CSDN博客

  • 相关阅读:
    “数字化重构系统,搞定 CEO 是第一步”
    神经网络算法的具体流程,神经网络算法难不难
    python提效小工具-统计xmind用例数量
    简要归纳UE5 Lumen全局光照原理
    C语言 指针初阶
    全球无人机灯光秀预计2028年将达到7.19亿美元,年复合增长率(CAGR)为21.46%
    Javascript 笔记:object
    洛谷P4316 绿豆蛙的归宿
    内存管理的概念
    pytorch 手写数字识别例子
  • 原文地址:https://blog.csdn.net/xunknown/article/details/139397896