[systemd-devel] systemd custom service to change rootfs
Lennart Poettering
lennart at poettering.net
Tue Aug 25 02:02:02 PDT 2015
On Tue, 25.08.15 16:31, nixun_992 at sina.com (nixun_992 at sina.com) wrote:
> Hi, folks:
> I am dealing with a problem, which is to use a overlay filesystem as the new root after the root system boot up. I am freshman on systemd service, so can anyone help me on my script errors? why it's failed?
> My service file, i put it under /usr/lib/systemd/system:
> >>>>>>
> [Unit]Description=Change root to overlayAfter=systemd-remount-fs.serviceConditionKernelCommandLine=|systemd.setenv [Service]TimeoutStartSec=0ExecStart=/usr/local/bin/ovl_chroot.sh [Install]WantedBy=local-fs.target
> >>>>
> My bash script for changing root filesystem
> >>>>#!/bin/bash echo "Start to mount overlay and change root to overlay" if [ ! -d /ovl_root/test1 ] ;then mkdir -p /ovl_root mkdir -p /ovl_root/test1 cd /ovl_root/test1 mkdir -p root mkdir -p work mkdir -p upperfi mount -t overlay overlay -olowerdir=/,upperdir=/ovl_root/test1/upper,workdir=/ovl_root/test1/work /ovl_root/test1/root cd /ovl_root/test1/root /usr/sbin/chroot /ovl_root/test1/root >>>
> This is the output of the status
> >>>>
> root at cr ~ # systemctl status ovl_chroot.service -l鈼?ovl_chroot.service - Change root to overlay Loaded: loaded (/usr/lib/systemd/system/ovl_chroot.service; enabled; vendor preset: disabled) Active: inactive (dead) since Tue 2015-08-25 16:26:43 UTC; 24s ago Process: 171 ExecStart=/usr/local/bin/ovl_chroot.sh (code=exited, status=0/SUCCESS) Main PID: 171 (code=exited, status=0/SUCCESS) Aug 25 16:26:43 cr systemd[1]: Started Change root to overlay.Aug 25 16:26:43 cr systemd[1]: Starting Change root to overlay...Aug 25 16:26:43 cr ovl_chroot.sh[171]: Start to mount overlay and change root to overlayAug 25 16:26:43 cr ovl_chroot.sh[171]: sh: cannot set terminal process group (171): Inappropriate ioctl for deviceAug 25 16:26:43 cr ovl_chroot.sh[171]: sh: no job control in this shellAug 25 16:26:43 cr ovl_chroot.sh[171]: sh-4.3# exit
>
> >>>
> But i run the script in the shell, it can change root to the specify directory. Anyone has any ideas?
> Thank you very muchXun
If you invoke "chroot" from a systemd service this will only change
the root directory of that specific service, but not the rest of the
system.
You are probably looking for "systemctl switch-root".
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list