Here is the unmount
method for unmounting all previously mounted folders:
https://unix.stackexchange.com/questions/61885/how-to-unmount-a-formerly-chrootd-filesystem
I use the following command to mount the /sys
and /dev
to the chroot
from the Ubuntu host
:
cd /path/to/chroot/
mount -t sysfs /sys sys
mount -o bind /dev dev
If I delete the /sys
and /dev
inside the chroot
without unmounting
first:
chroot /path/to/chroot
rm -rf /sys
rm -rf /dev
Will it delete everything
in the host system
and then cause damage
to the host system
?
Both methods of mounting (
-t sysfs
and-o bind
) will result in the files visible inside of the chroot environment to be the exact same files visible outside of the chroot environment, hence both mount points will be subject to (potentially) destructive user actions.The outcome of attempting to
rm -rf
those filesystems will vary, as some "files" (quoted as obviously even though they're technically files they're also technically not files) inside will be deletable / effectable by the user (user as in "regular user" or "root user"), while others won't (they'll be protected by extended attributes and - I'm pretty sure - some will be undeletable altoghether because of some sort of kernel protection);But suffice to say - speaking just about deletable files - that, e.g., at one point in time, deleting the wrong stuff in
/sys/firmware/efi/efivars
would downright brick your motherboard. I'm not clear on whether this has been partially / mostly / completely fixed by manufacturers, but you get my point.In short yes, you can affect your system as well as potentially damage it by attempting to remove
/dev
or/sys
from inside the chroot environment.