Thread #108603652
File: 1706586377226508.jpg (293.2 KB)
293.2 KB JPG
previous: >>108597697#define __NR_pivot_root 155
#define __NR_chroot 161
https://man7.org/linux/man-pages/man2/pivot_root.2.html
https://man7.org/linux/man-pages/man2/chroot.2.html
tl;dr:
change your filesystem/mount root
these syscalls are pretty neat. i think most people are probably familiar (or at least more familiar) with chroot. pivot_root seems a bit more esoteric, and it took me a few attempts at reading through the manpage before i started to fully understand it. the pivot portion of it really is key.
chroot, despite its manpage explicitly advising against it, is often used for security/sandboxing purposes. it's also pretty handy for fixing a fucked up install via live USB, or for acting within a qemu container, etc.
pivot_root feels more like what i used to think chroot did, where it's actually pivoting your root mount point
https://man7.org/linux/man-pages/man7/mount_namespaces.7.html is probably also worth reading, if you're interested
anyway, i know chroot has definitely saved my ass before. anyone else ever used it? if so, what for?
relevant resources:man manman syscalls
https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
14 RepliesView Thread
>>
>>
>>
>>
>>108603652
I remember trying to set up a little toy chroot jail on a server, and getting really annoyed by all the special files in /dev and the so in /lib
However, chroot jails aren't inescapable, so I've always wondered what the actual use case outside early boot is.
>>
>>
>>
>>
>>108604777
>cross-compiling packages
wouldn't a few compiler options be much simpler?
>>108604884
oh yeah, I got it done in the end(mostly with mknod), but removing them was super convoluted for some reason which I don't remember exactly
>>108605839
huh, that makes sense. Much better than deleting by hand and praying that you've deleted the correct(and all) the files
>>
>>108603652
>>108606941
kill yourself
>>
>>
>>
>>108603652
>anyway, i know chroot has definitely saved my ass before. anyone else ever used it? if so, what for?
Yeah, when my bootloader broke, I needed to chroot into my system, and run grub-mkconfig again. Thank god for chroot.