Jan 7, 2014

Ubuntu Lesson 03 - Add Swap space

The initial swap space of my Ubuntu is only 256 MB (with 4 GB RAM) so that the system frequently halts for tens seconds. To increase the size of virtual RAM for system performance and stability, you should increase your SWAP space.
The Swap size if 256.0 MB, checked after reboot.

Check the usage of file system: Add 5 GB swap space into /host is fine.
nas@ubuntu:~$ df
df: `/root/.gvfs': Permission denied
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/loop0      29496487  5774562  23721925  20% /
udev             1964448        4   1964444   1% /dev
tmpfs             789556      996    788560   1% /run
none                5120        0      5120   0% /run/lock
none             1973884    13416   1960468   1% /run/shm
/dev/sda3       61437948 12790320  48647628  21% /host
Check if any swap files have been enabled:
nas@ubuntu:~$ sudo swapon -s
[sudo] password for nas: 
Filename Type Size Used Priority
/host/ubuntu/disks/swap.disk            file 262140 119288 -1

Remove the small swap space.
nas@ubuntu:~$ sudo swapoff /host/ubuntu/disks/swap.disk
nas@ubuntu:~$ sudo rm /host/ubuntu/disks/swap.disk
Original swap file: swap.disk (path & size)

Swap.disk was removed

Create the 5 GB swap file: dd(dd --help to see the detail), if(inupt file=null file) of(output file=filename), bs(block size=1 KB), count(5M KB = 5 GB)
nas@ubuntu:~$ sudo dd if=/dev/zero of=/host/swapfile bs=1024 count=5000000
5000000+0 records in
5000000+0 records out
5120000000 bytes (5.1 GB) copied, 417.217 s, 12.3 MB/s
The speed of create swap space is very slow!
Initial /host: no swapfile

After 10 seconds, /host/swapfile grow to 280 MB only.
Create a linux swap area:
nas@ubuntu:~$ sudo mkswap /host/swapfile
Setting up swapspace version 1, size = 4999996 KiB
no label, UUID=fb7416cc-3889-4f0e-bdee-82fa723fb0be
Activate the swap file and check again after done:
nas@ubuntu:~$ sudo swapon /host/swapfile
nas@ubuntu:~$ swapon -s
Filename Type Size Used Priority
/host/swapfile                          file 4999996 0 -1
Make sure that the swap is permanent in the fstab file.
/swapfile       none    swap    sw      0       0 
  • Run command: sudo gedit /etc/fstab
  • Comment line #2 (old swap was removed) and add line #3 (add new swap)
  • Save & Exit

After reboot, you will see the swap increased to 4.8 GB.



No comments :

Post a Comment