Skip to main content

CentOS: Create Swap Partition

One of my CentOS 7 Core hosts on CloudCone has only 256MB of memory. Here's my note while enable swap partition for it.

[tuyendq@1 ~]$ free 
              total        used        free      shared  buff/cache   available
Mem:         237244       76768       44640       12780      115836      127416
Swap:             0           0           0
[tuyendq@1 ~]$ 
[tuyendq@1 ~]$ sudo dd if=/dev/zero of=/swap count=2049 bs=1MiB
[sudo] password for tuyendq: 
2049+0 records in
2049+0 records out
2148532224 bytes (2.1 GB) copied, 14.3186 s, 150 MB/s
[tuyendq@1 ~]$ 
[tuyendq@1 ~]$ sudo chmod 600 /swap 
[tuyendq@1 ~]$ which mkswap
/usr/sbin/mkswap
[tuyendq@1 ~]$ sudo mkswap /swap 
Setting up swapspace version 1, size = 2098172 KiB
no label, UUID=0cea54e6-42d4-49c9-8f9b-f30e62582acf
[tuyendq@1 ~]$ 
[tuyendq@1 ~]$ sudo swapon /swap
[tuyendq@1 ~]$ free
              total        used        free      shared  buff/cache   available
Mem:         237244       78120        7140       12780      151984      126116
Swap:       2098172           0     2098172
[tuyendq@1 ~]$ 
[tuyendq@1 ~]$ cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Jul 14 18:58:05 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/vda1 /                       ext4    defaults        1 1
#/dev/vda2 swap                    swap    defaults        0 0
[tuyendq@1 ~]$ 
[tuyendq@1 ~]$ echo "/swap swap swap defaults 0 0" | sudo tee -a /etc/fstab
/swap swap swap defaults 0 0
[tuyendq@1 ~]$ cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Jul 14 18:58:05 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/vda1 /                       ext4    defaults        1 1
#/dev/vda2 swap                    swap    defaults        0 0
/swap swap swap defaults 0 0
[tuyendq@1 ~]$ 

Popular posts from this blog

Powershell: Get-ChildItem

List, search/find files and directories with Get-ChildItem cmdlet.

Linux command: Check Current Shell

What is your current shell ?

Java: Free Online Courses

The Java™ Tutorials by Oracle The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails". https://docs.oracle.com/javase/tutorial/ Learn to Program in Java at edX.ogr Get started on the path to becoming a software engineer by learning core coding skills in Java—one of the most popular programming languages. https://www.edx.org/course/learn-to-program-in-java-0 Java Tutorial by javapoint.com https://www.javatpoint.com/java-tutorial Java Tutorial by SoloLearn.com I love SoloLearn because I can learn Java - and other popular programming languages - anywhere, any time on your mobile devices. https://www.sololearn.com/Course/Java/ Java on Azure https://docs.microsoft.com/en-us/learn/paths/java-on-azure/