0

The embedded system is based on NXP ARM iMX8Mini, the root filesystem is an overlayfs composed by three parts, these parts are filesystems that are contained inside files image. The partition who contains the three files that composing the root overlayfs is crypted using LUKS2. When the system starts, the script inside an initramfs compose the overlayfs and using switch_root, and systemd is launched.

When the system needs to be rebooted or halted, the system hangs because isn't able to disassemble the overlayfs and theirs components.

Below there is the script that I wrote in order to resolve the problem, but it doesn't work completely. The script stops systemd and other two processes and launches /bin/bash with PID 1 using chroot, but it doesn't unmount automatically the filesystems.

But after it I wrote this command on console:

umount /oldroot fsext/upper /fsext/lower_* /fsext/crypt_cont

It does unmount these filesystems.

At last when I wrote the command

cryptsetup luksClose crypt_cont

It hangs

I have no idea to solve this problem.

cd /

mount -t tmpfs -o size=200m tmpfs /ramroot
zcat /depot/core-image-initramfs.rootfs.cpio.gz | cpio -i --directory=/ramroot -H newc -v
mkdir /ramroot/oldroot
mkdir -p /ramroot/fsext/{crypt_cont,lower_so,lower_appl,upper}
mkdir -p /ramroot/var/volatile

systemctl stop syslog.socket
for SERVICE in dbus.service syslog.socket systemd-journald.service; do systemctl stop $SERVICE; done

for SERVICE in $(systemctl | grep service |grep running | sed 's/^ *//g' | cut -d " " -f 1); do
        if [[ "$SERVICE" != "serial-getty@ttymxc1.service" ]]; then
               echo ">$SERVICE<"
               systemctl stop "$SERVICE"
        else
               echo ">$SERVICE< - deferred stop"
        fi
done
sleep 5
systemctl stop systemd-journald.service

systemctl | grep service |grep running | sed 's/^ *//g' | cut -d " " -f 1


PID_LOGIN=$(ps -ef | grep "login" | head -n 1 | sed -e 's/ \+/ /g' | cut -d " " -f 2)
PID_SHELL=$(ps -ef | grep "\-sh" | head -n 1 | sed -e 's/ \+/ /g' | cut -d " " -f 2)

mount --make-rprivate /

cd /ramroot

for dir in crypt_cont lower_so lower_appl upper; do mount --move /mnt/$dir /ramroot/fsext/$dir; done

for dir in dev sys tmp run var/volatile proc; do mount --move /$dir /ramroot/$dir; done

pivot_root . oldroot

cd /

export MY_CMD="exec chroot . sh -c 'killall systemd;kill -9 $PID_SHELL $PID_LOGIN;umount /oldroot fsext/upper /fsext/lower_* /fsext/crypt_cont' </dev/console >/dev/console 2>&1"

eval $MY_CMD

This is the result:

.....
.......
[ 4298.969349] systemd-journald[7318]: Received SIGTERM from PID 1 (systemd).
[ 4298.969714] systemd[1]: Stopping Journal Service...
[ 4298.982270] systemd[1]: systemd-journald.service: Succeeded.
[ 4298.989023] systemd[1]: Stopped Journal Service.
Warning: Stopping systemd-journald.service, but it can still be activated by:
  systemd-journald-audit.socket
  systemd-journald.socket
  systemd-journald-dev-log.socket
serial-getty@ttymxc1.service
[ 4299.119629] systemd[1]: mnt-crypt_cont.mount: Succeeded.
[ 4299.131124] systemd[1]: mnt-upper.mount: Succeeded.
[ 4299.136221] systemd[1]: mnt-lower_appl.mount: Succeeded.
[ 4299.141666] systemd[1]: mnt-lower_so.mount: Succeeded.
[ 4299.182526] systemd[1]: run-user-0.mount: Succeeded.
[ 4299.187550] systemd[1]: var-volatile.mount: Succeeded.
[ 4299.193884] systemd[1]: tmp.mount: Succeeded.
[  !!  ] Failed to e[ 4299.296635] printk: sh: 66 output lines suppressed due to ratelimiting
xecute /sbin/init
sh-5.0# df
Filesystem                1K-blocks    Used Available Use% Mounted on
none                         622524       0    622524   0% /dev
runfs                        997148   17172    979976   2% /run
/dev/mapper/crypt_cont      3101324 3065124         0 100% /fsext/crypt_cont
/dev/loop0                  1350268 1037460    225036  83% /fsext/lower_so
/dev/loop1                    95088   82080      5840  94% /fsext/lower_appl
/dev/mapper/crypt_data_rw    273419    4072    250711   2% /fsext/upper
overlay                      273419    4072    250711   2% /oldroot
tmpfs                        997148       0    997148   0% /dev/shm
tmpfs                        997148       0    997148   0% /sys/fs/cgroup
tmpfs                        997148       4    997144   1% /tmp
tmpfs                        997148     200    996948   1% /var/volatile
tmpfs                        199428       0    199428   0% /run/user/0
tmpfs                        204800   94140    110660  46% /
sh-5.0# ps
  PID USER       VSZ STAT COMMAND
    1 root      3664 S    /bin/sh
    2 root         0 SW   [kthreadd]
    3 root         0 IW<  [rcu_gp]
    4 root         0 IW<  [rcu_par_gp]
    8 root         0 IW<  [mm_percpu_wq]
    9 root         0 SW   [ksoftirqd/0]
   10 root         0 RW   [rcu_preempt]
   11 root         0 SW   [migration/0]
   12 root         0 SW   [cpuhp/0]
   13 root         0 SW   [cpuhp/1]
   14 root         0 SW   [migration/1]
   15 root         0 SW   [ksoftirqd/1]
   18 root         0 SW   [cpuhp/2]
   19 root         0 SW   [migration/2]
   20 root         0 SW   [ksoftirqd/2]
   23 root         0 SW   [cpuhp/3]
   24 root         0 SW   [migration/3]
   25 root         0 SW   [ksoftirqd/3]
   28 root         0 SW   [kdevtmpfs]
   29 root         0 IW<  [netns]
   30 root         0 SW   [rcu_tasks_kthre]
   35 root         0 SW   [kauditd]
   36 root         0 SW   [oom_reaper]
   37 root         0 IW<  [writeback]
   38 root         0 SW   [kcompactd0]
   39 root         0 SWN  [ksmd]
   40 root         0 SWN  [khugepaged]
   62 root         0 IW<  [cryptd]
  119 root         0 IW<  [kintegrityd]
  120 root         0 IW<  [kblockd]
  121 root         0 IW<  [blkcg_punt_bio]
  122 root         0 IW<  [tpm_dev_wq]
  123 root         0 IW<  [ata_sff]
  124 root         0 IW<  [edac-poller]
  125 root         0 IW<  [devfreq_wq]
  126 root         0 SW   [watchdogd]
  127 root         0 IW<  [rpciod]
  128 root         0 IW<  [kworker/u9:0]
  129 root         0 IW<  [xprtiod]
  130 root         0 IW<  [cfg80211]
  189 root         0 SW   [kswapd0]
  190 root         0 IW<  [nfsiod]
  197 root         0 IW<  [nvme-wq]
  198 root         0 IW<  [nvme-reset-wq]
  199 root         0 IW<  [nvme-delete-wq]
  201 root         0 IW<  [vfio-irqfd-clea]
  202 root         0 IW<  [dm_bufio_cache]
  203 root         0 IW<  [sdhci]
  204 root         0 SW   [irq/45-mmc2]
  252 root         0 IW<  [mmc_complete]
  326 root         0 SW   [ion_system_heap]
  327 root         0 IW<  [galcore workque]
  328 root         0 SW   [galcore_deamon/]
  329 root         0 SW   [galcore_deamon/]
  330 root         0 IW<  [ipv6_addrconf]
  331 root         0 SW<  [krfcommd]
  333 root         0 SW   [spi1]
  335 root         0 IW<  [ci_power_lost]
  336 root         0 IW<  [ci_power_lost]
  337 root         0 IW<  [sdhci]
  338 root         0 SW   [irq/43-mmc0]
  339 root         0 SW   [irq/70-30b40000]
  340 root         0 IW<  [sdhci]
  342 root         0 SW   [irq/44-mmc1]
  344 root         0 IW<  [mmc_complete]
  345 root         0 IW<  [kworker/0:1H-mm]
  350 root         0 IW<  [WILC_wq]
  768 root         0 IW<  [kdmflush]
  769 root         0 IW<  [kcryptd_io/253:]
  770 root         0 IW<  [kcryptd/253:0]
  771 root         0 SW   [dmcrypt_write/2]
  773 root         0 IW<  [kworker/3:2H-kb]
  775 root         0 SW   [jbd2/dm-0-8]
  776 root         0 IW<  [ext4-rsv-conver]
  881 root         0 SW<  [loop0]
  882 root         0 SW   [jbd2/loop0-8]
  883 root         0 IW<  [ext4-rsv-conver]
  885 root         0 SW<  [loop1]
  886 root         0 SW   [jbd2/loop1-8]
  887 root         0 IW<  [ext4-rsv-conver]
 1257 root         0 IW<  [kdmflush]
 1258 root         0 IW<  [kcryptd_io/253:]
 1259 root         0 IW<  [kcryptd/253:1]
 1260 root         0 SW   [dmcrypt_write/2]
 1265 root         0 SW   [jbd2/dm-1-8]
 1266 root         0 IW<  [ext4-rsv-conver]
 1350 root         0 IW<  [kworker/1:3H-kb]
 1351 root         0 IW<  [kworker/2:3H-kb]
 4116 root         0 IW   [kworker/u8:0-ev]
 4497 root         0 IW   [kworker/u8:3-ev]
 5493 root         0 IW   [kworker/1:2-eve]
 6220 root         0 IW<  [kworker/3:1H]
 6624 root         0 IW   [kworker/3:2-eve]
 6704 root         0 IW   [kworker/1:1-eve]
 6719 root         0 IW<  [kworker/2:1H]
 6909 root         0 RW   [kworker/0:2-eve]
 7220 root         0 IW<  [kworker/0:0H]
 7285 root         0 IW<  [kworker/1:1H]
 7291 root         0 IW   [kworker/2:2-eve]
 7293 root         0 IW   [kworker/3:0-eve]
 7344 root         0 IW   [kworker/0:3-eve]
 7349 root         0 IW   [kworker/2:3-eve]
 7393 root         0 IW   [kworker/u8:1-ev]
 7394 root      3252 R    ps
sh-5.0#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.