clone vm

本文详细介绍了如何通过链接克隆方式复制虚拟机,并进行设备信息、网卡配置、主机名称及主机映射的修改步骤,确保克隆后的虚拟机能够正常运行并接入网络。

1.克隆(复制)虚拟机(链接克隆)

2.设备信息

   vim /etc/udev/rules.d/70-persistent-net.rules 

    删除eth0(来自于hdp01)

    修改eth1名称为eth0,复制mac址:00:0c:29:99:82:83

3.网卡配置(eth0)

   vim /etc/sysconfig/network-scripts/ifcfg-eth0 

   1)删除uuid

   2)修改HWADDR为新网卡的mac地址

   3)修改ip地址

4.主机名称

   vim /etc/sysconfig/network

5.主机映射

   vim /etc/hosts

private void btnCloneVm_Click(object sender, EventArgs e) { if (client == null) { MessageBox.Show("请先连接到vCenter Server", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cboTemplates.SelectedIndex < 0) { MessageBox.Show("请选择虚拟模板", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cboHostsClone.SelectedIndex < 0) { MessageBox.Show("请选择目标主机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (cboDatastores.SelectedIndex < 0) { MessageBox.Show("请选择数据存储", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string vmName = txtVmName.Text; if (string.IsNullOrWhiteSpace(vmName)) { MessageBox.Show("请输入虚拟机名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { Cursor = Cursors.WaitCursor; VirtualMachine template = (VirtualMachine)templates[cboTemplates.SelectedIndex]; HostSystem targetHost = (HostSystem)esxiHosts[cboHosts.SelectedIndex]; Datastore targetDatastore = datastores[cboDatastores.SelectedIndex]; // 创建克隆规范 VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec(); cloneSpec.Location = new VirtualMachineRelocateSpec(); cloneSpec.Location.Datastore = targetDatastore.MoRef; cloneSpec.Location.Host = targetHost.MoRef; cloneSpec.Location.Pool = ((ComputeResource)client.GetView(targetHost.Parent, null)).ResourcePool; cloneSpec.PowerOn = false; cloneSpec.Template = false; // 查找虚拟机文件夹 // 获取数据中心和文件夹 Datacenter dc = (Datacenter)client.GetView(template.Parent, null); Folder vmFolder = (Folder)client.GetView(dc.VmFolder, null); ManagedObjectReference[] childEntity = vmFolder.ChildEntity; foreach (ManagedObjectReference mor in childEntity) { if (mor.Type == "Folder") { vmFolder = (Folder)client.GetView(mor, null); break; } } // 执行克隆 ManagedObjectReference reference = template.CloneVM_Task(vmFolder.MoRef, vmName, cloneSpec); client.WaitForTask(reference); // 获取任务状态 VMware.Vim.Task taskInfo = (VMware.Vim.Task)client.GetView(reference, null); if (taskInfo.Info.State == TaskInfoState.success) { UpdateStatus($"成功从模板 '{template.Name}' 克隆虚拟机 '{vmName}' 到主机 '{targetHost.Name}'"); MessageBox.Show($"成功从模板 '{template.Name}' 克隆虚拟机 '{vmName}' 到主机 '{targetHost.Name}'", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); // 重新加载虚拟模板 LoadTemplates(); } else { UpdateStatus($"克隆虚拟机失败: {taskInfo.Info.Error.LocalizedMessage}"); MessageBox.Show($"克隆虚拟机失败: {taskInfo.Info.Error.LocalizedMessage}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { UpdateStatus($"克隆虚拟机时出错: {ex.Message}"); MessageBox.Show($"克隆虚拟机时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } }Folder vmFolder = (Folder)client.GetView(dc.VmFolder, null);{"无法将类型为“VMware.Vim.Folder”的对象强制转换为类型“VMware.Vim.Datacenter”。"}
最新发布
07-23
fn run_kvm(device_path: Option<&Path>, cfg: Config, components: VmComponents) -> Result<ExitState> { use devices::KvmKernelIrqChip; #[cfg(target_arch = "x86_64")] use devices::KvmSplitIrqChip; use hypervisor::kvm::Kvm; use hypervisor::kvm::KvmVcpu; use hypervisor::kvm::KvmVm; let device_path = device_path.unwrap_or(Path::new(KVM_PATH)); let kvm = Kvm::new_with_path(device_path) .with_context(|| format!("failed to open KVM device {}", device_path.display()))?; let guest_mem = create_guest_memory(&cfg, &components, &kvm)?; #[cfg(feature = "swap")] let swap_controller = if let Some(swap_dir) = cfg.swap_dir.as_ref() { Some( SwapController::launch(guest_mem.clone(), swap_dir, &cfg.jail_config) .context("launch vmm-swap monitor process")?, ) } else { None }; let vm = KvmVm::new(&kvm, guest_mem, components.hv_cfg).context("failed to create vm")?; #[cfg(target_arch = "x86_64")] if cfg.itmt { vm.set_platform_info_read_access(false) .context("failed to disable MSR_PLATFORM_INFO read access")?; } // Check that the VM was actually created in protected mode as expected. if cfg.protection_type.isolates_memory() && !vm.check_capability(VmCap::Protected) { bail!("Failed to create protected VM"); } let vm_clone = vm.try_clone().context("failed to clone vm")?; enum KvmIrqChip { #[cfg(target_arch = "x86_64")] Split(KvmSplitIrqChip), Kernel(KvmKernelIrqChip), } impl KvmIrqChip { fn as_mut(&mut self) -> &mut dyn IrqChipArch { match self { #[cfg(target_arch = "x86_64")] KvmIrqChip::Split(i) => i, KvmIrqChip::Kernel(i) => i, } } } let ioapic_host_tube; let mut irq_chip: KvmIrqChip = match cfg.irq_chip.unwrap_or(IrqChipKind::Kernel) { IrqChipKind::Userspace => { bail!("KVM userspace irqchip mode not implemented"); } IrqChipKind::Split => { #[cfg(not(target_arch = "x86_64"))] bail!("KVM split irqchip mode only supported on x86 processors"); #[cfg(target_arch = "x86_64")] { let (host_tube, ioapic_device_tube) = Tube::pair().context("failed to create tube")?; ioapic_host_tube = Some(host_tube); KvmIrqChip::Split( KvmSplitIrqChip::new( vm_clone, components.vcpu_count, ioapic_device_tube, Some(24), ) .context("failed to create IRQ chip")?, ) } } IrqChipKind::Kernel => { ioapic_host_tube = None; KvmIrqChip::Kernel( KvmKernelIrqChip::new(vm_clone, components.vcpu_count) .context("failed to create IRQ chip")?, ) } }; run_vm::<KvmVcpu, KvmVm>( cfg, components, vm, irq_chip.as_mut(), ioapic_host_tube, #[cfg(feature = "swap")] swap_controller, ) }
07-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值