10.5 Creation of Swap Space


The core program called Linux kernel reads programs and data from the hard disk into the memory area and executes them. When there is no free memory space for newly reading programs and data, the Linux kernel temporarily saves the programs and data that are not being used to the swap area. A swap partition is a partition area of a hard disk that Linux's kernel system temporarily uses instead of memory.

If you want to use the partition of the hard disk as the swap area, you need to allocate a partition corresponding to the memory size and create the swap file system in the partition.
10.5.1 Create Swap File System

Partitioning and creating file system for swap are performed, when installing, or when extending a hard disk newly.

To create a swap area (swap partition), use the mkswap command.

Format

mkswap Device_file


Create a swap file system.

Options

-c
Check the bad part and do not use it

Device_file
Device file for accessing a file system


10.5.2 Create swap space and Begin to use

If the command for start to use is executed after creating a swap space, it can be used. You can start and stop using the swap area with the swapon command.

Format

swapon -s [Device_file]


Display information on the device used as swap. Start using the swap file.

Options

-s
Display swap area you are using


Practice : Start using swap space


Create a swap area with the mkswap command. Create a swap file system on the partition where Id is 82 (for swap) with the mkswap command. Use the swapon command with the -s option to display the status of using the current swap area. Use the swapon command to start using the swap area.


# fdisk -l ↵
Display hard disk partition
Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 587 4715046 83 Linux
/dev/sda2 588 712 1004062+ 82 Linux swap / Solaris
/dev/sda3 713 783 570307+ 83 Linux
# mkswap -c /dev/sda2 ↵ Change /dev/sda2 to swap file
Setting up swapspace version 1, size = 1036378 kB
# swapon -s ↵ Show active swap area
# swapon /dev/sda2 ↵ Started using /dev/sda2 as a swap file system
# swapon -s ↵ Show active swap area
Filename Type Size Used Priority
/dev/sda2 partition 1012084 0 -4



Previous Next