0% found this document useful (0 votes)
4 views

SWAP PARTITION

swap partition

Uploaded by

divya25715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SWAP PARTITION

swap partition

Uploaded by

divya25715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SWAP PARTITIONS

A swap partition is a designated space on a computer's hard drive (or SSD) that is used by the
operating system as virtual memory. When the physical RAM (Random Access Memory) in a
computer is fully utilized, the operating system moves inactive or less frequently used data from
RAM to the swap partition. This frees up RAM for other tasks and prevents the system from
becoming sluggish or crashing due to lack of memory

swapon Command
Use the swapon command to activate a swap partition or to show the details about an
existing one. Follow the steps below:

1. Open the terminal (Ctrl + Alt + T).

2. Run the following command:

Command:swapon –show

free Command
The free command provides information about memory usage in the system,
including virtual memory. Run the following command:

free -m

How to Create a Swap Partition


Depending on your preference, create a new partition or use the free space from an
existing partition for a swap file. To create a new partition, you can use any disk
utility, such as fdisk, gdisk, or parted.

Steps:

1. Run the fdisk command for the disk you want to partition:

sudo fdisk [disk_path]

Replace [disk_path] with your disk identifier.


SWAP PARTITIONS
2. Type p and press Enter for an overview of the disk.

The output provides information about the available disk space for a new partition. If
the last partition ends before the last sector of the hard drive, there is enough space
to create a new partition. The output above shows the entire disk space is available
for creating a new partition.

3. Type n and press Enter to create a new partition. For partition type, enter p and
press Enter.

4. Set the partition number (or keep the default number 1) and press Enter to confirm.

. Enter the first available sector for the new partition and press Enter. You can also
keep the default one offered.

6. Set the last available sector for the partition. You can specify the partition size in
KiB, MiB, or GiB units. We will create a swap partition of 1GiB, so the command is:

+1G

7. Press p to verify the partition creation and confirm with Enter.

8. By default, the partition type is 83, while 82 is a partition type identifier for swap
space.

Type t and press Enter to change the partition type. Change the value to 82 and
press Enter.

9. Verify the change with p and confirm with Enter.

10. fdisk doesn't make any changes to the disk before confirmation. To proceed
with the changes, type w, and press Enter.

12. Update the partition table using the following syntax:

sudo partprobe [disk_path]

Replace [disk_path] with your disk name.

For example, for the disk /dev/sdb, run:


SWAP PARTITIONS

sudo partprobe /dev/sdb

13. Use the mkswap command to format the partition for swap space. The command
writes a swap signature in the partition, leaving the rest unformatted. The
unformatted space stores the memory pages.

Use the following syntax to format the partition and create a swap space:

sudo mkswap [disk_path]

vim /etc/fstab
mount -a[permanent mounting applied]
dd->deleted
i->insert
esc=to come out
:wq!
step 1:- adding hard disk
step 2:- lsblk (check wether disk added or not)
step 3:- fdisk /dev/sda
n
1
default (press enter)
+3G
t (82)
w
step 4:- partprobe (to update partition table)
step 5:- lsblk

step 6 :- mkswap /dev/sda1


step 7:- swapon /dev/sda1
step 8 :- (permanent mounting)
SWAP PARTITIONS

vim /etc/fstab
go to the last line and then press i to enter into insert mode

/dev/sda1 swap swap defaults 00


:wq!

swapon //check swap partition added or not


,,
SWAP PARTITIONS

You might also like