Add removekmod template command (#1230356)
removekmod GLOB [GLOB...] --allbut KEEPGLOB [KEEPGLOB...]
This can be used to remove kernel modules from under
/lib/modules/*/kernel/ while keeping specific items. This should be
easier than constructing find arguments to select the right things to
save.
(cherry picked from commit 11c9e0e8ee
)
Resolves: rhbz#1230356
This commit is contained in:
parent
b79ad68a50
commit
a37a59b3eb
@ -74,36 +74,21 @@ remove /var/lib/rpm/* /var/lib/yum
|
|||||||
remove /usr/share/icons/*/icon-theme.cache
|
remove /usr/share/icons/*/icon-theme.cache
|
||||||
|
|
||||||
## clean up kernel modules
|
## clean up kernel modules
|
||||||
<%
|
removekmod sound drivers/media drivers/hwmon drivers/video \
|
||||||
removekmods = """
|
net/atm net/bluetooth net/sched net/sctp \
|
||||||
sound drivers/media drivers/hwmon drivers/video
|
net/rds net/l2tp net/decnet net/netfilter net/ipv4 net/ipv6 \
|
||||||
net/atm net/bluetooth net/sched net/sctp
|
drivers/watchdog drivers/target drivers/rtc drivers/input/joystick \
|
||||||
net/rds net/l2tp net/decnet net/netfilter net/ipv4 net/ipv6
|
drivers/bluetooth drivers/hid drivers/edac \
|
||||||
drivers/watchdog drivers/target drivers/rtc drivers/input/joystick
|
drivers/usb/serial drivers/usb/host drivers/usb/misc \
|
||||||
drivers/bluetooth drivers/hid drivers/edac
|
fs/ocfs2 fs/ceph fs/nfsd fs/ubifs fs/nilfs2 \
|
||||||
drivers/usb/serial drivers/usb/host drivers/usb/misc
|
arch/x86/kvm
|
||||||
fs/ocfs2 fs/ceph fs/nfsd fs/ubifs fs/nilfs2
|
|
||||||
arch/x86/kvm
|
|
||||||
"""
|
|
||||||
%>
|
|
||||||
%for kmodpath in removekmods.split():
|
|
||||||
remove lib/modules/*/kernel/${kmodpath}
|
|
||||||
%endfor
|
|
||||||
remove lib/modules/*/{build,source,*.map}
|
|
||||||
## Need to keep virtio_console.ko and ipmi stuff in drivers/char
|
## Need to keep virtio_console.ko and ipmi stuff in drivers/char
|
||||||
## Also keep virtio-rng so that the installer can get sufficient randomness for
|
## Also keep virtio-rng so that the installer can get sufficient randomness for
|
||||||
## LUKS setup.
|
## LUKS setup.
|
||||||
runcmd chroot ${root} find /lib/modules \
|
removekmod drivers/char --allbut virtio_console hw_random \
|
||||||
-regex ".*/kernel/drivers/char/.*" \
|
virtio-rng ipmi
|
||||||
\! -name virtio_console.ko\* \
|
removekmod drivers/staging --allbut zram
|
||||||
\! -name hw_random \
|
remove lib/modules/*/{build,source,*.map}
|
||||||
\! -name virtio-rng.ko\* \
|
|
||||||
\! -name ipmi\* \
|
|
||||||
-delete
|
|
||||||
runcmd chroot ${root} find /lib/modules \
|
|
||||||
-regex ".*/kernel/drivers/staging/.*" \
|
|
||||||
\! -name zram\* \
|
|
||||||
-delete
|
|
||||||
## NOTE: depmod gets re-run after cleanup finishes
|
## NOTE: depmod gets re-run after cleanup finishes
|
||||||
|
|
||||||
## remove unused themes, theme engines, icons, etc.
|
## remove unused themes, theme engines, icons, etc.
|
||||||
|
@ -533,7 +533,63 @@ class LoraxTemplateRunner(object):
|
|||||||
self._getsize(*remove)/1024, self._getsize(*filelist)/1024)
|
self._getsize(*remove)/1024, self._getsize(*filelist)/1024)
|
||||||
self.remove(*remove)
|
self.remove(*remove)
|
||||||
else:
|
else:
|
||||||
logger.debug("%s: no files to remove!", cmd)
|
logger.debug("removefrom %s: no files to remove!", cmd)
|
||||||
|
|
||||||
|
def removekmod(self, *globs):
|
||||||
|
'''
|
||||||
|
removekmod GLOB [GLOB...] [--allbut] KEEPGLOB [KEEPGLOB...]
|
||||||
|
Remove all files and directories matching the given file globs from the kernel
|
||||||
|
modules directory.
|
||||||
|
|
||||||
|
If '--allbut' is used, all the files from the modules will be removed *except*
|
||||||
|
the ones which match the file globs. There must be at least one initial GLOB
|
||||||
|
to search and one KEEPGLOB to keep. The KEEPGLOB is expanded to be *KEEPGLOB*
|
||||||
|
so that it will match anywhere in the path.
|
||||||
|
|
||||||
|
This only removes files from under /lib/modules/*/kernel/
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
removekmod sound drivers/media drivers/hwmon drivers/video
|
||||||
|
removekmod drivers/char --allbut virtio_console hw_random
|
||||||
|
'''
|
||||||
|
cmd = " ".join(globs)
|
||||||
|
if "--allbut" in globs:
|
||||||
|
idx = globs.index("--allbut")
|
||||||
|
if idx == 0:
|
||||||
|
raise ValueError("removekmod needs at least one GLOB before --allbut")
|
||||||
|
|
||||||
|
# Apply keepglobs anywhere they appear in the path
|
||||||
|
keepglobs = globs[idx+1:]
|
||||||
|
if len(keepglobs) == 0:
|
||||||
|
raise ValueError("removekmod needs at least one GLOB after --allbut")
|
||||||
|
|
||||||
|
globs = globs[:idx]
|
||||||
|
else:
|
||||||
|
# Nothing to keep
|
||||||
|
keepglobs = []
|
||||||
|
|
||||||
|
filelist = set()
|
||||||
|
for g in globs:
|
||||||
|
for top_dir in rglob(self._out("/lib/modules/*/kernel/"+g)):
|
||||||
|
for root, _dirs, files in os.walk(top_dir):
|
||||||
|
filelist.update(root+"/"+f for f in files)
|
||||||
|
|
||||||
|
# Remove anything matching keepglobs from the list
|
||||||
|
matches = set()
|
||||||
|
for g in keepglobs:
|
||||||
|
globs_re = re.compile(fnmatch.translate("*"+g+"*"))
|
||||||
|
m = filter(globs_re.match, filelist)
|
||||||
|
if m:
|
||||||
|
matches.update(m)
|
||||||
|
else:
|
||||||
|
logger.debug("removekmod %s: no files matched!", g)
|
||||||
|
remove_files = filelist.difference(matches)
|
||||||
|
|
||||||
|
if remove_files:
|
||||||
|
logger.debug("removekmod: removing %d files", len(remove_files))
|
||||||
|
map(remove, remove_files)
|
||||||
|
else:
|
||||||
|
logger.debug("removekmod %s: no files to remove!", cmd)
|
||||||
|
|
||||||
def createaddrsize(self, addr, src, dest):
|
def createaddrsize(self, addr, src, dest):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user