Increase swap size

Question:
I have an old Fedora installation on my system. I have just upgraded my RAM from 256 to 512 MB. My swap partition is also of 512 MB. Is there any way by which I can increase my swap space to 1 GB without formatting and reinstalling my OS.

Answer:
Sure you can increase the size of swap without reinstalling the OS. This can be done by either adding a new
swap partition or creating a swap file, instead. Here, I will discuss the steps to add a new swap file to increase the swap size as this is possible even if you do not have free unpartitioned space in your hard disk for creating new partitions, but have free space on one of your partitions. To make a swap file of 1 GB,
multiply 1024 MB and 1024 to get a block size. Now, at a shell prompt, as the root user, type the following
command with the count being equalto the desired block size:

dd if=/dev/zero of=/swapfile bs=1024 count=1048576

Now set up the swap file:

mkswap /swapfile

Enable the swap file after creating it by using the following command:

swapon /swapfile

Add the following entry in the the /etc/fstab file to make the system activate this file as swap while booting
the system:

/swapfile swap swap defaults 0 0

This will enable your 1 GB swap space, every time your system boots. You can check the size of swap by
using the free command or by cat /proc/swap.

function configure_zram_parameters() { if [ $chp_supported -eq 1 ]; then configure_chp_zram_parameters return fi echo $comp_algorithm > /sys/block/zram0/comp_algorithm if [ -f /sys/block/zram0/disksize ]; then if [ -f /sys/block/zram0/use_dedup ]; then echo 1 > /sys/block/zram0/use_dedup fi if [ $swap_size_mb -gt 0 ]; then echo "swap_size_mb was already defined" elif [ $mem_total -le 524288 ]; then #config 384MB zramsize with ramsize 512MB swap_size_mb=384 elif [ $mem_total -le 1048576 ]; then #config 768MB zramsize with ramsize 1GB swap_size_mb=768 elif [ $mem_total -le 2097152 ]; then #config 1GB+256MB zramsize with ramsize 2GB swap_size_mb=1280 elif [ $mem_total -le 3145728 ]; then #config 1GB+512MB zramsize with ramsize 3GB swap_size_mb=1536 elif [ $mem_total -le 4194304 ]; then #config 2GB+512MB zramsize with ramsize 4GB swap_size_mb=2560 elif [ $mem_total -le 6291456 ]; then #config 3GB zramsize with ramsize 6GB swap_size_mb=3072 elif [ $mem_total -le 12582912 ]; then #config 5GB zramsize with ramsize 8GB and 12GB swap_size_mb=5120 else #config 7GB zramsize with ramsize 16GB or larger devices swap_size_mb=7680 fi zram_increase=$nandswap_sz_mb #0 if [ $zram_increase -gt $zram_increase_limit ]; then zram_increase=$zram_increase_limit fi if [[ "$fn_enable" == "false" || $hybridswap_has_insmod -eq 0 ]]; then zram_increase=0 fi disksize=$(expr $swap_size_mb \+ $zram_increase) echo "$disksize""M" > /sys/block/zram0/disksize fi if [ -f /dev/memcg/memory.zram_used_limit_mb ]; then echo $zram0_limit_size > /dev/memcg/memory.zram_used_limit_mb fi if [ $hybridswap_has_insmod -eq 1 ]; then configure_hybridswap_parameters fi }
最新发布
08-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值