ubuntu增加交换区

Process to Increase Size of Swap Partition and use it for Hibernation
Creating the swap partition
Activating the swap partition
Making the new swap partition work for hibernate (optional)
Creating the swap partition
Boot to Ubuntu install CD and choose the option to run Ubuntu now
Go to system -> GParted Partition Editor

Delete the swap partition and, if there is nothing else in it, the extended partition that holds it. (If by some miracle you’re able to resize your swap partition from here, I imagine your life will be a lot easier than mine.)
Decrease the size of your primary partition by the amount you want your new swap to be (I made mine 2x RAM + 500MB just to be safe). The easiest way to do this is to fill in the amount of space you want swap to be in the “free space following” field
In the free space that has now been created, choose new, type linux-swap and you can name the partition “swap” if you like
Hit the Apply button (should be a check mark) to write the changes to disk
When done, reboot back into Ubuntu
Activating the swap partition
(If your swap is on your primary hard drive, you don’t need to do anything here.) Now you need to find what partition your swap is on and what its UUID is. UUID?! you say? Well that’s the Universally Unique IDentifier for the partition so you can reference it even if it’s on a different mount point from boot-to-boot due to adding disks, etc.

Pull up a terminal and run gksu gparted & and enter your root password. The & lets this process run while still giving you access to the command line.

Right-click on your swap partition and choose Information. You should see the Path and UUID listed there. Keep this open for further reference.
Run gksu gedit /etc/fstab & and look for the line that has swap in it. It should be the third column, separated by spaces or tabs. You can either use the path or the UUID to tell Linux where to find your swap partition. I recommend UUID because it’ll stay constant even if you move the partition around or the disk somehow becomes sdb instead of sda or something like that. Make the appropriate edits and save the file. Your line should look something like this if you used UUID (with your UUID instead, of course):

UUID=41e86209-3802-424b-9a9d-d7683142dab7 none swap sw 0 0

or this if you used path: /dev/sda2 none swap sw 0 0

Save the file.
Enable the new swap partition with this command.

sudo swapon –all
OR

$ sudo swapon –all –verbose
swapon on /dev/sda2
swapon: /dev/sda2: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/sda2: pagesize=4096, swapsize=2147483648, devsize=2147483648
Confirm that the swap partition exists.

$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda2 partition 2097148 0 -1
Reboot to make sure the new swap gets activated properly at startup

发布于

2022-08-21

更新于

2023-08-18

许可协议

评论