TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The chroot Technique – a Swiss army multitool for Linux systems

301 pointsby mariuzabout 1 month ago

24 comments

seba_dos1about 1 month ago
With qemu-user and binfmt you can even chroot into foreign CPU architectures, which is a handy thing to have when you mount your phone&#x27;s eMMC to fix a hacking session gone wrong.<p>Though these days you may want to look into things like systemd-nspawn instead of plain chroot.
评论 #43635707 未加载
评论 #43635372 未加载
评论 #43640254 未加载
jasongillabout 1 month ago
This brings back memories - I owned a large web hosting company and we had thousands of machines. When hardware issues came up, or machines wouldn&#x27;t boot, using this method was our first line of defense - we&#x27;d boot the machine from a burned copy of &quot;Recovery Is Possible&quot; which was an all-in-one Linux distro for recovery, then mount the partitions and chroot in to figure out what is going on - or use rsync to migrate data off as needed.<p>Just looked and it looks like &quot;Recovery Is Possible&quot; hasn&#x27;t been updated in a dozen years which dates my story, but I fondly remember overnight phone calls from panicked new sysadmins and telling them to be calm and &quot;RIP it and get chrooted in&quot; and then waking up to help them troubleshoot.
评论 #43636108 未加载
评论 #43637254 未加载
dicroceabout 1 month ago
I actually wish that instead of docker &amp; etc we had just gotten a better chroot... Or maybe just a new kernel syscall that is chroot()++.
评论 #43633237 未加载
评论 #43632834 未加载
评论 #43633136 未加载
评论 #43633061 未加载
评论 #43635486 未加载
评论 #43632715 未加载
评论 #43633830 未加载
评论 #43632873 未加载
评论 #43634121 未加载
评论 #43632846 未加载
评论 #43632786 未加载
评论 #43640316 未加载
评论 #43640821 未加载
评论 #43643117 未加载
评论 #43643690 未加载
评论 #43632898 未加载
评论 #43633245 未加载
smallpipeabout 1 month ago
The arch linux install has a little wrapper around chroot, used to configure the installed system without booting it.<p><a href="https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;title&#x2F;Installation_guide#Chroot" rel="nofollow">https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;title&#x2F;Installation_guide#Chroot</a>
评论 #43632779 未加载
评论 #43632860 未加载
评论 #43638461 未加载
amstanabout 1 month ago
&gt; sudo mkdir &#x2F;rescue&#x2F;boot<p>&gt; sudo mount &#x2F;dev&#x2F;nvme0n1p3 &#x2F;rescue&#x2F;boot<p>This is a little extra. What you can generally do is immediatelly after chroot just run &#x27;mount -a&#x27; to mount everything from the chroot&#x27;s fstab. The empty `&#x2F;boot` probably already exists.
评论 #43635266 未加载
jimmaswellabout 1 month ago
I just installed Gentoo from WSL2 this way, on my secondary NVME on my Framework 16. Went without a hitch besides some minor things you need to be aware of:<p>-the lack of access to efi subsystem from wsl means you need to pass some extra flags to help grub&#x2F;etc along, and you may need to set it as the boot partition in the bios manually<p>-you&#x27;ll have to mount the drive to wsl with `wsl --mount &lt;DiskPath&gt; --bare`, after finding the right DiskPath with `Get-CimInstance -query &quot;SELECT * from Win32_DiskDrive&quot;`, and you might have to offline the disk first in Windows disk manager
评论 #43641130 未加载
a_t48about 1 month ago
Currently working on scripts to provision a drive outside of the machine it’s meant to go on using chroot. I’ve so far accidentally unmounted &#x2F;dev&#x2F;pts several times from the host system and running docker inside the chroot caused a hard lock. Fun stuff.
yobboabout 1 month ago
chroot was (is?) the recommended way of installing gentoo which is pedagogical.<p>There are various handy (chroot) techniques that are probably considered &quot;old school&quot; now. For example, having a &quot;rescue partition&quot; which can be booted into remotely, and from there reinstall or repair the &quot;main os&quot;. This is necessary when repartitioning remotely, for example.
评论 #43634135 未加载
ndsipa_pomuabout 1 month ago
Used this or at least a very similar technique a few times to fix boot issues.<p>I&#x27;ve got a version of the mounting command that I think is easier to use:<p><pre><code> for f in proc sys dev run dev&#x2F;pts ; do mount --bind &#x2F;$f &#x2F;mnt&#x2F;$f ; done </code></pre> Change the &quot;&#x2F;mnt&#x2F;$f&quot; to whatever mountpoint that you&#x27;re using which would be &quot;&#x2F;rescue&#x2F;$f&quot; to align with TFA.<p>I don&#x27;t know what difference it makes to have &#x2F;run mounted, but once you chroot into the mountpoint you can mount the boot partition etc and run whatever grub or mkinitramfs command you need to fix stuff.<p>I would leave the &#x2F;boot mounting to later in the process - after you chroot. This way you can easily check &#x2F;etc&#x2F;fstab for where the boot partition lives (or if there is one), so you only need to locate the root partition initially which is generally easy to figure out from the disk sizes.<p>There&#x27;s extra steps needed however if the system uses LVM.
Arch-TKabout 1 month ago
It&#x27;s kind of funny to see this being called a technique. It has been something I&#x27;ve done so many times to impressive results. To me, it&#x27;s just something you can do, among a million other things, if you know enough about Linux.
评论 #43639821 未加载
wang_liabout 1 month ago
The tools shouldn&#x27;t require the use of chroot. It is quite common on Solaris to be able to specify a path that should be considered the root directory for the tool, usually -R. This was super useful in a netboot world using nfs, and also for crash recovery.<p>If a system is screwed up enough, then a chroot strategy won&#x27;t work because it relies on the path you are chrooting to to be generally valid and functional. If it&#x27;s missing libraries you may well be screwed.
artemonsterabout 1 month ago
I can highly recommend: <a href="https:&#x2F;&#x2F;github.com&#x2F;fsquillace&#x2F;junest">https:&#x2F;&#x2F;github.com&#x2F;fsquillace&#x2F;junest</a>
remramabout 1 month ago
Creating a mount namespace and using pivot_root seems like a safer solution.
评论 #43633679 未加载
评论 #43636102 未加载
bigpeopleareoldabout 1 month ago
Ah - my attempt at doing this was almost there, except for the few bits that kept erroring out because I didn&#x27;t mount the proc,dev,etc. mountpoints correctly :) Something to give another whirl on. At the time, I wanted something simple without docker to store everything development-related using different libraries. This is where debootstrap+chroot comes in - to build against various versions of libraries in Debian (if I remember correctly - it&#x27;s been awhile.)
ameliusabout 1 month ago
What if I&#x27;m ssh&#x27;d into a Linux box and want to (say) format its root disk. Can I boot a new instance of Linux in memory and then access the root disk?
评论 #43643081 未加载
评论 #43643743 未加载
mycallabout 1 month ago
Is there already a wrapper utility to automate all of this process laid out in the article?
评论 #43633441 未加载
评论 #43633884 未加载
评论 #43633419 未加载
sgtabout 1 month ago
Once I had to rescue a SunOS system and edit &#x2F;etc&#x2F;vfstab but I only had ed to my disposal. At that point I had never touched ed before, so that was a bit of a learning exercise, for sure.
评论 #43635001 未加载
zokierabout 1 month ago
Sure, chroot can be useful in a pinch, but it would not be the first thing I&#x27;d reach to. If you got the partitions mounted, you can already do quite a lot of things without needing to chroot.
评论 #43635318 未加载
whalesaladabout 1 month ago
This is why Linux and Unix are so awesome. It’s really all just files.
评论 #43634773 未加载
评论 #43642977 未加载
andreareinaabout 1 month ago
This is how Linux From Scratch is done, and I&#x27;ve used the same technique to install missing video drivers that the Ubuntu install didn&#x27;t include for whatever reason.
miftassirriabout 1 month ago
Haha, learned this technique while installing Void Linux
评论 #43640487 未加载
ddoolinabout 1 month ago
Chroot has saved my system more times than I care to admit. I didn&#x27;t really understand how it worked though, interesting.
aussieguy1234about 1 month ago
What we all know as Docker and containers is really just fancy chroot.<p>On non Linux systems, it&#x27;s fancy chroot inside a Linux VM.
评论 #43638687 未加载
budmichstelkabout 1 month ago
Saved me many times from reaching for the CD to rescue my main. When you install Arch it uses this technique, very lightweight.