分区Linux系统下创建Swap分区的指南(linux创建swap)

Do you need more Swap space for your Linux system? The biggest problem is, where does it come from? The ideal setup is to have an actual partition dedicated to being used as swap space.This article will guide you through creating a disk partition — a contiguous area on a physical or virtual hard disk — on a Linux-based system and converting it to a Swap area in order to increase the RAM capacity of a computer system.

Most current Linux distributions use the GNU Parted utility to partition disks. To create a partition, you’ll need to make sure that you’re running your computer as a superuser. After that, determine which disk you would like to partition and use the fdisk utility to create a partition.

Once you’ve obtained root privileges, you’ll need to identify the disk that you want to partition:

sudo fdisk -l

The output from this command will look something like this:

Disk /dev/sda: 21.5 GB, 21474836480 bytes
4 heads, 16 sectors/track, 655360 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

In this example, you can see that there’s a 21.5 GB drive which is located at /dev/sda. This is the drive that we will be partitioning.

Once you’ve identified the drive you would like to partition you can use the fdisk utility to create a partition.

sudo fdisk /dev/sda

After running this command, You’ll be presented with the fdisk prompt where you can enter commands to create or delete partitions.

You’ll now want to create a new partition. To do that, enter the “n” command which will open a new partition window.

You’ll now be asked how much space you want to allocate to your new partition. Enter the size and select the “primary” option.

Once you have created the partition, you’ll need to set it as a Swap partition. To do this, you’ll need to enter the “t” command, then select the partition number of the newly created partition. This will open a window where you’ll be asked to enter the partition type, which is “82”.

Finally, after you’ve done all the above, you’ll need to save the changes. To do this, enter the “w” command and the changes will be written to disk.

The newly created Swap partition is now ready to be used. You can enable it by running the following command:

sudo mkswap /dev/sda1

And then, turn it on with the following command:

sudo swapon /dev/sda1

Now, you’ve successfully created a new Swap partition in Linux! You can check the output of the ‘free -m’ command to make sure that the Swap space has been added, and you can modify the ‘/etc/fstab’ file to make sure that the partition is automatically enabled at every reboot.


数据运维技术 » 分区Linux系统下创建Swap分区的指南(linux创建swap)