5

In Linux boot order, the kernel will execute /sbin/init, however, I can see another file /init existing in the file system on my linux (CentOS 8 WSL2, Ubuntu 20 WSL2).

They are different binaries:

$ diff /init /sbin/init
Binary files /init and /sbin/init differ

What are the differences between /sbin/init and /init?

gavenkoa
  • 1,906
  • 5
  • 31
  • 38
Dee
  • 641
  • 1
  • 10
  • 20

2 Answers2

7

/usr/sbin/init or /sbin/init is the executable starting the SysV initialization system. For compatibility reason, when systemd is installed, it's an alias to an executable of the systemd world.

The executable /init is unusual, in a Linux system. I suggest to investigate the reasons why it's present. It could be the part of a malware.

Romain
  • 105
  • 4
Claude Frantz
  • 477
  • 4
  • 16
  • 2
    You're right that it's unusual to find /init on the rootfs, however, it would be completely normal to find one inside an initramfs... – u1686_grawity May 31 '20 at 07:34
  • @Claude /init, it's in the official Ubuntu WSL2, downloaded as default from Windows Store. Shouldn't be an issue. However, i guess /init is used by kernel instead of /sbin/init-->/lib/systemd/systemd, and I can't use systemctl – Dee May 31 '20 at 08:04
2

You mentioned WSL 2. Microsoft still runs special Linux kernel inside VM and because the goal is not to strictly emulate they introduced own custom init process: like what's the point to start cron/cups/X/etc in every distro you installed.

Microsoft altered init process to avoid useless resource consumption (according to expected use cases of WSL 2).

When you import a Linux distro image Microsoft adds own file /init which is shared among all distros!

Even more: according to How does WSL/WSL2/WSLg work without systemd? WSL 2 is utilizing a single VM to run all distros. So the kernel is the same and the instance of the kernel in memory is shared, separation is done though Linux namespaces.

gavenkoa
  • 1,906
  • 5
  • 31
  • 38