What to Prepare
(1) EC2 Instance (CentOS6) can be an existing running one (2) Snapshot of the root device from which the conversion is made (3) EBS Volume created from (2) (SSD is faster) (3) Empty EBS Volume (SSD is faster)
Check your DEVICE
# fdisk -l |grep dev
Disk /dev/xvda: 10.7 GB, 10737418240 bytes
Disk /dev/xvdb: 4289 MB, 4289200128 bytes
Disk /dev/xvdf: 10.7 GB, 10737418240 bytes <-PV環境のRoot device
Disk /dev/xvdg: 10.7 GB, 10737418240 bytes <-空のEBS volume="" ```="" ##="" 作業開始="" 1.pvのdiskを縮小し、コピー容量を減らす="" ```="" 作業前の状態確認="" #="" mount="" ev/xvdf="" nt/="" #="" df="" -h="" ev/xvdf="" filesystem="" size="" used="" avail="" use%="" mounted="" on="" ev/xvdf="" 9.9g="" 2.3g="" 7.2g="" 24%="" nt="" #="" umount="" nt/="" 縮小化="" #="" e2fsck="" -f="" ev/xvdf="" #="" resize2fs="" -m="" ev/xvdf="" resize2fs="" 1.41.12="" (17-may-2010)="" resizing="" the="" filesystem="" on="" ev/xvdf="" to="" 598879="" (4k)="" blocks.="" the="" filesystem="" on="" ev/xvdf="" is="" now="" 598879="" blocks="" long.="" 作業後の状態確認="" #="" mount="" ev/xvdf="" nt/="" #="" df="" -h="" ev/xvdf="" filesystem="" size="" used="" avail="" use%="" mounted="" on="" ev/xvdf="" 2.3g="" 2.2g="" 0="" 100%="" nt="" #="" umount="" nt/="" ```=""> **NOTE:**
>
> - Make a note of the block size (this time 598879 blocks) 2. Create an image to a new disk
ls /dev/xvd*
/dev/xvda /dev/xvda1 /dev/xvdb /dev/xvdf /dev/xvdg
Partitioning (one-liner)
parted /dev/xvdg --script 'mklabel msdos mkpart primary 1M -1s print quit'
Confirm
ls /dev/xvd*
/dev/xvda /dev/xvda1 /dev/xvdb /dev/xvdf /dev/xvdg /dev/xvdg1
udevadm info --query=property --name=/dev/xvdg1
UDEV_LOG=3 DEVPATH=/devices/vbd-51808/block/xvdg/xvdg1 MAJOR=202 MINOR=97 DEVNAME=/dev/xvdg1 DEVTYPE=partition SUBSYSTEM=block ID_PATH=xen-vbd-51808 ID_PART_TABLE_TYPE=dos LVM_SBIN_PATH=/sbin DEVLINKS=/dev/block/202:97 /dev/disk/by-path/xen-vbd-51808-part1
*What parted does is as follows. **If you create the above partitions, you don't need to do the following**.
parted /dev/xvdg
(parted) print Model: Xen Virtual Block Device (xvd) Disk /dev/xvdg: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos
Number Start End Size Type File system Flags
(parted) mklabel msdos (parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? Start? 1M End? -1s (parted) print Model: Xen Virtual Block Device (xvd) Disk /dev/xvdg: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos
Number Start End Size Type File system Flags 1 1049kB 10.7GB 10.7GB primary (parted) quit
/dev/xvdg1 has been created. If not, do the following:
partprobe /dev/xvdg
udevadm settle
3. Disk Copy
dd if=/dev/xvdf of=/dev/xvdg1 bs=4K count=598879
598879+0 records in 598879+0 records out 2453008384 bytes (2.5 GB) copied, 73.0507 s, 33.6 MB/s
Copy status check
mount /dev/xvdg1 /mnt/
df -h /mnt/
Filesystem Size Used Avail Use% Mounted on /dev/xvdg1 2.3G 2.2G 0 100% /mnt
Restore to original size
resize2fs /dev/xvdg1
Verify that it has been extended
df -h /dev/xvdg1
Filesystem Size Used Avail Use% Mounted on /dev/xvdg1 9.9G 2.3G 7.2G 24% /mnt
> **NOTE:**
>
> - Now we use the block size above
> - 2.5 GB, a little over 1 minute
4. Chroot Preparation
ls -l /mnt/dev/
total 0 crw------- 1 root root 5, 1 Mar 30 2012 console crw-rw-rw- 1 root root 1, 3 Mar 30 2012 null crw-rw-rw- 1 root root 5, 0 Mar 30 2012 tty crw-rw-rw- 1 root root 1, 5 Mar 30 2012 zero
Copy device
cp -a /dev/xvdg /dev/xvdg1 /mnt/dev/
ls -l /mnt/dev/
total 0 crw------- 1 root root 5, 1 Mar 30 2012 console crw-rw-rw- 1 root root 1, 3 Mar 30 2012 null crw-rw-rw- 1 root root 5, 0 Mar 30 2012 tty brw-rw---- 1 root disk 202, 96 Jul 11 02:10 xvdg brw-rw---- 1 root disk 202, 97 Jul 11 03:08 xvdg1 crw-rw-rw- 1 root root 1, 5 Mar 30 2012 zero
Creating a Proc File
mount -t proc none /mnt/proc
5. Configure various settings to HVM
chroot /mnt
*Working with chroot below. (chroot)# yum list grub grub.x86_64 1:0.97-83.el6 @base *If it is not included, install it
(chroot)# ls -l /boot/grub/grub.conf *If there is no link, create a SymbolicLink (chroot)# ln -s /boot/grub/menu.lst /boot/grub/grub.conf (chroot)# ls -l /boot/grub/grub.conf lrwxrwxrwx 1 root root 19 July 11, 2014 13:47 /boot/grub/grub.conf -> /boot/grub/menu.lst
(chroot)# ls -l /etc/grub.conf *If there is no link, create a SymbolicLink (chroot)# ln -s /boot/grub/grub.conf /etc/grub.conf (chroot)# ls -l /etc/grub.conf lrwxrwxrwx 1 root root 13:47, 11 July 2014 /etc/grub.conf -> /boot/grub/grub.conf
(chroot)# ls /mnt/boot/grub/stage *If there is a file, delete the existing one. (chroot)# rm -f /mnt/boot/grub/stage
(chroot)# cp /mnt/usr//grub//stage /mnt/boot/grub/ (chroot)# ls -l /mnt/boot/grub/stage -rw-r--r-- 1 root root 13380 Jul 11 03:09 /mnt/boot/grub/e2fs_stage1_5 -rw-r--r-- 1 root root 12620 Jul 11 03:09 /mnt/boot/grub/fat_stage1_5 -rw-r--r-- 1 root root 11748 Jul 11 03:09 /mnt/boot/grub/ffs_stage1_5 -rw-r--r-- 1 root root 11756 Jul 11 03:09 /mnt/boot/grub/iso9660_stage1_5 -rw-r--r-- 1 root root 13268 Jul 11 03:09 /mnt/boot/grub/jfs_stage1_5 -rw-r--r-- 1 root root 11956 Jul 11 03:09 /mnt/boot/grub/minix_stage1_5 -rw-r--r-- 1 root root 14412 Jul 11 03:09 /mnt/boot/grub/reiserfs_stage1_5 -rw-r--r-- 1 root root 512 Jul 11 03:09 /mnt/boot/grub/stage1 -rw-r--r-- 1 root root 126100 Jul 11 03:09 /mnt/boot/grub/stage2 -rw-r--r-- 1 root root 126100 Jul 11 03:09 /mnt/boot/grub/stage2_eltorito -rw-r--r-- 1 root root 12024 Jul 11 03:09 /mnt/boot/grub/ufs2_stage1_5 -rw-r--r-- 1 root root 11364 Jul 11 03:09 /mnt/boot/grub/vstafs_stage1_5 -rw-r--r-- 1 root root 13964 Jul 11 03:09 /mnt/boot/grub/xfs_stage1_5
(chroot)# ls -l /mnt/boot/grub/device.map *If there is, delete the existing ones (chroot)# rm -f /mnt/boot/grub/device.map
6. grub installation
(chroot)# cat < > device (hd0) /dev/xvdo
root (hd0,0) setup (hd0) EOF
*What grub does is as follows. **If you create the above partitions, you don't need to do the following**.
(chroot)# grub --batch Probing devices to guess BIOS drives. This may take a long time. GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename.] grub> device (hd0) /dev/xvdg grub> root (hd0,0) grub> setup (hd0) grub> quit
7. Low-level disk check
Label Verification (chroot)# tune2fs -l /dev/xvdg1 |grep name Filesystem volume name: _/
FSCK Verification (chroot)# tune2fs -l /dev/xvdg1 |egrep "Maximum| Check" Maximum mount count: 28 Check interval: 15552000 (6 months) Changed not to do fsck on startup (chroot)# tune2fs -i 0 -c 0 /dev/xvdg1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1 Setting interval between checks to 0 seconds (chroot)# tune2fs -l /dev/xvdg1 |egrep "Maximum| Check" Maximum mount count: -1 Check interval: 0 ()
8. Changing Grub Settings
(chroot)# cp -a /boot/grub/menu.lst{,.org} (chroot)# vi /boot/grub/menu.lst root (hd0) ↓ root (hd0,0)
kernel /boot/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=LABEL=/ ↓ kernel /boot/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=LABEL=/ console=ttyS0 xen_pv_hvm=enable
(chroot)# diff /boot/grub/menu.lst{,.org} 6,7c6,7 < root (hd0,0) < kernel /boot/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=LABEL=_/ console=ttyS0 xen_pv_hvm=enable
root (hd0) kernel /boot/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=LABEL=_/
Changing the setting of fstab (Coco and others should follow the existing settings)
LABEL=_/ / ext4 defaults 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
9. Work done
(chroot)# exit
rm -f /mnt/dev/xvdg*
ls -l /mnt/dev/
total 0 crw------- 1 root root 5, 1 Mar 30 2012 console crw-rw-rw- 1 root root 1, 3 Mar 30 2012 null crw-rw-rw- 1 root root 5, 0 Mar 30 2012 tty crw-rw-rw- 1 root root 1, 5 Mar 30 2012 zero
umount /mnt/proc /mnt
df -h /dev/xvdg1
Filesystem Size Used Avail Use% Mounted on
- 1.9G 156K 1.9G 1% /dev
Now you need to take a Snapshot of /dev/xvdg and create an AMI from the Snapshot. You can work here from the ManagementConsole.
Reference Links[](http://www.agilegroup.co.jp/technote/t1micro-to-t2micro-migration.html "EC2のt1.microをt2.microへ移行する")</-空のEBS>