Commits

Michał Górny  committed 05f2da8

Support --destructive, to remove kernels refed by bootloader.

  • Participants
  • Parent commits caea37a

Comments (0)

Files changed (2)

File ecleankernel/cli.py

 	parser.add_option('-b', '--bootloader',
 			dest='bootloader', default='auto',
 			help='Bootloader used (auto, lilo, symlinks)')
+	parser.add_option('-d', '--destructive',
+			dest='destructive', action='store_true', default=False,
+			help='Destructive mode: remove kernels even when referenced by bootloader')
 	parser.add_option('-p', '--pretend',
 			dest='pretend', action='store_true', default=False,
 			help='Print the list of kernels to be removed and exit')
 	kernels = find_kernels()
 	removals = get_removal_list(kernels,
 			limit = None if opts.all else 0,
-			bootloader = opts.bootloader)
+			bootloader = opts.bootloader,
+			destructive = opts.destructive)
 
 	if not removals:
 		print('No outdated kernels found.')

File ecleankernel/process.py

 		if k.vmlinuz is None:
 			yield k
 
-def get_removal_list(kernels, limit = 0, bootloader = 'auto'):
+def get_removal_list(kernels, limit = 0, bootloader = 'auto', destructive = False):
 	""" Get a list of outdated kernels to remove. With explanations. """
 
 	out = RemovedKernelDict()
 		raise SystemError('No vmlinuz found. This seems ridiculous, aborting.')
 
 	if limit is None or limit > 0:
-		used = ()
-		for bl, getfunc in bootloaders:
-			if bootloader in ('auto', bl):
-				try:
-					used = getfunc()
-				except Exception:
-					pass
-				else:
-					lastbl = bl
-					break
-
-		realpaths = [os.path.realpath(x) for x in used]
-		if not realpaths:
-			raise SystemError('Unable to get kernels from bootloader config (%s)'
-					% bootloader)
-
-		prefix = '/boot/vmlinuz-'
-		def unprefixify(filenames):
-			for fn in filenames:
-				if fn.startswith(prefix):
-					yield fn[len(prefix):]
-				else:
-					print('Note: strangely named used kernel (%s)' % fn)
-
-		used = frozenset(unprefixify(realpaths))
+		if not destructive:
+			used = ()
+			for bl, getfunc in bootloaders:
+				if bootloader in ('auto', bl):
+					try:
+						used = getfunc()
+					except Exception:
+						pass
+					else:
+						lastbl = bl
+						break
+
+			realpaths = [os.path.realpath(x) for x in used]
+			if not realpaths:
+				raise SystemError('Unable to get kernels from bootloader config (%s)'
+						% bootloader)
+
+			prefix = '/boot/vmlinuz-'
+			def unprefixify(filenames):
+				for fn in filenames:
+					if fn.startswith(prefix):
+						yield fn[len(prefix):]
+					else:
+						print('Note: strangely named used kernel (%s)' % fn)
+
+			used = frozenset(unprefixify(realpaths))
+
 		if limit is not None:
 			raise NotImplementedError('Limiting number of removed kernels not supported yet')
 		for k in kernels:
-			if k.version not in used:
+			if destructive:
+				out.add(k, 'unwanted')
+			elif k.version not in used:
 				out.add(k, 'not referenced by bootloader (%s)' % lastbl)
 
 	current = os.uname()[2]