def wipe_swap_linux(devices, proc_swaps): """Shred the Linux swap file and then reinitilize it""" if devices is None: return if 0 < count_swap_linux(): raise RuntimeError('Cannot wipe swap while it is in use') for device in devices: logger.info("wiping swap device '%s'", device) safety_limit_bytes = 16 * 1024 ** 3 # 16 gibibytes actual_size_bytes = get_swap_size_linux(device, proc_swaps) if actual_size_bytes > safety_limit_bytes: raise RuntimeError( 'swap device %s is larger (%d) than expected (%d)' % (device, actual_size_bytes, safety_limit_bytes)) uuid = get_swap_uuid(device) # wipe FileUtilities.wipe_contents(device, truncate=False) # reinitialize logger.debug('reinitializing swap device %s', device) args = ['mkswap', device] if uuid: args.append("-U") args.append(uuid) (rc, _, stderr) = General.run_external(args) if 0 != rc: raise RuntimeError(stderr.replace("\n", ""))
def wipe_swap_linux(devices, proc_swaps): """Shred the Linux swap file and then reinitialize it""" if devices is None: return if 0 < count_swap_linux(): raise RuntimeError('Cannot wipe swap while it is in use') for device in devices: #if '/cryptswap' in device: # logger.info('Skipping encrypted swap device %s.', device) # continue # TRANSLATORS: The variable is a device like /dev/sda2 logger.info(_("Wiping the swap device %s."), device) safety_limit_bytes = 29 * 1024**3 # 29 gibibytes actual_size_bytes = get_swap_size_linux(device, proc_swaps) if actual_size_bytes > safety_limit_bytes: raise RuntimeError( 'swap device %s is larger (%d) than expected (%d)' % (device, actual_size_bytes, safety_limit_bytes)) uuid = get_swap_uuid(device) # wipe FileUtilities.wipe_contents(device, truncate=False) # reinitialize # TRANSLATORS: The variable is a device like /dev/sda2 logger.debug(_("Reinitializing the swap device %s."), device) args = ['mkswap', device] if uuid: args.append("-U") args.append(uuid) (rc, _stdout, stderr) = General.run_external(args) if 0 != rc: raise RuntimeError(stderr.replace("\n", ""))
def wipe_swap_linux(devices, proc_swaps): """Shred the Linux swap file and then reinitilize it""" if devices is None: return if 0 < count_swap_linux(): raise RuntimeError('Cannot wipe swap while it is in use') for device in devices: logger.info("wiping swap device '%s'", device) safety_limit_bytes = 29 * 1024 ** 3 # 29 gibibytes actual_size_bytes = get_swap_size_linux(device, proc_swaps) if actual_size_bytes > safety_limit_bytes: raise RuntimeError( 'swap device %s is larger (%d) than expected (%d)' % (device, actual_size_bytes, safety_limit_bytes)) uuid = get_swap_uuid(device) // wipe 실행 FileUtilities.wipe_contents(device, truncate=False) // 초기화 logger.debug('reinitializing swap device %s', device) args = ['mkswap', device] if uuid: args.append("-U") args.append(uuid) (rc, _, stderr) = General.run_external(args) if 0 != rc: raise RuntimeError(stderr.replace("\n", ""))