Sunday, 15 March 2009

Creating a FEDORA 10 CHROOT Environment in DEBIAN SID

Fedora is a linux distribution supported by a community: fedoraproject.org and by Red Hat enterprise.
Fedora (Wikipedia)

Current release name is Fedora 10.


Fedora packages are provided in rpm format. We can manage these packages using rpm tool, and use yum to deal with repositories.

Debian sid provides the rpm tool so our first task will be installing it in our Debian system:
#aptitude install rpm

This tool will allow us to install fedora packages in our debian system using a separate database and a different directory than / .


We create the directory to place our Fedora chroot environment:
$mkdir Fedora
$cd Fedora
$mkdir Distro


We are going to download the minimal amount of rpm packages required for our Fedora distro.

Navigating through fedora project web page we can find some mirrors, e.g:
http://glup.uv.es/mirror/fedora/linux/
http://ftp.uni-kl.de/pub/linux/fedora/linux/
Choose one near you.

Within those mirrors we find where packages are:
http://glup.uv.es/mirror/fedora/linux/releases/10/Fedora/i386/os/Packages/
http://ftp.uni-kl.de/pub/linux/fedora/linux/releases/10/Fedora/i386/os/Packages/


We can download every package we need using wget tool.
Although we only show the installing rpm command, you will have to download every rpm package prior to install it.
NOTE: Package version may not coincide, but the same package name and same installing order are mandatory.

If we need some file to satisfy a dependency, but don't know which package contains it, this web page can help us:
http://rpmfind.net


Our goal is to install a minimal working Fedora distro. Some important packages are needed to acomplish that: bash, rpm and yum.

Bash will provide us a shell, rpm is needed to manage rpm packages, and yum will allow us to continue installing packages in our chroot enviroment using some rpm repositories and solving dependency problems.


We begin installing the packages:
/home/foo/Fedora/Distro is the directory where our chroot environment will be placed.

#export FEDORA_DISTRO_DIR="/home/foo/Fedora/Distro"
rpm --root $FEDORA_DISTRO_DIR/ -i setup-2.7.4-1.fc10.noarch.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i filesystem-2.4.19-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i basesystem-10.0-1.noarch.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libgcc-4.3.2-7.i386.rpm


"--nodeps" option is needed because glibc package has cross dependencies.
rpm --root $FEDORA_DISTRO_DIR/ -i glibc-2.9-2.i686.rpm --nodeps

rpm --root $FEDORA_DISTRO_DIR/ -i ncurses-base-5.6-20.20080927.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i ncurses-libs-5.6-20.20080927.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i bash-3.2-29.fc10.i386.rpm

Bash is now installed so we could execute chroot if we would want.

rpm --root $FEDORA_DISTRO_DIR/ -i tzdata-2008h-1.fc10.noarch.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i glibc-common-2.9-2.i386.rpm


rpm --root $FEDORA_DISTRO_DIR/ -i ncurses-5.6-20.20080927.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libsepol-2.0.33-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libselinux-2.0.73-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libstdc++-4.3.2-7.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i pcre-7.8-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i zlib-1.2.3-18.fc9.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i info-4.12-4.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i grep-2.5.1a-61.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libattr-2.4.43-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libacl-2.2.47-3.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libcap-2.10-2.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i audit-libs-1.7.8-6.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i cracklib-2.8.12-2.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i cracklib-dicts-2.8.12-2.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i db4-4.7.25-5.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i coreutils-6.12-17.fc10.i386.rpm -nodeps
rpm --root $FEDORA_DISTRO_DIR/ -i pam-1.0.2-2.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i popt-1.13-4.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i logrotate-3.7.7-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i bzip2-libs-1.0.5-3.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i compat-db45-4.5.20-5.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i elfutils-libelf-0.137-3.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i readline-5.2-13.fc9.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i lua-5.1.4-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i file-libs-4.26-3.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i nspr-4.7.2-2.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i sqlite-3.5.9-2.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i nss-3.12.2.0-3.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i crontabs-1.10-23.fc10.noarch.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i e2fsprogs-libs-1.41.3-2.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i keyutils-libs-1.2-3.fc9.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i krb5-libs-1.6.3-16.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libidn-0.6.14-8.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i ca-certificates-2008-7.noarch.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i openssl-0.9.8g-11.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i cyrus-sasl-lib-2.1.22-19.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i openldap-2.4.12-1.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libssh2-0.18-7.fc9.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i libcurl-7.18.2-7.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i curl-7.18.2-7.fc10.i386.rpm
rpm --root $FEDORA_DISTRO_DIR/ -i rpm-libs-4.6.0-0.rc1.7.i386.rpm --nodeps
rpm --root $FEDORA_DISTRO_DIR/ -i rpm-4.6.0-0.rc1.7.i386.rpm


RPM ACOMPLISHED!! We would be able to enter the chroot environment an install packages with rpm.


Packages needed to create new users and change their passwords:
rpm -i shadow-utils-4.1.2-8.fc10.i386.rpm
rpm -i gamin-0.1.9-6.fc10.i386.rpm --nodeps
rpm -i glib2-2.18.2-3.fc10.i386.rpm
rpm -i libuser-0.56.9-1.i386.rpm
rpm -i passwd-0.75-2.fc9.i386.rpm


Terminal to login in the system: (actually we will use agetty instead)
rpm -i mingetty-1.08-2.fc9.i386.rpm


Packages needed to install YUM tool.
rpm -i expat-2.0.1-5.i386.rpm
rpm -i gdbm-1.8.0-29.fc10.i386.rpm
rpm -i python-libs-2.5.2-1.fc10.i386.rpm --nodeps
rpm -i python-2.5.2-1.fc10.i386.rpm
rpm -i libgpg-error-1.6-2.i386.rpm
rpm -i libgcrypt-1.4.3-2.fc10.i386.rpm
rpm -i libksba-1.0.4-1.fc10.i386.rpm
rpm -i pth-2.0.7-7.i386.rpm
rpm -i dirmngr-1.0.2-1.fc10.i386.rpm
rpm -i libusb-0.1.12-20.fc10.i386.rpm
rpm -i chkconfig-1.3.38-1.i386.rpm
rpm -i pinentry-0.7.4-5.fc9.i386.rpm
rpm -i gnupg2-2.0.9-3.fc10.i386.rpm
rpm -i gpgme-1.1.7-1.fc10.i386.rpm
rpm -i pygpgme-0.1-8.fc9.i386.rpm
rpm -i python-iniparse-0.2.3-3.fc9.noarch.rpm
rpm -i rpm-python-4.6.0-0.rc1.7.i386.rpm
rpm -i python-urlgrabber-3.0.0-10.fc10.noarch.rpm
rpm -i libxml2-2.7.2-1.fc10.i386.rpm
rpm -i yum-metadata-parser-1.1.2-10.fc10.i386.rpm
rpm -i yum-3.2.20-3.fc10.noarch.rpm


Yum is now installed in our system. So we add a repository.

We edit and add this into $FEDORA_DISTRO_DIR/etc/yum.conf file:
Change baseurl to the mirror url you choose.

[Fedora10]
name=Fedora 10
baseurl=http://ftp.uni-kl.de/pub/linux/fedora/linux/releases/10/Fedora/i386/os


NOTE: We will need to run: #yum update to take into account this new repository, when our chroot environment will be working.


MOUNTING DIRECTORIES
Lets mount the directories needed for our chroot environment:

# cd $FEDORA_DISTRO_DIR
# mount --bind /proc proc
# mount --bind /sys sys
# mount --bind /proc/bus/usb proc/bus/usb
# mount --bind /dev dev
# mount --bind /dev/shm dev/shm
# mount --bind /dev/pts dev/pts
# mount --bind /tmp tmp # to use X-Windows
# mkdir -p lib/init/rw
# mount --bind /lib/init/rw lib/init/rw



We copy these files to be able to resolve localhost and dns
# cp /etc/hosts $FEDORA_DISTRO_DIR/etc/
# cp /etc/resolv.conf $FEDORA_DISTRO_DIR/etc/


Create a working /etc/mtab file:
# cp /etc/mtab $FEDORA_DISTRO_DIR/etc #edit this file to correct values. e.g:
proc /proc proc rw,noexec,nosuid,nodev 0 0
sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0
udev /dev tmpfs rw,mode=0755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0


NOTE: You can left proc and sysfs only, if you want.

ENTER INTO THE CHROOT JAIL:
Sid:# chroot $FEDORA_DISTRO_DIR

We are now in the Fedora 10 environment!!


Now we import the repository key:
Fedora:# wget http://ftp.uni-kl.de/pub/linux/fedora/linux/releases/10/Fedora/i386/os/RPM-GPG-KEY-fedora-i386
Fedora:# rpm --import RPM-GPG-KEY-fedora-i386
Fedora:# yum update



We can install new packages. e.g:
Fedora:# yum install man-pages
Fedora:# yum install man


Fedora:# yum install iputils #ping utility.



Before login in the standar way we need to CREATE A NEW USER AND CHANGE PASSWORDS:

To solve password changing problem: "passwd: User not known to the underlying authentication module"
Fedora:# yum install shadow-utils
Fedora:# pwconv #to create /etc/shadow file.


We create fedoraUser:
Fedora:# adduser fedoraUser

Fedora:# passwd # change root password.
Fedora:# passwd fedoraUser # change fedoraUser password.





To ENTER INTO THE CHROOT JAIL IN THE STANDARD WAY, without CONTROLLING TTY error, we will use agetty command:

Fedora:# yum install util-linux-ng #to obtain agetty command.
Sid:$ su -c "chroot ChDistro /sbin/agetty 38400 $(tty)"

We can login as fedoraUser.




USING SID X-Windows:

Sid:$xhost +local:`hostname` # Allow connections from local machine.

Fedora:$ export DISPLAY=:0.0 if you are using 0.0 display in Sid distro.
Fedora:$ xclock





INSTALLING EMACS

Fedora:# yum install emacs

We get this error, to solve it we will install some fonts e.g dejavu ones:

# Emacs fonts problems it is solved installing some fonts:
"Pango-CRITICAL **: No fonts found:
This probably means that the fontconfig
library is not correctly configured. You may need to
edit the fonts.conf configuration file. More information
about fontconfig can be found in the fontconfig(3) manual
page and on http://fontconfig.org"


Fedora:# yum install dejavu-fonts




INSTALLING FIREFOX

Fedora:# yum install firefox


Some errors occur:

D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory

solved with:
#dbus-uuidgen --ensure


GConf Error: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://www.gnome.org/projects/gconf/ for information. (Details - 1: Failed to get connection to session: Failed to execute dbus-launch to autolaunch D-Bus session)

solved installing:
#yum install dbus-x11 so /usr/bin/dbus-launch will be available.




SOUND SUPPORT IN OUR CHROOT

Fedora:# ls -l /dev/snd/*
We see a group number, 29 in my system. This is audio group in my Sid distro.
Fedora:# groupadd -g 29 audio
Fedora:# ls -l /dev/snd*
Fedora:# usermod -a -G audio fedoraUser

we can check if audio group was added:
Fedora:# groups fedoraUser

I use alsa in my system so:
Fedora:# yum install alsa-lib

Now we can use sound applications in our Fedora chroot environment.

4 comentarios:

Anonymous said...

Thank you sooooo much. A part of it was wat was exactly looking for, even more than that. You are awesome buddy :)

Vicente Hernando said...

Glad to know it was useful to you :)

Mosaab Alzoubi said...

https://github.com/moceap/mkchroot

Vicente Hernando said...

Thank you for the link.