SlideShare a Scribd company logo
1 of 8
How to Create Custom CentOS AMI for EBS Storage
Author : Kanwar Batra
Audience : System Administrators, Architects, Technical Managers.
Relevance : This document outlines the Amazon AMI creation and Conversion to a EBS Boot device.
Prepare a Linux Host
Install a CentOS machine on a Physical , Virtual infrastructure. ( This document is based on the CentOS 6.4 Minimal Install cd)
Update the Yum repository ( Run command as )root
sudo yum -y update ;
sudo yum install -y MAKEDEV
Setup the environment with ec2 credentials . Change your root (The file start with a Dot).bashrc file with attached
Source the root bashrc
#source ~/.bashrc
Install Linux Packages below
# yum -y install e2fsprogs ruby java-1.6.0-openjdk unzip wget
Download your x509 Private Key and Certificate from the AWS Security Credentials. If none exist create new
Private Key format : pk-<Alpha Numeric String>.pem
x509 Cert format : cert-<alpha Numeric string>.pem
Copy the above certificates to /opt/ec2/certificates
cp -rf pk<Alpha Numeric String>.pem /opt/ec2/certificates/ec2-pk.pem
cp -rf cert<Alpha Numeric String>.pem /opt/ec2/certificates/ec2-cert.pem
Download the EC2 api and Ami command line utilities
wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
Unzip the downloaded tools to /opt/ec2/tools. Combine both tools in same directory ( Say no to any existing files).
cp "ec2-api-tools.zip" /opt/ec2/tools-rp
cp "ec2-ami-tools.zip" /opt/ec2/tools-rp
EC2 api and ami utilities are java base. Set JAVA_HOME if not set
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64 (Eg For Open JDK)
export JAVA_HOME=/usr/java/jdk1.7.0_25 ( for Oracle/Sun Java)
Verify Java Version
java -version
Check the ec2 regions that would determine location for image
[root@nf_lnx_ami bin]# ./ec2-describe-region
REGION eu-west-1 ec2.eu-west-1.amazonaws.com
REGION sa-east-1 ec2.sa-east-1.amazonaws.com
REGION us-east-1 ec2.us-east-1.amazonaws.com
REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
REGION us-west-2 ec2.us-west-2.amazonaws.com
REGION us-west-1 ec2.us-west-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com
REGION ap-southeast-2 ec2.ap-southeast-2.amazonaws.com
Verify the availability Zones that you can connect
ec2-describe-availability-zones --region us-east-1 ( The output should look as below)
AVAILABILITYZONE us-east-1a available us-east-1
AVAILABILITYZONE us-east-1b available us-east-1
AVAILABILITYZONE us-east-1c available us-east-1
AVAILABILITYZONE us-east-1d available us-east-1
Steps to Build the AMI
Installing the Operating System
To build the EBS Based AMI first we will create a Instance Base AMI and then after upload will convert it to EBS Storage AMI.
Start the image creation in an empty directory. (eg /opt/ec2/images)
Create an empty file using dd
dd if=/dev/zero of=/opt/ec2/images/centos-6.4-Minimal-x86_64-base.img bs=1M
count=10240
Initialize the image file with a filesystem
`mkfs.ext4 -F -j /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img
Create an empty directory and mount the initialized image file as a loopback
mount -o loop /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img /mnt/ec2-image/
Verify the image mounted using the mount command
mount
df -h | grep image
/opt/ec2/images/centos-6.4-Minimal-x86_64-base.img 9.9G 151M 9.2G 2% /mnt/ec2-image
Setup directories in the image before installing the Operating system
mkdir -p /mnt/ec2-image/{dev,etc,proc,sys}
mkdir -p /mnt/ec2-image/var/{cache,log,lock,lib/rpm}
Create minimum required devices on /dev in the image location using MAKEDEV ignore any File exists warnings .
/sbin/MAKEDEV -d /mnt/ec2-image/dev -x console
/sbin/MAKEDEV -d /mnt/ec2-image/dev -x null
/sbin/MAKEDEV -d /mnt/ec2-image/dev -x zero
/sbin/MAKEDEV -d /mnt/ec2-image/dev -x urandom
Mount the current running O/S dev,ptr into the image's root filesystem built above.
mount -o bind /dev /mnt/ec2-image/dev
mount -o bind /dev/pts /mnt/ec2-image/dev/pts
mount -o bind /dev/shm /mnt/ec2-image/dev/shm
mount -o bind /proc /mnt/ec2-image/proc
mount -o bind /sys /mnt/ec2-image/sys
Verify the mount for the new root fs is visible using Mount command.
mount | grep image
/dev on /mnt/ec2-image/dev type none (rw,bind)
/dev/pts on /mnt/ec2-image/dev/pts type none (rw,bind)
/dev/shm on /mnt/ec2-image/dev/shm type none (rw,bind)
/proc on /mnt/ec2-image/proc type none (rw,bind)
/sys on /mnt/ec2-image/sys type none (rw,bind)
Add a yum config of the centos image in /opt/ec2/yum directory as attached
Install the Base packages and O/S supporting utilities using the above created yum-xen.conf
yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y groupinstall Base
yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install *openssh*
dhclient
yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install grub
yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install
selinux-policy selinux-policy-targeted
yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install vi *openjdk*
Configure Network for Image
Update the files in the Image root file system
vi /mnt/ec2-image/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
vi /mnt/ec2-image/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
Setup network to start on boot
/usr/sbin/chroot /mnt/ec2-image /sbin/chkconfig --level 2345 network on
Selinux configuration
Relabel Selinux label in the image
touch /mnt/ec2-image/.autorelabel
Update /etc/sysconfig/selinux
SELINUX=disabled
Storage and File system setup
create a base fstab on the image . Please make sure the first device is xvde as it is the Amazon xen default root device.
cat > /opt/ec2/image/etc/fstab <<EOF
/dev/xvde1 / ext4 defaults,noatime 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
EOF
Configure the boot file - grub.conf in the image boot directory
Create a default grub file as and then from command lineattached here
$ ln -s /boot/grub/grub.conf /mnt/ec2-image/boot/grub/menu.lst
$ kern=`ls /mnt/ec2-image/boot/vmlin* | awk -F / '{print $NF}'`
$ ird=`ls /mnt/ec2-image/boot/initramfs*.img|awk -F/ '{print $NF}'`
$ sed -ie "s/vmlinuz/$kern/" /mnt/ec2-image/boot/grub/grub.conf
$ sed -ie "s/initramfs/$ird/" /mnt/ec2-image/boot/grub/grub.conf
Securing Login
Add the following parameters or uncomment if they exist in /etc/ssh/sshd_config for the image
vi /mnt/ec2-image/etc/ssh/sshd_config
PermitRootLogin without-password
UseDNS no
Add the validation for root user with Private Key. Script attached
Register the validation script as a service and update it's run level from command line
$ /bin/chmod +x /mnt/ec2-image/etc/init.d/ec2-get-ssh
$ /usr/sbin/chroot /mnt/ec2-image /sbin/chkconfig --level 34 ec2-get-ssh on
Cleanup before AMI Bundle creation
Run the and verify the mounts bound to source have been removedattached cleanup script
$ mount ( Verify no new root filesystem directories are bound to the host)
AMI creation and upload (Instance Base AMI)
Get the kernel information for your location. This is dependent on the EC2_URL environment variable. the following is for
us-east-1 (use highlighted in our example)
ec2-describe-images 
--owner amazon
--region us-east-1 | grep "amazon/pv-grub-hd0" | awk '{ print $1, $2, $3, $5, $7 }'
IMAGE aki-b2aa75db amazon/pv-grub-hd00_1.03-i386.gz available i386
IMAGE aki-b4aa75dd amazon/pv-grub-hd00_1.03-x86_64.gz available x86_64
IMAGE aki-b6aa75df amazon/pv-grub-hd0_1.03-i386.gz available i386
IMAGE amazon/pv-grub-hd0_1.03-x86_64.gz available x86_64aki-88aa75e1
Bundle the AMI using the following command. Make sure all the AWS environment variables are setup (Will run for a while
based on image size)
ec2-bundle-image 
--cert $EC2_CERT 
--privatekey $EC2_PRIVATE_KEY 
--image /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img 
--prefix centos-6.4-Minimal-x86_64-base 
--user $AWS_ACCOUNT_NUMBER 
--destination /opt/ec2/ami 
--arch x86_64 
--kernel aki-88aa75e1
The output will log message about splitting the image and create a manifest. Finally you should see (ec2-bundle-image
complete.)
Upload the AMI to Amazon and verify that all parts are uploaded
ec2-upload-bundle 
--manifest /opt/ec2/ami/centos-6.4-Minimal-x86_64-base.manifest.xml 
--bucket $AWS_AMI_BUCKET 
--access-key $AWS_ACCESS_KEY_ID 
--secret-key $AWS_SECRET_ACCESS_KEY
Register the AMI with the appropriate Kernel ID, you should get the final AMI created info as in blue below
ec2-register $AWS_AMI_BUCKET/centos-6.4-Minimal-x86_64-base.manifest.xml --name "CentOS 6.4 base (x86_64)"
--description "CentOS 6.4 b (x86_64) Base AMI" --architecture x86_64 --kernel aki-88aa75e1
IMAGE ami-5beea532
This completes the full AMI build and Upload for the Instance Base AMI.
Converting Instance Base AMI to EBS AMI
Amazon does not provide building the EBS AMI directly from their CLI. To build a EBS AMI follow the steps below
Launch AWS Console and navigate to EC2
To create the instance click the "Launch Instance" button on the Dashboard. Please note instance is created in the selected
Zone
Zone Selected (Top Right shows the Current Selected Zone. Dropdown show all Zones)
Create Instance use Launch Instance (using the Instance Based AMI we created )
Steps to convert to an EBS Backed AMI
Login to the Instance that was launched in the previous step
Create a EBS Volume by navigating to "Volumes" in the EC2 Dashboard
Volume Parameters
Volume Type : Provisioned IOPS(io1)
Size : 20 GiB
IOP's : 200
Availability Zone : <Pick from List>
Snapshot : no snapshot
Attach the EBS Volume to the Instance created with the Instance based AMI
Steps to Attache EBS Volume
Login to the instance as root
fdisk -l
fdisk /dev/xvdj (You should see the attached EBS from the list our's shows xvdj)
Create a primary partition using following flags one in Fdisk
(n - new partition, p- Primary Partition, 1 - first partition , choose 1st and last cylinder of disk, w - write)
Create a filesystem on the new EBS disk
mkfs.ext4 /dev/xvdj1
Create a directory to mount the new Volume
mkdir /mnt/ebsvol
Sync the root filesystem to the mounted directory
rsync -avH --exclude /mnt --exclude /sys --exclude /proc --exclude /dev / /mnt/ebsvol
Create the required directories and devices
# mkdir -p /mnt/ebsvol/{dev,etc,proc,sys}
# /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x console
# /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x null
# /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x zero
Copy the resolv.conf to the /mnt/ebsvol/etc
cat /etc/resolv.conf > /mnt/ebsvol/etc/resolv.conf
Update the grub.conf in /mnt/ebsvol/boot/grub directory
replace (hd0) -> (hd0,0)
Sync the filesystem
sync;sync;sync;sync
Unmount the EBS volume
umount /mnt/ebsvol
Detach the EBS Volume from the instance from the AWS Console
Create a Snapshot of the EBS Volume from the AWS Console
Create an Image from Snapshot from the "Snapshot" in AWS Console
During Instance Registration you must Select the correct KERNEL_ID for your desired Zone or the EBS AMI instance will
give errors during startup.
Launch an Instance with the correct KERNEL_ID and you should see a running EBS Instance.
Benefits of EBS Based instances are that you can snapshot a ebs instance and is easy to recover if accidently terminated when
Termination Protection is Disabled. As long as you maintain frequent snapshots.
References:
This tutorial was built using the following tutorials
http://blog.bashton.com/2012/how-to-make-your-own-centos-6-amis/
http://www.practicalclouds.com/content/guide/
http://amazonaws.michael–martinez.com/
http://wiki.sysconfig.org.uk/display/howto/Build+your+own+Core+CentOS+5.x+AMI+for+Amazon+EC2
http://lists.centos.org/pipermail/centos/2011-January/105377.html
http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os
-5-5-kernel/
Howto createcustomcentosam iforebsstorage-200913-1043-13

More Related Content

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Howto createcustomcentosam iforebsstorage-200913-1043-13

  • 1. How to Create Custom CentOS AMI for EBS Storage Author : Kanwar Batra Audience : System Administrators, Architects, Technical Managers. Relevance : This document outlines the Amazon AMI creation and Conversion to a EBS Boot device. Prepare a Linux Host Install a CentOS machine on a Physical , Virtual infrastructure. ( This document is based on the CentOS 6.4 Minimal Install cd) Update the Yum repository ( Run command as )root sudo yum -y update ; sudo yum install -y MAKEDEV Setup the environment with ec2 credentials . Change your root (The file start with a Dot).bashrc file with attached Source the root bashrc #source ~/.bashrc Install Linux Packages below # yum -y install e2fsprogs ruby java-1.6.0-openjdk unzip wget Download your x509 Private Key and Certificate from the AWS Security Credentials. If none exist create new Private Key format : pk-<Alpha Numeric String>.pem x509 Cert format : cert-<alpha Numeric string>.pem Copy the above certificates to /opt/ec2/certificates cp -rf pk<Alpha Numeric String>.pem /opt/ec2/certificates/ec2-pk.pem cp -rf cert<Alpha Numeric String>.pem /opt/ec2/certificates/ec2-cert.pem Download the EC2 api and Ami command line utilities wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip Unzip the downloaded tools to /opt/ec2/tools. Combine both tools in same directory ( Say no to any existing files). cp "ec2-api-tools.zip" /opt/ec2/tools-rp cp "ec2-ami-tools.zip" /opt/ec2/tools-rp EC2 api and ami utilities are java base. Set JAVA_HOME if not set export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64 (Eg For Open JDK) export JAVA_HOME=/usr/java/jdk1.7.0_25 ( for Oracle/Sun Java) Verify Java Version java -version Check the ec2 regions that would determine location for image [root@nf_lnx_ami bin]# ./ec2-describe-region REGION eu-west-1 ec2.eu-west-1.amazonaws.com REGION sa-east-1 ec2.sa-east-1.amazonaws.com REGION us-east-1 ec2.us-east-1.amazonaws.com REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com REGION us-west-2 ec2.us-west-2.amazonaws.com REGION us-west-1 ec2.us-west-1.amazonaws.com REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com REGION ap-southeast-2 ec2.ap-southeast-2.amazonaws.com
  • 2. Verify the availability Zones that you can connect ec2-describe-availability-zones --region us-east-1 ( The output should look as below) AVAILABILITYZONE us-east-1a available us-east-1 AVAILABILITYZONE us-east-1b available us-east-1 AVAILABILITYZONE us-east-1c available us-east-1 AVAILABILITYZONE us-east-1d available us-east-1 Steps to Build the AMI Installing the Operating System To build the EBS Based AMI first we will create a Instance Base AMI and then after upload will convert it to EBS Storage AMI. Start the image creation in an empty directory. (eg /opt/ec2/images) Create an empty file using dd dd if=/dev/zero of=/opt/ec2/images/centos-6.4-Minimal-x86_64-base.img bs=1M count=10240 Initialize the image file with a filesystem `mkfs.ext4 -F -j /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img Create an empty directory and mount the initialized image file as a loopback mount -o loop /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img /mnt/ec2-image/ Verify the image mounted using the mount command mount df -h | grep image /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img 9.9G 151M 9.2G 2% /mnt/ec2-image Setup directories in the image before installing the Operating system mkdir -p /mnt/ec2-image/{dev,etc,proc,sys} mkdir -p /mnt/ec2-image/var/{cache,log,lock,lib/rpm} Create minimum required devices on /dev in the image location using MAKEDEV ignore any File exists warnings . /sbin/MAKEDEV -d /mnt/ec2-image/dev -x console /sbin/MAKEDEV -d /mnt/ec2-image/dev -x null /sbin/MAKEDEV -d /mnt/ec2-image/dev -x zero /sbin/MAKEDEV -d /mnt/ec2-image/dev -x urandom Mount the current running O/S dev,ptr into the image's root filesystem built above. mount -o bind /dev /mnt/ec2-image/dev
  • 3. mount -o bind /dev/pts /mnt/ec2-image/dev/pts mount -o bind /dev/shm /mnt/ec2-image/dev/shm mount -o bind /proc /mnt/ec2-image/proc mount -o bind /sys /mnt/ec2-image/sys Verify the mount for the new root fs is visible using Mount command. mount | grep image /dev on /mnt/ec2-image/dev type none (rw,bind) /dev/pts on /mnt/ec2-image/dev/pts type none (rw,bind) /dev/shm on /mnt/ec2-image/dev/shm type none (rw,bind) /proc on /mnt/ec2-image/proc type none (rw,bind) /sys on /mnt/ec2-image/sys type none (rw,bind) Add a yum config of the centos image in /opt/ec2/yum directory as attached Install the Base packages and O/S supporting utilities using the above created yum-xen.conf yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y groupinstall Base yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install *openssh* dhclient yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install grub yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install selinux-policy selinux-policy-targeted yum -c /opt/ec2/yum/yum-xen.conf --installroot=/mnt/ec2-image -y install vi *openjdk* Configure Network for Image Update the files in the Image root file system vi /mnt/ec2-image/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes TYPE=Ethernet USERCTL=yes PEERDNS=yes IPV6INIT=no vi /mnt/ec2-image/etc/sysconfig/network NETWORKING=yes HOSTNAME=localhost.localdomain Setup network to start on boot /usr/sbin/chroot /mnt/ec2-image /sbin/chkconfig --level 2345 network on Selinux configuration Relabel Selinux label in the image touch /mnt/ec2-image/.autorelabel
  • 4. Update /etc/sysconfig/selinux SELINUX=disabled Storage and File system setup create a base fstab on the image . Please make sure the first device is xvde as it is the Amazon xen default root device. cat > /opt/ec2/image/etc/fstab <<EOF /dev/xvde1 / ext4 defaults,noatime 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 EOF Configure the boot file - grub.conf in the image boot directory Create a default grub file as and then from command lineattached here $ ln -s /boot/grub/grub.conf /mnt/ec2-image/boot/grub/menu.lst $ kern=`ls /mnt/ec2-image/boot/vmlin* | awk -F / '{print $NF}'` $ ird=`ls /mnt/ec2-image/boot/initramfs*.img|awk -F/ '{print $NF}'` $ sed -ie "s/vmlinuz/$kern/" /mnt/ec2-image/boot/grub/grub.conf $ sed -ie "s/initramfs/$ird/" /mnt/ec2-image/boot/grub/grub.conf Securing Login Add the following parameters or uncomment if they exist in /etc/ssh/sshd_config for the image vi /mnt/ec2-image/etc/ssh/sshd_config PermitRootLogin without-password UseDNS no Add the validation for root user with Private Key. Script attached Register the validation script as a service and update it's run level from command line $ /bin/chmod +x /mnt/ec2-image/etc/init.d/ec2-get-ssh $ /usr/sbin/chroot /mnt/ec2-image /sbin/chkconfig --level 34 ec2-get-ssh on Cleanup before AMI Bundle creation Run the and verify the mounts bound to source have been removedattached cleanup script $ mount ( Verify no new root filesystem directories are bound to the host) AMI creation and upload (Instance Base AMI) Get the kernel information for your location. This is dependent on the EC2_URL environment variable. the following is for us-east-1 (use highlighted in our example) ec2-describe-images --owner amazon
  • 5. --region us-east-1 | grep "amazon/pv-grub-hd0" | awk '{ print $1, $2, $3, $5, $7 }' IMAGE aki-b2aa75db amazon/pv-grub-hd00_1.03-i386.gz available i386 IMAGE aki-b4aa75dd amazon/pv-grub-hd00_1.03-x86_64.gz available x86_64 IMAGE aki-b6aa75df amazon/pv-grub-hd0_1.03-i386.gz available i386 IMAGE amazon/pv-grub-hd0_1.03-x86_64.gz available x86_64aki-88aa75e1 Bundle the AMI using the following command. Make sure all the AWS environment variables are setup (Will run for a while based on image size) ec2-bundle-image --cert $EC2_CERT --privatekey $EC2_PRIVATE_KEY --image /opt/ec2/images/centos-6.4-Minimal-x86_64-base.img --prefix centos-6.4-Minimal-x86_64-base --user $AWS_ACCOUNT_NUMBER --destination /opt/ec2/ami --arch x86_64 --kernel aki-88aa75e1 The output will log message about splitting the image and create a manifest. Finally you should see (ec2-bundle-image complete.) Upload the AMI to Amazon and verify that all parts are uploaded ec2-upload-bundle --manifest /opt/ec2/ami/centos-6.4-Minimal-x86_64-base.manifest.xml --bucket $AWS_AMI_BUCKET --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY Register the AMI with the appropriate Kernel ID, you should get the final AMI created info as in blue below ec2-register $AWS_AMI_BUCKET/centos-6.4-Minimal-x86_64-base.manifest.xml --name "CentOS 6.4 base (x86_64)" --description "CentOS 6.4 b (x86_64) Base AMI" --architecture x86_64 --kernel aki-88aa75e1 IMAGE ami-5beea532 This completes the full AMI build and Upload for the Instance Base AMI. Converting Instance Base AMI to EBS AMI Amazon does not provide building the EBS AMI directly from their CLI. To build a EBS AMI follow the steps below Launch AWS Console and navigate to EC2 To create the instance click the "Launch Instance" button on the Dashboard. Please note instance is created in the selected Zone Zone Selected (Top Right shows the Current Selected Zone. Dropdown show all Zones)
  • 6. Create Instance use Launch Instance (using the Instance Based AMI we created ) Steps to convert to an EBS Backed AMI Login to the Instance that was launched in the previous step Create a EBS Volume by navigating to "Volumes" in the EC2 Dashboard Volume Parameters Volume Type : Provisioned IOPS(io1) Size : 20 GiB IOP's : 200 Availability Zone : <Pick from List> Snapshot : no snapshot Attach the EBS Volume to the Instance created with the Instance based AMI Steps to Attache EBS Volume Login to the instance as root fdisk -l fdisk /dev/xvdj (You should see the attached EBS from the list our's shows xvdj) Create a primary partition using following flags one in Fdisk (n - new partition, p- Primary Partition, 1 - first partition , choose 1st and last cylinder of disk, w - write) Create a filesystem on the new EBS disk mkfs.ext4 /dev/xvdj1 Create a directory to mount the new Volume mkdir /mnt/ebsvol
  • 7. Sync the root filesystem to the mounted directory rsync -avH --exclude /mnt --exclude /sys --exclude /proc --exclude /dev / /mnt/ebsvol Create the required directories and devices # mkdir -p /mnt/ebsvol/{dev,etc,proc,sys} # /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x console # /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x null # /sbin/MAKEDEV -v -d /mnt/ebsvol/dev -x zero Copy the resolv.conf to the /mnt/ebsvol/etc cat /etc/resolv.conf > /mnt/ebsvol/etc/resolv.conf Update the grub.conf in /mnt/ebsvol/boot/grub directory replace (hd0) -> (hd0,0) Sync the filesystem sync;sync;sync;sync Unmount the EBS volume umount /mnt/ebsvol Detach the EBS Volume from the instance from the AWS Console Create a Snapshot of the EBS Volume from the AWS Console Create an Image from Snapshot from the "Snapshot" in AWS Console During Instance Registration you must Select the correct KERNEL_ID for your desired Zone or the EBS AMI instance will give errors during startup. Launch an Instance with the correct KERNEL_ID and you should see a running EBS Instance. Benefits of EBS Based instances are that you can snapshot a ebs instance and is easy to recover if accidently terminated when Termination Protection is Disabled. As long as you maintain frequent snapshots. References: This tutorial was built using the following tutorials http://blog.bashton.com/2012/how-to-make-your-own-centos-6-amis/ http://www.practicalclouds.com/content/guide/ http://amazonaws.michael–martinez.com/ http://wiki.sysconfig.org.uk/display/howto/Build+your+own+Core+CentOS+5.x+AMI+for+Amazon+EC2 http://lists.centos.org/pipermail/centos/2011-January/105377.html http://www.ioncannon.net/system-administration/1205/installing-cent-os-5-5-on-ec2-with-the-cent-os -5-5-kernel/