Remove /dev mount point without unmount in Host

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?

Asked By: stackbiz

||

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.

Answered By: kos
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.