如何将 Solaris 容器从一个 zfs 文件系统移动到另一个 zfs 文件系统?

如何将 Solaris 容器从一个 zfs 文件系统移动到另一个 zfs 文件系统?

如果按照文档说明的那样工作,这似乎是一件简单的事情。但是,由于 zoneadm 移动过程中的一些错误,它无法工作。想想看。首先让我展示一下文档中的内容:

http://docs.oracle.com/cd/E19455-01/817-1592/gcgnc/index.html

好吧,这意味着在同一台服务器上将非全局区域从一个地方移动到另一个地方的命令只是

zoneadm -z zonename move /some/new/pathname

这看起来非常简单……但是,如果非全局区域中的内容包含目录,而文件名中包含特殊(并非完全简单的 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]
#

太好了...现在是 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...

# 

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

# 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)
# 

失败是因为 cpio(zoneadm move 使用的东西)无法处理特殊字符。如果下载 GNU automake 源 tarball 并执行 configure,然后使用 make check 进行 make,您将在测试套件区域内看到大量特殊字符。这将导致 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. 

我对么 ?

编辑——这是 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@/
# 

OP 的注释:OpenSolaris 项目被 Oracle 扼杀,这太糟糕了,因为我们很容易就能看到 zoneadm 如何调用 cpio,并将其更改为使用更适合该任务的更好的东西。我通过自己进行移动解决了这个问题,并使用 Jörg Schilling 的“star”或 POSIX 标准 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.

答案1

替代方案:通过 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 上的快照,您可以根据需要保留或删除它。

相关内容