6

/ is the highest directory in Linux. Is there a way to fake that to something else say /opt/rpmbuild/BUILDROOT?

Here's my problem space. I am trying to re-package a COTS into RPM format. The COTS came in a form of binary and I need to install that first before packaging it into RPM. The install is installing it into /opt/app directory, and I want it to install it into /opt/rpmbuild/BUILDROOT/opt/app but I couldn't force that to happen.

mailq
  • 17,023
  • 2
  • 37
  • 69

3 Answers3

6

chroot /opt/rpmbuild/BUILDROOT can do this, but it requires that you have a working OS installed within the chroot directory.

Instead of using chroot, a simpler option would be to create a symlink from /opt/app to /opt/rpmbuild/BUILDROOT/opt/app:

mkdir -p /opt/rpmbuild/BUILDROOT/opt/app
ln -s /opt/rpmbuild/BUILDROOT/opt/app /opt/app

Then the installation will think it's working in /opt/app, but will in fact go into /opt/rpmbuild/BUILDROOT/opt/app.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • Symlinks will not work if they refer a file/folder outside the root jail. Actually they will be relative to jail's root folder. You can use hardlinks or, better, bind mounts. – Mircea Vutcovici Nov 03 '11 at 21:06
  • Thank you for your suggestion. The key is chroot but like you said you need to have a working OS installed within the chroot directory. – Chun Tat David Chu Nov 03 '11 at 21:19
  • @MirceaVutcovici: I think I wasn't clear. I meant instead of chroot, not with it. Edited to clarify. – Andrew Schulman Nov 03 '11 at 23:19
2

Have a look into man chroot, this should help you.

Sven
  • 98,649
  • 14
  • 180
  • 226
0

What you want, but you may not have asked in your question is this: a combination of chroot and overlayfs

modprobe overlay
mount -t overlay overlay -o lowerdir=/,upperdir=/home/overlay/root_fs/upper,workdir=/home/overlay/root_fs/work /home/overlay/root_fs/root_slash
cd /home/overaly/root_fs/root_slash
chroot .

I mean: you'll need 'overlay file system' kernel module and necessary userspace tools to mount it; you'll also need these three folders - one for work, one for upper where the changes will be saved and the chroot one. This way you can use as a base your O.S. with all media's mounted, shares, etc and on top write only changes to the overlay file system. The changes in your case are the 'installation files'.