CentOS upgrade - access to chroot in %pre?

Matt Rose mrose at n-able.com
Tue Aug 25 18:26:39 UTC 2009


quick, non-tested sample code to give you an idea, the following *WILL 
NOT* work on your machine, unless you're  really lucky and have your 
root partition as the second partition on the first hard drive.

Even if it does work, it won't really do anything.

%pre --interpreter /usr/bin/python --erroronfail --log=/tmp/kspre.log
import sys,os,time,shutil,parted,re,subprocess,zipfile
sys.path.append("/usr/lib/anaconda")
import isys,iutil

### This finds the first hard drive
drive = isys.hardDriveDict().keys()[0]

### The following will mount the second partition on the first harddrive 
as /tmp/sysimage
rootloc = "/tmp/sysimage"
os.makedirs(rootloc)
rootdrive = "/dev/%s2" % drive
isys.mount(rootdrive,rootloc,fstype="ext3")

###The following does some work to set up a somewhat sane chroot environment
os.system("chmod 644 /dev/null")
isys.mount("/dev","/tmp/sysimage/dev",fstype="tmpfs")
isys.mount("/proc","/tmp/sysimage/proc",fstype="proc")
isys.mount("/selinux","/tmp/sysimage/selinux",fstype="selinuxfs")

###The following function lets you open up subprocesses in the chroot 
environment
def chroot():
    os.chroot(rootloc)

###The following runs an rpm command to check the release in the chroot
subprocess.Popen("rpm -qa   
*release",preexec_fn=chroot,shell=True,stdout=subprocess.PIPE).stdout.read()

###Cleanup
isys.umount("/tmp/sysimage/dev")
isys.umount("/tmp/sysimage/proc")
isys.umount("/tmp/sysimage/selinux")
isys.umount("/tmp/sysimage")





Matt Rose wrote:
> Yes, on upgrade, but it's not easy.  You have to detect and mount the 
> partitions by hand.  If you know some python, you can include the 
> anaconda libs and helper functions, but if you're just using sh, you'd 
> have one hell of a %pre script.
>
> Matt
>
> Moray Henderson (ICT) wrote:
>> Hi everyone,
>>
>> Is it possible to make the /mnt/sysimage/... chroot available to the %pre script of a CentOS 5.3 upgrade?
>>
>>
>> Moray.
>> "To err is human.  To purr, feline"
>>
>>
>>
>> _______________________________________________
>> Kickstart-list mailing list
>> Kickstart-list at redhat.com
>> https://www.redhat.com/mailman/listinfo/kickstart-list
>>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/kickstart-list/attachments/20090825/1d007a06/attachment.htm>


More information about the Kickstart-list mailing list