[PATCH livecd-tools] edit-livecd: -k --kickstart option
by apevec@redhat.com
Adds kickstart option for using kickstart file as an recipe for editing
a livecd image.
Following directives are honored:
part / --size <new rootfs size to be resized to>
bootloader --append "!opt-to-remove opt-to-add"
repo --baseurl=file://path-to-RPMs
%pre
%post
%packages
Cc: jboggs(a)redhat.com
---
imgcreate/creator.py | 4 +-
imgcreate/kickstart.py | 8 +++
tools/edit-livecd | 151 ++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 150 insertions(+), 13 deletions(-)
diff --git a/imgcreate/creator.py b/imgcreate/creator.py
index deb9d95..745a481 100644
--- a/imgcreate/creator.py
+++ b/imgcreate/creator.py
@@ -658,7 +658,7 @@ class ImageCreator(object):
except:
pass
- def __run_post_scripts(self):
+ def _run_post_scripts(self):
for s in kickstart.get_post_scripts(self.ks):
(fd, path) = tempfile.mkstemp(prefix = "ks-script-",
dir = self._instroot + "/tmp")
@@ -717,7 +717,7 @@ class ImageCreator(object):
self._create_bootconfig()
- self.__run_post_scripts()
+ self._run_post_scripts()
kickstart.SelinuxConfig(self._instroot).apply(ksh.selinux)
def launch_shell(self):
diff --git a/imgcreate/kickstart.py b/imgcreate/kickstart.py
index 345c638..2537fb6 100644
--- a/imgcreate/kickstart.py
+++ b/imgcreate/kickstart.py
@@ -546,6 +546,14 @@ def inst_langs(ks):
return ks.handler.packages.instLangs
return ""
+def get_pre_scripts(ks):
+ scripts = []
+ for s in ks.handler.scripts:
+ if s.type != ksparser.KS_SCRIPT_PRE:
+ continue
+ scripts.append(s)
+ return scripts
+
def get_post_scripts(ks):
scripts = []
for s in ks.handler.scripts:
diff --git a/tools/edit-livecd b/tools/edit-livecd
index 659cfae..ab86960 100755
--- a/tools/edit-livecd
+++ b/tools/edit-livecd
@@ -29,12 +29,16 @@ import shutil
import subprocess
import optparse
import logging
+import rpm
+import glob
from imgcreate.debug import *
from imgcreate.errors import *
from imgcreate.fs import *
from imgcreate.live import *
from imgcreate.creator import *
+import imgcreate.kickstart as kickstart
+from imgcreate import read_kickstart
class ExistingSparseLoopbackDisk(SparseLoopbackDisk):
"""don't want to expand the disk"""
@@ -110,6 +114,9 @@ class LiveImageEditor(LiveImageCreator):
self._LiveImageCreatorBase__isodir = None
"""directory where the iso is staged"""
+ self.ks = None
+ """optional kickstart file as a recipe for editing the image"""
+
# properties
def __get_image(self):
if self._LoopImageCreator__imagedir is None:
@@ -206,7 +213,8 @@ class LiveImageEditor(LiveImageCreator):
self._get_fslabel()
self.fslabel = self._LoopImageCreator__fslabel
- self._LoopImageCreator__image_size = os.stat(self._image)[stat.ST_SIZE]
+ if self._LoopImageCreator__image_size == None:
+ self._LoopImageCreator__image_size = os.stat(self._image)[stat.ST_SIZE]
self._LoopImageCreator__instloop = ExtDiskMount(
ExistingSparseLoopbackDisk(self._image,
@@ -355,12 +363,15 @@ class LiveImageEditor(LiveImageCreator):
except IOError, e:
raise CreatorError("Failed to open '%s' : %s" % (fpath, e))
else:
+ release = None
for line in cfgf:
i = line.find('Welcome to ')
if i > -1:
release = line[i+11:-2]
break
cfgf.close()
+ if not release:
+ return
ntext = dt.translate(None, '-') + '-' + _builder + '-Remix-' + release
@@ -396,12 +407,33 @@ class LiveImageEditor(LiveImageCreator):
if os.path.exists(src):
os.rename(src, cfgf)
- args = ['/bin/sed', '-i',
- '-e', 's/Welcome to .*/Welcome to ' + self._releasefile + '!/',
- '-e', 's/root=[^ ]*/root=live:CDLABEL=' + self.name + '/',
- '-e', 's/rootfstype=[^ ]* [^ ]*/rootfstype=auto ro/',
- '-e', 's/liveimg .* quiet/liveimg quiet/', cfgf]
-
+ args = ['/bin/sed', '-i']
+ if self._releasefile:
+ args.append('-e')
+ args.append('s/Welcome to .*/Welcome to ' + self._releasefile + '!/')
+ if self.clone:
+ args.append('-e')
+ args.append('s/rootfstype=[^ ]* [^ ]*/rootfstype=auto ro/')
+ args.append('-e')
+ args.append('s/liveimg .* quiet/liveimg quiet/')
+ args.append('-e')
+ args.append('s/root=[^ ]*/root=live:CDLABEL=' + self.name + '/')
+ if self.ks:
+ # bootloader --append "!opt-to-remove opt-to-add"
+ for param in kickstart.get_kernel_args(self.ks,"").split():
+ if param.startswith('!'):
+ param=param[1:]
+ # remove parameter prefixed with !
+ args.append('-e')
+ args.append("/^ append/s/%s //" % param)
+ # special case for last parameter
+ args.append('-e')
+ args.append("/^ append/s/%s$//" % param)
+ else:
+ # append parameter
+ args.append('-e')
+ args.append("/^ append/s/$/ %s/" % param)
+ args.append(cfgf)
dev_null = os.open("/dev/null", os.O_WRONLY)
try:
subprocess.Popen(args,
@@ -415,10 +447,96 @@ class LiveImageEditor(LiveImageCreator):
finally:
os.close(dev_null)
+ def _run_pre_scripts(self):
+ for s in kickstart.get_pre_scripts(self.ks):
+ (fd, path) = tempfile.mkstemp(prefix = "ks-script-",
+ dir = self._instroot + "/tmp")
+
+ os.write(fd, s.script)
+ os.close(fd)
+ os.chmod(path, 0700)
+
+ env = self._get_post_scripts_env(s.inChroot)
+
+ if not s.inChroot:
+ env["INSTALL_ROOT"] = self._instroot
+ preexec = None
+ script = path
+ else:
+ preexec = self._chroot
+ script = "/tmp/" + os.path.basename(path)
+
+ try:
+ subprocess.check_call([s.interp, script],
+ preexec_fn = preexec, env = env)
+ except OSError, e:
+ raise CreatorError("Failed to execute %%post script "
+ "with '%s' : %s" % (s.interp, e.strerror))
+ except subprocess.CalledProcessError, err:
+ if s.errorOnFail:
+ raise CreatorError("%%post script failed with code %d "
+ % err.returncode)
+ logging.warning("ignoring %%post failure (code %d)"
+ % err.returncode)
+ finally:
+ os.unlink(path)
+
+ class simpleCallback:
+ def __init__(self):
+ self.fdnos = {}
+
+ def callback(self, what, amount, total, mydata, wibble):
+ if what == rpm.RPMCALLBACK_TRANS_START:
+ pass
+
+ elif what == rpm.RPMCALLBACK_INST_OPEN_FILE:
+ hdr, path = mydata
+ print "Installing %s\r" % (hdr["name"])
+ fd = os.open(path, os.O_RDONLY)
+ nvr = '%s-%s-%s' % ( hdr['name'], hdr['version'], hdr['release'] )
+ self.fdnos[nvr] = fd
+ return fd
+
+ elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
+ hdr, path = mydata
+ nvr = '%s-%s-%s' % ( hdr['name'], hdr['version'], hdr['release'] )
+ os.close(self.fdnos[nvr])
+
+ elif what == rpm.RPMCALLBACK_INST_PROGRESS:
+ hdr, path = mydata
+ print "%s: %.5s%% done\r" % (hdr["name"], (float(amount) / total) * 100),
+
+ def install_rpms(self):
+ if kickstart.exclude_docs(self.ks):
+ rpm.addMacro("_excludedocs", "1")
+ if not kickstart.selinux_enabled(self.ks):
+ rpm.addMacro("__file_context_path", "%{nil}")
+ if kickstart.inst_langs(self.ks) != None:
+ rpm.addMacro("_install_langs", kickstart.inst_langs(self.ks))
+ # start RPM transaction
+ ts=rpm.TransactionSet(self._instroot)
+ for repo in kickstart.get_repos(self.ks):
+ (name, baseurl, mirrorlist, proxy, inc, exc) = repo
+ if baseurl.startswith("file://"):
+ baseurl=baseurl[7:]
+ elif not baseurl.startswith("/"):
+ raise CreatorError("edit-livecd accepts only --baseurl pointing to a local folder with RPMs (not YUM repo)")
+ if not baseurl.endswith("/"):
+ baseurl+="/"
+ for pkg_from_list in kickstart.get_packages(self.ks):
+ # TODO report if package listed in ks is missing
+ for pkg in glob.glob(baseurl+pkg_from_list+"-[0-9]*.rpm"):
+ fdno = os.open(pkg, os.O_RDONLY)
+ hdr = ts.hdrFromFdno(fdno)
+ os.close(fdno)
+ ts.addInstall(hdr,(hdr,pkg), "u")
+ ts.run(self.simpleCallback().callback,'')
+
def parse_options(args):
parser = optparse.OptionParser(usage = """
%prog [-n=<name>]
[-o=<output>]
+ [-k=<kickstart-file>]
[-s=<script.sh>]
[-t=<tmpdir>]
[-e=<excludes>]
@@ -439,6 +557,9 @@ def parse_options(args):
parser.add_option("-o", "--output", type="string", dest="output",
help="specify directory for new iso file.")
+ parser.add_option("-k", "--kickstart", type="string", dest="kscfg",
+ help="Path or url to kickstart config file")
+
parser.add_option("-s", "--script", type="string", dest="script",
help="specify script to run chrooted in the LiveOS "
"fsimage")
@@ -530,10 +651,10 @@ def main():
print >> sys.stderr, "You must run edit-liveos as root"
return 1
- if stat.S_ISBLK(os.stat(LiveOS).st_mode):
- name = get_fsvalue(LiveOS, 'LABEL') + '.edited'
- elif options.name and options.name != os.path.basename(LiveOS):
+ if options.name:
name = options.name
+ elif stat.S_ISBLK(os.stat(LiveOS).st_mode):
+ name = get_fsvalue(LiveOS, 'LABEL') + '.edited'
else:
name = os.path.basename(LiveOS) + ".edited"
@@ -557,9 +678,17 @@ def main():
editor.skip_minimize = options.skip_minimize
try:
+ if options.kscfg:
+ editor.ks = read_kickstart(options.kscfg)
+ # part / --size <new rootfs size to be resized to>
+ editor._LoopImageCreator__image_size = kickstart.get_image_size(editor.ks)
editor.mount(LiveOS, cachedir = None)
editor._configure_bootloader(editor._LiveImageCreatorBase__isodir)
- if options.script:
+ if editor.ks:
+ editor._run_pre_scripts()
+ editor.install_rpms()
+ editor._run_post_scripts()
+ elif options.script:
print "Running edit script '%s'" % options.script
editor._run_script(options.script)
else:
--
1.7.7.4
12 years, 2 months
Changes to 'refs/tags/livecd-tools-17.3'
by Brian C. Lane
Tag 'livecd-tools-17.3' created by Brian C. Lane <bcl(a)redhat.com> at 2011-12-22 01:08 +0000
Tag as livecd-tools-17.3
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQEVAwUATvKDFhF+jBaO/jp/AQJ73Qf/btzR5XZsAvW1F75Reqnhzv47U+kN/hv3
+aSar4XF6bM4YxuNfnz52f55xcr61KkaLElLeEh8IMhvwuR0TXSbpR6ETGgqCutc
udEWBNnbPCpKDINvXka0WpgZP1N4tPg8R8B8hsVAF2HYrLAcq+bI0rStJ1uox5q5
GanBrLmAxVrkqJwHZW6luiNkcMQqVnBjzWFEoKWEueXs/7Q0TlZfde3uexx4de5Z
3KYQdDsfX/4WGeLtVJ/VvGic0cFsuL6Hqg5XsfcoKg6lc3Guv1U4OwrFcogrxqmd
mSDyidcsuoyZsCz+gt6/o5p4QbZFaHLtl+OihgdJPTupDLNG44xvYQ==
=wjJH
-----END PGP SIGNATURE-----
Changes since livecd-tools-17.2:
Brian C. Lane (3):
Install edit-livecd to /usr/bin
python-imgcreate: remove -f from second lokkit call (#769457)
Version 17.3
---
Makefile | 3 ++-
imgcreate/kickstart.py | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
---
12 years, 3 months
Changes to 'refs/tags/livecd-tools-16.10'
by Brian C. Lane
Tag 'livecd-tools-16.10' created by Brian C. Lane <bcl(a)redhat.com> at 2011-12-22 01:24 +0000
Tag as livecd-tools-16.10
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQEVAwUATvKGuRF+jBaO/jp/AQIm3Qf9HiUFXODwwl5KuItMfSqnCbKgrQ4t2udc
YKgyguX4UJtktKm80LGO18HciPJ0QqlBLWxkbV1JRXVEw9ShXaJkRves85KBk6SP
4R2Djp7nx9Lod1JipuPWAKkW9VrhTYd0q+hhSdQzUpAH6g+Q0ljXXWFGBXyghyTn
decZeYPEpB2yLL2eMkCburZR+5LkoCJ/tBxJFCmvlaR2FaMuKA8AYBDiiRwDrkc8
bffYyO82WTH3Z7hrpF+5xQ/diNUcp3rf6e77c8dCwZ7S5UvM0QexUdRQ7xywrByD
3r9QMgrAzl+ZWtTTFIS3voerCcQrlt0UzaYK/V/P3nD6K/VHwP+32w==
=WMBR
-----END PGP SIGNATURE-----
Changes since livecd-tools-16.9:
Brian C. Lane (3):
Install edit-livecd to /usr/bin
python-imgcreate: remove -f from second lokkit call (#769457)
Version 16.10
---
Makefile | 3 ++-
imgcreate/kickstart.py | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
---
12 years, 3 months
Branch 'f16-branch' - 2 commits - imgcreate/kickstart.py Makefile
by Brian C. Lane
Makefile | 2 +-
imgcreate/kickstart.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
New commits:
commit a634ae0427764b37a1d0ae8ad0dab89d6a569e7e
Author: Brian C. Lane <bcl(a)redhat.com>
Date: Wed Dec 21 17:23:53 2011 -0800
Version 16.10
diff --git a/Makefile b/Makefile
index e35cacf..68804c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-VERSION = 16.9
+VERSION = 16.10
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
commit 48e24d462517b6dcc01e4f5f47ff1ab17000baa1
Author: Brian C. Lane <bcl(a)redhat.com>
Date: Wed Dec 21 14:47:40 2011 -0800
python-imgcreate: remove -f from second lokkit call (#769457)
lokkit gets called twice. -f is fine for the first call, but on the
second it wipes out any firewall settings. Remove it from the
SelinuxConfig class.
diff --git a/imgcreate/kickstart.py b/imgcreate/kickstart.py
index 345c638..09f5ed3 100644
--- a/imgcreate/kickstart.py
+++ b/imgcreate/kickstart.py
@@ -425,7 +425,7 @@ class SelinuxConfig(KickstartConfig):
def apply(self, ksselinux):
if os.path.exists(self.path("/usr/sbin/lokkit")):
- args = ["/usr/sbin/lokkit", "-f", "--quiet", "--nostart"]
+ args = ["/usr/sbin/lokkit", "--quiet", "--nostart"]
if ksselinux.selinux == ksconstants.SELINUX_ENFORCING:
args.append("--selinux=enforcing")
12 years, 3 months
2 commits - imgcreate/kickstart.py Makefile
by Brian C. Lane
Makefile | 2 +-
imgcreate/kickstart.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
New commits:
commit b3bcec8900e94580c51906af94c383bb4166a18a
Author: Brian C. Lane <bcl(a)redhat.com>
Date: Wed Dec 21 14:50:21 2011 -0800
Version 17.3
diff --git a/Makefile b/Makefile
index ca9c004..b03b2c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-VERSION = 17.2
+VERSION = 17.3
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
commit d00a4d83188fbc911bd55954a2011c91b650128f
Author: Brian C. Lane <bcl(a)redhat.com>
Date: Wed Dec 21 14:47:40 2011 -0800
python-imgcreate: remove -f from second lokkit call (#769457)
lokkit gets called twice. -f is fine for the first call, but on the
second it wipes out any firewall settings. Remove it from the
SelinuxConfig class.
diff --git a/imgcreate/kickstart.py b/imgcreate/kickstart.py
index 345c638..09f5ed3 100644
--- a/imgcreate/kickstart.py
+++ b/imgcreate/kickstart.py
@@ -425,7 +425,7 @@ class SelinuxConfig(KickstartConfig):
def apply(self, ksselinux):
if os.path.exists(self.path("/usr/sbin/lokkit")):
- args = ["/usr/sbin/lokkit", "-f", "--quiet", "--nostart"]
+ args = ["/usr/sbin/lokkit", "--quiet", "--nostart"]
if ksselinux.selinux == ksconstants.SELINUX_ENFORCING:
args.append("--selinux=enforcing")
12 years, 3 months
Announcing - A new way to make live media with livemedia-creator
by Brian C. Lane
livemedia-creator is a new addition to the lorax project. Its goal is to
create live images using anaconda so that we have one place to maintain
the logic defining what an installed system should look like.
lorax-17.1 contains the first release which should be working well
enough for people to experiment with. See the README.livemedia-creator
for details and examples. The current version can be used to create
bootable disk images or to convert those images into a bootable .iso
Development disussion will be on the anaconda-devel-list, and bugs can
be filed against lorax. I'll either take them or you can assign them to
bcl(a)redhat.com
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
12 years, 3 months
Not enough space for building a livecd on the / filesystem???
by Joshua C.
I've been creating livecds from livecds for quite some time now
without problems. Currently I'm getting a message about insufficient
free space:
Transaction couldn't start:
installing package man-pages-3.32-14.fc16.noarch needs 5MB on the / filesystem
installing package iwl5000-firmware-8.83.5.1_1-1.fc16.noarch needs 6MB
on the / filesystem
installing package ipw2200-firmware-3.1-5.fc15.noarch needs 6MB on the
/ filesystem
installing package ql2500-firmware-5.06.02-1.fc16.noarch needs 7MB on
the / filesystem
installing package rt73usb-firmware-1.8-8.fc15.noarch needs 7MB on the
/ filesystem
installing package iwl3945-firmware-15.32.2.9-5.fc15.noarch needs 7MB
on the / filesystem
installing package rootfiles-8.1-7.fc15.noarch needs 7MB on the / filesystem
installing package atmel-firmware-1.3-8.fc15.noarch needs 8MB on the /
filesystem
installing package
libertas-usb8388-firmware-2:5.110.22.p23-5.fc15.noarch needs 8MB on
the / filesystem
installing package rt61pci-firmware-1.2-8.fc15.noarch needs 8MB on the
/ filesystem
installing package zd1211-firmware-1.4-5.fc15.noarch needs 9MB on the
/ filesystem
installing package mtr-2:0.82-1.fc16.x86_64 needs 9MB on the / filesystem
installing package ivtv-firmware-2:20080701-21.noarch needs 10MB on
the / filesystem
installing package iwl4965-firmware-228.61.2.24-3.fc15.noarch needs
10MB on the / filesystem
installing package ipw2100-firmware-1.3-12.fc15.noarch needs 11MB on
the / filesystem
Error creating Live CD : Unable to install: Could not run transaction.
That's ridiculous. There are more than 26GB free on the HDD where the
build takes place and there're 8GB free memory on the machine. The
command I'm using is
livecd-creator --config=/mnt/win/fedora-cache/ks-files/fedora-livecd-kde.ks
--fslabel=Fedora16-`date +%F`-Custom-Build --title=Fedora-`date +%F`
--product=Fedora-`date +%F` --tmpdir=/mnt/win/fedora-cache/tmp/
--cache=/mnt/win/fedora-cache/cache/ --verbos
and as I said it's been working for quite some time now. The last
livecd I built was on Dec 12 and everything was fine. Can someone help
me fix this? How to point to the free memory?
--joshua
12 years, 3 months
live cd fedora 16
by sandeep babu
hi im sandeep,
i downloaded the files for live cd of fedora 16. i downloaded a file
called 'Fedora 16 i686 Live Desktop'. This folder had a file called GPL and
three folders called EFI , isolinux and LiveOS which had a no of files
inside. I am not able to burn an iso image from these files for creating a
live cd of fedora 16. i am using the infrarecorder disc burning software
for creating a live cd ...please direct me which files to select from these
files and burn the iso image....i had referred to the fedora documentation
but it has not helped. the documentation says to just burn the iso image
but i am not able to identify it...plzzz help me for i want to test this
edition of fedora 16....thanks in advance...and byeee...
12 years, 3 months
The 'firewall' option
by Lars Bjørndal
While making a custom livecd, the firewall option does not seems to work
correctly. Specifying in the kicstart file
'firewall --enabled --service=mdns --ssh' or 'firewall --enabled
--service=mdns --service=ssh' or 'firewall --enabled --service=mdns
--port=22', will create a firewall that don't let an ssh client connect.
I've used Fedora 15 to create the livecd. Is this a known problem?
Regards,
Lars
12 years, 3 months