How to attach and mount EBS volume into EC2 Instance Ubuntu 10.10

ec2 ebs amazon

Updated!
Before you do this, backup all /var into /var-backup by sudo rsync -avr /var/* /var-backup/
After mounting EBS, you can rsync restore /var by sudo rsync -avr /var-backup/* /var/

Using EBS volume can decrease risk of server crash suddenly or "permission denied" problem in EC2 server. The logic, after we create instance store, we create new EBS volume which we can set the capacity as we need. In this cases, i create 60GB EBS and will using it as /var in instance store. Now, let configure our EC2 and using EBS as indepent storage.

1. Create EBS Volume and attach it into instance store in EC2 panel management. Use same region, ex : east-1b
2. Login into instance store SSH.
3. In my configuration, EBS Volume located in /dev/sdg. So remember what yours.

4. Use sudo fdisk -l to see if your EBS already attached

Disk /dev/sdg: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

5. Formating EBS Volume so we can use it by sudo mkfs -t ext4 /dev/sdg and you will get result :

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3932160 inodes, 15728640 blocks
786432 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
480 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424

This will takes a long time, like 10-30 minutes.

6. Edit /etc/fstab and add this :
/dev/sdg        /var    auto    defaults,nobootwait,noatime     0       0

and reboot from EC2 panel management. Now, you use EBS for all installed program and www.

Tags:



You should follow me here

Comments

In most of the tutorial /dev/sdg is used, but in step 5 /dev/sdf is used (sudo mkfs -t ext4 /dev/sdf). I think this is supposed to be /dev/sdg

Great Andrew, you're right! My fault. Now already edited. Thanks :)

Does this remap the existing /var directory to the EBS volume? If so, what happens to all the data that was currently in the /var directory? Isn't that required to start many of the services?

Yes, you're right. Before doing this, please backup your /var into some folder. Later, after EBS mounted and pointed into /var, you can synchronize with your backup.

This article already updated based on your comment. Thanks!

while i am entering in my server to format my custom amazon volume it shows like this

ubuntu@ip-10-204-43-33:~$ sudo mkfs -t ext4 /dev/sdn
mke2fs 1.41.11 (14-Mar-2010)
/dev/sdn is entire device, not just one partition!
Proceed anyway? (y,n)

it shows like /dev/sdn is entire partiotion so what s wrong with this? what i have to do?
Is it cause any problem?

as well as look down for my fdisk -l and give your suggestion plz

Disk /dev/sdn: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdn doesn't contain a valid partition table

DO NOT DO THIS!!!! I've followed this guy instructions and now my instance is not accessible anymore. Man, you've ruined my a day: you should be more careful and test those things

Make sure you following all my guide.
In case you got problem, your instance should be accessible.

I have tried this into my server and there no problem.

Just as a side note, if you have an EC2 instance that won't boot because of a misconfigured file (I messed up my fstab just yesterday in attempting to get EBS volumes to automatically mount on my instance), you can unmount the ebs from the ec2 instance, spin up another ec2 to which you can attach the drive from your dead instance, fix the config, and the reattach the drive to your old ec2 instance, saving the machine.

Here's a better description (the jan. 7 response):

https://forums.aws.amazon.com/thread.jspa?threadID=82730

Thanks John!

Great , everything worked. i just have one problem which is that the cron does not work. it's running but does not do anything, any hints?

Cron should works by default. Please double check your cron syntax.

Everything worked fine, except that cron does not run anymore. even if the crond service is started, it does not execute any task after this. any hints?

Add new comment