Crafting and Configuring Swap with fdisk
To format using fdisk
and configure a swap partition, you'll need to follow these steps:
- Open fdisk: Start by opening
fdisk
with the disk you want to partition. For example, if you want to partition/dev/sdb
, you'd run:
sudo fdisk /dev/sdb
- Create a New Partition: Once in
fdisk
, typen
to create a new partition. - Choose Partition Type: You'll be prompted to choose the partition type. For a swap partition, you'll typically use type
82
, which is Linux swap. - Set Partition Size: Specify the size for your swap partition. This depends on your system's needs, but it's often recommended to make it at least as large as your system's RAM, especially if you plan to use hibernation.
- Write Changes and Exit: After creating the partition, type
w
to write the changes to the disk and exitfdisk
. - Format the Partition: Once the partition is created, you need to format it as a swap partition. You can do this using the
mkswap
command. For example:
sudo mkswap /dev/sdbx
Again, replace /dev/sdbx
with the actual device name of your swap partition. You can check the new swap partition using the lsblk
command. If it does not appear, try the swapon -a
command to activate the new swap partition.
- Make Swap Permanent: To ensure the swap partition is activated automatically on system boot, add an entry for it in the
/etc/fstab
file. Open/etc/fstab
in a text editor, and add a line like this:
/dev/sdbx none swap sw 0 0
Replace /dev/sdbx
with the actual device name of your swap partition.
- Verify Swap: Finally, you can verify that the swap partition is active and working correctly by using the
free
command:
free -h
- This command will display information about memory and swap usage.
That's it! You've now created and configured a swap partition using fdisk
.