On 09/04/17 15:58, GiaThnYgeia wrote: > A while ago while Thomas Schmitt was helping me with dd and xorriso in > backing up systems and partitions into usb and back the issue of not > having a swap partition in my system came up, since I chose not to > during the installation, and how to create one, lead me into a search of > doing just that. > > In the page > https://askubuntu.com/questions/33697/how-do-i-add-a-swap-partition-after-system-installation > there are instructions that I believe work just as well on Debian to > either create a new partition for swap or create a swap file, which I > did not know it was an option. > I chose the second as my partitioning has become complex and most of the > drive is not available during boot-up. So I assume it would run to an > error if I did this on a partition that is not available during boot. > > Below you will find the exact instructions I used and worked fine for me > on Stretch (I believe to be true for all Debian). > > But here come some questions: > 1 What is the difference functionally of having a swap partition from > having a swap file? Is it that you can use a separate physical disk > that will take the wear and tear of swaping?
A swap partition is not subject to the controls of a file system. That is, it can't get fragmented, it can be positioned at the fast (or slow) end of a disk, it can be (as you suggest) placed on a completely separate device. It can be shared between dual-booting Linux systems. A swap file does not take up potentially precious space on the partition table (for example, you can only have 4 primary partitions). > 2 Is swap size relevant to ram, should it be equal, greater, smaller? > Advantages disadvantages? I rarely see in a workstation and my/our use > anywhere close to 4GB being used, it usually maxes out around 2,5GB. No, > no killing games here, maybe some chess and gnubg. Is it that a Ram of > 1GB would benefit from 2-4GB swap space while with 16GB or Ram swap > would never be used? If you want to use suspend-to-disk hibernation, it should be at least equal to RAM (suspend-to-disk DOES use compression, but if you have a lot in RAM and a lot in swap and it doesn't compress well, equal-to-RAM tends to be the sweet spot). Otherwise, the old rule used to be 1.5×RAM. Again, equal to RAM should be plenty if you have 4GB. Swap allows the kernel to move infrequently-used pages out to disk and prioritise the fast RAM for frequently-used pages. So, even if you have 16GB of RAM, the kernel can use that for the more important stuff (disk caches for example). > > 3 chmod 600 for the swapfile. Why? 600 means that the owner of the file can read and write to the file, but no-one else can (rw-------). This improves the security of the file. > 4 Is "dd bs=1M count=4M" that defines the 4,000Mb of space/size of the > file? No, that would be 4,000,000Mb. "bs=" indicates the "block size" that dd should write and "count=" indicates the number of /those blocks/ to be written. So you're asking for four million megabytes. For 4,000Mb, you'd be best with "dd bs=1M count=4000". > > I am now going to use gnubg to test my mem capabilities. I think making > it calculate best move 4-5 moves ahead in bg or chess will stress the > system out :) > > _______________________________________________________ > > # Create an empty file (1K * 4M = 4 GiB) > sudo mkdir -v /var/cache/swap > cd /var/cache/swap > sudo dd if=/dev/zero of=swapfile bs=1K count=4M > sudo chmod 600 swapfile > > # Convert newly created file into a swap space file. > sudo mkswap swapfile > > # Enable file for paging and swapping. > sudo swapon swapfile > > # Verify by: swapon -s or top: > top -bn1 | grep -i swap > # KiB Swap: 4194300 total, 4194300 free > > # To disable, use > sudo swapoff swapfile. > > # Add it into fstab file to make it persistent on the next system > # boot. > echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a > /etc/fstab > > # Re-test swap file on startup by: > sudo swapoff swapfile > sudo swapon -va > _____________________________________________________________ > > >