🌐 🇵🇱 Polski · 🇬🇧 EN
The system uses a SWAP partition as additional virtual memory when physical memory is insufficient or running slowly. Before the system can utilize a SWAP partition, appropriate disk space must be reserved for this specific purpose. When creating this type of partition, there are minor differences compared to the standard partitions we created previously, as we are dealing with a different partition type. Let's create a SWAP partition.
Step 1 - Use the "fdisk" tool to begin
# fdisk /dev/hdd
Step 2 - Create a new partition
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-16644, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-16644, default
16644): +2048M
When creating a partition, the default partition type ID is 83 (Linux). For a SWAP partition, the type must be changed to ID 82 (Linux Swap). If you want to see all partition type codes, use the "l" option.
Step 3 - Changing the partition type
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Step 4 - Verifying that the change was performed correctly
# Command (m for help) : p
Disk /dev/hdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x00079351
Device Boot Start End Blocks Id System
/dev/hdd1 1 262 2104483+ 82 Linux swap / Solaris
Step 5 - Exiting the "fdisk" tool and saving changes.
# Command (m for help): w
As you can see, the procedure for creating the partition itself does not change much; you just need to remember the partition type ID. Let's try to create a SWAP partition again, this time using the "parted" tool.
Step 1 - Launching the tool and selecting the disk.
# parted /dev/hdd
Step 2 - Creating the partition.
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? linux-swap
Start? 0
End? 2048m
A non-default partition type is defined, and unlike with fdisk, you don't need to create a standard partition first and then change its type; we set the correct one immediately.
Step 3 - Verifying that everything went correctly.
Model: VBOX HARDDISK (ide)
Disk /dev/hdd: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 512B 2048MB 2048MB primary
Step 4 - After exiting the parted tool, re-read the partition table
# partprobe /dev/hdd
Comments