diff mbox series

[v2,2/9] use host-systemctl preset all to enable units

Message ID 20191111172443.6874-3-jeremy.rosen@smile.fr
State Changes Requested
Headers show
Series use host-systemd to enable units | expand

Commit Message

Jérémy ROSEN Nov. 11, 2019, 5:24 p.m. UTC
since v234 upstream recommands using systemctl preset-all to enable units.
* add a buildroot specific preset file
* use that file to disable getty@tty1
* make systemd depend on host-systemd
* remove all link-creating code that systemd does for us.

This does not change how other systemd-enabled packages work.
---
 package/systemd/80-buildroot.preset |   5 ++
 package/systemd/Config.in           |   1 +
 package/systemd/systemd.mk          | 102 ++++------------------------
 3 files changed, 18 insertions(+), 90 deletions(-)
 create mode 100644 package/systemd/80-buildroot.preset

Comments

Yann E. MORIN Dec. 5, 2019, 11:33 a.m. UTC | #1
Jérémy, All,

On 2019-11-11 18:24 +0100, Jérémy Rosen spake thusly:
> since v234 upstream recommands using systemctl preset-all to enable units.
[--SNIP--]
> diff --git a/package/systemd/Config.in b/package/systemd/Config.in
> index aef39abe27..58c7696d65 100644
> --- a/package/systemd/Config.in
> +++ b/package/systemd/Config.in
> @@ -35,6 +35,7 @@ menuconfig BR2_PACKAGE_SYSTEMD
>  	select BR2_PACKAGE_KMOD_TOOLS
>  	select BR2_TARGET_TZ_INFO
>  	select BR2_NEEDS_HOST_UTF8_LOCALE
> +	select BR2_PACKAGE_HOST_SYSTEMD

Here you select a symbol that no longer exists in your v2, but if you
follow what I suggest in my reply to the previous patch, you'll have to
keep it as it is here (but add a comment why it is needed, like we do
in eudev and host-eudev):

    select BR2_PACKAGE_HOST_SYSTEMD # for systemctl, during target-finalize

and...

[--SNIP--]
> diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> index d1db60b5ef..dc2ed80e7d 100644
> --- a/package/systemd/systemd.mk
> +++ b/package/systemd/systemd.mk
> @@ -12,6 +12,7 @@ SYSTEMD_INSTALL_STAGING = YES
>  SYSTEMD_DEPENDENCIES = \
>  	$(if $(BR2_PACKAGE_BASH_COMPLETION),bash-completion) \
>  	host-gperf \
> +	host-systemd \

... you'll have to remove this build-order dependency.

[--SNIP--]
> +define SYSTEMD_PRESET_ALL
> +	$(HOST_DIR)/bin/systemctl --root=$(TARGET_DIR) preset-all
> +endef
> +SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_PRESET_ALL

As I already noted in my previous review, and as we discussed on IRC:
this actually changes the current behaviour of a few packages, which so
far installed their unit files but did not explicitly enable them.

With this patch, these units are now enabled by default.

This is an acceptable change in behaviour: installing units but not
enabling them is probably on oversight, as no such package have
explanations why this is so, neither in their .mk, nor in the commit
log introducing the unit installation (or the package as a whole).

This change of behaviour should however be explained prominently in
the commit log.

Thanks! :-)

Regards,
Yann E. MORIN.

> +
> +
>  SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV)
>  SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV)
>  
> -- 
> 2.24.0.rc1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Yann E. MORIN Dec. 5, 2019, 1:07 p.m. UTC | #2
Jérémy, All,

An additional comment, see below...

On 2019-11-11 18:24 +0100, Jérémy Rosen spake thusly:
> since v234 upstream recommands using systemctl preset-all to enable units.
[--SNIP--]
> diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> index d1db60b5ef..dc2ed80e7d 100644
> --- a/package/systemd/systemd.mk
> +++ b/package/systemd/systemd.mk
[--SNIP--]
> -define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
> -	mkdir -p $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
> -	ln -sf ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
> -		$(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
> +define SYSTEMD_INSTALL_PRESET
> +	$(INSTALL) -D -m 644 package/systemd/80-buildroot.preset $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset

We have a variable that refers to the directory of the package:
    $(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset [...]

Note that this comment is applicable to other patches in your series (at
least the wpasuplicant one, for example).

Regards,
Yann E. MORIN.
Jérémy ROSEN Dec. 7, 2019, 11:39 a.m. UTC | #3
Are you sure you want me to do that ?

I mean... I'll use SYSTEMD_PKGDIR in the systemd recipe, but for all the
others I rather leave the
code as it was previously. Yes it's cleaner but it's an independent fix (I
don't touch those lines in
the first place)

the general replacement packages/xxx => XXX_PKGDIR is also needed in other
places in these recipes
that have nothing to do with systemd, so it would be a half fix at best.

Moreover, those are tricky to test since it means compiling in lots of
packages.

I'd rather keep this cleanup as a separate thing, it's probably better done
with some sort of automated tool

Le jeu. 5 déc. 2019 à 14:07, Yann E. MORIN <yann.morin.1998@free.fr> a
écrit :

> Jérémy, All,
>
> An additional comment, see below...
>
> On 2019-11-11 18:24 +0100, Jérémy Rosen spake thusly:
> > since v234 upstream recommands using systemctl preset-all to enable
> units.
> [--SNIP--]
> > diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> > index d1db60b5ef..dc2ed80e7d 100644
> > --- a/package/systemd/systemd.mk
> > +++ b/package/systemd/systemd.mk
> [--SNIP--]
> > -define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
> > -     mkdir -p
> $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
> > -     ln -sf
> ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
> > -
>  $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
> > +define SYSTEMD_INSTALL_PRESET
> > +     $(INSTALL) -D -m 644 package/systemd/80-buildroot.preset
> $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
>
> We have a variable that refers to the directory of the package:
>     $(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset [...]
>
> Note that this comment is applicable to other patches in your series (at
> least the wpasuplicant one, for example).
>
> Regards,
> Yann E. MORIN.
>
> --
>
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics'
> conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___
>      |
> | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is
> no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v
>  conspiracy.  |
>
> '------------------------------^-------^------------------^--------------------'
>
Jérémy ROSEN Dec. 7, 2019, 11:40 a.m. UTC | #4
to be a bit more precise : I'll fix the lines I touch in all recipes, I
just don't want to expand beyond that

Le sam. 7 déc. 2019 à 12:39, Jérémy ROSEN <jeremy.rosen@smile.fr> a écrit :

> Are you sure you want me to do that ?
>
> I mean... I'll use SYSTEMD_PKGDIR in the systemd recipe, but for all the
> others I rather leave the
> code as it was previously. Yes it's cleaner but it's an independent fix (I
> don't touch those lines in
> the first place)
>
> the general replacement packages/xxx => XXX_PKGDIR is also needed in other
> places in these recipes
> that have nothing to do with systemd, so it would be a half fix at best.
>
> Moreover, those are tricky to test since it means compiling in lots of
> packages.
>
> I'd rather keep this cleanup as a separate thing, it's probably better
> done with some sort of automated tool
>
> Le jeu. 5 déc. 2019 à 14:07, Yann E. MORIN <yann.morin.1998@free.fr> a
> écrit :
>
>> Jérémy, All,
>>
>> An additional comment, see below...
>>
>> On 2019-11-11 18:24 +0100, Jérémy Rosen spake thusly:
>> > since v234 upstream recommands using systemctl preset-all to enable
>> units.
>> [--SNIP--]
>> > diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
>> > index d1db60b5ef..dc2ed80e7d 100644
>> > --- a/package/systemd/systemd.mk
>> > +++ b/package/systemd/systemd.mk
>> [--SNIP--]
>> > -define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
>> > -     mkdir -p
>> $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
>> > -     ln -sf
>> ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
>> > -
>>  $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
>> > +define SYSTEMD_INSTALL_PRESET
>> > +     $(INSTALL) -D -m 644 package/systemd/80-buildroot.preset
>> $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
>>
>> We have a variable that refers to the directory of the package:
>>     $(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset [...]
>>
>> Note that this comment is applicable to other patches in your series (at
>> least the wpasuplicant one, for example).
>>
>> Regards,
>> Yann E. MORIN.
>>
>> --
>>
>> .-----------------.--------------------.------------------.--------------------.
>> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics'
>> conspiracy: |
>> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___
>>      |
>> | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There
>> is no  |
>> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v
>>  conspiracy.  |
>>
>> '------------------------------^-------^------------------^--------------------'
>>
>
>
> --
> [image: SMILE]  <http://www.smile.eu/>
>
> 20 rue des Jardins
> 92600 Asnières-sur-Seine
> *Jérémy ROSEN*
> Architecte technique
>
> [image: email] jeremy.rosen@smile.fr
> [image: phone]  +33 6 88 25 87 42
> [image: url] http://www.smile.eu
>
> [image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
> <https://www.facebook.com/smileopensource> [image: LinkedIn]
> <https://www.linkedin.com/company/smile> [image: Github]
> <https://github.com/Smile-SA>
>
> [image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
> <https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
>
Yann E. MORIN Dec. 7, 2019, 4:42 p.m. UTC | #5
Jérémy, All,

Please, do not top-post, please...

On 2019-12-07 12:39 +0100, Jérémy ROSEN spake thusly:
> Are you sure you want me to do that ?
> I mean... I'll use SYSTEMD_PKGDIR in the systemd recipe, but for all the others I rather leave the 

No, it is just about the usage _you_ are introducing. Of course, I
am not suggesting that you change the existing ones, unless you are
actually touching that code too.

Regards,
Yann E. MORIN.

> code as it was previously. Yes it's cleaner but it's an independent fix (I don't touch those lines in
> the first place)
> the general replacement packages/xxx => XXX_PKGDIR is also needed in other places in these recipes
> that have nothing to do with systemd, so it would be a half fix at best.
> Moreover, those are tricky to test since it means compiling in lots of packages.
> I'd rather keep this cleanup as a separate thing, it's probably better done with some sort of automated tool
> Le jeu. 5 déc. 2019 à 14:07, Yann E. MORIN < [1]yann.morin.1998@free.fr> a écrit :
> 
>   Jérémy, All,
> 
>   An additional comment, see below...
> 
>   On 2019-11-11 18:24 +0100, Jérémy Rosen spake thusly:
>   > since v234 upstream recommands using systemctl preset-all to enable units.
>   [--SNIP--]
>   > diff --git a/package/systemd/ [2]systemd.mk b/package/systemd/ [3]systemd.mk
>   > index d1db60b5ef..dc2ed80e7d 100644
>   > --- a/package/systemd/ [4]systemd.mk
>   > +++ b/package/systemd/ [5]systemd.mk
>   [--SNIP--]
>   > -define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
>   > -     mkdir -p $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
>   > -     ln -sf ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
>   > -           
>    $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
>   > +define SYSTEMD_INSTALL_PRESET
>   > +     $(INSTALL) -D -m 644 package/systemd/80-buildroot.preset
>   $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
> 
>   We have a variable that refers to the directory of the package:
>       $(INSTALL) -D -m 644 $(SYSTEMD_PKGDIR)/80-buildroot.preset [...]
> 
>   Note that this comment is applicable to other patches in your series (at
>   least the wpasuplicant one, for example).
> 
>   Regards,
>   Yann E. MORIN.
> 
>   --
>   .-----------------.--------------------.------------------.--------------------.
>   |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
>   | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___           
>      |
>   | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
>   | [6]http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
>   '------------------------------^-------^------------------^--------------------'
> 
> --
> 
> +-----------------------------------------------------------------------------------------------------------------------+
> |                               | Jérémy ROSEN                                                                |
> | [7]3D"SMILE"[8]          | Architecte technique                                                                  |
> |                               | [9]3D"email"   [10]jeremy.rosen@smile.fr                                    |
> | 20 rue des Jardins            | [11]3D"phone"   +33 6 88 25 87 42                                           |
> | 92600 Asnières-sur-Seine | [12]3D"url"   [13]http://www.smile.eu                                            |
> |                               | [14]3D"Twitter"   [15]3D"Facebook"   [16]3D"LinkedIn"   [17]3D"Github" |
> +-----------------------------------------------------------------------------------------------------------------------+
> 
> [18]3D"Découvrez
> 
> Links:
> 1. mailto:yann.morin.1998@free.fr
> 2. http://systemd.mk
> 3. http://systemd.mk
> 4. http://systemd.mk
> 5. http://systemd.mk
> 6. http://ymorin.is-a-geek.org/
> 7. http://www.smile.eu/
> 8. http://www.smile.eu/
> 9. Image: http://ftp.smile.fr/client/Communication/signature/img/mail.png
> 10. mailto:jeremy.rosen@smile.fr
> 11. Image: http://ftp.smile.fr/client/Communication/signature/img/phone.png
> 12. Image: http://ftp.smile.fr/client/Communication/signature/img/web.png
> 13. http://www.smile.eu/
> 14. https://twitter.com/GroupeSmile
> 15. https://www.facebook.com/smileopensource
> 16. https://www.linkedin.com/company/smile
> 17. https://github.com/Smile-SA
> 18. https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature
diff mbox series

Patch

diff --git a/package/systemd/80-buildroot.preset b/package/systemd/80-buildroot.preset
new file mode 100644
index 0000000000..4074901cbd
--- /dev/null
+++ b/package/systemd/80-buildroot.preset
@@ -0,0 +1,5 @@ 
+# Higher priority than systemd presets
+
+# by default systemd enables a getty on tty1
+# we don't want that because tty1 may not exist
+disable getty@.service
diff --git a/package/systemd/Config.in b/package/systemd/Config.in
index aef39abe27..58c7696d65 100644
--- a/package/systemd/Config.in
+++ b/package/systemd/Config.in
@@ -35,6 +35,7 @@  menuconfig BR2_PACKAGE_SYSTEMD
 	select BR2_PACKAGE_KMOD_TOOLS
 	select BR2_TARGET_TZ_INFO
 	select BR2_NEEDS_HOST_UTF8_LOCALE
+	select BR2_PACKAGE_HOST_SYSTEMD
 	help
 	  systemd is a system and service manager for Linux,
 	  compatible with SysV and LSB init scripts. systemd provides
diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
index d1db60b5ef..dc2ed80e7d 100644
--- a/package/systemd/systemd.mk
+++ b/package/systemd/systemd.mk
@@ -12,6 +12,7 @@  SYSTEMD_INSTALL_STAGING = YES
 SYSTEMD_DEPENDENCIES = \
 	$(if $(BR2_PACKAGE_BASH_COMPLETION),bash-completion) \
 	host-gperf \
+	host-systemd \
 	kmod \
 	libcap \
 	util-linux \
@@ -52,12 +53,6 @@  endif
 ifeq ($(BR2_PACKAGE_AUDIT),y)
 SYSTEMD_DEPENDENCIES += audit
 SYSTEMD_CONF_OPTS += -Daudit=true
-define SYSTEMD_INSTALL_SERVICE_AUDIT
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../../usr/lib/systemd/system/auditd.service \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/auditd.service
-endef
-
 else
 SYSTEMD_CONF_OPTS += -Daudit=false
 endif
@@ -65,11 +60,6 @@  endif
 ifeq ($(BR2_PACKAGE_CRYPTSETUP),y)
 SYSTEMD_DEPENDENCIES += cryptsetup
 SYSTEMD_CONF_OPTS += -Dlibcryptsetup=true
-define SYSTEMD_INSTALL_TARGET_CRYPTSETUP
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../../usr/lib/systemd/system/remote-cryptsetup.target \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/remote-cryptsetup.target
-endef
 else
 SYSTEMD_CONF_OPTS += -Dlibcryptsetup=false
 endif
@@ -270,11 +260,6 @@  endif
 
 ifeq ($(BR2_PACKAGE_SYSTEMD_MACHINED),y)
 SYSTEMD_CONF_OPTS += -Dmachined=true
-define SYSTEMD_INSTALL_TARGET_MACHINED
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../../lib/systemd/system/machines.target \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/machines.target
-endef
 else
 SYSTEMD_CONF_OPTS += -Dmachined=false
 endif
@@ -318,11 +303,6 @@  endif
 
 ifeq ($(BR2_PACKAGE_SYSTEMD_PSTORE),y)
 SYSTEMD_CONF_OPTS += -Dpstore=true
-define SYSTEMD_INSTALL_SERVICE_PSTORE
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/systemd-remount-fs.service.wants
-	ln -sf ../../../../lib/systemd/system/systemd-pstore.service \
-		$(TARGET_DIR)/etc/systemd/system/systemd-remount-fs.service.wants/systemd-pstore.service
-endef
 else
 SYSTEMD_CONF_OPTS += -Dpstore=false
 endif
@@ -337,24 +317,6 @@  endif
 ifeq ($(BR2_PACKAGE_SYSTEMD_NETWORKD),y)
 SYSTEMD_CONF_OPTS += -Dnetworkd=true
 SYSTEMD_NETWORKD_USER = systemd-network -1 systemd-network -1 * - - - Network Manager
-define SYSTEMD_INSTALL_SOCKET_NETWORKD
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/sockets.target.wants
-	ln -sf ../../../../lib/systemd/system/systemd-networkd.socket \
-		$(TARGET_DIR)/etc/systemd/system/sockets.target.wants/systemd-networkd.socket
-endef
-define SYSTEMD_INSTALL_SERVICE_NETWORKD
-	ln -sf ../../../lib/systemd/system/systemd-networkd.service \
-		$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.network1.service
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../../lib/systemd/system/systemd-networkd.service \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/systemd-networkd.service
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/network-online.target.wants
-	ln -sf ../../../../lib/systemd/system/systemd-networkd-wait-online.service \
-		$(TARGET_DIR)/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/network-pre.target.wants
-	ln -sf ../../../../lib/systemd/system/systemd-network-generator.service \
-		$(TARGET_DIR)/etc/systemd/system/network-pre.target.wants/systemd-network-generator.service
-endef
 SYSTEMD_NETWORKD_DHCP_IFACE = $(call qstrip,$(BR2_SYSTEM_DHCP))
 ifneq ($(SYSTEMD_NETWORKD_DHCP_IFACE),)
 define SYSTEMD_INSTALL_NETWORK_CONFS
@@ -374,13 +336,6 @@  define SYSTEMD_INSTALL_RESOLVCONF_HOOK
 endef
 SYSTEMD_CONF_OPTS += -Dresolve=true
 SYSTEMD_RESOLVED_USER = systemd-resolve -1 systemd-resolve -1 * - - - Network Name Resolution Manager
-define SYSTEMD_INSTALL_SERVICE_RESOLVED
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../lib/systemd/system/systemd-resolved.service \
-		$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.resolve1.service
-	ln -sf ../../../../lib/systemd/system/systemd-resolved.service \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/systemd-resolved.service
-endef
 else
 SYSTEMD_CONF_OPTS += -Dresolve=false
 endif
@@ -388,15 +343,6 @@  endif
 ifeq ($(BR2_PACKAGE_SYSTEMD_TIMESYNCD),y)
 SYSTEMD_CONF_OPTS += -Dtimesyncd=true
 SYSTEMD_TIMESYNCD_USER = systemd-timesync -1 systemd-timesync -1 * - - - Network Time Synchronization
-define SYSTEMD_INSTALL_SERVICE_TIMESYNCD
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/sysinit.target.wants
-	ln -sf ../../../../lib/systemd/system/systemd-timesyncd.service \
-		$(TARGET_DIR)/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
-	ln -sf ../../../../lib/systemd/system/systemd-time-wait-sync.service \
-		$(TARGET_DIR)/etc/systemd/system/sysinit.target.wants/systemd-time-wait-sync.service
-	ln -sf ../../../lib/systemd/system/systemd-timesyncd.service \
-		$(TARGET_DIR)/etc/systemd/system/dbus-org.freedesktop.timesync1.service
-endef
 else
 SYSTEMD_CONF_OPTS += -Dtimesyncd=false
 endif
@@ -447,18 +393,8 @@  SYSTEMD_CONF_OPTS += -Dfallback-hostname=$(SYSTEMD_FALLBACK_HOSTNAME)
 endif
 
 define SYSTEMD_INSTALL_INIT_HOOK
-	ln -fs ../lib/systemd/systemd $(TARGET_DIR)/sbin/init
-	ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/halt
-	ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/poweroff
-	ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/reboot
-	ln -fs ../bin/systemctl $(TARGET_DIR)/sbin/shutdown
-	ln -fs ../../../lib/systemd/system/multi-user.target \
-		$(TARGET_DIR)/etc/systemd/system/default.target
-	ln -fs ../../../lib/systemd/system/reboot.target \
-		$(TARGET_DIR)/etc/systemd/system/ctrl-alt-del.target
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
-	ln -sf ../../../../lib/systemd/system/remote-fs.target \
-		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/remote-fs.target
+	ln -fs multi-user.target \
+		$(TARGET_DIR)/usr/lib/systemd/system/default.target
 endef
 
 define SYSTEMD_INSTALL_MACHINEID_HOOK
@@ -466,9 +402,6 @@  define SYSTEMD_INSTALL_MACHINEID_HOOK
 endef
 
 SYSTEMD_POST_INSTALL_TARGET_HOOKS += \
-	SYSTEMD_INSTALL_TARGET_CRYPTSETUP \
-	SYSTEMD_INSTALL_TARGET_MACHINED \
-	SYSTEMD_INSTALL_SOCKET_NETWORKD \
 	SYSTEMD_INSTALL_INIT_HOOK \
 	SYSTEMD_INSTALL_MACHINEID_HOOK \
 	SYSTEMD_INSTALL_RESOLVCONF_HOOK
@@ -492,10 +425,6 @@  define SYSTEMD_USERS
 	$(SYSTEMD_TIMESYNCD_USER)
 endef
 
-define SYSTEMD_DISABLE_SERVICE_TTY1
-	rm -f $(TARGET_DIR)/etc/systemd/system/getty.target.wants/getty@tty1.service
-endef
-
 ifneq ($(call qstrip,$(BR2_TARGET_GENERIC_GETTY_PORT)),)
 # systemd needs getty.service for VTs and serial-getty.service for serial ttys
 # note that console-getty.service should be used on /dev/console as it should not have dependencies
@@ -523,30 +452,23 @@  define SYSTEMD_INSTALL_SERVICE_TTY
 endef
 endif
 
-define SYSTEMD_INSTALL_SERVICE_AUTOVT
-	ln -sf ../../../lib/systemd/system/getty@.service \
-		$(TARGET_DIR)/lib/systemd/system/autovt@.service
-endef
 
-define SYSTEMD_INSTALL_SERVICE_BOOT_CHECK
-	mkdir -p $(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires
-	ln -sf ../../../../lib/systemd/system/systemd-boot-check-no-failures.service \
-		$(TARGET_DIR)/etc/systemd/system/boot-complete.target.requires/systemd-boot-check-no-failures.service
+define SYSTEMD_INSTALL_PRESET
+	$(INSTALL) -D -m 644 package/systemd/80-buildroot.preset $(TARGET_DIR)/usr/lib/systemd/system-preset/80-buildroot.preset
 endef
 
 define SYSTEMD_INSTALL_INIT_SYSTEMD
-	$(SYSTEMD_DISABLE_SERVICE_TTY1)
+	$(SYSTEMD_INSTALL_PRESET)
 	$(SYSTEMD_INSTALL_SERVICE_TTY)
-	$(SYSTEMD_INSTALL_SERVICE_AUTOVT)
-	$(SYSTEMD_INSTALL_SERVICE_RESOLVED)
-	$(SYSTEMD_INSTALL_SERVICE_TIMESYNCD)
 	$(SYSTEMD_INSTALL_NETWORK_CONFS)
-	$(SYSTEMD_INSTALL_SERVICE_PSTORE)
-	$(SYSTEMD_INSTALL_SERVICE_NETWORKD)
-	$(SYSTEMD_INSTALL_SERVICE_AUDIT)
-	$(SYSTEMD_INSTALL_SERVICE_BOOT_CHECK)
 endef
 
+define SYSTEMD_PRESET_ALL
+	$(HOST_DIR)/bin/systemctl --root=$(TARGET_DIR) preset-all
+endef
+SYSTEMD_TARGET_FINALIZE_HOOKS += SYSTEMD_PRESET_ALL
+
+
 SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV)
 SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV)