如何迁移CentOS6.5镜像至火山引擎

操作系统
问题描述

如何迁移 CentOS 6.5 镜像到火山引擎

解决方案
注意执行以下操作前,通过快照或其他方式保留原始系统文件

1. CentOS-Base.repo 和 epel.repo yum源配置

[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Base.repo 

[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.volces.com/centos-vault/6.10/os/x86_64
gpgcheck=0
enabled=1

[root@localhost ~]# cat /etc/yum.repos.d/epel.repo 
[epel]
name=EPEL
baseurl=http://mirrors.volces.com/fedora-archive/epel/6/x86_64/
gpgcheck=0
enabled=1

2. 安装cloud-init相关软件包

yum install cloud-init cloud-utils-growpart dracut-modules-growroot -y && dracut -f

3. 配置cloud-init

复制以下内容至 /etc/cloud/cloud.cfg
users:
- default  

disable_root: 0
ssh_pwauth: 1
growpart:
    mode: auto
    devices: ['/']
    ignore_growroot_disabled: false

mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys: 1
syslog_fix_perms: ~
disable_vmware_customization: false

manage_etc_hosts: localhost

cloud_init_modules:
  - disk_setup
  - migrator
  - bootcmd
  - write-files
  - growpart
  - resizefs
  - set_hostname
  - update_hostname
  - update_etc_hosts
  - rsyslog
  - users-groups
  - ssh

cloud_config_modules:
  - mounts
  - locale
  - set-passwords
  - rh_subscription
  - yum-add-repo
  - package-update-upgrade-install
  - timezone
  - puppet
  - chef
  - salt-minion
  - mcollective
  - disable-ec2-metadata
  - runcmd

cloud_final_modules:
  - rightscale_userdata
  - scripts-per-once
  - scripts-per-boot
  - scripts-per-instance
  - scripts-user
  - ssh-authkey-fingerprints
  - keys-to-console
  - phone-home
  - final-message
  - power-state-change

system_info:
  # distro: rhel # centos则打开此配置
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd
复制以下内容至/etc/cloud/cloud.cfg.d/90_dpkg.cfg
datasource_list: [ConfigDrive, OpenStack]

datasource:
    OpenStack:
        metadata_urls: [ http://169.254.169.254 , http://100.96.0.96 ]
        max_wait: -1
        timeout: 5
        retries: 5
        apply_network_config: True

4. 删除不需要的配置文件

echo > /etc/udev/rules.d/70-persistent-net.rules 
rm -rf /var/lib/cloud

5. 更新网卡配置文件

cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

6. 设置cloud-init开机启动

chkconfig --add cloud-init

7. 更新GRUB菜单timeout显示时间为10秒

[root@localhost ~]# cat /boot/grub/grub.conf 

default=0
timeout=10   <------- 修改为10秒或更长
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=e7d1725a-1225-4c78-a5be-bbbc3a5508a1 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /boot/initramfs-2.6.32-431.el6.x86_64.img

8. 查看initrd中是否有virtio驱动

[root@localhost ~]# lsinitrd /boot/initramfs-2.6.32-431.el6.x86_64.img | grep virtio
-rwxr--r--   1 root     root        23576 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/block/virtio_blk.ko
-rwxr--r--   1 root     root        23864 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/scsi/virtio_scsi.ko
drwxr-xr-x   2 root     root            0 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/virtio
-rwxr--r--   1 root     root        12552 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/virtio/virtio.ko
-rwxr--r--   1 root     root        19384 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/virtio/virtio_pci.ko
-rwxr--r--   1 root     root        17696 Feb 22 13:22 lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/virtio/virtio_ring.ko

9. 使用dd命令复制系统盘所有数据至镜像文件

dd if=/dev/xda of=/mnt/centos6.img
10. 清理当前系统更改的配置
chkconfig --del cloud-init
11. 按照文档步骤导入镜像

https://www.volcengine.com/docs/6396/69081

如果您有其他问题,欢迎您联系火山引擎技术支持服务

380
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论