Select Page

Sources:

  1. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
  2. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

 

Steps to success 🙂

  • You can either create EBS (elastic block store) volume during creation of the new EC2 instance or you can create it separately and attach later.
  • EBS volumes are managed in EC2 web GUI – in ELASTIC BLOCK STORE part
  • Here you can attach it to the running instances too.
  • Once volume is attached log in to the instance using ssh
  • New volume is now visible only in output of “lsblk” command. Output looks like this:
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda 202:0 0 40G 0 disk
    `-xvda1 202:1 0 40G 0 part /
    xvdf 202:80 0 100G 0 disk 
    • Volume xvda already has a partition xvda1 mounded as “/”
      • sudo file -s /dev/xvda

        will show something like

        /dev/xvda: DOS/MBR boot sector
      • sudo file -s /dev/xvda1

        will show something like

        /dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx, volume name "xxxxxxxx" (needs journal recovery) (extents) (large files) (huge files)
    • volume xvdf does not have any partition
      • sudo file -s /dev/xvdf

        will show raw block device:

        /dev/xvdf: data
  • You can either create new partition on this device or format disk directly. I usually create new partition just because I am used to it from “real hardware”. But you can format directly the EBS volume as AWS help suggests because it is most likely already some encapsulation anyway.
    • To create a partition use
      sudo fdisk /dev/xvdf
    • commands:
      • p (show partitions) – output will be empty:
        Disk /dev/xvdf: 100 GiB, 107374182400 bytes, 209715200 sectors
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: dos
        Disk identifier: xxxxxxxxxx
      • n (create new partition} + p (primary) + ENTER on other options
      • p (show partitions) – output will show new partition:
        Disk /dev/xvdf: 100 GiB, 107374182400 bytes, 209715200 sectors
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: dos
        Disk identifier: xxxxxxxxxx
        
        Device Boot Start End Sectors Size Id Type
        /dev/xvdf1 2048 209715199 209713152 100G 83 Linux

         

      • w (write changes to disk)
      • now “lsblk” will show new partition created but not mounted:
        NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
        xvda 202:0 0 40G 0 disk
        `-xvda1 202:1 0 40G 0 part /
        xvdf 202:80 0 100G 0 disk
        `-xvdf1 202:81 0 100G 0 part
      • “sudo file -s /dev/xvdf” now shows:
        /dev/xvdf: DOS/MBR boot sector; partition 1 : ID=0x83, start-CHS (0x0,32,33), end-CHS (0x2fe,42,44), startsector 2048, 209713152 sectors, extended partition table (last)
      • “sudo file -s /dev/xvdf1” shows:
        /dev/xvdf1: data
  • Format volume (or partition) using:
    • if you do not have a partition:
      sudo mkfs -t ext4 /dev/xvdf
    • if you created a partition:
      sudo mkfs -t ext4 /dev/xvdf1
  • make mounting point:
    sudo mkdir /mnt/pointname

    – like /mnt/data

  • mount:
    sudo mount /dev/xvdf1 /mnt/pointname
  • disk is now visible in output of “df” command
  • allow write access to all:
    sudo chmod a+w /mnt/pointname
  • check new disk UUID:
    ls -al /dev/disk/by-uuid/
    • output will look like:
      total 0
      drwxr-xr-x 2 root root 80 Aug 3 11:55 .
      drwxr-xr-x 4 root root 80 Aug 3 10:55 ..
      lrwxrwxrwx 1 root root 11 Aug 3 11:55 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -> ../../xvdf1
      lrwxrwxrwx 1 root root 11 Aug 3 10:55 zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz -> ../../xvda1
  • make backup of /etc/fstab:
    cp /etc/fstab /etc/fstab.orig
  • add disk to fstab to be automatically mounted after reboot:
    UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/mountpoint ext4 defaults,nofail 0 2