Warning: When using
--rbind
, some subdirectories of dev/
and sys/
will not be unmountable. Attempting to unmount with umount -l
in this situation will break your session, requiring a reboot. If possible, use -o bind
instead.In the following example, /location/of/new/root
is the directory where the new root resides.
First, mount the temporary API filesystems:
# cd /location/of/new/root # mount -t proc /proc proc/ # mount -t sysfs /sys sys/ # mount --rbind /dev dev/
And optionally:
# mount --rbind /run run/
If you are running a UEFI system, you will also need access to EFI variables. Otherwise, when installing GRUB, you will receive a message similar to: UEFI variables not supported on this machine
:
# mount --rbind /sys/firmware/efi/efivars sys/firmware/efi/efivars/
Next, in order to use an internet connection in the chroot environment, copy over the DNS details:
# cp /etc/resolv.conf etc/resolv.conf
Finally, to change root into /location/of/new/root
using a bash shell:
# chroot /location/of/new/root /bin/bash
Note: If you see the error:
chroot: cannot run command '/usr/bin/bash': Exec format error
, it is likely that the architectures of the host environment and chroot environment do not match.chroot: '/usr/bin/bash': permission denied
, remount with the execute permission:mount -o remount,exec /location/of/new/root
.
After chrooting, it may be necessary to load the local bash configuration:
# source /etc/profile # source ~/.bashrc
Tip: Optionally, create a unique prompt to be able to differentiate your chroot environment:
# export PS1="(chroot) $PS1"
When finished with the chroot, you can exit it via:
# exit
Then unmount the temporary file systems:
# cd / # umount --recursive /location/of/new/root
Note: If there is an error mentioning something like
umount: /path: device is busy
, this usually means that either: a program (even a shell) was left running in the chroot or that a sub-mount still exists. Quit the program and use findmnt -R /location/of/new/root
to find and then umount
sub-mounts. It may be tricky to umount
some things and one can hopefully have umount --force
work. As a last resort, use umount --lazy
which just releases them. In either case to be safe, reboot
as soon as possible if these are unresolved to avoid possible future conflicts.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your article helped me a lot, is there any more related content? Thanks!
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.