Next let's take a look at how to add and delete swap partitions in linux vps. I will use the Xen VPS to create swap partitions.
Root permission is required for all operations
1. Create a swap Partition
First, use fdisk-l to view hard disk partitions.
The Code is as follows: |
Copy code |
Fdisk-l DefaultDisk/dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065*512 = 8225280 bytes Sector size (logical/physical): 512 bytes/512 bytes I/O size (minimum/optimal): 512 bytes/512 bytes Disk identifier: 0x00097743 Device Boot Start End Blocks Id System /Dev/sda1*1 2481 19922944 83 Linux |
There is only one partition.
Create a new partition for swap switching.
The Code is as follows: |
Copy code |
Fdisk/dev/sda
[Root @ itnmg ~] # Fdisk/dev/sda WARNING: DOS-compatible mode is deprecated. It's stronugly recommended Switch off the mode (command 'C') and change display units Sectors (command 'U '). Command (m for help): m Command action A toggle a bootable flag B edit bsd disklabel C toggle the dos compatibility flag D delete a partition L list known partition types M print this menu displays the Help menu N add a new partition create a partition O create a new empty DOS partition table P print the partition table shows the partition table Q quit without saving changes does not save and exits S create a new empty Sun disklabel T change a partition's system id to change the partition type U change display/entry units V verify the partition table W write table to disk and exit save and exit X extra functionality (experts only) Command (m for help ): |
What we commonly use is the ones marked in Chinese.
Enter n to create a new partition.
The Code is as follows: |
Copy code |
DefaultCommand (m for help): n Command action E extended P primary partition (1-4) |
Select create extended partition or primary partition. Here we select primary partition and enter p
The Code is as follows: |
Copy code |
Defaultp Partition number (1-4 ): |
Enter the Partition Number, 1-4. Because sda1 is available, enter 2
The Code is as follows: |
Copy code |
DefaultPartition number (1-4): 2 First cylinder (2498-2610, default 2498 ): |
Enter the start position. Do not change it here. Press enter.
The Code is as follows: |
Copy code |
DefaultUsing default value 2498 Last cylinder, + cylinders or + size {K, M, G} (2498-2610, default 2610 ): |
Input + 200 M, set to M.
At this time, there is no reverse return information. Enter p to view the partition information.
The Code is as follows: |
Copy code |
Default Device Boot Start End Blocks Id System /Dev/sda1*1 2497 20056128 83 Linux /Dev/sda2 2498 2523 208845 83 Linux |
A new partition has been created. Enter w to save and exit. After exiting, the partition will be reloaded.
Create a swap on the newly created Partition
The Code is as follows: |
Copy code |
Mkswap/dev/sda2 Swapon- |
Set the system to enable the swap file, edit the/etc/fstab file, and add the following content:
The Code is as follows: |
Copy code |
/Dev/sda2 swap defaults 0 0 |
Free-m view results
2. Delete swap partitions
Disable swap Partition
The Code is as follows: |
Copy code |
Swapoff-
|
Delete A swap Partition
The Code is as follows: |
Copy code |
Fdisk/dev/sda |
This operation is similar to the operation when adding a partition. You just need to delete the partition and enter d.
The Code is as follows: |
Copy code |
Partition number (1-4 ): |
Enter the Partition Number to delete, 2
Enter p to view the partition information. The partition has been deleted.
Enter w to save and exit.
Modify the/etc/fstab file and delete/dev/sda2 swap defaults 0 0 save
Note:
Install the VPS of the linux operating system and add swap partitions (only VPS using Xen virtual technology is supported. Currently, OpenVZ does not support adding swap ).