Fedora equivalent of debootstrap

Debian has a lovely command for quickly creating new Debian installs, debootstrap. In a single command line you can create an entire new chrooted Debian install.

Sadly Fedora lacks the simplicity of debootstrap, but there are relatively easy ways to get some of the functionality of debootstrap, which I will document here.

Firstly the suggested method is to use mock, as described here. Mock is a bit heavyweight and rather too interactive.

You can use yum directly:

# mkdir /tmp/root
# cp /etc/yum.repos.d/fedora.repo /tmp/test.repo
edit /tmp/test.repo if you want to change distro, arch, etc,
and change the name of the repo in this file to "test"
# yum -c /tmp/test.repo \
  --disablerepo=* --enablerepo=test \
  --disableplugin=* \
  --installroot=/tmp/root \
  install list of packages

That will create a basic chroot environment in /tmp/root. Even a simple root filesystem with a few packages can be quite large — 200 MB is not uncommon.

There’s a little bit of post configuration still needed. You’ll find that the chroot /dev is empty. I investigated this and found that mock, etc actually create the basic dev nodes manually, which is painful but not too difficult.

debootstrap –foreign

Now debootstrap has a nice foreign feature, which allows you to make a chroot for an entirely different architecture, eg. a ppc chroot from an i386 host. Yum won’t let you do this, or more precisely, rpm will try to run the %pre and %post scripts and probably fail.

I suspect it is possible to modify yum so that it passes --noscripts to rpm, and saves up the scripts for you to run after the guest has booted (as does debootstrap).

Non-root

You have to run the yum command as root, and unlike debootstrap it is not possible to use fakeroot, or at least I couldn’t make it work. I think it fails at the chroot step, which fakeroot cannot really fake.

Making an initramfs (initrd.img)

It’s easy to create an initramfs image, however first you need to create a startup script for the kernel to run when it boots. Just create a shell script (or even a program, but a shell script is most common) called /init. By which I mean, it must be at the top of the root, so /tmp/root/init. The script or program must be executable (chmod +x).

To create the final initramfs:

cd /tmp/root
find -print0 | cpio -o0c | gzip > /tmp/initrd.img

You can test boot the image using qemu:

qemu -kernel /some/kernel -initrd /tmp/initrd.img -m 1024 -hda /dev/zero

(Enough memory is required in the guest to extract the root filesystem, plus more to run programs).

Future

There is certainly room for a modified mock or a Fedora-specific debootstrap. Having to create device nodes by hand is particularly unsatisfying — I’m not sure why these aren’t created by some base RPM.

11 Comments

Filed under Uncategorized

11 responses to “Fedora equivalent of debootstrap

  1. jef spaleta

    Have you look at what the Fedora ARM group are doing with regard to bootstrapping root filesystems for ARM?

    http://fedoraproject.org/wiki/Architectures/ARM/RfsBuild

    -jef

  2. Rahul Sundaram

    I have had a few people ask for those. It would be totally nice if you could spend sometime on solving this neatly. Maybe talk to Panu and Seth Vidal as well on how we can modify RPM and yum to do this in a better way

  3. rwmj

    Jef, thanks, exactly the sort of thing I was looking for.

    Rahul, can’t promise anything, but my current project involves lots of cross-building of root filesystems so the “foreign” functionality is quite important to me.

  4. Dan Horรกk

    I am using chroot environment built by mock quite regularly and I even successfully tried to install bootable system with “yum –installroot”. I wrote a simple wrapper around “yum –installroot” that executes some required post install steps.

    The missing device nodes could be part of the filesystem or setup packages. Similar situation was with some other files that were normally created by anaconda (/etc/hosts iirc).

  5. jef spaleta

    There’s probably some compelling synergy between the problem space you are dealing with and what the Fedora ARM people are dealing with across a number of fronts.

    You’ll also probably want to poke the Suse people concerning their Suse Studio infrastructure. And the moblin people about how they bootstrap appliance instances for developers.

    -jef

  6. rwmj

    Thanks Dan, I’m going to go back and take another look at mock today.

    Glad my initramfs builds and runs though ๐Ÿ™‚

  7. Pingback: febootstrap: Fedora equivalent of debootstrap « Richard WM Jones

  8. Pingback: install a chroot-fedora environment « Liu Xinyun's Kulakism

  9. Davlet Panech

    Project-Builder includes “rpmbootstrap”, with command line interface (nearly) identical to debootstrap. I haven’t tried it yet, but it claims to support many different RPM-base distros.

    See http://trac.project-builder.org/

    • rich

      rpmbootstrap requires root. If you’re allowed to use root, you might just as well run yum --installroot=/path directly. The point about febootstrap and debootstrap is that neither require root, since they use fakeroot and/or fakechroot. This allows you to run them in all sorts of situations where root access is unavailable or undesirable, eg. during “make”.

  10. tschmelcher

    I tried to use yum --installroot. It ignored the --installroot argument and clobbering my host system. Now I have to reinstall my OS. ๐Ÿ˜ฆ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.