logoalt Hacker News

Joker_vDtoday at 12:08 PM4 repliesview on HN

What if we remount the filesystem(s) at /dev/sda as read-only first? Then make a small ramfs with statically-linked curl in it and exec it. Hmm. Ideally, you'd also want to call reboot(2) after it's done...


Replies

duskwufftoday at 7:33 PM

One bit of magic you may be interested in is pivot_root, which allows another filesystem to take the place of the root filesystem (e.g. / and /mnt become /old and /). It's usually used during startup, to allow the "real" root filesystem to take the place of the initrd, but could have other uses.

show 1 reply
tremontoday at 7:22 PM

You also don't want to do this under any kind of memory pressure, because the kernel will happily drop read-only pages from memory if it thinks they can be re-read from disk when needed.

astralbijectiontoday at 12:54 PM

All of those things get covered in parts 2, 3, and 4 :)

show 1 reply
akdev1ltoday at 12:41 PM

in most cases you could just drop back into the initramfs that is included in most distros

Or if you have access to the boot command line you can also usually stop the boot process before pivot_root happens (hence you’ll be left running in the initramfs environment)

On Fedora/EL it would be done by putting `rd.break` in the kernel command line