Clone ZFS-based Solaris xVM domain

本文介绍如何使用ZFS文件系统的快照功能来快速克隆带有相同配置的域。通过关闭源域并创建其根磁盘的快照,然后制作一个可写的克隆,可以高效地复制出几乎相同的域配置,且仅占用实际变化部分的存储空间。
 

Introduction

If you're using a ZFS volume as the root disk for a domain, you can make use of the snapshotting facilities to quickly "clone" another domain with the same configuration. By taking a clone of the root disk, you can very quickly provision similar domains, and even better, the nature of the clone means the only extra storage used is that of the differences between the domains.We're working on ways of automating this procedure, but for now these are the steps you'll need to take.

Step-by-step

First, we need to shutdown the domain we're cloning so we can take a consistent snapshot of the disk:

xm shutdown -w domain1

Alternatively, you might want to do a sys-unconfig in the domain so the new clone will come up with the configuration screens.

Now we take a snapshot of the root disk used by 'domain1', and then a clone (writable snapshot) :

zfs snapshot pool/domain1-root@clone
zfs clone pool/domain1-root@clone pool/domain2-root

If you now do a zfs list, you should see the snapshot and clone present, and using next to no additional disk space. For our last step, we need to duplicate domain1's configuration. First dump the configuration to a file:

virsh dumpxml domain1 >domain1.xml
cp domain1.xml domain2.xml

You will need to make at least three changes. First, you will want a new name for your domain, so edit this line:

<name>domain1</name>

with the new name:

<name>domain2</name>

Second, you must remove the UUID line so virsh will generate a new domain configuration. Remove the line that looks like this:

<uuid>72bb96b6e6cf13594fb0cd1290610611</uuid>

Finally we have to point to the new disk by editing the following line:

<source dev='/dev/zvol/dsk/export/domain1-root'/>

to be:

<source dev='/dev/zvol/dsk/export/domain2-root'/>

Finally, tell virsh about the new domain:

virsh define domain2.xml

Now you can boot your cloned domain!

`git clone --local` 是 Git 提供的一个命令选项,用于从**本地文件系统中的另一个 Git 仓库**克隆出一个新的仓库副本。与通过网络(如 `https://` 或 `git@`)克隆不同,`--local` 表示使用本地磁盘上的路径进行克隆,这通常会更快,因为不需要网络传输。 ### 使用方式 ```bash git clone --local /path/to/local/repo /path/to/new/repo ``` 或者更常见的是,直接使用路径而无需显式写 `--local`,因为 Git 默认在检测到本地路径时会自动使用本地协议: ```bash git clone /path/to/local/repo ``` 但如果你希望**强制使用本地 Git 实现机制**(绕过硬链接等优化),可以显式加上 `--local`。 --- ### 示例:使用 `git clone --local` 假设你有一个本地的 Git 仓库位于 `/home/user/myproject/.git`,你想克隆它: ```bash git clone --local /home/user/myproject myproject-local-clone ``` 这会在当前目录下创建一个名为 `myproject-local-clone` 的新目录,并将原仓库的内容完整复制过去。 --- ### 关键选项说明 | 选项 | 含义 | |------|------| | `--local` | 使用本地文件系统优化策略(默认启用)。Git 可能使用硬链接来加快克隆速度。 | | `--no-hardlinks` | 禁用硬链接,强制复制所有文件,适用于需要完全独立副本的情况。 | 例如: ```bash git clone --local --no-hardlinks /home/user/myproject myproject-copy ``` 这个命令确保即使在同一个文件系统上也进行完整复制,避免共享数据。 --- ### 注意事项 1. **`--local` 是默认行为** 当你克隆一个本地路径时,Git 自动使用本地优化,所以 `--local` 通常是多余的。以下两个命令效果相同: ```bash git clone /path/to/repo git clone --local /path/to/repo ``` 2. **仅适用于本地路径** 不能对远程 URL 使用 `--local`: ```bash git clone --local https://github.com/user/repo.git # ❌ 错误 ``` 3. **安全性与权限** 克隆本地仓库时,需确保对源路径有读取权限。 4. **工作树 vs .git 目录** 如果源路径是一个带工作区的 Git 仓库(非裸仓库),`git clone` 会正常克隆代码和历史。如果是裸仓库(`.git` 文件夹本身),也可以克隆。 --- ### 对比:普通克隆 vs 本地克隆 | 类型 | 命令 | 特点 | |------|------|------| | 本地克隆 | `git clone /path/to/repo` | 快速,无网络,可能使用硬链接 | | 远程克隆 | `git clone https://...` | 需要网络,慢一些,安全验证 | | 强制非硬链接本地克隆 | `git clone --no-hardlinks /path/to/repo` | 安全独立副本 | --- ### 底层原理简述 当使用 `--local` 且未指定 `--no-hardlinks` 时,Git 在同一文件系统上可能会使用**硬链接**来连接对象数据库(`.git/objects` 中的文件),从而节省磁盘空间并加速克隆过程。这对于快速创建多个测试副本非常有用。 但如果你打算移动或删除原始仓库,请注意:如果使用了硬链接,删除原始对象文件可能导致克隆仓库损坏。因此,在备份或归档场景中建议使用: ```bash git clone --no-hardlinks /original/repo backup-repo ``` 以保证完整性。 --- ### 总结 `git clone --local` 是一种高效的克隆方式,适用于本地已有仓库的复制。虽然大多数情况下你可以省略 `--local`(Git 自动识别),但在脚本中明确写出有助于提高可读性和控制行为。 常用推荐命令: ```bash # 快速克隆(允许硬链接) git clone /path/to/local/repo fast-clone # 安全克隆(完全独立副本) git clone --no-hardlinks /path/to/local/repo safe-clone ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值