Shred the Linux swap file and then reinitialize it
(devices, proc_swaps)
| 267 | |
| 268 | |
| 269 | def wipe_swap_linux(devices, proc_swaps): |
| 270 | """Shred the Linux swap file and then reinitialize it""" |
| 271 | if devices is None: |
| 272 | return |
| 273 | if 0 < count_swap_linux(): |
| 274 | raise RuntimeError('Cannot wipe swap while it is in use') |
| 275 | for device in devices: |
| 276 | # if '/cryptswap' in device: |
| 277 | # logger.info('Skipping encrypted swap device %s.', device) |
| 278 | # continue |
| 279 | # TRANSLATORS: The variable is a device like /dev/sda2 |
| 280 | logger.info(_("Wiping the swap device %s."), device) |
| 281 | safety_limit_bytes = 29 * 1024 ** 3 # 29 gibibytes |
| 282 | actual_size_bytes = get_swap_size_linux(device, proc_swaps) |
| 283 | if actual_size_bytes > safety_limit_bytes: |
| 284 | raise RuntimeError( |
| 285 | f'swap device {device} is larger ({actual_size_bytes})' |
| 286 | f' than expected ({safety_limit_bytes})') |
| 287 | uuid = get_swap_uuid(device) |
| 288 | # wipe |
| 289 | wipe_contents(device, truncate=False) |
| 290 | # reinitialize |
| 291 | # TRANSLATORS: The variable is a device like /dev/sda2 |
| 292 | logger.debug(_("Reinitializing the swap device %s."), device) |
| 293 | args = ['mkswap', device] |
| 294 | if uuid: |
| 295 | args.append("-U") |
| 296 | args.append(uuid) |
| 297 | (rc, _stdout, stderr) = General.run_external(args) |
| 298 | if 0 != rc: |
| 299 | raise RuntimeError(stderr.replace("\n", "")) |
| 300 | |
| 301 | |
| 302 | def wipe_memory(): |
no test coverage detected