将jail从ezjail迁移到iocage
由于以前的jail都是用ezjail创建和管理的,需要全部迁移到iocage下面。
下面以nc(ezjail下面创建并维护的一个jail,里面有nextcloud)为例。
使用iocage创建空jail
# iocage create -e -n nc
- -e, --empty
创建空jail
- -n, --name TEXT
指定jail名称
查看建好的空jail:
# iocage list
+-----+------+-------+--------------+---------------+
| JID | NAME | STATE | RELEASE | IP4 |
+=====+======+=======+==============+===============+
| 9 | emby | up | 13.1-RELEASE | 192.168.0.121 |
+-----+------+-------+--------------+---------------+
| - | nc | down | EMPTY | - |
+-----+------+-------+--------------+---------------+
# cd /zroot/iocage/jails/nc
# ls
config.json fstab root
config.json内容如下:
{
"cloned_release": "EMPTY",
"host_hostname": "nc",
"host_hostuuid": "nc",
"jail_zfs_dataset": "iocage/jails/nc/data",
"release": "EMPTY"
}
fstab文件为空,root目录为空。
复制旧数据
由于ezjail管理jail采用软链接将bin指向basejail/bin,以保证jail能正常运行。例如:
# ls -ls /zroot/ezjail/nc/bin
1 lrwxr-xr-x 1 root wheel 13 7月 19 08:17 /zroot/ezjail/nc/bin -> /basejail/bin
但是对于宿主机,这种软链接是无法直接复制的。在宿主机创建软链接指向ezjail的basejail:
# ln -s /usr/jails/basejail /basejail
然后就可以使用以下命令将要迁移的jail从ezjail的目录复制到iocage的jail目录:
# rsync -a --copy-links /zroot/ezjail/nc/ /zroot/iocage/jails/nc/root/
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/45-latin.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/45-generic.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/50-user.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/40-nonlatin.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/60-generic.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/60-latin.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/65-nonlatin.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/30-metric-aliases.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/20-unhint-small-vera.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/90-synthetic.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/65-fonts-persian.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/10-scale-bitmap-fonts.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/10-hinting-slight.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/51-local.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/80-delicious.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/49-sansserif.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/local/etc/fonts/conf.d/69-unifont.conf"
symlink has no referent: "/zroot/ezjail/nc/usr/tests/local"
rsync: [sender] readlink_stat("/zroot/ezjail/nc/usr/tests/sys/pjdfstest/tests/tests/tests
/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests
/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests/tests")
failed: Too many levels of symbolic links (62)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at
main.c(1347) [sender=3.2.4]
前面几行应该是链接失效,后面/zroot/ezjail/nc/usr/tests/sys/pjdfstest/目录下的tests指向它自己,似乎是个死循环。
另,rsync的-a选项为归档模式,包含-rlptgoD选项(没有-A、-X、-U、-N、-H);--copy-links表示将符号链接转换为file/dir。
# cd /zroot/ezjail/nc/usr/local/etc/fonts/conf.d
# ls -ls
total 14
1 lrwxr-xr-x 1 root wheel 54 7月 3 13:04 10-hinting-slight.conf -> /usr/local/etc/fonts/conf.avail/10-hinting-slight.conf
1 lrwxr-xr-x 1 root wheel 58 7月 3 13:04 10-scale-bitmap-fonts.conf -> /usr/local/etc/fonts/conf.avail/10-scale-bitmap-fonts.conf
1 lrwxr-xr-x 1 root wheel 57 7月 3 13:04 20-unhint-small-vera.conf -> /usr/local/etc/fonts/conf.avail/20-unhint-small-vera.conf
1 lrwxr-xr-x 1 root wheel 54 7月 3 13:04 30-metric-aliases.conf -> /usr/local/etc/fonts/conf.avail/30-metric-aliases.conf
1 lrwxr-xr-x 1 root wheel 48 7月 3 13:04 40-nonlatin.conf -> /usr/local/etc/fonts/conf.avail/40-nonlatin.conf
1 lrwxr-xr-x 1 root wheel 47 7月 3 13:04 45-generic.conf -> /usr/local/etc/fonts/conf.avail/45-generic.conf
1 lrwxr-xr-x 1 root wheel 45 7月 3 13:04 45-latin.conf -> /usr/local/etc/fonts/conf.avail/45-latin.conf
1 lrwxr-xr-x 1 root wheel 49 7月 3 13:04 49-sansserif.conf -> /usr/local/etc/fonts/conf.avail/49-sansserif.conf
1 lrwxr-xr-x 1 root wheel 44 7月 3 13:04 50-user.conf -> /usr/local/etc/fonts/conf.avail/50-user.conf
1 lrwxr-xr-x 1 root wheel 45 7月 3 13:04 51-local.conf -> /usr/local/etc/fonts/conf.avail/51-local.conf
1 lrwxr-xr-x 1 root wheel 47 7月 3 13:04 60-generic.conf -> /usr/local/etc/fonts/conf.avail/60-generic.conf
1 lrwxr-xr-x 1 root wheel 45 7月 3 13:04 60-latin.conf -> /usr/local/etc/fonts/conf.avail/60-latin.conf
1 lrwxr-xr-x 1 root wheel 53 7月 3 13:04 65-fonts-persian.conf -> /usr/local/etc/fonts/conf.avail/65-fonts-persian.conf
1 lrwxr-xr-x 1 root wheel 48 7月 3 13:04 65-nonlatin.conf -> /usr/local/etc/fonts/conf.avail/65-nonlatin.conf
1 lrwxr-xr-x 1 root wheel 47 7月 3 13:04 69-unifont.conf -> /usr/local/etc/fonts/conf.avail/69-unifont.conf
1 lrwxr-xr-x 1 root wheel 33 7月 3 13:04 70-yes-bitmaps.conf -> ../conf.avail/70-yes-bitmaps.conf
1 lrwxr-xr-x 1 root wheel 49 7月 3 13:04 80-delicious.conf -> /usr/local/etc/fonts/conf.avail/80-delicious.conf
1 lrwxr-xr-x 1 root wheel 49 7月 3 13:04 90-synthetic.conf -> /usr/local/etc/fonts/conf.avail/90-synthetic.conf
5 -rw-r--r-- 1 root wheel 978 7月 3 13:04 README
实际上这些软链接都是指向它们上一层的conf.avail目录中的文件。同样,执行以下命令在宿主机创建对应的软链接:
# ln -s /zroot/ezjail/nc/usr/local/etc/fonts /usr/local/etc/fonts
然后再执行rsync命令同步两边的目录。但依然未能解决tests/local的死循环问题,但似乎不影响最终结果。
修改config.json文件,根据实际情况修改两个参数:
另外,可以加上【"boot": 1,】以另此jail可以自动启动。
以上修改jail属性的操作也可以通过命令来执行:
# iocage set ip4_addr="em0|192.168.0.117/24" boot=1 nc
启用新jail
首先要停掉旧的jail以释放IP地址,然后再启动新jail:
# ezjail-admin stop nc
Stopping jails: nc.
# iocage start nc
* Starting nc
+ Started OK
+ Using devfs_ruleset: 1001 (iocage generated default)
+ Using IP options: ip4.addr=em0|192.168.0.117 ip4.saddrsel=1 ip4=new ip6.saddrsel=1 ip6=new
+ Starting services OK
+ Executing poststart OK
# iocage list
+-----+------+-------+--------------+---------------+
| JID | NAME | STATE | RELEASE | IP4 |
+=====+======+=======+==============+===============+
| 9 | emby | up | 13.1-RELEASE | 192.168.0.121 |
+-----+------+-------+--------------+---------------+
| 26 | nc | up | 13.1-RELEASE | 192.168.0.117 |
+-----+------+-------+--------------+---------------+
验证jail迁移成功后即可删除ezjail中的jail了。
更新fstab
如果ezjail中要迁移的jail的fstab文件有特殊设置,比如下面这样的:
# more /etc/fstab.bt
/usr/jails/basejail /ztemp/ezjail/bt/basejail nullfs ro 0 0
/ztemp/bt /ztemp/ezjail/bt/bt nullfs rw 0 0
第一行的basejail在iocage不需要,只要将第二行的内容复制到新jail的fstab文件中并作适当修改:
/ztemp/bt /zroot/iocage/jails/bt/root/bt nullfs rw 0 0
注意:
- /zroot/iocage/jails/bt/root/bt目录需要手动创建
- 修改完成后重启jail可能会提示不成功,再启动一次应该就可以了
收尾
完成迁移后需要删除掉前面曾经创建的两个链接。
/basejail这个可以先保留,以便迁移其他jail时使用,等全部迁移完毕就可以删除了。