1

We can have the full filesystem structure of any OS in a directory. To which we can chroot, so it will behave as good as native login.

Is there any way to install the an OS onto a partition with the help of chroot ?

e.g. I want to install Ubuntu-14.04 in my /home/SHW/Ubuntu-14.04 directory. Once installed, I can chroot into it and can do some user-space work

( Installing the OS onto a partition and mounting that at /home/SHW/Ubuntu-14.04 is not what I'm looking for)

EDIT:

Though I have mentioned Ubuntu in original question, but my target OS is developed by third party from scratch. As per the @mattdm, debootstrap is useful for ubuntu. But I need almost similar solution to install any OS

  • you do not need a full install to chroot. you can use virtual host, export / and mount it via nfs. – Archemar Sep 12 '14 at 12:43
  • on a second tough, try looking at xen. (I dont provide a full answer because I no longer have a xen to check what should be done). – Archemar Sep 12 '14 at 12:49
  • If you're looking for "an installer" that lets you install an OS into a directory without the concept of block devices/partitions, have a look at how gentoo or crux are installed. (substitute /mnt with your /home/SHW/gentoo directory in the instructions). Please note that in many situations your commands in the chroot will want access to /proc and other parts of the system. If you want ubuntu or something else, it is probably easier to just copy it with tar from an installation or running livecd. – MattBianco Sep 12 '14 at 13:37
2

Yes! This is what debootstap is for — at least in Debian-derived distributions like Ubuntu. There are great, straightforward instructions for doing (almost) exactly what you're looking for on the Ubuntu wiki: https://wiki.ubuntu.com/DebootstrapChroot. This has some important steps for bind mounting /proc/, /dev/ and /sys/ which you'll need for the chroot part.

Unfortunately, in the Fedora/RPM-based distro world, we don't have anything quite like that, although a) I think anaconda, the Fedora installer, can actually do this, but there's not good documentation for the process and b) you can just yum install packages into a chroot, which will work but isn't quite the same as getting a real system installed there. The Mock tool does "b" in order to provide a clean environment for package building, and does the bind mounts and everything, and you can actually use it (with mock shell) for other things in a pinch.

I say "almost exactly what you're looking for" because a chroot OS won't behave quite like a native install. To get closer, you want to use containers, which are basically a system for using Linux kernel features to make that chroot seem more like a full native OS to applications running in it. Right now, the hot topic in this space is Docker, a simple tool for managing and launching containers of all sorts. You can make your own base images (starting by using debootstrap in a chroot, for example!) or you can launch existing ones from the registry. Try:

$ sudo docker run -i -t fedora /bin/bash

even on an Ubuntu system, and that'll download and put you at a shell prompt inside a Fedora-based container. Or you can use the ubuntu base on Fedora or anywhere else — the only requirement is that the host kernel isn't ancient (or, of course, you can just run the same OS in the container as your host OS).

  • debootstrap is for native Ubuntu only. My target OS is non-standard. I have ISO of it. How can I used the above mentioned methods/tools to achieve the goal. Once installed, rather invoking any application, I'm more interested to explore their filesystem structure – SHW Sep 15 '14 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.