1. # Ramdisk creation:
    • # determine the number of megabytes of the ramdisk, its location and its mount point:
      export RAMDISKSIZE=128000
      export RAMDISK=/dev/ram
      export RAMMOUNTPOINT=/mnt/ram
    • # create the ramdisk (using dd makes sure it does not have holes):
      sudo dd if=/dev/zero of=$RAMDISK bs=1k count=$RAMDISKSIZE
    • # initialize the ramdisk with a filesystem:
      sudo mke2fs -vm0 $RAMDISK $RAMDISKSIZE
    • # activate the new ramdisk:
      sudo mkdir -p $RAMMOUNTPOINT
      sudo mount $RAMDISK $RAMMOUNTPOINT
    • # change the ramdisk permissions:
      sudo chmod a+rwx /mnt/ram
  2. # Swap file creation:
    • # determine the number of megabytes of the swapfile and its location (make sure to specify a target location with enough free space to accomodate the swap file!! Creating a swap file on the root filesystem is not recommended...):
      export SWAPSIZE=512
      export SWAPFILE=/var/run/swapfile.$SWAPSIZE
    • # create the swap file (using dd makes sure the swap file does not have holes):
      sudo dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPSIZE && sync && sync
    • # initialize the swap file:
      sudo mkswap -c $SWAPFILE
    • # check the current swap settings:
      cat /proc/swaps
    • # activate the new swap space:
      sudo swapon $SWAPFILE
    • # compare the new swap settings with the previous ones:
      cat /proc/swaps
    • # if you wish to use this swap file permanently, you should add it to the /etc/fstab:
      echo $SWAPFILE swap swap default 0 0|sudo bash -c "cat >> /etc/fstab"