Solve: How to add an EBS volume to a Windows EC2 instance and configure it

This post is divided in two sections. In the first section you will see how to create an EBS volume and in the next section we will show you how to configure the EBS volume in windows instance.
Create EBS Volume
  • Go to AWS Console > EC2
  • In the left panel select “Volumes” .
  • Once in the “Volume” screen select “Create Volume”
  • In the “Create Volume” window specify the size of disk and the Availability Zone  in which you want the disk to be created.
Tip:- The disk should be in same AZ as your EC2 instance.
  • Now in the left pane again select the “Volume” to see all your volumes.
  • Select the volume you just created and after that in the upper menu click on “Actions” and select “Attach volume”
  • In “Attach volume” window select the instance to which you want to attach the volume and click on “Attach”.

Configure EBS volume in Windows
  • Login to your windows EC2 instance using RDP. Once inside the instance, from the Start menu go to  “Computer Management” as mentioned below.
Start > Control Panel > System and Security > Administrative Tools > Computer Management
  • Click on Disk Management on the left pane.
  • Here we can see the new disk but it’s still offline. Right click on the new disk and select “Online”.
  • Once the disk is online right click again on the disk and select “Initialize Disk”.

  • If disk is below 2TB, select MBR and click OK
  • Finally right click on the pane where size is shown(refer image below). Select “New Simple Volume”
  • Leave other options as default and click “Next” till you come to “Assign Drive Letter or Path”.  Here we have assigned the drive letter E .
  • Leave everything else as default in next windows and click on finish.
  • Now if we go to “This PC/ My computer” we should see the new disk.


So here we have attached an EBS volume to the Windows EC2 instance. Do let us know in comments section if you have any query.





How to sell other state car in India

When I planned to move from Gurgaon to Pune I was in dilemma over whether to sell my Gurgaon registered car in Gurgaon or take it with me to Pune.
Since the new company I was joining was paying for relocation so car shifting cost was not an issue.

Solved: How to extend or grow a linux filesystem under LVM

In this post we will see how to grow a Linux filesystem without reboot.
  • Let's check our current filesystem. We want to extend this filesystem by 200MB.
[root@cloudvedas CVFS1]# df -h /CVFS1
Filesystem                  Size Used Avail Use% Mounted on
/dev/mapper/cvsvg-cldvdsvol1 47M 12M    32M  26%   /CVFS1
[root@cloudvedas CVFS1]#
  • First check if we have free space in VG
[root@cloudvedas /]# vgs
 VG    #PV    #LV    #SN    Attr    VSize    VFree
 cvsvg  1      1      0      wz--n- 196.00m  144.00m
 rhel   1      3      0      wz--n- 7.51g    36.00m
[root@cloudvedas /]#
  • Since we don't have 200MB free in "cvsvg" so we will add a new disk to it. First label the disk for LVM and get it under LVM control using pvcreate.
[root@cloudvedas CVFS1]# pvcreate /dev/sdb2
 Physical volume "/dev/sdb2" successfully created
[root@cloudvedas CVFS1]#
  • Add the new partition to our VG.
[root@cloudvedas CVFS1]# vgextend cvsvg /dev/sdb2
 Volume group "cvsvg" successfully extended
[root@cloudvedas CVFS1]#
  • Check the VG size again.
[root@cloudvedas CVFS1]# vgs
 VG    #PV   #LV    #SN    Attr    VSize    VFree
 cvsvg  2     1      0     wz--n-  444.00m  392.00m
 rhel   1     3      0     wz--n-  7.51g    36.00m
[root@cloudvedas CVFS1]#
  • Now we have the required space so, let's extend the volume first.
[root@cloudvedas CVFS1]# lvextend -L +200M /dev/cvsvg/cldvdsvol1
 Size of logical volume cvsvg/cldvdsvol1 changed from 52.00 MiB (13 extents) to 252.00 MiB (63 extents).
 Logical volume cldvdsvol1 successfully resized
  • On checking the LV we can see it's now extended as is now of 252MB.
[root@cloudvedas CVFS1]# lvs
 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
 cldvdsvol1 cvsvg -wi-ao---- 252.00m
 root rhel -wi-ao---- 6.67g
 swap rhel -wi-ao---- 820.00m
 testvol1 rhel -wi-a----- 4.00m
[root@cloudvedas CVFS1]#
  • Let's increase the filesystem now using resize2fs.
[root@cloudvedas CVFS1]# resize2fs /dev/cvsvg/cldvdsvol1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/cvsvg/cldvdsvol1 is mounted on /CVFS1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/cvsvg/cldvdsvol1 is now 258048 blocks long.
  • Check the file system now.
[root@cloudvedas CVFS1]# df -h /CVFS1
Filesystem                   Size Used Avail Use% Mounted on
/dev/mapper/cvsvg-cldvdsvol1 241M  13M  217M  6%   /CVFS1
[root@cloudvedas CVFS1]#
Great so we have now extended the filesystem.

Solved: How to label a disk in Linux

In this post we will see how to label a new disk in Linux and create a new LVM partition.
Step 1 Scan the new LUNS.
Step 2 List the available disks and identify the one you want to use.
  fdisk -l |grep /dev/ |grep -v dm
Step 3 Use fdisk to label the disk. Here we are using disk sdb .
[root@cloudvedas scsi_host]# fdisk /dev/sdb
 Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.

Device does not contain a recognized partition table
 Building a new DOS disklabel with disk identifier 0x909f2c7b.

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
 Disk label type: dos
 Disk identifier: 0x909f2c7b

Device Boot Start End Blocks Id System

Command (m for help):
Step 4 Create Primary partition using option "n" of size 200MB.
Command (m for help): n
 Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
 Select (default p): p
 Partition number (1-4, default 1):
 First sector (2048-2097151, default 2048):
 Using default value 2048
 Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +200M
 Partition 1 of type Linux and of size 200 MiB is set
(Don't miss the + used before 200M. It's very critical else it won't work as expected)
Step 4 Now let's check our new partition
Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
 Disk label type: dos
 Disk identifier: 0xc1c8c781

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 83 Linux

Command (m for help):
Step 5 In the above output we can see that the new partition is a standard linux partition.  Let's Change the partition type to Linux LVM. Here we will use "8e" which is a Hex code for LVM. You can type L to list all codes.
Command (m for help): t
 Selected partition 1
 Hex code (type L to list all codes): 8e

-Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
 Disk label type: dos
 Disk identifier: 0xc1c8c781

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 8e Linux LVM

Command (m for help):
Step 6 Finally save the changes with option "w"
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Step 7 Let's list the partition table to cross check that our partition table is saved correctly.
[root@cloudvedas /]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
 Disk label type: dos
 Disk identifier: 0x0aa5ab95

Device Boot Start End Blocks Id System
 /dev/sdb1 2048 411647 204800 8e Linux LVM
 [root@cloudvedas /]#
Cool! So, we have now a LVM partition which we can bring under LVM control using pvcreate.

LVM Crash course

In this post we will give you a crash course on Linux LVM (Logical Volume Manager). This post will cover the most used LVM commands in a Linux Admin life.
Before we start first let's go through the concepts.
Physical Volumes (PVs): Storage devices (physical hard disks, partitions, RAID arrays etc.) provides raw storage
Volume Groups (VGs): Combine multiple PVs to create a group. They can be mirror or concatenation of PVs.
Logical Volumes (LVs): Create smaller volumes from the Volume Group(VG) as per your size requirement. You can can use the LVs to create filesystem on them.
Below commands are for RHEL 7.
All the below commands will require root access. You can either run them with sudo  or switch to root user as mentioned below.
sudo su -
Install LVM
[root@cloudvedas ~]# yum install lvm2*
Check LVM version
[root@cloudvedas ~]# lvm version
Label the new disk and bring it under LVM using pvcreate
Create PV (Physical Volume)
[root@cloudvedas ~]# pvcreate /dev/sdb1
Show PV
[root@cloudvedas ~]# pvs /dev/sdb1
Create VG (Volume Group)
[root@cloudvedas ~]# vgcreate cvsvg /dev/sdb1
Show VG
[root@cloudvedas ~]# vgs cvsvg
Display VG
[root@cloudvedas ~]# vgdisplay cvsvg
Extend VG
[root@cloudvedas ~]# vgextend cvsvg /dev/sdb2
Create LV (Logical Volume)
[root@cloudvedas ~]# lvcreate -L 500M cvsvg -n cldvdsvol1
Display LV 
[root@cloudvedas ~]# lvdisplay /dev/cvsvg/cldvdsvol1
Create mirror volume
 lvcreate -L 100M -m1 -n cvmirrorvol1 cvsvg
Create striped volume
[root@cloudvedas ~]# lvcreate -L 50M -i 3 -I 64 -n stripevol cvsvg
Here
-i|--stripes (Number of disks in stripe)
-I|Stripe size
Extend LV
lvextend -L +20M /dev/cvsvg/stripevol
De-activate volume
lvchange -an /dev/cvsvg/stripevol
Activate volume
lvchange -ay /dev/cvsvg/stripevol
Remove LV
Ensure filesystem is unmounted before running this
lvremove /dev/cvsvg/stripevol
Create filesystem
mkfs -t ext4 /dev/cvsvg/cldvdsvol1
Create directory
mkdir /CVFS1
Mount filesystem
mount /dev/cvsvg/cldvdsvol1  /CVFS1
All the available LVM commands
[root@cloudvedas ~]# lvm help
 Available lvm commands:
 Use 'lvm help <command>' for more information

devtypes Display recognised built-in block device types
 dumpconfig Dump configuration
 formats List available metadata formats
 help Display help for commands
 lvchange Change the attributes of logical volume(s)
 lvconvert Change logical volume layout
 lvcreate Create a logical volume
 lvdisplay Display information about a logical volume
 lvextend Add space to a logical volume
 lvmchange With the device mapper, this is obsolete and does nothing.
 lvmdiskscan List devices that may be used as physical volumes
 lvmsadc Collect activity data
 lvmsar Create activity report
 lvreduce Reduce the size of a logical volume
 lvremove Remove logical volume(s) from the system
 lvrename Rename a logical volume
 lvresize Resize a logical volume
 lvs Display information about logical volumes
 lvscan List all logical volumes in all volume groups
 pvchange Change attributes of physical volume(s)
 pvresize Resize physical volume(s)
 pvck Check the consistency of physical volume(s)
 pvcreate Initialize physical volume(s) for use by LVM
 pvdata Display the on-disk metadata for physical volume(s)
 pvdisplay Display various attributes of physical volume(s)
 pvmove Move extents from one physical volume to another
 pvremove Remove LVM label(s) from physical volume(s)
 pvs Display information about physical volumes
 pvscan List all physical volumes
 segtypes List available segment types
 tags List tags defined on this host
 vgcfgbackup Backup volume group configuration(s)
 vgcfgrestore Restore volume group configuration
 vgchange Change volume group attributes
 vgck Check the consistency of volume group(s)
 vgconvert Change volume group metadata format
 vgcreate Create a volume group
 vgdisplay Display volume group information
 vgexport Unregister volume group(s) from the system
 vgextend Add physical volumes to a volume group
 vgimport Register exported volume group with system
 vgmerge Merge volume groups
 vgmknodes Create the special files for volume group devices in /dev
 vgreduce Remove physical volume(s) from a volume group
 vgremove Remove volume group(s)
 vgrename Rename a volume group
 vgs Display information about volume groups
 vgscan Search for all volume groups
 vgsplit Move physical volumes into a new or existing volume group
 version Display software and driver version information
[root@cloudvedas ~]#