Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: how to chroot, simple and fast

  1. #1
    Join Date
    Apr 2007
    Location
    /home/Helsinki
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    how to chroot, simple and fast

    Pick up a liveCD, version doesn't matter, you could use any distro, as long as it ables you to enter to console.


    # means run with root or sudo

    1. Create a mountpoint
    Code:
    # mkdir /mount/point
    2. Mount /proc /sys /dev to chroot
    Code:
    # mount -o bind /proc /mount/point/proc
    # mount -o bind /dev /mount/point/dev
    # mount -o bind /dev/pts /mount/point/dev/pts
    # mount -o bind /sys /mount/point/sys
    3. Copy resolv.conf to networking
    Code:
    # cp /etc/resolv.conf /mount/point/etc/resolv.conf
    4.Open bash in chroot
    Code:
    # chroot /mount/point /bin/bash
    5. Do what you have to do and then exit chroot
    Code:
    exit
    there may be more elegant way of achieving this, but this one has stuck to me.

    Hope this helps someone, this is probably posted on multiple sites, but what the heck, now no need to search around
    Last edited by taavikko; May 12th, 2009 at 05:59 PM.
    I won't answer to difficult guestions.

  2. #2
    Join Date
    Jun 2008
    Location
    Manchester, UK
    Beans
    425
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    May I ask what this is used for and what it actually does?

  3. #3
    Join Date
    Apr 2006
    Location
    Finland
    Beans
    42
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    It creates a "jailed" copy of the current operating environment within the current operating environment, so you can run stuff without affecting your main environment.

  4. #4
    Join Date
    Jun 2005
    Location
    Pacific NorthWest
    Beans
    2,782
    Distro
    Ubuntu Development Release

    Smile Re: how to chroot, simple and fast

    I was just talking in the Hal thread & my script looks very similar......I'll post it this evening---at work right now......
    "Let's nobody be dead today----Looks very bad on my report" One of my favourite lines from AVATAR
    Linux User#395230
    Ubuntu User# 13498

  5. #5
    Join Date
    Mar 2007
    Location
    Hempstead, NY
    Beans
    1,694
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    Here's my chroot bash script.

    Code:
    #!/bin/bash
    mount --bind /dev /media/disk/dev
    mount --bind /proc /media/disk/proc
    mount --bind /sys /media/disk/sys
    mount --bind /dev/pts /media/disk/dev/pts
    cp /etc/resolv.conf /media/disk/etc/resolv.conf
    chroot /media/disk
    The resolv.conf line is essential for using apt or aptitude to update your packages. Without it, you won't be able to use DNS.
    Last edited by Starks; May 11th, 2009 at 08:31 PM.

  6. #6
    Join Date
    Jun 2008
    Location
    Manchester, UK
    Beans
    425
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    So you could use it to test new packages then

  7. #7
    Join Date
    Jul 2008
    Beans
    1,491

    Re: how to chroot, simple and fast

    Or fix a borked OS, because you get full control over the packages installed in the "jail".

  8. #8
    Join Date
    Jun 2005
    Location
    Pacific NorthWest
    Beans
    2,782
    Distro
    Ubuntu Development Release

    Smile Re: how to chroot, simple and fast

    Hey Starks---looks like you are using the same one I am---I just point to stuff that's in /mnt --- helps to have 4 drives with 5 OS installs.....

    Code:
    #!/bin/bash
    sudo mount --bind /dev /mnt/Karmic/dev
    sudo mount --bind /proc /mnt/Karmic/proc
    sudo mount --bind /sys /mnt/Karmic/sys
    sudo cp /etc/resolv.conf /mnt/Karmic/etc/resolv.conf
    sudo chroot /mnt/Karmic su
    "Let's nobody be dead today----Looks very bad on my report" One of my favourite lines from AVATAR
    Linux User#395230
    Ubuntu User# 13498

  9. #9
    Join Date
    Apr 2007
    Location
    /home/Helsinki
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    Quote Originally Posted by Starks View Post
    Here's my chroot bash script.
    The resolv.conf line is essential for using apt or aptitude to update your packages. Without it, you won't be able to use DNS.
    If modem is providing the DNS then there's no need to copy resolv.conf
    At least that I'm aware of.

    Case may be different if behind proxy or connected directly to ISP
    I won't answer to difficult guestions.

  10. #10
    Join Date
    Mar 2007
    Location
    Hempstead, NY
    Beans
    1,694
    Distro
    Ubuntu Development Release

    Re: how to chroot, simple and fast

    Quote Originally Posted by taavikko View Post
    If modem is providing the DNS then there's no need to copy resolv.conf
    At least that I'm aware of.

    Case may be different if behind proxy or connected directly to ISP
    As far as I understand, the resolv.conf step is necessary because the chroot'd environment is isolated from the internet under most circumstances.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •