• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

volume

Encrypt Volume via Terraform

April 9, 2019

Here’s the Terraform script to encrypt an unencrypted volume. It creates a snapshot, encrypts a snapshot, and encrypts the volume.

#
# Set Variables
#
variable "volume" {
  description = "The Volume to encrypt: vol-12345678901234567"
}
variable "region" {
  description = "The Region: us-east-2"
}
variable "az" {
  description = "The AZ: us-east-2a"
}
 
#
# Set Credentials
#
provider "aws" {
	access_key = "put-your-access-key-here"
	secret_key = "put-your-secret-key-here"
	region = "${var.region}"
}
 
/*
#
# Create Unencrypted Volume
#
resource "aws_ebs_volume" "unencrypted_volume" {
  availability_zone = "${var.az}"
  size              = 10
  tags = {
    Name = "Unencrypted_Volume"
  }
}
*/
 
#
# Create Unencrypted Snapshot
#
resource "aws_ebs_snapshot" "unencrypted_snapshot" {
  #volume_id = "${aws_ebs_volume.unencrypted_volume.id}"
  volume_id = "${var.volume}"
  tags = {
    Name = "Unencrypted_Snapshot"
  }
}
 
#
# Create Encrypted Snapshot
#
resource "aws_ebs_snapshot_copy" "encrypted_snapshot" {
  source_snapshot_id = "${aws_ebs_snapshot.unencrypted_snapshot.id}"
  source_region      = "${var.region}"
  encrypted = true
  tags = {
    Name = "Encrypted_Snapshot"
  }
}
 
#
# Created Encrypted Volume
#
resource "aws_ebs_volume" "encrypted_volume" {
  availability_zone = "${var.az}"
  snapshot_id = "${aws_ebs_snapshot_copy.encrypted_snapshot.id}"
  tags = {
    Name = "Encrypted_Volume"
  }
}

# # Set Variables # variable "volume" { description = "The Volume to encrypt: vol-12345678901234567" } variable "region" { description = "The Region: us-east-2" } variable "az" { description = "The AZ: us-east-2a" } # # Set Credentials # provider "aws" { access_key = "put-your-access-key-here" secret_key = "put-your-secret-key-here" region = "${var.region}" } /* # # Create Unencrypted Volume # resource "aws_ebs_volume" "unencrypted_volume" { availability_zone = "${var.az}" size = 10 tags = { Name = "Unencrypted_Volume" } } */ # # Create Unencrypted Snapshot # resource "aws_ebs_snapshot" "unencrypted_snapshot" { #volume_id = "${aws_ebs_volume.unencrypted_volume.id}" volume_id = "${var.volume}" tags = { Name = "Unencrypted_Snapshot" } } # # Create Encrypted Snapshot # resource "aws_ebs_snapshot_copy" "encrypted_snapshot" { source_snapshot_id = "${aws_ebs_snapshot.unencrypted_snapshot.id}" source_region = "${var.region}" encrypted = true tags = { Name = "Encrypted_Snapshot" } } # # Created Encrypted Volume # resource "aws_ebs_volume" "encrypted_volume" { availability_zone = "${var.az}" snapshot_id = "${aws_ebs_snapshot_copy.encrypted_snapshot.id}" tags = { Name = "Encrypted_Volume" } }

Filed Under: Linux Tagged With: encrypt, snapshot, terraform, volume

LVM Extend Physical Volume

March 14, 2019

The following are instructions on how to extend a disk volume with LVM.

# aws cli extend volume
aws ec2 modify-volume --region us-east-1 \
--volume-id vol-xxxxxxxxxxxx --size 15 \
--volume-type gp2
# check volumes before
lsblk
# extend via growpart
growpart /dev/xvdf 1
# check volumes after
lsblk
# resize physical volume
pvresize /dev/xvdf1
# check physical volume
pvscan
# extend logical volume
lvresize -l +100%FREE /dev/data/data
# check logical volume
lvscan
# check mounts
df -Th
# resize file system
resize2fs /dev/data/data
# or
xfs_growfs /dev/mapper/root
xfs_growfs /dev/xvda1
# check mounts again for new size
df -Th

# aws cli extend volume aws ec2 modify-volume --region us-east-1 \ --volume-id vol-xxxxxxxxxxxx --size 15 \ --volume-type gp2 # check volumes before lsblk # extend via growpart growpart /dev/xvdf 1 # check volumes after lsblk # resize physical volume pvresize /dev/xvdf1 # check physical volume pvscan # extend logical volume lvresize -l +100%FREE /dev/data/data # check logical volume lvscan # check mounts df -Th # resize file system resize2fs /dev/data/data # or xfs_growfs /dev/mapper/root xfs_growfs /dev/xvda1 # check mounts again for new size df -Th

Filed Under: Cloud, Linux Tagged With: disk, extend, lvm, physical, volume

Extend LVM volume

January 28, 2019

Extending a LVM logical volume can be tricky. Extending a physical volume especially a boot drive is even more challenging. To make things simple, you can just easily add a new physical disk to your physical volume group. Here are the steps:

# add disk to your instance. 
fdisk /dev/sdh
pvcreate /dev/sdh1
vgextend system /dev/sdh1
lvextend -l +100%FREE /dev/system/opt
resize2fs /dev/system/opt

# add disk to your instance. fdisk /dev/sdh pvcreate /dev/sdh1 vgextend system /dev/sdh1 lvextend -l +100%FREE /dev/system/opt resize2fs /dev/system/opt

The fdisk command requires a few steps inside such as creating a new partition, changing the partition to type to “8e” which is Linux LVM, and then writing your changes to disk.

The rest are pretty much self explanatory. It’s about creating a physical volume, extending the volume group, extending the logical volume, and then finally resizing the file system.

Filed Under: Cloud Tagged With: extend, lvm, volume

Extend an EBS Volume

March 5, 2018

As a Cloud Engineer, I get a few requests to extend an EBS volume. For example, the application owner wants to double the size of the /data volume from 10GB to 20GB. The nice part about extending an EBS volume is that it can all be done on the fly without bringing down the instance. Adding more storage can be done via the AWS Console. Check out this article from AWS about modifying an EBS volume. But that’s just the first part. Although you’ve doubled the disk space, you still have to let the system know it now has doubled it’s disk space. The second part is to grow or resize the file system. Here’s the other article on how to extend a file system.

# expand
growpart /dev/xvdb
# for ext2, ext3 and ext4
resize2fs /dev/xvdb
# for xfs
xfs_growfs -d /dev/xvdb

# expand growpart /dev/xvdb # for ext2, ext3 and ext4 resize2fs /dev/xvdb # for xfs xfs_growfs -d /dev/xvdb

Filed Under: Cloud Tagged With: ebs, extend, volume

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Home
  • About
  • Archives

Copyright © 2023