我正在编写一个 bash 命令来在名为 chroot 的内部部署 gluster格鲁斯特根。我在将文件从主机挂载到 chroot 时遇到问题。 Schroot 的手册页建议如下:
$ man schroot.conf | grep -A4 setup.fstab=
setup.fstab=filename
The filesystem table file to be used to mount filesystems within the chroot. The format of this file is the same as for /etc/fstab, documented in fstab(5). The only difference is
that the mountpoint path fs_dir is relative to the chroot, rather than the root. Also note that mountpoints are canonicalised on the host, which will ensure that absolute symlinks
point inside the chroot, but complex paths containing multiple symlinks may be resolved incorrectly; it is inadvisable to use nested symlinks as mountpoints.
但是当我尝试在 中使用此配置值时/etc/schroot/chroot.d/glusterchroot.conf
,目录似乎没有安装。我还需要添加其他内容才能使其正常工作吗?
配置
内容/etc/schroot/chroot.d/glusterchroot.conf
:
user@computer:~$ cat /etc/schroot/chroot.d/glusterchroot.conf
#
#
[glusterchroot]
description=Gluster server chroot
directory=/srv/glusterchroot
root-users=root
setup.fstab=glusterchroot/fstabfile
root-groups=root
内容/etc/schroot/glusterchroot/fstabfile
:
user@computer:~$ cat /etc/schroot/glusterchroot/fstabfile
/run/udev /run/udev none bind,create=file 0 0
sys /sys sysfs defaults 0 1
proc /proc proc defaults 0 0
/dev/ /dev none bind,create=file 0 0
/run/lvm /run/lvm none bind,create=file 0 0
/run/udev /run/udev none bind,create=file 0 0
glusterchroot 信息:
user@computer:~$ schroot -i -c glusterchroot
─── Chroot ───
Name glusterchroot
Description Gluster server chroot
Type plain
Message Verbosity normal
Users
Groups
Root Users root
Root Groups root
Aliases
Preserve Environment false
Default Shell
Environment Filter ^(BASH_ENV|CDPATH|ENV|HOSTALIASES|IFS|KRB5_CONFIG|KRBCONFDIR|KRBTKFILE|KRB_CONF|LD_.*|LOCALDOMAIN|NLSPATH|PATH_LOCALE|RES_OPTIONS|TERMINFO|TERMINFO_DIRS|TERMPATH)$
Run Setup Scripts false
Configuration Profile default
Script Configuration
Session Managed false
Session Cloned false
Session Purged false
Path /srv/glusterchroot
Directory /srv/glusterchroot
Personality undefined
User Modifiable Keys
Root Modifiable Keys
User Data
setup.config default/config
setup.copyfiles default/copyfiles
setup.fstab glusterchroot/fstabfile
setup.nssdatabases default/nssdatabases
请注意,我也尝试过使用默认值setup.fstab
,其中/etc/schroot/default/fstab
也存在下面所述的相同问题。
问题
ls
chroot 中挂载的目录:
user@computer:~$ sudo schroot -d / -c glusterchroot -- ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
user@computer:~$ sudo schroot -d / -c glusterchroot -- ls /proc
user@computer:~$ sudo schroot -d / -c glusterchroot -- ls /run
lock mount
user@computer:~$ sudo schroot -d / -c glusterchroot -- ls /sys
需要这些安装的命令示例:
user@computer:~$ sudo schroot -d / -c glusterchroot -- findmnt
findmnt: can't read /proc/mounts: No such file or directory
ls
来自主机的相同目录:
user@computer:~/Documents/gitRepos/generalK8s/glusterchroot$ ls /proc
1 1186 188 233 2541 2719 2864 3548 4 503 76879 903 96 driver mdstat thread-self
10 12 19 2334 2551 2720 2909 3549 40 506 777 90370 96493 dynamic_debug meminfo timer_list
100 1223 192 2338 2557 2721 2941 3551 404 507 778 904 96522 execdomains misc tty
101 124 1942 234 2561 2722 2965 3565 41 508 782 905 96847 fb modules uptime
1017 1254 1964 2344 2570 2723 2997 35710 4194 59014 784 906 97 filesystems mounts version
1019 1266 197 2362 2579 2724 3 3581 42 59433 787 907 98 fs mtrr version_signature
103 127 2 2366 2580 2725 30 3593 43 59435 788 910 99 interrupts net vmallocinfo
1032 13 20 24 2589 2726 3049 36 435 59541 8 913 acpi iomem pagetypeinfo vmstat
1047 135 21 2427 26 2728 3052 3613 4358 6 83498 914 asound ioports partitions zoneinfo
105 14 22 2444 2664 2737 3057 3629 4380 60307 86954 915 bootconfig irq pressure
106 15 2268 2477 2668 2743 3075 3639 44 60565 87016 91540 buddyinfo kallsyms schedstat
109 157 2281 2484 2678 2747 31 3640 4417 60773 87483 916 bus kcore scsi
11 16 2282 2487 2683 2748 3124 367 4498 68293 87490 917 cgroups keys self
110 1777 2288 25 2699 2785 32 3676 45 68316 87498 919 cmdline key-users slabinfo
1110 18 2289 2500 27 28 3220 37 471 70459 877 92 consoles kmsg softirqs
1111 1827 2290 2517 2701 2811 3234 3757 4792 75503 880 920 cpuinfo kpagecgroup stat
113 1848 2300 2524 2712 2812 3265 3768 4824 76661 881 922 crypto kpagecount swaps
114 185 2310 2525 2714 282 33 3784 4835 76738 883 93 devices kpageflags sys
115 186 2321 2532 2716 2821 34 38 4842 76855 884 93656 diskstats loadavg sysrq-trigger
1184 187 2329 2537 2717 2830 3545 39 5 76873 89805 94 dma locks sysvipc
user@computer:~/Documents/gitRepos/generalK8s/glusterchroot$ ls /sys
block bus class dev devices firmware fs hypervisor kernel module power
user@computer:~/Documents/gitRepos/generalK8s/glusterchroot$ ls /run
acpid.pid crond.pid docker.sock log openvpn-client screen spice-vdagentd udev
acpid.socket crond.reboot fsck lvm openvpn-server sendsigs.omit.d sshd udisks2
alsa cups gdm3 motd.d plymouth shm sshd.pid user
avahi-daemon dbus gdm3.pid mount pppconfig sm-notify.pid sudo utmp
blkid dmeventd-client initctl netns rpcbind snapd systemd uuidd
console-setup dmeventd-server initramfs network rpcbind.lock snapd-snap.socket thermald vpnagentd.pid
containerd docker irqbalance NetworkManager rpcbind.sock snapd.socket tmpfiles.d wpa_supplicant
credentials docker.pid lock openvpn rpc_pipefs speech-dispatcher ubuntu-advantag
答案1
这里的线索就Run Setup Scripts false
在 的输出中schroot -i -c glusterchroot
。如果您阅读,man schroot.conf
您将看到以下行:
type=type
The type of the chroot. Valid types are ‘plain’, ‘directory’, ‘file’, ‘loopback’, ‘block-device’, ‘btrfs-snapshot’, ‘zfs-snapshot’ and ‘lvm-snapshot’. If empty or omitted, the de‐
fault type is ‘plain’. Note that ‘plain’ chroots do not run setup scripts and mount filesystems; ‘directory’ is recommended for normal use (see “Plain and directory chroots”, below).
一旦我更新/etc/schroot/chroot.d/glusterchroot.conf
到以下我的问题就解决了:
[glusterchroot]
description=Gluster server chroot
preserve-environment=true
directory=/srv/glusterchroot
root-users=root
personality=linux
setup.fstab=default/fstab
type=directory
root-groups=root