Solve the problem that the root directory of Ubuntu has insufficient memory and cannot be turned on

My configuration environment:
VMware 16pro: 16.2.4 build-20089737
Ubuntu: 22.04.1

foreword

This problem is really vomiting blood. The disk memory has been consumed by the system files, and the disk space that you are not rich in is eaten up with the number of operations. In the end, my Ubuntu broke out in silence, opened it directly, and the graphical interface could not be started after booting.
insert image description here
Then I asked my linux teacher, and finally I was able to boot, and also helped me expand the space where the root directory is located. Thank you teacher, how can I live without you! (dog head ing)

Solve the problem of not being able to boot due to insufficient memory

reason:

In fact, my Ubuntu did not perform serious file damage (delete important system configuration files, such as files under /etc and /dev), but because the disk space allocated to the root directory is too small, after a few commands, it will be blocked. full. As a result, the GUI cannot be mounted when Ubuntu starts.

solve:

1. Start Ubuntu first
insert image description here
. 2. Press and hold "shift" on the boot interface to enter.
insert image description here
3. Enter the shell command line mode. Detailed steps
delete

Here you have entered the Recovery Menu
insert image description here
insert image description here
4. Check the disk space and delete unimportant files
Up to here, it is the same as the operation in the terminal, so I won’t repeat it here. Only after deleting some files and releasing the memory, Ubuntu will not freeze when booting.

For example, delete the firefox browser, delete the log file (log) under /var

However, this is only a temporary solution to the boot problem. To practice the operation of ubuntu, the temporary free space is not enough. In order to get it done once and for all, the key is to expand the capacity of the disk where the root directory is located .

Ubuntu root directory memory expansion method

step1, allocate external memory to the virtual machine

Because the disk space is full, it may be that the partition occupies all the memory and there is no remaining space, so the disk expansion must be performed first to increase the remaining space. After that, partition expansion can be performed.
insert image description here

Expand any directory in Ubuntu

1. First download the gparted tool to visualize the disk

 sudo apt-get install gparted

2. Start gparted

sudo gparted

You can clearly see the used space and unused space in the visual interface
insert image description here

3. Then enter the disk to check the disk partition where the root directory is located. After
insert image description here
entering the disk, you can clearly see the partition plan made when downloading ubuntu. My partition has been changed, it was not like this before.
insert image description here
insert image description here
Under normal circumstances, the expansion of the root directory is completed here, but I am not. My situation at that time was very complicated, sda2 was the system file partition, sda3 was the swap partition, and sda4 was the personal file system partition. Since the adjacent partitions are all occupied, space cannot be allocated to sda2.

Capacity expansion requirements:
1. The status of the expanded disk must be unallocated.
2. Only the space adjacent to the disk to be expanded can be expanded to sda2 where the root directory is located.

Therefore, there is a key on the right side of sda2, which cannot be expanded directly, but can only expand the adjacent space of the disk to be expanded to him, so the original swap /dev/sda3 and /dev/sda5 are deleted, and the memory space is released for sda2 . (If there is data in the disk, copy it to other places first, and then delete it.)
After deleting, repeat the expansion steps to expand the capacity normally.
After the expansion is completed, the swap partition and personal file system partition must be recreated . This is done with the help of the teacher. I am not very good at operation. I found a tutorial, which is almost like this.
How to Create a New Partition in Ubuntu

If there is an unallocated disk in the adjacent space of the root directory, just expand it directly.

Summarize:

  1. If Ubuntu is stuck after startup, you can press and hold the "shift" key to enter the shell command line mode to perform related operations during startup to find out the reason why it cannot start.
  2. There are two cases of insufficient memory. One is that there is unallocated space in the virtual machine, but the space allocated to the root directory is full. Here, you can directly perform operations related to root directory expansion; the other is that there is no space in the virtual machine. For the remaining space, you need to expand the disk first, and then expand the root directory.
  3. The expansion steps are not difficult, but there may be a series of problems (including insufficient Boot permissions, file rwx permission modification, copy file content error, etc.), if you don’t understand it, it is recommended to reinstall the Ubuntu system, and then install it The memory space of the root directory is expanded.

Reference content:

  • How to expand the root directory of Ubuntu (simple and practical version): https://blog.csdn.net/weixin_53063839/article/details/125685403
  • Ubuntu 20.04 root directory disk expansion (quick and easy):
    https://blog.csdn.net/weixin_43764974/article/details/124042351

Guess you like

Origin blog.csdn.net/weixin_52248428/article/details/127268914