Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
I want to add the partprobe command to initramfs image so that it is available during the %pre stage of a kickstart install. I've done some reading and the dracut ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    37

    How can I add a binary to initramfs image?


    I want to add the partprobe command to initramfs image so that it is available during the %pre stage of a kickstart install. I've done some reading and the dracut command appears to be what I'm supposed to use, but it's not exactly clear what the steps are.

    I have a custom CentOS iso I've created and I use this during a virt-install command that I run to create a VM based on this custom iso. I want to use partprobe during the %pre phase of the kickstart install, but it is not part of initramfs. What's the process I need to follow to add partprobe to initramfs?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by PeterSteele View Post
    I want to add the partprobe command to initramfs image so that it is available during the %pre stage of a kickstart install. I've done some reading and the dracut command appears to be what I'm supposed to use, but it's not exactly clear what the steps are.

    I have a custom CentOS iso I've created and I use this during a virt-install command that I run to create a VM based on this custom iso. I want to use partprobe during the %pre phase of the kickstart install, but it is not part of initramfs. What's the process I need to follow to add partprobe to initramfs?
    Hi,

    I think the initramfs file is a gzipped CPIO archive. You can confirm by doing:

    Code:
    file /boot/initramfs-x.xx.img
    If it reports back gzipped compress data, then you can try gunzipping it to STDOUT, and piping that to cpio, e.g.:

    Code:
    mkdir /tmp/working/;cd /tmp/working
    gunzip < /boot/initramfs-x.xx.img |cpio -i
    Then copy your file(s) to the dir you've created, that now contains the initramfs file hierarchy, e.g.:

    Code:
    cp /bin/program /tmp/working/bin/
    Then create a new initramfs image using find and piping STDOUT to cpio and piping that to gzip, e.g.:

    Code:
    find | cpio -H newc -o |gzip -9 > /tmp/initramfs-new.img
    Note: you have to be careful when you add binaries to a different root filesystem (which is exactly what an initramfs is - a mini Linux system): the binary may very well be expecting dependent libraries to also be in place in that initramfs filesystem. You will find out soon enough, when you try to run the binary in the initramfs execution. One way to see what libs a binary wants is via the ldd program, e.g.:

    Code:
    ldd /bin/program
    that command will list all the libraries that /bin/program needs to run.

    I have no idea what libs are in your initramfs file - they could be the same ones from your host OS, or could be different, lighter versions. Of course, you could also use a statically compiled binary, to avoid this hassle entirely.

    Another completely different solution would be to provide the binary (and any required libs) on some sort of external media that the client system has access to, during the install. I am thinking of a PXE booted install (and using a mounted NFS or SMB share, e.g.), or even a CD. you can have the program on this media/share and you can tell your script calling it where to find the required libs using the LD_LIBRARY_PATH environmental variable. Very handy.

    Good luck!

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    37
    I was in a hurry when I made my posting and I should have been a little more clear. I actually know how to deal with these comrpessed gzip/cpio files, I've added files to the initrd.img image before. My problem is that I cannot find the initramfs-x.xx.img file on the custom iso I've created. There is a directory called /image and in that are several img files, including initrd.img. But there is no initramfs.img file anywhere within the iso, at least not by that name.

    My intent was to add what I needed to initramfs.img on the iso itself, like I've done with initrd.img in the past, but it appears the initramfs.img is either created on the fly or is embedded in one of the core packages on the iso. On an installed system the file is located under /boot, but this directory isn't present on the iso.

    So where is initramfs?

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by PeterSteele View Post
    I was in a hurry when I made my posting and I should have been a little more clear. I actually know how to deal with these comrpessed gzip/cpio files, I've added files to the initrd.img image before. My problem is that I cannot find the initramfs-x.xx.img file on the custom iso I've created. There is a directory called /image and in that are several img files, including initrd.img. But there is no initramfs.img file anywhere within the iso, at least not by that name.

    My intent was to add what I needed to initramfs.img on the iso itself, like I've done with initrd.img in the past, but it appears the initramfs.img is either created on the fly or is embedded in one of the core packages on the iso. On an installed system the file is located under /boot, but this directory isn't present on the iso.

    So where is initramfs?
    I think perhaps the answer lies in how you are creating your ISO image. Can you share those commands, and possibly also what you use to create the initramfs, if you think that is necessary, too?

  5. #5
    Just Joined!
    Join Date
    Nov 2010
    Posts
    37
    I followed the process here, more or less, to create my custom iso. That part works fine and I use the custom iso to install CentOS systems without issues. I wanted to make a change however in my kickstart script that involved making partitions in %pre by called parted directly. When you create partitions though you have to call partx to have the kernel reread the partition table and partx isn't part of the default initramfs.

    I'm assuming anyway that this initramfs is the image that is loaded and running during the %pre phase. I haven't made any changes to initramfs though because I can't find it anywhere on the CentOS iso, either on the original or in my custom iso. I assume that it is packaged up inside one of the core OS files, or perhaps it is created on the fly.

    In any event, I've decided to change my process to avoid having to make this change to initramfs. I'd be curious though what the process is in the event I need to go back to this plan.

  6. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by PeterSteele View Post
    I followed the process here, more or less, to create my custom iso. That part works fine and I use the custom iso to install CentOS systems without issues. I wanted to make a change however in my kickstart script that involved making partitions in %pre by called parted directly. When you create partitions though you have to call partx to have the kernel reread the partition table and partx isn't part of the default initramfs.

    I'm assuming anyway that this initramfs is the image that is loaded and running during the %pre phase. I haven't made any changes to initramfs though because I can't find it anywhere on the CentOS iso, either on the original or in my custom iso. I assume that it is packaged up inside one of the core OS files, or perhaps it is created on the fly.

    In any event, I've decided to change my process to avoid having to make this change to initramfs. I'd be curious though what the process is in the event I need to go back to this plan.
    In this case of the article you linked to, the file you are interested is initrd.img (which you mentioned), specified in the isolinux.cfg file. It is the same thing as an initramfs image.

    You don't have to put the partx command in that file if you don't want. You can put it anywhere on your CDROM (along w/any required libs, too), and then mount the CD (which you're already doing) and call partx from your %pre script using the proper path.

  7. #7
    Just Joined!
    Join Date
    Nov 2010
    Posts
    37
    I originally thought initrd.img and initramfs.img were one and the same, and I went ahead and added partprobe to initrd.img. But based on what I observed, these two image files are not in fact the same. This page here talks about this a bit. The key difference is that initrd.img is statically created whereas initramfs is dynamically created. This page in fact may help me resolve this problem. I'll need to do some tests.

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    yes, initramfs is the new breed, but for what you are trying to do, the differences are negligible, i think. also the initrd format is not going away any time soon.

    something else i though about, install CDs that are based on RHEL often use an install.img to do the majority of their installs. the initrd (in the /isolinux dir) just gets the drives detected and starts everything up, then the filesystem in the install.img is extracted and run. the install.img is usually in the /images dir, and can be thought of as a self contained Live Linux image, customized for installing the OS.

    just some thoughts, anyway.

  9. #9
    Just Joined!
    Join Date
    Nov 2010
    Posts
    37
    What I want to do is some partitioning work in the %pre section, and I'd like to add both partprobe and partx to the image that runs during the %pre phase. I thought it was initrd.img and added these binaries to /sbin in this image. However, the commands where not present in /sbin in the environment that %pre runs in. It uses initramfs instead, and that's where I need to add these binaries. The initramfs image though is created dynamically, and I need to modify the tool that creates this image. I think it is dracut, but I've also seen references to mkrootfs. Not sure yet what the correct process is.

  10. #10
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by PeterSteele View Post
    What I want to do is some partitioning work in the %pre section, and I'd like to add both partprobe and partx to the image that runs during the %pre phase. I thought it was initrd.img and added these binaries to /sbin in this image. However, the commands where not present in /sbin in the environment that %pre runs in. It uses initramfs instead, and that's where I need to add these binaries. The initramfs image though is created dynamically, and I need to modify the tool that creates this image. I think it is dracut, but I've also seen references to mkrootfs. Not sure yet what the correct process is.
    I think you need to modify the "stage2.img" file, does that exist in your /images directory? It is akin to the install.img file.

    See this thread for more on modifying the stage2 image:

    Building a custom CentOS 5 kickstart disc, part 4

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •