nit] Description=VIRT0 chroot mount service After=local-fs.target [Service] Type=oneshot…
- User
nit] Description=VIRT0 chroot mount service After=local-fs.target
[Service] Type=oneshot ExecStart=/usr/bin/mount --bind /sys /opt/virt0/sys ExecStart=/usr/bin/mount --bind /proc /opt/virt0/proc ExecStart=/usr/bin/mount --bind /dev /opt/virt0/dev
ExecStop=/usr/bin/umount /opt/virt0/sys ExecStop=/usr/bin/umount /opt/virt0/proc ExecStop=/usr/bin/umount /opt/virt0/dev
RemainAfterExit=yes
[Install] WantedBy=multi-user.target
This service makes 5s delay when system boots. How to make this service not required by anyone else and remove waiting when boot?
- Assistant
To prevent this service from causing a delay during the system boot process, you can modify the configuration to start the service in the background, allowing other boot tasks to continue without waiting for it to finish. Here's what you can do:
-
Change the Service Type: Update the
Typefromoneshottosimpleto allow the service to run in the background. When usingsimple, systemd will not wait for the service to complete before moving on to subsequent services. -
Add Background Execution: You can use shell commands to run the mounts in the background.
-
Make Sure it is Not Required by Other Units: Ensure that no service lists this service as a dependency. This means removing it from any
Requires=orWants=directives in other unit files.
Here's how you could modify the unit file to achieve this:
[Unit] Description=VIRT0 chroot mount service After=local-fs.target [Service] Type=simple ExecStart=/bin/sh -c '/usr/bin/mount --bind /sys /opt/virt0/sys & \ /usr/bin/mount --bind /proc /opt/virt0/proc & \ /usr/bin/mount --bind /dev /opt/virt0/dev & wait' ExecStop=/bin/sh -c '/usr/bin/umount /opt/virt0/sys; /usr/bin/umount /opt/virt0/proc; /usr/bin/umount /opt/virt0/dev' RemainAfterExit=yes [Install] WantedBy=multi-user.targetAdditional Considerations:
-
Check Dependencies: Double-check any other service files for dependencies on this service. If you find any such dependencies, consider whether they are necessary or if you can adjust those services to avoid waiting for this chroot setup.
-
Review
WantedBy: If you are sure that no other system unit or service requires this mount service to finish before starting, retainingWantedBy=multi-user.targetshould suffice. Otherwise, you might consider adding a custom target if necessary. -
Testing: After making these changes, remember to reload the systemd configuration using
sudo systemctl daemon-reloadand then test the service and boot sequence to ensure it behaves as expected without delaying startup.
-