如何将 Solaris Container 从一个 zfs 文件系统移动到同一服务器上的另一个文件系统?

pau*_*ken 5 solaris

这似乎是一件简单的事情,如果它只能按照文档工作。但是,由于 zoneadm 移动过程中的一些错误,它不起作用。去搞清楚。首先让我展示一下琐碎的文档所说的内容:

http://docs.oracle.com/cd/E19455-01/817-1592/gcgnc/index.html
Run Code Online (Sandbox Code Playgroud)

那就是说将非全局区域从一个地方移动到同一服务器上的另一个地方的命令只是

zoneadm -z zonename move /some/new/pathname
Run Code Online (Sandbox Code Playgroud)

这看起来非常琐碎......但是,如果非全局区域中有任何内容,其中目录在文件名中具有特殊(并非完全平凡的 ascii )字符,那么该过程就会失败。请允许我演示:

第一步:关闭区域。确保它因此停止:

# zlogin -C -e\@ z_001
[Connected to zone 'z_001' console]

node002 console login: root
Password: 
Last login: Sun Jul 21 05:12:17 on console
Jul 25 17:50:06 node002 login: ROOT LOGIN /dev/console
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
node002-sparc-SunOS5.10 # shutdown -g0 -y -i0    

Shutdown started.    Thu Jul 25 17:51:06 GMT 2013

Changing to init state 0 - please wait
Broadcast Message from root (console) on node002 Thu Jul 25 17:51:07...
THE SYSTEM node002 IS BEING SHUT DOWN NOW ! ! !
Log off now or risk your files being damaged

node002-sparc-SunOS5.10 # showmount: node002: RPC: Program not registered
svc.startd: The system is coming down.  Please wait.
svc.startd: 70 system services are now being stopped.
syslogd: /dev/sysmsg: I/O error
svc.startd: The system is down.

[NOTICE: Zone halted]
@.
[Connection to zone 'z_001' console closed]
#
Run Code Online (Sandbox Code Playgroud)

太好了 .. 现在是 zoneadm 移动:

# zoneadm -z z_001 move /zones/z_001
Moving across file-systems; copying zonepath /zone/z_001...zoneadm: zone 'z_001': 'copy' failed with exit code 5.

The copy failed.
More information can be found in /var/log/zoneAAAcwaOwX

Cleaning up zonepath /zones/z_001...

# 
Run Code Online (Sandbox Code Playgroud)

失败的?让我们看看为什么:

# cat  /var/log/zoneAAAcwaOwX
cpio: Error with fstatat() of "", errno 2, No such file or directory
cpio: Error with fstatat() of "root/usr/local/build/automake-1.13_SunOS5.10_sparcv9/t/instspc.dir/a", errno 2, No such file or directory
cpio: Cannot open directory b, errno 2, No such file or directory
cpio: Error with fstatat() of "root/usr/local/build/automake-1.13_SunOS5.10_sparcv9/t/instspc.dir/a", errno 2, No such file or directory
cpio: Error with fstatat() of "b", errno 2, No such file or directory
62026208 blocks
5 error(s)
# 
Run Code Online (Sandbox Code Playgroud)

失败,因为 cpio( zoneadm move 使用的东西)无法处理特殊字符。如果下载 GNU automake 源 tarball 并进行配置,然后使用 make 检查进行 make,您将在 testsuite 区域内看到成堆的特殊字符。这将导致 Solaris 上的 cpio 崩溃。

所以我希望有一些 Solaris 大师可以为我确认两件事:

1) the only zone config file I need to edit is in /etc/zones
2) I can edit that one file myself and do the move of the zone 
    filesystem myself also. 
Run Code Online (Sandbox Code Playgroud)

我对么 ?

编辑----这是cpio无法正确处理的目录和字符:

# ls -lapb /zone/z_001/root/usr/local/build/automake-1.13_SunOS5.10_sparcv9/t/instspc.dir
total 1398
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 `/
drwxr-xr-x   2 gnuism  other          2 Dec 31  2012 \012/
drwxr-xr-x  64 gnuism  other         74 Dec 31  2012 ./
drwxr-xr-x  42 gnuism  other       4045 Dec 31  2012 ../
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 '/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 "/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 $/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 \/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 &/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 #/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 a\012b/
-rw-r--r--   1 gnuism  other      38455 Dec 31  2012 aclocal.m4
lrwxrwxrwx   1 gnuism  other         59 Dec 31  2012 ar-lib -> /usr/local/build/automake-1.13_SunOS5.10_sparcv9/lib/ar-lib
drwxr-xr-x   2 gnuism  other          7 Dec 31  2012 autom4te.cache/
drwxr-xr-x   3 gnuism  other          6 Dec 31  2012 build-a_lf_b/
.
.
.
drwxr-xr-x   2 gnuism  other          2 Dec 31  2012 dest-tab/
drwxr-xr-x   2 gnuism  other          2 Dec 31  2012 dest-tilde/
-rwxr-xr-x   1 gnuism  other      13997 Dec 31  2012 install-sh
-rw-r--r--   1 gnuism  other       1395 Dec 31  2012 Makefile.am
-rw-r--r--   1 gnuism  other      39656 Dec 31  2012 Makefile.in
-rwxr-xr-x   1 gnuism  other       6873 Dec 31  2012 missing
-rw-r--r--   1 gnuism  other         49 Dec 31  2012 source.c
drwxr-xr-x   2 gnuism  other          8 Dec 31  2012 sub/
drwxr-xr-x   2 gnuism  other          3 Dec 31  2012 @&t@/
# 
Run Code Online (Sandbox Code Playgroud)

来自 OP 的注释:太糟糕了 OpenSolaris 项目被 Oracle 终止了,因为我们很容易看到 zoneadm 如何调用使用 cpio 并将其更改为使用远未完成任务的东西。我通过自己进行移动解决了这个问题,并使用了 Jörg Schilling 的“star”或 POSIX Standard TAR 来进行 zonemove。

Solution : 

    1 - Manually do the copy with a better tool from the source to dest. 

        1.1 - get sources for star from ftp://ftp.berlios.de/pub/schily/
        1.2 - extract them
        1.3 - cd into the extracted star sources and run /usr/xpg4/bin/make
        1.4 - once that ends just run /usr/xpg4/bin/make install 

        you now have star and it can handle anything that lives on a filesystem

        1.5 - do a copy from source to dest path with star 

            /opt/schily/bin/star -copy -p -acl -sparse -dump -C source . dest

    2 - cd to /etc/zones and edit the zonefile xml to use the new zonepath

    3 - edit the "index" file in /etc/zones to use the new zonepath

Special Detail to note : 

    1 - if you edit the zone XML file but do not edit the zonepath in the 
        index file you will get a warning message when you try to boot the zone : 

        # zoneadm -z z_001 boot 
        The XML repository has zonepath '/z/001',
        but the index file has zonepath '/zone/z_001'.
        These must match, so fix the incorrect entry.
Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 2

替代方案:通过 ZFS 进行复制,然后更改区域路径。

使用您的参数:

  • 区域名称:z_001
  • 旧 zpool 名称:zone
  • 新 zpool 名称:zones
  • 区域位于 ZFS 文件系统 zone/z_001 上

我们有以下程序:

  1. 关闭该区域。
  2. 拍摄其 ZFS 文件系统的快照:zfs snapshot zone/z_001@premove
  3. 传输快照:zfs send zone/z_001@premove | zfs recv zones/z_001
  4. 分离区域:zoneadm -z z_001 detach
  5. 更改路径:zonecfg -z z_001 set zonepath=/zones/z_001
  6. 重新连接区域:zoneadm -z z_001 attach
  7. 启动区域。

步骤 4-6 为您更改 /etc/zones/index。

您不必关闭该区域;您可以拍摄并发送快照,然后将其关闭,然后拍摄并发送第二个快照,该快照将是增量的且更小且更快:zfs send -i zone/z_001@premove zone/z_001@snap2 | zfs recv zones/z_001

您最终也会在目标 zpool 上获得一个快照,您可以根据需要保留或删除该快照。