Skip to content

Instantly share code, notes, and snippets.

@cavi21
Created February 11, 2011 18:59
Show Gist options
  • Select an option

  • Save cavi21/822822 to your computer and use it in GitHub Desktop.

Select an option

Save cavi21/822822 to your computer and use it in GitHub Desktop.
Crear una particion swap en los EC2 que no la tienen
# Sacado de http://support.rightscale.com/06-FAQs/FAQ_0023_-_How_can_I_create_a_swap_partition_in_EC2%3F
#!/bin/bash -e
# RightScript: Create and initialise swap file
#
# Description: Creates a swap file and actions a swapon.
#
# Author: Chris Fordham <[email protected]>
# Copyright (c) 2007-2008 by RightScale Inc., all rights reserved worldwide
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Set default variable values
: ${SWAP_SIZE_MEGABYTES:=1024}
: ${SWAP_FILE_LOCATION:=/var/swap.space}
if (( SWAP_SIZE_MEGABYTES <= 0 )); then
echo 'No swap size provided, exiting.'
exit 1
elif [ -e "$SWAP_FILE_LOCATION" ]; then
echo "$SWAP_FILE_LOCATION" already exists, skipping.
fi
if ! swapon -s | grep -qF "$SWAP_FILE_LOCATION"; then
echo Creating "$SWAP_FILE_LOCATION", "$SWAP_SIZE_MEGABYTES"MB.
dd if=/dev/zero of="$SWAP_FILE_LOCATION" bs=1024 count=$(($SWAP_SIZE_MEGABYTES*1024))
mkswap "$SWAP_FILE_LOCATION"
swapon "$SWAP_FILE_LOCATION"
echo 'Swap status:'
swapon -s
else
echo Swap "$SWAP_FILE_LOCATION" file already on.
fi
if ! grep "$SWAP_FILE_LOCATION" /etc/fstab; then
echo 'Adding swap file to fstab.'
echo "$SWAP_FILE_LOCATION swap swap defaults 0 0" >> /etc/fstab
fi
echo 'Done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment