Linux noob - what does this mean:

Associate
Joined
10 Jul 2006
Posts
2,423
it is quicker to do it if you dont do it from a usb key. rsync the filesystem to the pc, mount bind /proc and /dev to its proc and dev, and chroot to it.

Basically I have a Ubuntu image that is on a USB key that I want to edit, but it's taking ages doing in on the USB stick so I was told todo this but I have no idea what it means.

Anyone know?
 
What you have been told is that to work on the local drive, the easiest is to copy all files from the usb stick to a location on your workstation's HDD (on linux), and then chroot into it. Read up on chroot if you're not sure what it does, but it basically allows you to swap the root for whatever you have just copied from the USB stick. You can work locally and then copy back the changes.

The mount bind is the command you have to do before the chroot, I recommend you read up on how to do a chroot, it's not very hard, but basically you have to use /dev and /proc with the `-o bind` option before chrooting. The bind option is because you are remounting part of an existing filesystem to another part.

Using rsync is more efficient than normal copying since you can copy just the changes. Again if you're not sure read up on it, or use unison which is quite a nice GUI for it which is very simple to use.

I hope I didn't confuse you more.
 
The mount bind is the command you have to do before the chroot, I recommend you read up on how to do a chroot, it's not very hard, but basically you have to use /dev and /proc with the `-o bind` option before chrooting. The bind option is because you are remounting part of an existing filesystem to another part.

Right....as far as I can see...the mount bind just mounts the folders somewhere else....how does that help and where am I supposed to mount them?
 
Right....as far as I can see...the mount bind just mounts the folders somewhere else....how does that help and where am I supposed to mount them?

Thats what "mount -o bind" does. You need to mount /dev and /proc because you are going to change where / (slash) is.

Therefore your tree looks like this : (lets say you have coppied your linux on your usb stick to /home/cheetah/joggler_chroot)

/bin
/etc
/home -> /cheetah -> /joggler_chroot ->
/lib
/proc
/root
/var

Inside the joggler_chroot you'll get /bin, /etc/ and all what is in your slash again. So chroot will change what you see as slash to /home/cheetah/joggler_chroot. But because /dev and /proc are pseudo filesystems they wont be created unless you actually boot (they will just be empty). So you remount /proc + /dev to /home/cheetah/joggler_chroot before changing your slash to /home/cheetah/joggler_chroot.

I hope that makes (some) sense.

Also have a look at schroot, which is a method of setting up chroot's to be more usable and not need to be root. It's also handy when working with multiple chroot environments.

Note: some people will tell you that mounting /proc is not needed when chrooting, I've found that in linux it's better to do it.
 
just like a normal mount,

mount -o options device_to_mount mount_point

so you want to do this :
mount -o bind /proc /home/user/joggler/proc

Here is a script i knocked up a few months back before i learned about schroot, maybe it'll explain better. Notice I copy the resolv.conf file to get networking.

#!/bin/bash
#
# 32bit chroot script for Ubuntu
# Copyright (C) 2010 Brendan Le Foll
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# get the number of command-line arguments given
ARGC=$#
# default ubuntu release
DISTRO_VERSION="hardy"
CHROOTS_DIR="/var/chroot/"
ARCH="i386"
MOUNT_HOME=false

show_usage() {
echo "Usage: chroot-32bit [distro]"
echo "distro is meant to be a ubuntu codename. Default is hardy"
echo "edit the CHROOTS_DIR to set the chroot path. Default is $CHROOTS_DIR"
echo "edit the DISTRO_VERSION to set the default linux ditro. Default is $DISTRO_VERSION"
echo "-h shows this help"
exit
}

start_chroot() {
echo "Starting $DISTRO_VERSION chroot"
cd $CHROOTS_DIR$DISTRO_VERSION-$ARCH
sudo mount -o bind /dev dev/
sudo mount -o bind /proc proc/
sudo mount -o bind /tmp tmp/
if $MOUNT_HOME; then
sudo mount -o bind /home home/
fi
#for networking
sudo cp -L /etc/resolv.conf etc/resolv.conf

sudo chroot $CHROOTS_DIR$DISTRO_VERSION-$ARCH/ setarch $ARCH /bin/bash
}

clean_chroot() {
# once bash session is closed - clean up !
sudo umount $CHROOTS_DIR$DISTRO_VERSION-$ARCH/dev
sudo umount $CHROOTS_DIR$DISTRO_VERSION-$ARCH/proc
sudo umount $CHROOTS_DIR$DISTRO_VERSION-$ARCH/tmp
if $MOUNT_HOME; then
sudo umount $CHROOTS_DIR$DISTRO_VERSION-$ARCH/home
fi
}

case $1 in
"-h"|"--help")
show_usage
;;
esac

# if we have chosen a custom distro or not mounted root
if [[ $ARGC -eq 1 ]]; then
DISTRO_VERSION=$1
if [[ -d $CHROOTS_DIR$DISTRO_VERSION-$ARCH ]]; then
start_chroot
clean_chroot
else
echo $CHROOTS_DIR$DISTRO_VERSION-$ARCH
show_usage
fi
else
if [[ -d $CHROOTS_DIR$DISTRO_VERSION-$ARCH ]]; then
start_chroot
clean_chroot
else
echo "Please check DISTRO_VERSION and CHROOTS_DIR in vars or see usage with -h!"
fi
fi
 
Last edited:
Back
Top Bottom