Resize the swap partition to free space and reassign it to the root partition

1.Insert and boot your Ubuntu Live CD/USB

2.Mount the root partition (assuming nvme0n1p2 is your root partition):

sudo mkdir /mnt/root
sudo mount /dev/nvme0n1p2 /mnt/root

3.Edit the /etc/fstab file within the root partition:

sudo vi /mnt/root/etc/fstab

4.Comment out or delete the swap entry, then save it. e.g.:

# UUID=yourUUID none swap sw 0 0

5.Start GParted:

sudo gparted

6.Shrink swap partition nvme0n1p3:

Right-click nvme0n1p3 swap partition, choose Resize/Move.

Adjust it to the desired size (e.g., 16GB).

Click Resize/Move.

7.Expand root partition nvme0n1p2(Note: Resize operations are possible only on contiguous space.):

Right-click nvme0n1p2 root partition, choose Resize/Move.

Drag the right slider to use the space freed from the swap partition.

Click Resize/Move.

8.Mount the root partition again:

sudo mount /dev/nvme0n1p2 /mnt/root

Edit the /etc/fstab file within the root partition:

sudo vi /mnt/root/etc/fstab

modify the existing swap entry with the new UUID

9.Reboot to your normal system, not the Live CD/USB.

10.Enable the new swap partition:

sudo swapon -a

11.Check if the new swap partition is active:

sudo swapon --show

Confirm root and swap partition sizes:

df -hT

留下评论

通过 WordPress.com 设计一个这样的站点
从这里开始