Aws-storage

From Bashlinux
Revision as of 22:35, 14 February 2011 by Manpaz (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Persistent Storage

Prepare the work environment

Before start ensure you have the latest EC2 API tools installed on system.

Get API tools from any of the following sources Download the latest EC2 API from Amazon: [1]

And follow the instructions in [Bundling an AMI#Installing API tools] to install or replace the current API.


#!wiki warning
'''Warning'''

Older releases of EC2 API cannot handle persistent volume commands.


Create volume

  1. Look for available zones
 # ec2-describe-availability-zones
 AVAILABILITYZONE	us-east-1a	available
 AVAILABILITYZONE	us-east-1b	available
 AVAILABILITYZONE	us-east-1c	available
 
  1. Create a volume, the Template:\-s specifies the size in Gigabytes.
 # ec2-create-volume -z us-east-1a -s 549755813888
 Client.InvalidParameterValue: Volume of 549755813888GiB is too large; maximum is 1024GiB.
 # ec2-create-volume -z us-east-1a -s 128
 VOLUME	vol-cd2dc8a4	128		us-east-1a	creating	2008-08-29T01:07:22+0000
 
  1. Check the volume status
 # ec2-describe-volumes
 VOLUME	vol-cd2dc8a4	128		us-east-1a	available	2008-08-29T01:07:22+0000
 


Attach volume to an instance

  1. Get the instance name
 # ec2-describe-instances
 RESERVATION	r-9f5c9ff6	367161194499	default
 INSTANCE	i-577aae3e	ami-43ab4f2a	ec2-75-101-129-154.compute-1.amazonaws.com	domU-12-31-39-00-A2-02 .compute-1.internal	running	bashlinux-general-server-keypair	0		m1.small	2008-06-20T01:57:42+0000	us-east-1a
 
  1. Attach the volume using the instance name `i-577aae3e` obtained from the last command, note that `/dev/sdb` must not exist, in case it does, then just use another name not used yet
 # ec2-attach-volume vol-cd2dc8a4 -i i-577aae3e -d /dev/sdb
 ATTACHMENT	vol-cd2dc8a4	i-577aae3e	/dev/sdb	attaching	2008-08-29T01:18:06+0000
 
  1. Login into the instance
 # ssh -i .ssh/bashlinux-general-server-keypair [email protected]
 
  1. Format the new attached drive `/dev/sdb`
 [root@ec2 ~]# mkfs -t ext3 /dev/sdb
 mke2fs 1.39 (29-May-2006)
 /dev/sdb is entire device, not just one partition!
 Proceed anyway? (y,n) y
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 16777216 inodes, 33554432 blocks
 1677721 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=0
 1024 block groups
 32768 blocks per group, 32768 fragments per group
 16384 inodes per group
 Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872

 Writing inode tables: done
 Creating journal (32768 blocks): done
 Writing superblocks and filesystem accounting information: done

 This filesystem will be automatically checked every 38 mounts or
 180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
  1. Mount the new partitioned drive
 [root@ec2 ~]# mkdir -p /mnt/storage
 [root@ec2 ~]# mount /dev/sdb /mnt/storage
 
  1. Check new partition space
 [root@ec2 ~]# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda1             4.0G  4.0G     0 100% /
 none                  851M     0  851M   0% /dev/shm
 /dev/sda2             147G  388M  139G   1% /mnt
 /dev/sdb              126G  188M  120G   1% /mnt/storage
 


Remove volume

  1. Login into the instance
 # ssh -i .ssh/bashlinux-general-server-keypair [email protected]
 
  1. Unmount the volume
 [root@ec2 log]# umount /mnt/storage
 
  1. Check the volume was unmounted
 [root@ec2 log]# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda1             4.0G  4.0G     0 100% /
 none                  851M     0  851M   0% /dev/shm
 /dev/sda2             147G  388M  139G   1% /mnt
 
  1. Logout from the instance
 [root@ec2 log]# exit
 
  1. Detach the volume
 # ec2-detach-volume vol-cd2dc8a4 -i i-577aae3e -d /dev/sdb
 ATTACHMENT	vol-cd2dc8a4	i-577aae3e	/dev/sdb	detaching	2008-08-29T01:18:06+0000
 
  1. Delete volume
 # ec2-delete-volume vol-cd2dc8a4
 VOLUME	vol-cd2dc8a4
 
  1. Check deleted volume
 # ec2-describe-volumes
 VOLUME	vol-cd2dc8a4	128		us-east-1a	deleting	2008-08-29T01:07:22+0000