2015年3月12日 星期四

AWS T1.Micro 轉 T2.Micro 流程

T1.Micro 轉 T2.Micro 流程


前置準備(此步驟為AWS Console作業)
0.T1.Micro 要預先裝好GRUB 沒裝後面也不用做了
1.主機 開啟一台作業用EC2 命名EC2-Working
2.T1.Micro 建立Snapshot -->建立 Volume (T1.Micro.Source)
3.建立目的地Volume (T2.Micro.Dest)
4.將T1.Micro.Source 掛載到EC2-Working的 /dev/sdm
5.將T2.Micro.Dest 掛載到EC2-Working的 /dev/sdo

T2.Micro.Dest 處理作業(以下作業皆使用root權限)
1.建立Partition
#parted /dev/xvdo --script 'mklabel msdos mkpart primary 1M -1s print quit'
2.Partion偵測
#partprobe /dev/xvdo
3.udev偵測
#udevadm settle

T1.Micro.Source 處理作業
1.檔案系統檢查
#e2fsck -f /dev/xvdm
2.Resize檔案系統
#resize2fs -M /dev/xvdm
3.記下輸出的數值
- Output from resize command:
Resizing the filesystem on /dev/xvdm to 1391485 (4k) blocks.
The filesystem on /dev/xvdm is now 1391485 blocks long.

將T1.Micro.Source複製到T2.Micro.Dest
1.Disk Dump
#dd if=/dev/xvdm of=/dev/xvdo1 bs=4K count=1391485  輸入剛剛查出的數值
2.完成後Resize
#resize2fs /dev/xvdo1

Grub 安裝前置準備
# mount /dev/xvdo1 /mnt
# cp -a /dev/xvdo /dev/xvdo1 /mnt/dev/
# rm -f /mnt/boot/grub/*stage*
# cp /mnt/usr/*/grub/*/*stage* /mnt/boot/grub/
# rm -f /mnt/boot/grub/device.map

Grub 安裝
# cat <> device (hd0) /dev/xvdo
> root (hd0,0)
> setup (hd0)
> EOF
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/xvdo
grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  31 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+31 p (hd0,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.

刪除Temp Device
# rm -f /mnt/dev/xvdo /mnt/dev/xvdo1

Grub設定更新
#vi /mnt/boot/grub/menu.lst
下列內容要修改
root (hd0) 改成 root (hd0,0)
console=* 改成 console=ttyS0
在kernel 參數後面追加 xen_pv_hvm=enable
example:
# created by imagebuilder
default=0
timeout=1
hiddenmenu
title Amazon Linux 2014.03 (3.10.42-52.145.amzn1.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-3.10.42-52.145.amzn1.x86_64 root=LABEL=/ console=ttyS0 LANG=ja_JP.UTF-8 KEYTABLE=us xen_pv_hvm=enable
initrd /boot/initramfs-3.10.42-52.145.amzn1.x86_64.img

 更新檔案系統表
 #vi /mnt/etc/fstab
 若沒有其他設定要追加可以不做修改

 修改檔案系統標簽
# e2label /dev/xvdo1 /
# sync
# umount /mnt

檔案系統掛載
1.新增一T2.Micro Instance
2.待開機完成後,關機並且將原來的 Root EBS detach(可順便把該volume刪除)
3.將T2.Micro.Dest 掛載到 /dev/xvda
4.開機,登入驗證

reference:
1.https://forums.aws.amazon.com/thread.jspa?messageID=553638
2.http://www.agilegroup.co.jp/technote/t1micro-to-t2micro-migration.html

計算機容量單位

1 bit = 0 or 1
1 Byte = 8 bit
1 KB = 1024 Bytes(KiloBytes) 10^3
1 MB = 1024 KB(MegaBytes) 10^6
1 GB = 1024 MB(GigaBytes) 10^9
1 TB = 1024 GB(TeraBytes) 10^12
1 PB = 1024 TB(PetaBytes) 10^15
1 EB = 1024 PB(ExaBytes) 10^18
1 ZB = 1024 EB(ZettaBytes) 10^21
1 YB = 1024 ZB(YottaBytes) 10^24
1 BB = 1024 YB(BrontoBytes) 10^27