Adding a disk to an Amazon EC2 instance

1

I am using Amazon EC2 instance where I have low disk space

[root@ip-10-59-143-73 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde1            5.7G  3.3G  2.3G  60% /
none                  1.9G     0  1.9G   0% /dev/shm

I added "Elastic Block" > Volumes > 5GB volume and attached to the instance ID.

I rebooted the instance and got a new disk device in /dev/

[root@ip-10-59-143-73 ~]# ll /dev/xvd*
brw-rw---- 1 root disk 202,  65 Jun 12 12:16 /dev/xvde1
brw-rw---- 1 root disk 202, 144 Jun 12 12:16 /dev/xvdj
brw-rw---- 1 root disk 202, 146 Jun 12 12:28 /dev/xvdj2 <<<< new one

[root@ip-10-59-143-73 ~]# cat /proc/partitions
major minor  #blocks  name

 202       65    6291456 xvde1  <<<< Old 6GB volume
 202      144  419395584 xvdj
 202      146    5242880 xvdj2  <<<< new one

[root@ip-10-59-143-73 ~]# mount
/dev/xvde1 on / type ext4 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

[root@ip-10-59-143-73 ~]# cat /etc/fstab
LABEL=_/   /         ext4    defaults        1 1
none       /proc     proc    defaults        0 0
none       /sys      sysfs   defaults        0 0
none       /dev/pts  devpts  gid=5,mode=620  0 0
none       /dev/shm  tmpfs   defaults        0 0

xvde1 was old one xvdj2 may be the new one.

How do I add the new disk to my usable disk space?

Follow up:

1) Clear the confusion: - Amazon EC2 does all automatic but adding disk space is not automated, it has to be manually (not like there Elastic IP or VPC like).

2) Feed

$ ll /dev/xvd*
brw-rw---- 1 root disk 202,  65 Jun 12 12:37 /dev/xvde1
brw-rw---- 1 root disk 202, 144 Jun 12 12:37 /dev/xvdj
brw-rw---- 1 root disk 202, 146 Jun 12 12:37 /dev/xvdj2

$ mkfs.ext4 /dev/xvdj
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
26214400 inodes, 104848896 blocks
5242444 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3200 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, 20480000, 23887872, 71663616, 78675968, 
    102400000

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

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

$ cat /etc/fstab # Before
LABEL=_/   /         ext4    defaults        1 1
none       /proc     proc    defaults        0 0
none       /sys      sysfs   defaults        0 0
none       /dev/pts  devpts  gid=5,mode=620  0 0
none       /dev/shm  tmpfs   defaults        0 0

$ cat /etc/fstab # After
LABEL=_/   /         ext4    defaults        1 1
none       /proc     proc    defaults        0 0
none       /sys      sysfs   defaults        0 0
none       /dev/pts  devpts  gid=5,mode=620  0 0
none       /dev/shm  tmpfs   defaults        0 0
/dev/xvdj   /volume_one  ext4  noatime  0 0

$ mkdir /volume_one
$ mount /volume_one
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde1            5.7G  3.3G  2.3G  60% /
none                  1.9G     0  1.9G   0% /dev/shm
/dev/xvdj             394G  199M  374G   1% /volume_one

YumYumYum

Posted 2013-06-12T16:22:26.760

Reputation: 1 399

1Is the new disk detected during boot (check your dmesg log)? Did you partition it (gpart, fdisk, ...). Did you format any of those partitions (e.g. mke2fs)? Did you add it to /etc/fstab? – Hennes – 2013-06-12T16:32:19.853

blkfront: xvdj2: barriers disabled dmesg shows this log. I just added the volume. Thinking that Amazon automagically will manage that, cause most of the extra thing when we add it automatically add (such as Elastic IP, it auto apply the changes). So for new Disk space i was expecting they do it auto. But i dont know if it has to be manually done like you explained? – YumYumYum – 2013-06-12T16:39:29.367

1You have the new disk, but you need to create volumes on it. First either 1a) partition the disk with gpart /dev/xvdj2. or 1B) decide to use the whole disk raw. 2) Format those volume(s). 3) Mount the newly formatted volume. Preferably automatically on reboot. For this edit the filesystem tables (e.g. vi /etc/fstab). – Hennes – 2013-06-12T16:47:10.207

@Hennes: Thank you please see my Follow up section. Confused why its showing 374G ? i took only 5GB disk making no sense to me. What have i done wrong???? – YumYumYum – 2013-06-12T17:05:21.363

1I do not know why it is showing 374G for xvdj. Maybe that is the total disk space which Amazon is ready to hand out to users at this location? Note that I am just guessing here. I never used an Amazon instance. My answers are from generic unix/Linux knowledge. – Hennes – 2013-06-12T17:15:25.933

OK - :) It must be Amazon BUG, cause in software its telling me 5 GiB capacity. but in Linux command line i am getting 374 G, very weird , i am wondering if they not charge me a huge bill for there own bugs. LOL – YumYumYum – 2013-06-12T19:19:12.393

Answers

-1

Instead of attaching new disks you can always increase your current volume sizes. You just need to snapshot your current disk, create a new volume with more space and then attach back to your instance using the same mount point used before.

In any case: both expanding disks or allocating new ones. Amazon has a pretty clear documentation with step-by-step instructions on how to handle it on Linux systems.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-expand-volume.html

Gus Fune

Posted 2013-06-12T16:22:26.760

Reputation: 136