(Created page with "DISCLAIMER: This can potentially wreck your Linux installation so use it at your own risk! == creating chroot with obs == === Prerequisites === first you need to setup a projec…") |
(→creating chroot with obs) |
||
| (One intermediate revision not shown) | |||
| Line 2: | Line 2: | ||
== creating chroot with obs == | == creating chroot with obs == | ||
| + | Please note that most likely you don't need to do this and instead you want to do | ||
| + | |||
| + | osc chroot [target] | ||
=== Prerequisites === | === Prerequisites === | ||
| Line 91: | Line 94: | ||
=== Exit the chroot === | === Exit the chroot === | ||
| - | When you're done hacking inside the chroot type 'exit' to exit it and the script will unmount the | + | When you're done hacking inside the chroot type 'exit' to exit it and the script will unmount the mounted things from it. |
=== Removing the chroot directory === | === Removing the chroot directory === | ||
DISCLAIMER: This can potentially wreck your Linux installation so use it at your own risk!
Contents |
Please note that most likely you don't need to do this and instead you want to do
osc chroot [target]
first you need to setup a project with a build target that you want to use as the chroot (e.g. Trunk:Testing ia23).
After you have created the OBS project, create a "dummy" spec file. It can be something like this:
Name: test
Summary: Test yaml
Version: 0.0.1
Release: 0
Group: Applications/Multimedia
License: GPL
Source100: test.yaml
BuildRequires: nano
BuildRequires: zypper
BuildRequires: wget
BuildRequires: openssh-clients
%description
Testing
%prep
%build
%install
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
Check out your OBS project and trigger a local build for you target
osc co home:[your_username] cd [your-dummy-package] osc build --no-verify [target]
copy the build root e.g. to your home directory
sudo cp /var/tmp/build-root my-chroot
At this point you have the chroot but you still need to mount and chroot into it..
Create the following script that handles the mounts and unmounts.
# enter-chroot.sh
#!/bin/bash
bindpath=$PWD/$1
echo "Mounting the directories..."
mount -o bind /proc $bindpath/proc
mount -o bind /proc/sys/fs/binfmt_misc $bindpath/proc/sys/fs/binfmt_misc
mount -o bind /sys $bindpath/sys
mount -o bind /dev $bindpath/dev
mount -o bind /dev/pts $bindpath/dev/pts
mount -o bind /dev/shm $bindpath/dev/shm
mount -o bind /var/lib/dbus $bindpath/var/lib/dbus
mount -o bind /var/run/dbus $bindpath/var/run/dbus
mkdir -p $bindpath/parentroot
mount -o bind / $bindpath/parentroot
mkdir -p $bindpath/lib/modules/`uname -r`
mount -o bind /lib/modules/`uname -r` $bindpath/lib/modules/`uname -r`
cp /etc/resolv.conf $bindpath/etc/resolv.conf
echo "Entering chroot"
chroot $bindpath
echo "Unmounting the directories..."
umount $bindpath/lib/modules/`uname -r`
umount $bindpath/parentroot
umount $bindpath/var/run/dbus
umount $bindpath/var/lib/dbus
umount $bindpath/dev/shm
umount $bindpath/dev/pts
umount $bindpath/dev
umount $bindpath/sys
umount $bindpath/proc/sys/fs/binfmt_misc
umount $bindpath/proc
echo "Done."
Use the script to enter the chroot
sudo ./enter-chroot.sh my-chroot
When you're done hacking inside the chroot type 'exit' to exit it and the script will unmount the mounted things from it.
If you decide to 'rm -rf' the chroot directory make sure that anything is not mounted to it since you can destroy your linux installation by removing it when something is mounted.
check if something is mounted there be
mount
if the print from the command contains paths pointing to the chroot directory umount it them before removing the chroot directory or you will find yourself reinstalling your system.