debian

如何使用Debian Cobbler进行系统迁移

小樊
47
2025-09-24 21:02:38
栏目: 智能运维

使用Debian Cobbler进行系统迁移的步骤

1. 准备迁移环境

在目标Debian服务器上安装Cobbler及依赖组件,确保系统已更新:

sudo apt-get update
sudo apt-get install cobbler cobbler-web tftp-server dhcp apache2 pykickstart

启动并启用Cobbler服务:

sudo systemctl start cobblerd
sudo systemctl enable cobblerd

2. 配置Cobbler核心参数

编辑Cobbler主配置文件/etc/cobbler/settings,设置关键参数:

运行cobbler check检查配置完整性,根据提示修复问题(如缺失/var/lib/cobbler/loaders中的引导文件,可通过cobbler get-loaders下载)。

3. 导入源系统镜像

将待迁移的Debian系统ISO镜像挂载并导入Cobbler:

sudo mkdir -p /mnt/debian_iso
sudo mount -o loop /path/to/debian.iso /mnt/debian_iso
sudo cobbler import --path=/mnt/debian_iso --name=debian-migration-source
sudo umount /mnt/debian_iso

导入后,Cobbler会自动创建对应的distro(如debian-migration-source-x86_64),包含系统内核和初始化镜像。

4. 调整PXE引导配置(Debian特有)

Debian的默认initrd.gz不适合PXE启动,需替换为官方Netboot版本:

# 下载Debian Netboot initrd.gz(以Debian 12为例)
wget -O /root/debian12-netboot.gz https://mirrors.ustc.edu.cn/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz

# 拼接原有initrd.gz与Netboot版本(路径根据导入的distro调整)
cat /var/www/cobbler/distro_mirror/debian-migration-source/install.amd/initrd.gz /root/debian12-netboot.gz > /var/www/cobbler/pub/debian-migration-source-netboot.gz

# 修改distro配置,使用新的initrd.gz
sudo cobbler distro edit --name=debian-migration-source-x86_64 --initrd "/var/www/cobbler/pub/debian-migration-source-netboot.gz"

5. 创建自动化安装Seed文件

Seed文件用于Debian无人值守安装,需定制语言、网络、分区等参数。示例路径:/var/lib/cobbler/templates/migration-seed.seed

# 基本语言与区域设置
d-i debian-installer/locale string en_US.UTF-8
d-i keyboard-configuration/xkb-keymap select us
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 网络配置(自动获取IP)
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string migrated-host
d-i netcfg/get_domain string example.com

# 镜像源设置(替换为目标仓库)
d-i mirror/country string manual
d-i mirror/http/hostname string mirrors.tuna.tsinghua.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 分区配置(自动清空磁盘并创建默认分区)
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

# 用户与密码(设置root密码)
d-i passwd/root-login boolean true
d-i passwd/root-password password YourSecurePassword
d-i passwd/root-password-again password YourSecurePassword

# 安装完成后重启
d-i finish-install/reboot_in_progress note

6. 关联Profile与Seed文件

将Seed文件与导入的distro关联,创建可用的profile

sudo cobbler profile add --name=debian-migration-profile --distro=debian-migration-source-x86_64 --kickstart=/var/lib/cobbler/templates/migration-seed.seed

7. 配置DHCP服务

编辑Cobbler的DHCP模板/etc/cobbler/dhcp.template,确保包含以下关键配置(根据网络环境调整):

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.200;
    option routers 192.168.1.1;
    option domain-name-servers 8.8.8.8;
    filename "pxelinux.0";
}

同步Cobbler配置以应用DHCP设置:

sudo cobbler sync

8. 执行系统迁移

注意事项

0
看了该问题的人还看了