You are not logged in.
Hello, I'm very new to Arch and to Linux as a whole, so there is a question: what is the difference between "chroot" and "systemctl switch-root" commands?
When I installed Arch there were two options to use arch-chroot script or do the same manually by chroot in order to install some base packages. After I found systemctl's one and I'm confused... I'm just curious and I havn't tried it yet, because I don't know what it does.
Offline
From the systemctl man page:
Switches to a different root directory and executes a new system manager process below it. This is intended for usage in inital RAM disks ("initrd"), and will transition from the initrd's system manager process (a.k.a. "init" process) to the main system manager process.
From the chroot man page:
chroot - run command or interactive shell with special root directory
Chroot and systemctl switch-root are two different things, so don't try to use them interchangeabley.
Offline
Hello Timfayz,
Here is my take on the differences between the two systems:
chroot is a system call that shifts what a process expects to be the root directory. In other words, you can mount a new file system to the root directory, like a usb stick, and chroot into the new file system. Now the system will no longer see the root directory as root. It will see the new file system as root. The only problem with this is the new file system will inherit the old system calls, processes and environment variables.
When using the systemd method of changing root this does not happen. You are guaranteed to invoke a completely independent environment with localized system calls, processes and environment variables.
I hope that helps.
Offline
Bruinn,
Your take is incorrect. Switch-root cannot be used as a chroot replacement. The reason for this is that chroot only changes the root directory of a single process, whereas switch-root changes the entire system's root directory. The man page for switch-root specifically says that it is intended for initial RAM disks. You can also guarantee clean environment variables with chroot by doing something such as this:
env -i TERM=$TERM SHELL=/bin/bash HOME=$HOME $(which chroot) [chroot-dir] /bin/bashIf you are looking for completely independent environments, you would either be using a virtual machine or some form of lightweight virtualization such as LXC.
Offline
Atomicbeef,
I never stated Switch-root should be used as a chroot replacement. I was stating my take on the differences between the two. My understanding of the two systems is from a blog article written by Lennart Poettering. I will look up the blog post and post it shortly.
Offline
Here is the link I was referring to. If I mislead anyone I apologize.
Offline
I don't think that blog article you linked to is talking about switch-root. I couldn't find any mention of switch-root and the article mainly talked about using chroot in systemd services. From what I've found in my research, switch-root is only supposed to be used during the early boot process.
Offline
Thank you guys anyway! Both of your opinions are worth to me. At least, now I have veryyy superficial difference understanding!
Offline