This article is for users that change AWS region around the world.
  • Base
    • CentOS
  • Issue
    • The problem occurs because specific region does not have PV Instance.
  • Fixing
    • Resolved by copying the file with rsync after mounting PV Volume and HVM Volume.
  • info
    • Original PV Instance : orig_pv_instance
    • New HVM Instance : new_hvm_instance
    • Original PV volume : orig_pv_vol
    • Duplicated PV Volume : dup_pv_vol
    • New HVM Volume : new_hvm_vol

Migrating the EC2 Instance 

1. Duplication PV volume that want to move. (Using the Snapshot)

  1. Volumes menu -> Select the PV instance
  2. Right click -> Create Snapshot (pv_snap)
  3. Snapshots menu -> Select ‘pv_snap’ and Created Volume
  4. Setting up items and check availability zone
    1. AZ shall be the same as the place you want to move

2. Create HVM Instance such as PV instance OS

3. Duplication HVM volume using Step 1.

4. Copied PV Volume(dup_pv_vol) and HVM Volume(new_hvm_vol) attach to the PV Instance(orig_pv_instance)

  1. Volume menu -> Select the dup_pv_vol
  2. Right click -> Attach Volume
    1. Instance : orig_pv_instance
    2. Device : /dev/sdm (have your way)
  3. Volume menu -> Select the new_hvm_vol
  4. Right click -> Attach Volume
    1. Instance : orig_pv_instance
    2. Device : /dev/sdo (have your way)

5. PV Instance lauch and connect

6. Check volume size and Mount volumes

  1. Ensure PV and HVM Volumes attachment
    1. using $ fdisk -l
      1. If volume size not correct, follow step 2. 
      2. And when size is correct to follow next step.
    2. PV and HVM volumes mount.
      1. $ mount [pv volume dir] // Want to mount the pv directory.​
      2. $ mount [hvm volume dir] // Want to mount the hvm directory.​
  2. Modify volume size (pv and hvm)
    1. $ fdisk [volume]​ // Want to modify the volume.
      1. Command (m for help) : u
      2. Command (m for help) : p
      3. Command (m for help) : d
      4. Command (m for help) : n
      5. Command action : p
      6. Partition number (1-4) : 1
      7. First sector (17-41943039, default 17): 2048
      8. Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): <Enter>
      9. Command (m for help) : p
      10. Command (m for help) : a
      11. Partition number (1-4) : 1
      12. Command (m for help) : w
    2. $ reboot
    3. mount check
      1. $ dh -h
      2. If not mounted, follow next step.
        1. ​$ fdisk -l
        2. $ mount [dir] // Want to mount the directory.​
    4. change to volume size.
      1. $ resize2fs [dir] // Want to change size the directory.

7. Copying Files using rsync

  • It takes long time.
  • Working instance must have all the authorities that to use at Source PV Volume.
  • Make use using the following script.
#pv_to_hvm.sh
#!/bin/sh
cd /HVM
cp /HVM/etc/fstab /root/
for dir in $(ls -l | awk '{print $NF}'| egrep -v 'boot|lib'); do rm -rf $dir; echo "deleted $dir"; done
rm -rf /HVM/lib64
cd /HVM/lib/
cp -rpf /HVM/lib/modules /root/modules_bkp/
rm -rf /HVM/lib/*
mkdir /HVM/lib/modules
chmod -w /HVM/lib/modules
cp -rpf /root/modules_bkp/ /HVM/lib/modules/
rm -rf /PV/boot
rsync -aAXHPv /PV/ /HVM/
rm -rf /HVM/.auto*
mv /HVM/etc/fstab /HVM/etc/bak_fstab
cp /root/fstab /HVM/etc/

8. Volume umount

  • Make sure you used the image files in the configuration file before you umount the Volume
    • open /HVM/boot/grub/grub.conf file in /HVM/lib/modules.
    • ​check images
      • title image file
      • kernel image file
      • initrd image file
  • PV and HVM volume amount

9. Stop the PV Instance(orig_pv_instance) and detach the HVM Volume(new_hvm_vol)

10. Detach root volume in the HVM Instance(new_hvm_instance)

11. Attach to the working HVM volume(new_hvm_volume) in HVM Instance(new_hvm_instance)

12. Launch HVM Instance(new_hvm_instance)


반응형

'Programming > AWS' 카테고리의 다른 글

[S3Cmd] S3 사이즈 확인  (0) 2016.08.21
[AWS-CLI] S3 다른 리전 버킷으로 복사  (0) 2016.08.21