How to chroot properly into your OS/distro

From a LiveCD or if you're doing something like converting your non-RAID install to mdadm here's how you would chroot properly (you have to mount your proc, sys and dev on the running system/LiveCD to your chroot environment if you want things to work right, especially if you need to run update-initramfs due to a driver change etc..)

*replace "path" with your mount/chroot path

mount -o bind /proc /mnt/path/proc
mount -o bind /dev/ mnt/path/dev
mount -o bind /sys /mnt/path/sys
chroot /mnt/path

Here's a handy script to do it (basically just give it the path to your chroot and it does the rest):

#!/bin/bash
if [ -z "$1" ]; then
 echo "Usage $0 chroot/dir"
 exit 1
fi

destination=$1
for mountit in proc sys dev dev/pts; do
   mount -o bind /$mountit $destination/$mountit
done

 

Here's a handy script to unmount the chroot'd system paths:

#!/bin/bash
if [ -z "$1" ]; then
 echo "Usage $0 chroot/dir"
 exit 1
fi

#note since /dev/pts is mounted inside /dev you have to unmount /dev/pts first rather than when we mounted /dev above we would mount /dev/pts after the fact
destination=$1
for mountit in dev/pts proc sys dev; do
   umount $destination/$mountit
done


Tags:

chroot, os, distrofrom, livecd, converting, raid, install, mdadm, mount, proc, sys, dev, update, initramfs, etc, quot, bind, mnt, bin, bash, z, echo, usage, dir, fi, destination, mountit, pts, unmount, paths, mounted, umount,

Latest Articles

  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt