Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Using a chroot to manipulate another installation.

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Using a chroot to manipulate another installation.

#1 Post by edbarx »

Using a chroot in Debian is not as difficult as it sounds, and the power inherent in chroot is amazing to the point of restoring bootability to an otherwise unbootable installation. One such instance can arise if the kernel is uninstalled leaving an installation without it.


The Procedure:
  1. For conformity, create a directory under /mnt say sda2.

    Code: Select all

    mkdir /mnt/sda2
  2. Mount the root partition holding the installation to be modified. I will assume it is: /dev/sda2

    Code: Select all

    mount /dev/sda2 /mnt/sda2
  3. I found that for the chroot to work properly I had to bind the /sys, /proc and /dev directories as follows:

    Code: Select all

    mount -o bind /sys /mnt/sda2/sys
    mount -o bind /proc /mnt/sda2/proc
    mount -o bind /dev /mnt/sda2/dev
  4. Do the actual chroot as follows:

    Code: Select all

    chroot /mnt/sda2 /bin/sh
    If you are going to install packages containing daemons, you may need to prevent them from starting. The Debian Chroot Wiki contains this information.
  5. After finishing with the chroot, exit.

    Code: Select all

    exit
  6. Unmount the bound file systems.

    Code: Select all

    umount /mnt/sda2/dev
    umount /mnt/sda2/proc
    umount /mnt/sda2/sys
  7. Finally unmount the partition. If applicable to your case, unmount the other partitions that make part of the repaired installation. Finally, unmount the partition (in our case, sda2).

    Code: Select all

    umount /mnt/sda2
I use this same procedure to configure a new installation after installing it with debootstrap.


Using chroot to repair grub-pc from within a LiveCD session or from within another running session.
The first thing I found about repairing an otherwise badly behaving grub-pc, is by purging it completely together with its configuration files. This means, when I was asked to remove the grub files I replied in the affirmative.


The Procedure
  1. Purge grub-pc together with all its files under /boot.

    Code: Select all

    # apt-get remove --purge grub-pc
    Needless to repeat, answer that you want to delete all traces of grub-pc.
  2. Reinstall grub-pc.

    Code: Select all

    # apt-get install grub-pc
    When asked where to install the first stage select the MBR or the protective MBR in case of GPT.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

zilleplus
Posts: 10
Joined: 2013-09-14 13:50

Re: Using a chroot to manipulate another installation.

#2 Post by zilleplus »

nice guide, for those who want to do this in a image from a qemu/kvm use this line:

add module:

Code: Select all

modprobe nbd max_part=16
link image to network block device:

Code: Select all

kvm-nbd -c /dev/nbd1 debian.raw
all the rest is the same use /dev/nbd1p1 instead of /dev/sda1.

Post Reply