This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
Chroot
Chroot (Change root) is a Unix system utility used to change the apparent root directory to create a new environment logically separate from the main system's root directory. This new environment is known as a "chroot jail." A user operating inside the jail cannot see or access files outside of the environment they have been locked into.
Chroot'un ana kullanım alanlarından birisi Linux sistemi içerisinde test veya uyumluluk amaçlı farklı bir sistem ortamı yaratmaktır. Sanallaştırma yazılımı gerektirmediği için genelde sanallaştırmaya hafif bir alternatif olarak görülür.
Prerequisites
Setting up the environment
Yeni bir kuruluma başlarken ilk olarak yapmanız gereken işlem chroot olarak kullanılacak dizinin oluşturulmasıdır, örneğin /mnt/chrootdizini
user $
mkdir /mnt/chrootdizini
user $
cd /mnt/chrootdizini
Farklı bir disk bölümünde zaten var olan bir kurulumu bağlamak isterseniz aşağıdaki komutu çalıştırabilirsiniz. <AYGIT>
yerine kurulumun yapıldığı disk bölümün girdiğinize emin olun:
user $
mkdir /mnt/chrootdizini
user $
mount /dev/AYGIT /mnt/chrootdizini
Zaten bulunduğunuz kök dizinin altında bir kurulum var ise, yukarıdaki adımları uygulamanıza gerek yok.
Unpacking system files and the Portage tree (new installations)
When building a new install, the next step is to download the stage3 and Portage tarballs and set them up in the chroot location. For more information on this process please see Downloading the stage tarball and Unpacking the stage tarball in the Gentoo Handbook.
root #
tar xvjpf stage3-*.tar.bz2 -C /mnt/mychroot
root #
links http://distfiles.gentoo.org/snapshots/
root #
tar xvjf portage-*.tar.bz2 -C /mnt/mychroot/usr
Yapılandırma
Chroot'a giriş yapmadan önce bazı dizinleri bağlamamız (mount etmemiz) gerekmekte:
root #
mount --rbind /dev /mnt/mychroot/dev
root #
mount --make-rslave /mnt/mychroot/dev
root #
mount -t proc /proc /mnt/mychroot/proc
root #
mount --rbind /sys /mnt/mychroot/sys
root #
mount --make-rslave /mnt/mychroot/sys
root #
mount --rbind /tmp /mnt/mychroot/tmp
Ayrıca ana sistemden bazı temel yapılandırma dosyalarını da kopyalamalısınız. Bu aşamada yeni kurulum değilse make.conf dosyasını kopyalamayın:
user $
cp /etc/portage/make.conf /mnt/chrootdizini/etc/portage # Yeni kurulum değilse bu adımı es geçin.
user $
cp /etc/resolv.conf /mnt/chrootdizini/etc
copypasta option (optional)
It's possible to invoke this command to save time if you're able to copy+paste.
Do not forgett to change /mnt/mychrooto AND /dev/sda4 for your variables if neccesary!!
root #
mkdir /mnt/mychroot && cd /mnt/mychroot && mount /dev/sda4 /mnt/mychroot && mount --rbind /dev /mnt/mychroot/dev && mount --make-rslave /mnt/mychroot/dev && mount -t proc /proc /mnt/mychroot/proc && mount --rbind /sys /mnt/mychroot/sys && mount --make-rslave /mnt/mychroot/sys && mount --rbind /tmp /mnt/mychroot/tmp && chroot /mnt/mychroot /bin/bash
In Chroot environment do not forgett on:
root #
source /etc/profile
root #
env-update
root #
export PS1="(chroot) $PS1"
Usage
Artık chroot ortamına giriş yapabiliriz:
root #
chroot /mnt/chrootdizini /bin/bash
root #
env-update
root #
source /etc/profile
root #
export PS1="(chroot) $PS1"
Yeni kurulum sırasında Pportage'ı senkronize edip herşeyin güncel olduğuna emin olun.
root #
emerge --sync
The system is now ready; feel free to install software, mess with settings, test experimental packages and configurations without having any effect on the main system. To leave the chroot simply type exit or press Ctrl+d. Doing so will return the console back to the normal environment. Do not forget to umount the directories that have been mounted.
Init scripts
If setting up chroots is a task that is needed to be performed often, it is possible to speed up the mounting of the directories by using an init script. The script could be added to the default runlevel and therefore set up automatically on system boot:
/etc/init.d/mychroot
#!/sbin/openrc-run depend() { need localmount need bootmisc } start() { ebegin "Mounting chroot directories" mount -o rbind /dev /mnt/mychroot/dev > /dev/null & mount -t proc none /mnt/mychroot/proc > /dev/null & mount -o bind /sys /mnt/mychroot/sys > /dev/null & mount -o bind /tmp /mnt/mychroot/tmp > /dev/null & eend $? "An error occurred while mounting chroot directories" } stop() { ebegin "Unmounting chroot directories" umount -f /mnt/mychroot/dev > /dev/null & umount -f /mnt/mychroot/proc > /dev/null & umount -f /mnt/mychroot/sys > /dev/null & umount -f /mnt/mychroot/tmp > /dev/null & eend $? "An error occurred while unmounting chroot directories" }
Eğer farklı bir dizin veya disk bölümü kullanıyorsanız gerekli değişiklikleri yapmayı unutmayın.