Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I am somewhat of a beginner to the world of Linux and shell scripting and had a quick question about post scripts in the kickstart file used for LiveCD-Creator. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2012
    Posts
    6

    LiveCD-Creator Chroot Kickstart Environment Question


    Hello,

    I am somewhat of a beginner to the world of Linux and shell scripting and had a quick question about post scripts in the kickstart file used for LiveCD-Creator. Namely I need to copy /etc/resolv.cfg from the current system to the live image being created and then run some commands on the new live image.

    Basically livecd-creator creates a temporary directory in /var/tmp called imgcreate-* (replace asterisk with some random hash). I have two options I can either run the post script with or without chroot.
    Code:
    %post --nochroot
    If I do run it with chroot then I am not able to copy resolv.cfg. Any suggestions or assistance would be greatly appreciated.

    Thanks

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by wert158 View Post
    Hello,

    I am somewhat of a beginner to the world of Linux and shell scripting and had a quick question about post scripts in the kickstart file used for LiveCD-Creator. Namely I need to copy /etc/resolv.cfg from the current system to the live image being created and then run some commands on the new live image.

    Basically livecd-creator creates a temporary directory in /var/tmp called imgcreate-* (replace asterisk with some random hash). I have two options I can either run the post script with or without chroot.
    Code:
    %post --nochroot
    If I do run it with chroot then I am not able to copy resolv.cfg. Any suggestions or assistance would be greatly appreciated.

    Thanks
    i think if you figure out where the root filesystem is mounted, then you can simply use that directory and copy your files to the new filesystem, relative to that dir.

    example ks file:
    Code:
    %post --nochroot --log=/tmp/postinstall.log
    
    rootdir=/mnt/sysimage
    if ! [ -d $rootdir ]; then
      echo The root filesystem mount point $rootdir was not found
      exit 1
    fi
    
    cp /tmp/resolv.cfg $rootdir/etc/
    that is just an example, of course. i don't know where the installer mounts your root filesystem, or where your resolv.cfg file is located.

  3. #3
    Just Joined!
    Join Date
    Jun 2012
    Posts
    6
    Thank you for your quick response atreyu,

    I'm sorry I should've provided more detailed code and background for others to work with. This script is the one that I am trying to run at post. The problem is that LiveCD-Creator mounts its temporary root filesystem at /var/tmp/imgcreate-* (*=some random hash). I'm just looking for a much more efficient way (less hackish) than looping through all the imgcreate-* folders to copy resolv.cfg and run some scripts. Unfortunately, I don't believe livecd-creator provides a way to reference its mount point.
    Code:
    ##############################
    # Run Post Scripts
    ##############################
    %post --nochroot --log=/root/post_install.log
    
    for directory in /var/tmp/imgcreate-*; do
    cp /etc/resolv.conf $directory/install_root/etc/resolv.conf  
    /usr/sbin/chroot $directory/install_root <<EOS
    
    ##############################
    # Initialize the MySQL Databases
    ##############################
    /sbin/service mysqld start
    /opt/perfsonar_ps/toolkit/scripts/initialize_databases
    /sbin/service mysqld stop
     
    ##############################
    # Remove Un-needed Cron Scripts
    ##############################
    rm -f /etc/cron.daily/cups
    rm -f /etc/cron.daily/makewhatis.cron
    rm -f /etc/cron.daily/mlocate.cron
    rm -f /etc/cron.daily/prelink
    rm -f /etc/cron.daily/rpm
    rm -f /etc/cron.weekly/makewhatis.cron
    
    ##############################
    # Force Enable Shadow Passwords
    ##############################
    /usr/sbin/pwconv
    
    ##############################
    # Force Root Password Change
    ##############################
    /usr/bin/chage -d 0 root
    
    ##############################
    # Cleanup
    ##############################
    rm $directory/install_root/root/.bash_history
    rm $directory/install_root/etc/resolv.conf
    touch $directory/install_root/etc/resolv.conf
    done
    %end

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    so in this part here:
    for directory in /var/tmp/imgcreate-*; do
    cp /etc/resolv.conf $directory/install_root/etc/resolv.conf
    you are trying to resolve multiple imgcreate-* dirs, right?

    i see that those directories are made when i create an image, but that postinstall script is run in the live system when booted from the created image, right? in that case, there is only one imgcreate-* dir, isn't there? so, the asterisk is expanding to only one directory anyway.

    or is that wrong, and the booted image has multiple imgcreate-* dirs?

  6. #5
    Just Joined!
    Join Date
    Jun 2012
    Posts
    6
    Yeah my issue was with multiple imgcreate-* dirs. I believe you are correct in saying that livecd-creator only creates one, however after several failed build attempts it left a number of imgcreate-* folders in my tmp because cleanup did not occur as the operation was aborted halfway through.

    It looks like I found a solution here (Sorry no links ):
    fedora(DOT)12(DOT)n6(DOT)nabble(DOT)com/using-post-nochroot-td2650488(DOT)html
    The script should provide a global variable $INSTALL_ROOT to use.

    I will mark this as solved and thank you so much for your assistance.

Posting Permissions

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