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

  • python mysql install error: /bin/sh: 1: mysql_config: not found /bin/sh: 1: mariadb_config: not found /bin/sh: 1: mysql_config: not found mysql_config --version
  • FreePBX 17 How To Add a Trunk
  • Docker Container Onboot Policy - How to make sure a container is always running
  • FreePBX 17 How To Add Phones / Extensions and Register
  • Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes. solution
  • Cisco How To Use a Third Party SIP Phone (eg. Avaya, 3CX)
  • 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 17 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