chroot

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Chroot and the translation is 21% complete.
Outdated translations are marked like this.
வளங்கள்

chroot (change root) என்பது முதன்மை முறைமையின் வேர் அடைவிலிருந்து ஏரணப்படி பிரிக்கப்பட்ட ஒரு புதிய சூழலை உருவாக்குவதற்காகத் தோற்ற நிலை வேர் அடைவை மாற்றுவதற்குப் பயன்படுத்தப்படும் ஒரு ஊனிக்ஸ் முறைமை பயன்கூறு நிரலாகும். இந்த புதிய சூழலானது "chroot சிறை" என அழைக்கப்படும். இந்த சிறைக்குள் வேலை செய்யும் பயனரால், பூட்டப்பட்டிருக்கும் சூழலுக்கு வெளியில் உள்ள கோப்புகளைப் பார்க்கவோ அணுகவோ இயலாது.

சோதித்தல் அல்லது மென்பொருள் ஒவ்வுமை கண்டறிதல் நோக்கத்திற்காக இப்போதைய லினக்ஸ் முறைமையின் மேல் ஒரு தனி லினக்ஸ் முறைமையை உருவாக்குவதை chroot செய்தலின் முதன்மை பயன்பாடுகளுள் ஒன்றாகும். Chroot ஆனது மெய்நிகராக்கியின் துணையில்லாமல் இயங்குவதால் பொதுவாக இது மெய்நிகராக்கத்திற்கான எடைகுறைந்த மாற்றாகப் பார்க்கப்படுகிறது.

முன் தேவைகள்

சூழலை அமைத்தல்

ஒரு புதிய chroot அமைவை உருவாக்க, முதலில் chroot ஆனது தங்குவதற்கு ஒரு அடைவை உருவாக்க வேண்டும். எடுத்துக்காட்டாக, chroot ஐ /mnt/mychroot என்னும் இடத்தில் உருவாக்கலாம்:

user $mkdir /mnt/mychroot
user $cd /mnt/mychroot

பகிர்வில் இருந்து இப்போதுள்ள நிறுவலை ஏற்ற, பின்வரும் கட்டளையை இயக்கலாம். கீழுள்ள எடுத்துக்காட்டில் உள்ள <DEVICE> என்னும் சரத்திற்குப் பதிலாக இப்போதைய நிறுவலின் இயக்கி மற்றும் பகிர்வை இடுவதை உறுதிசெய்து கொள்ளவும்:

user $mkdir /mnt/mychroot
user $mount /dev/<DEVICE> /mnt/mychroot

நிறுவலானது இப்போதைய வேர் கோப்பு முறைமையின் துணை அடைவில் முன்பு உருவாக்கப்பட்டிருந்தால், மேலுள்ள படிகளை தவிர்த்துக்கொள்ளலாம்.

முறைமை கோப்புகள் மற்றும் Portage மர (புதிய நிறுவல்கள்) தொகுப்புகளைத் திறத்தல்

புதிய நிறுவலைக் கட்டுவதின் அடுத்த படியாக, நிலை3 மற்றும் Portage tarball களை பதிவிறக்கி பின் அவற்றை chroot இருப்பிடத்தில் அமைக்க வேண்டும். இந்த செயல்முறையைப் பற்றிய மேலும் தகவல்களுக்கு, ஜென்டூ கையேட்டில் உள்ள நிலை tarball ஐ பதிவிறக்குதல் மற்றும் நிலை tarball ஐ கட்டவிழ்தல்

root #links http://distfiles.gentoo.org/releases/amd64/autobuilds/
root #tar xvjpf stage3-*.tar.bz2 -C /mnt/mychroot

உள்ளமைவு

chroot ற்குள் நுழைவதற்கு முன், பல அடைவுகளை ஏற்ற வேண்டியுள்ளது:

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

சில அடிப்படை உள்ளமைவு கோப்புகள் புரவலில் இருந்து நகலெடுத்து வைக்க வேண்டியுள்ளது, இப்போதைய நிறுவலைப் பயன்படுத்தும்போது make.conf இன் மேல் நகலெடுக்க வேண்டாம்:

user $cp /etc/portage/make.conf /mnt/mychroot/etc/portage # இப்போதைய நிறுவலை பயன்படுத்தும்போது, இந்த படியை தவிர்த்து கொள்ளவும்.
user $cp /etc/resolv.conf /mnt/mychroot/etc

பயன்பாடு

இது முடிந்தவுடன், பின்வரும் கட்டளைகளை இயக்கி chroot சூழலிற்குள் நுழையவும்:

root #chroot /mnt/mychroot /bin/bash
root #env-update && . /etc/profile
root #export PS1="(chroot) $PS1"

ஒரு புதிய நிறுவலை உருவாக்கும்போது, எல்லாம் நாளிதுவரைக்கும் இருப்பதை உறுதிசெய்வதற்கு Portage ஆனது ஒத்திசைக்கப்பட்டிருக்க வேண்டும்.

(chroot) root #emerge-webrsync
(chroot) root #emerge --sync

முறைமை இப்போது தயாராக உள்ளது; தயங்காமல் இனி மென்பொருளை நிறுவலாம், அமைப்புகளோடு விளையாடலாம், சோதனை வழி தொகுப்புகள் மற்றும் உள்ளமைவுகளை சோதித்துப் பார்க்கலாம் (ஏனெனில் இவை எதுவும் இனி முதன்மை முறைமையில் எந்தவித தாக்கத்தையும் ஏற்படுத்தாது). chroot இல் இருந்து வெளியேற எளிமையாக exit எனத் தட்டச்சு செய்யவும் அல்லது Ctrl+d விசை கூட்டை அழுத்தவும். இவ்வாறு செய்வதால் தூண்டியானது இயல்பான சூழலுக்குத் திரும்பிவிடும். ஏற்றப்பட்ட அடைவுகளை umount செய்ய மறந்துவிடாதீர்.

systemd-nspawn

If the system uses systemd, systemd-nspawn can be used, which can automatically handle much of the boilerplate required in administering chroots. For example, to enter a chroot via systemd-nspawn with the same configuration as specified in the Configuration section, simply run:

root #cp /etc/portage/make.conf /mnt/mychroot/etc/portage
root #systemd-nspawn -D /mnt/mychroot --bind=/tmp --resolv-conf=/etc/resolv.conf

Init குறுநிரல்கள்

chroot ஐ அமைக்கும் செயலை அடிக்கடி செய்ய வேண்டிய நிலை ஏற்பட்டால், ஒரு init குறு நிரலைப் பயன்படுத்தி அடைவுகளின் ஏற்றத்தை வேகப்படுத்த இயலும். குறு நிரலை முன்னிருப்பு ஓடுநிலையில் சேர்ப்பதன்மூலம் முறைமை துவக்கத்தில் இது தானியக்கமாக இயங்குமாறு செய்யலாம்:

கோப்பு /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"
}

வேறு அடைவு அல்லது பகிர்வைப் பயன்படுத்தும்போது, start() செயலாற்றியில் தேவையான ஏற்றுதல் கட்டளைகளைச் சேர்த்து, /mnt/chroot என்பதைப் பொருத்தமான பெயருக்கு மாற்றவும்.

Sound and graphics

The software running inside the chroot will by default not have access to the system sound- and display-server. Fixing this is done by either sharing a socket, or by running the communication with TCP over localhost.

Wayland

Wayland uses a socket to connect clients with the compositor. This socket needs to be shared with the chroot to make graphical applications work. The general procedure for finding this socket is:[1]

  1. If WAYLAND_SOCKET is set, interpret it as a file descriptor number on which the connection is already established, assuming that the parent process configured the connection for us.
  2. If WAYLAND_DISPLAY is set, concat with XDG_RUNTIME_DIR to form the path to the Unix socket.
  3. Assume the socket name is wayland-0 and concat with XDG_RUNTIME_DIR to form the path to the Unix socket.

Using WAYLAND_DISPLAY and XDG_RUNTIME_DIR is fine in most cases and will be used here. By default XDG_RUNTIME_DIR is set to /run/user/$(uid). This directory will not be available in the chroot because the #Configuration instructions bind mounts /run non-recursively. Assuming the user's uid is 1000, this can be solved by either bind-mounting /run/user/1000 with:

root #mkdir -p /mnt/mychroot/run/user/1000
root #mount --bind /run/user/1000 /mnt/mychroot/run/user/1000

or by simply recursively bind mounting /run with:

root #mount --rbind /run /mnt/mychroot/run

The Wayland library dev-libs/wayland uses the same procedure for finding out the socket as listed above. So to share the socket with the chroot, the only thing that's needed to do is defining XDG_RUNTIME_DIR and WAYLAND_DISPLAY. Here it is assumed that the Wayland socket name WAYLAND_DISPLAY is wayland-0.

(chroot) root #useradd -m user
(chroot) root #su -l user
(chroot) user $export XDG_RUNTIME_DIR=/run/user/1000
(chroot) user $export WAYLAND_DISPLAY=wayland-0
(chroot) user $MOZ_ENABLE_WAYLAND=1 firefox-bin

Permission errors will occur if the user in the chroot does not have permissions to access the Wayland socket. This can be solved by using user namespace remapping or ACLs. The easiest solution is to just make sure that the user ids match. The useradd -u, --uid UID option can be used when creating a user.

PipeWire

Like Wayland, PipeWire uses a socket to connect clients to the PipeWire daemon.

Applications assume that the PipeWire socket will be located in ${XDG_RUNTIME_DIR}/pipewire-0, so the only thing that's needed to get PipeWire clients to connect to the host's daemon is to expose XDG_RUNTIME_DIR to the chroot. This process is identical to the one described in #Wayland. To expose XDG_RUNTIME_DIR, often /run/user/$(uid), the following commands are used:

root #mkdir -p /mnt/mychroot/run/user/1000
root #mount --bind /run/user/1000 /mnt/mychroot/run/user/1000

XDG_RUNTIME_DIR will not be set when logging in inside the chroot, therefore XDG_RUNTIME_DIR needs to exported so the PipeWire client can find the socket:

(chroot) user $export XDG_RUNTIME_DIR=/run/user/1000
(chroot) user $pw-cli

Xorg

Xorg by default listens on a socket located in /tmp/.X11-unix/X${DISPLAY}, as well as on localhost TCP port 6000 + ${DISPLAY}[2]. The instructions in #Configuration bind mounts /tmp, and therefore no additional configuration is needed except setting the DISPLAY variable before running a graphical application:

(chroot) user $DISPLAY=:0 firefox-bin

If the uid of the user inside the chroot does not match the uid outside the chroot, then setting permissions with xhost will be needed. To allow all local connections, run outside the chroot:

user $xhost +local:

இதையும் காண்க

External resources

References

  1. https://wayland-book.com/protocol-design/wire-protocol.html
  2. So if DISPLAY=:12, then Xorg will listen on localhost TCP port 6012