Because I spent most of the day understanding this issue for myself, and because pulling up the ayurchen link requires a google cache search, I thought I would post a slightly more detailed walkthrough, extracting a very useful answer from ayurchen.
What is swap space and why use it?
The swap space is the disk space used by Linux (and most other operating systems) to store objects from memory when real physical memory begins to overflow. Since a drive is generally slower than memory, Linux first saves the least used objects in the swap and stores as much as possible in memory. It is generally recommended, if possible, to have a swap space of equal size compared to your memory. Read more about the swap area here .
Where should I install this?
Ubuntu 12.04 LTS AMI, which I also started working with, is first configured without swap space, as the size and number of your storage devices may vary. But most of them come with a large free ephemeral data storage device. Since S3 storage is limited in cost, an ephemeral disk is a good place for a page file. Mine has the same device name as in the question, /dev/xvdb
, but you can configure it during instance startup.
How do I adjust the swap space on my ephemeral disk?
Swap space can be configured in a single file or on a device partition. A file can be represented by non-contiguous blocks on disk, while a partition is a predefined set of contiguous blocks. Since reading and reading the disc is faster, you do not need to constantly move the read heads over long distances, we get better performance using the partition. (That is why the question is above discounts using the file as a workaround.)
Linux comes with many disk partition management programs, including fdisk, sfdisk, parted, etc. We will use sfdisk
because it can accept all the necessary arguments from a shell script. This is important because ephemeral storage is lost every time we βstopβ our instance. Thus, we installed the script in a file that runs automatically every time the instance starts, /etc/rc.local
.
# Unmount the drive in-case it is already mounted. Umount throws an error if
Finally, I preferred to include my installation information in /etc/fstab
, which is a Ubuntu system file that tells you how to automatically process the various available devices. It also starts at startup.
/dev/xvdb1 swap swap sw,nobootwait 0 0 /dev/xvdb2 /mnt2 ext4 defaults,nobootwait 0 0
The nobootwait parameter should ensure that Ubuntu does not freeze when booting from "The drive for / dev / xvdb (1/2) is not ready or not. Keep waiting or Press S to skip the installation or M to manually restore."
Make sure you create a folder in /mnt2
or wherever you plan to install it using mkdir.
How to debug problems that I encountered?
You can run the rc.local script with sudo /etc/rc.local
to see how it starts troubleshooting. sudo fdisk -l
should show your new partitions after startup. If this looks ok, try installing devices using sudo mount /dev/xvdb1
. This will use the configuration stored in fstab. If this fails, try playing with your settings and adjust fstab accordingly.