démonter sys / fs / cgroup / systemd après chroot, sans redémarrer

Context: J'explore comment copyr une installation Debian 9 ("Stretch") LVM sur LUKS ordinaire à partir d'une key USB (le "lecteur source") sur un lecteur formaté ZFS (le "lecteur cible") afin de réaliser une installation ZFS-on-LUKS. Mon process est basé sur ce HOWTO . * Je pense que l'aspect ZFS est sans rapport avec la question que j'aimerais aider, mais je le mentionne au cas où cela count.

Dans le cadre de mon process, pendant que Stretch s'exécute à partir du lecteur source, je monte le système de files racine ( / ) ZFS cible sur /mnt . Je lie alors récursivement:

  • /dev à /mnt/dev
  • /proc à /mnt/proc
  • /sys à /mnt/sys .

Je chroote ensuite dans /mnt .

(Dans le futur, quand je suis chrooté dans /mnt , j'ai l'intention d'exécuter update-initramfs , update-grub , etc, pour configurer le contenu de la partition /boot ).

Je chroot alors le chroot , et mon problème commence. Je trouve que je peux démonter /mnt/dev et /mnt/proc , mais pas /mnt/sys . Ce dernier refuse de démonter car il contient /mnt/sys/fs/cgroup/systemd , que le système pense pour certaines raisons "en cours d'utilisation". Le reformatting du lecteur ZFS et le redémarrage corrigent le problème, mais ralentissent énormément les itérations de mon process d'apprentissage et de documentation.

Mes questions sont les suivantes:

– Comment puis-je démonter /mnt/sys après le chroot, sans redémarrer?

– La défaillance ( umount: /mnt/sys/fs/cgroup/systemd: target is busy ) est-elle attendue? Sinon, contre quel logiciel dois-je déposer un rapport de bogue: umount , cgroups , systemd , le kernel Linux , ou quelque chose d'autre?

Voici (je pense) un exemple de travail minimal . (Si vous avez de la difficulté à reproduire cela et pensez que j'ai peut-être manqué une étape, faites le moi savoir.) Tout d'abord, le passe-partout:

 # 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 

Et voici la partie centrale de la question:

 # 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. NB 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 copyd 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 

À cette dernière étape, je reçois:

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

Au cas où cela findmnt utile: findmnt montre l'arborescence sys complète montée deux fois: une fois à /sys et identiquement à /mnt/sys .

* Debian Jessie Root sur ZFS, CC BY-SA 3.0 , par Richard Laager et George Melikov .

Vous devez append mount --make-rslave /mnt/"$i" après votre première command de assembly, pour définir les indicateurs de propagation corrects pour ces points de assembly.

Ils protègent l'hôte contre les modifications apscopes à l'intérieur de l'environnement chroot, et aident à prévenir les situations de blocage comme les vôtres.