AWS persistent storage
From Bashlinux
Setup the work environment
Before start ensure you have the latest EC2 API tools installed on system. Download the latest EC2 API from Amazon EC2 API Tools and follow the instructions in Building an AMI to install or replace the current API.
Error creating thumbnail: File missing
|
Warning Older releases of EC2 API cannot handle persistent volume commands. |
Working with volumes
How to create a volume
- Look for available zones
# ec2-describe-availability-zones AVAILABILITYZONE us-east-1a available AVAILABILITYZONE us-east-1b available AVAILABILITYZONE us-east-1c available
- Create a volume, the -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
- Check the volume status
# ec2-describe-volumes VOLUME vol-cd2dc8a4 128 us-east-1a available 2008-08-29T01:07:22+0000
How to attach a volume to an instance
- 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
- 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
- Login into the instance
# ssh -i .ssh/bashlinux-general-server-keypair [email protected]
- 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.
- Mount the new partitioned drive
[root@ec2 ~]# mkdir -p /mnt/storage [root@ec2 ~]# mount /dev/sdb /mnt/storage
- 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
How to remove a volume
- Login into the instance
# ssh -i .ssh/bashlinux-general-server-keypair [email protected]
- Unmount the volume
[root@ec2 log]# umount /mnt/storage
- 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
- Logout from the instance
[root@ec2 log]# exit
- 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
- Delete volume
# ec2-delete-volume vol-cd2dc8a4 VOLUME vol-cd2dc8a4
- Check deleted volume
# ec2-describe-volumes VOLUME vol-cd2dc8a4 128 us-east-1a deleting 2008-08-29T01:07:22+0000