Ubuntu virtual machine storage space expansion

1. First adjust the virtual hard disk size in the virtual machine settings.

virtual box in "Virtual Media Manager"

After setting up, I opened the virtual machine and found that it still prompted that there was not enough space.

2. Delete the primary partition and recreate it

Open the terminal in the ubuntu virtual machine and use df -h to view the primary partition hard disk

df -h

You can see the only hard disk /dev/sda1 (the name may be different, look for the rightmost slash "/" in the box below)

Note: The next operation may be risky. It is recommended to back up the virtual machine first (create a snapshot)

Execute the command in the terminal: (note that the last one is sda, not sda1)

sudo fdisk /dev/sda

Type d and press Enter, it will prompt that it has been deleted.

If you have not done anything with the virtual disk before, just delete it once. If there is more than one and you want to delete them all, just continue with d

Type the commands in sequence: (the default prompt is to press Enter directly)

For example, after expansion, the capacity is 40G, but the system will occupy points, so type +39G ( "+" and "G" cannot be less, and must be capitalized )

n
p
1
2048
+39G

After the partition size is selected, a signature will be included, asking whether to remove the signature. If not removed, the partition format at this time is ntfs. We need a partition in ntfs format, so do not remove it and enter n;

Type w. (referring to save and exit)

If your hands are shaking and the configuration is wrong, you can type q and press Enter (exit without saving)

Restart

sudo reboot

The restart process may be a bit slow.

After the startup is completed, the terminal executes:

sudo resize2fs /dev/sda1

After the execution is successful, type df -h to check the capacity. If nothing unexpected happens, it is successful.

Guess you like

Origin blog.csdn.net/qq_35858902/article/details/128766317