Thread #108603652
HomeIndexCatalogAll ThreadsNew ThreadReply
H
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 man

man 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/
+Showing all 14 replies.
>>
bampu
>>
>>108603652
*pomf*
>>
>>108603652
Nope, can't say I've ever used chroot, or if I have I don't remember. It definitely sounds like one of those things you'd want to be able to do, though, so we've finally found a useful syscall.
>>
>>108603652
me on the bottom
>>
>>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.
>>
>>108604321
chroot is very useful for cross-compiling packages

> chroot jails aren't inescapable
namespaces + user mapping
>>
>>108604321
You have to either mount or link those directories inside the chroot
From the Debian wiki
# for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do mount -B $i /mnt/$i; done 
>>
>>108604321
they're useful to apt remove packages from a live USB if you, for example, fuck up your graphics drivers
>>
>>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
>>
bampu
>>
>>108603652
>>108606941
kill yourself
>>
love yourself op
>>
Don't love yourself, OP. Love the me that loves you!
>>
>>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.

Reply to Thread #108603652


Supported: JPG, PNG, GIF, WebP, WebM, MP4, MP3 (max 4MB)