再起動せずにchroot後にsys/fs/cgroup/systemdを削除する

再起動せずにchroot後にsys/fs/cgroup/systemdを削除する

背景:ZFS-onを有効にするために、サムドライブ(「ソースドライブ」)からZFSフォーマットドライブ(「ターゲットドライブ」)に通常のLVM-on-LUKS Debian 9(「Stretch」)インストールをコピーする方法を探しています。 -LUKSのインストール。私のプロセスは以下に基づいています。このガイド.* ZFSの側面は、私が解決しようとしている問題とは関係がないと思いますが、重要な場合に備えて言及しています。

プロセスの一部としてソースドライブからStretchを実行するときは、/ターゲットZFSルート()ファイルシステムをマウントします/mnt。その後、再帰的にバインドします。

  • /dev到着/mnt/dev
  • /proc到着/mnt/proc
  • /sys到着する/mnt/sys

それから/mnt

(後でchrootするときなどを実行してパーティションの内容を構成する/mnt予定です。)update-initramfsupdate-grub/boot

それからやめ、chroot問題が始まりました。削除できることがわかり/mnt/devました/mnt/procしかし、/mnt/sys。後者は、/mnt/sys/fs/cgroup/systemdシステムが何らかの理由で「使用中」であると考えるものを含んでいるため、削除を拒否します。 ZFSドライブを再フォーマットして再起動することで問題は解決しましたが、学習と文書化プロセスの繰り返し速度が大幅に遅くなりました。

私の質問は次のとおりです

-/mnt/sys再起動せずにchroot後に削除する方法は?

- umount: /mnt/sys/fs/cgroup/systemd: target is busyfailure() は予想されますか?それ以外の場合は、どのソフトウェアに対してバグレポートを送信する必要がありますか?削除cgroupシステム、これLinuxカーネル、または他のものか。

これは(私の考えでは)最小限の作業例。 (これを再現するのが難しく、私が1つのステップを逃したと思ったら教えてください。)まず、定型句は次のようになります。

# Activate the ZFS kernel module
/sbin/modprobe zfs

# Set variables
BOOT_POOL=bpool
ROOT_POOL=rpool
DIRS_TO_COPY=(boot bin etc home lib lib64 opt root sbin srv usr var)
FILES_TO_COPY=(initrd.img initrd.img.old vmlinuz vmlinuz.old)
VIRTUAL_FILESYSTEM_DIRS=(dev proc sys)

## Partition target drive
# 1MB BIOS boot partition
sgdisk -a2048 -n1:2048:4095     -t1:EF02 $1 -c 1:"bios_boot_partition"
wait
# 510MB partition for /boot ZFS filesystem
sgdisk -a2048 -n2:4096:1052671  -t2:BF07 $1 -c 2:"zfs_boot_partition"
wait
# Remaining drive space, except the last 510MiB in case of future need:
# partition to hold the LUKS container and the root ZFS filesystem
sgdisk -a2048 -n3:1052672:-510M -t3:8300 $1 -c 3:"luks_zfs_root_partition"
wait

# Before proceeding, ensure /dev/disk/by-id/ knows of these new partitions
partprobe
wait

# Create the /boot pool
zpool create -o ashift=12            \
             -O atime=off            \
             -O canmount=off         \
         -O compression=lz4      \
         -O normalization=formD  \
             -O mountpoint=/boot     \
             -R /mnt                 \
             $BOOT_POOL "$1"-part2
wait

# Create the LUKS container for the root pool
cryptsetup luksFormat "$1"-part3               \
                      --hash sha512            \
                      --cipher aes-xts-plain64 \
              --key-size 512
wait

# Open LUKS container that will contain the root pool
cryptsetup luksOpen "$1"-part3 "$DRIVE_SHORTNAME"3_crypt
wait

# Create the root pool
zpool create -o ashift=12           \
             -O atime=off           \
             -O canmount=off        \
             -O compression=lz4     \
             -O normalization=formD \
             -O mountpoint=/        \
             -R /mnt                \
             $ROOT_POOL /dev/mapper/"$DRIVE_SHORTNAME"3_crypt
wait

# Create ZFS datasets for the root ("/") and /boot filesystems
zfs create -o canmount=noauto -o mountpoint=/      "$ROOT_POOL"/debian
zfs create -o canmount=noauto -o mountpoint=/boot  "$BOOT_POOL"/debian

# Mount the root ("/") and /boot ZFS datasets
zfs mount "$ROOT_POOL"/debian
zfs mount "$BOOT_POOL"/debian

# Create datasets for subdirectories
zfs create                     -o setuid=off              "$ROOT_POOL"/home
zfs create -o mountpoint=/root                            "$ROOT_POOL"/home/root
zfs create -o canmount=off     -o setuid=off  -o exec=off "$ROOT_POOL"/var
zfs create -o com.sun:auto-snapshot=false                 "$ROOT_POOL"/var/cache
zfs create                                                "$ROOT_POOL"/var/log
zfs create                                                "$ROOT_POOL"/var/mail
zfs create                                                "$ROOT_POOL"/var/spool
zfs create -o com.sun:auto-snapshot=false     -o exec=on  "$ROOT_POOL"/var/tmp
zfs create                                                "$ROOT_POOL"/srv
zfs create -o com.sun:auto-snapshot=false     -o exec=on  "$ROOT_POOL"/tmp

# Set the `bootfs` property. ***TODO: IS THIS CORRECT???***
zpool set bootfs="$ROOT_POOL"/debian "$ROOT_POOL"

# Set correct permission for tmp directories
chmod 1777 /mnt/tmp
chmod 1777 /mnt/var/tmp

これが問題の重要な部分です。

# Copy Debian install from source drive to target drive
for i in "${DIRS_TO_COPY[@]}"; do 
    rsync --archive --quiet --delete /"$i"/ /mnt/"$i"
done
for i in "${FILES_TO_COPY[@]}"; do
    cp -a /"$i" /mnt/
done
for i in "${VIRTUAL_FILESYSTEM_DIRS[@]}"; do
    # Make mountpoints for virtual filesystems on target drive
    mkdir /mnt/"$i"
    # Recursively bind the virtual filesystems from source environment to the
    # target. N.B. This is using `--rbind`, not `--bind`.
    mount --rbind /"$i"  /mnt/"$i"
done

# `chroot` into the target environment
chroot /mnt /bin/bash --login

# (Manually exit from the chroot)

# Delete copied files
for i in "${DIRS_TO_COPY[@]}" "${FILES_TO_COPY[@]}"; do
    rm -r /mnt/"$i"
done

# Remove recursively bound virtual filesystems from target
for i in "${VIRTUAL_FILESYSTEM_DIRS[@]}"; do
    # First unmount them
    umount --recursive --verbose --force /mnt/"$i" || sleep 0
    wait
    # Then delete their mountpoints
    rmdir /mnt/"$i"
    wait
done

最後のステップで、次のようになります。

umount: /mnt/sys/fs/cgroup/systemd: target is busy
    (In some cases useful info about processes that
     use the device is found by lsof(8) or fuser(1).)

役に立つ場合:findmntインストールsysツリー全体を2回表示します(一度はに/sys、一度は)/mnt/sys

*ZFSのDebian Jessie Root、CC-SA 3.0、リチャードラージ、ジョージメリコフ

ベストアンサー1

mount --make-rslave /mnt/"$i"これらのマウントポイントに正しい伝播フラグが設定されるように、最初のマウントコマンドの後にそれを追加する必要があります。

chroot環境内で行われた変更からホストを保護し、あなたなどのブロック状況を防ぐのに役立ちます。

おすすめ記事