pygrub: verify chosen kernel really exists Verify that the chosen kernel really exists, and fail with an informative error if it does not. Signed-off-by: Andrew Cooper diff -r 32034d1914a6 tools/pygrub/src/pygrub --- a/tools/pygrub/src/pygrub +++ b/tools/pygrub/src/pygrub @@ -821,10 +821,15 @@ if __name__ == "__main__": if not fs: raise RuntimeError, "Unable to find partition containing kernel" + # Does the chosen kernel really exist ? + try: + data = fs.open_file(chosencfg["kernel"]).read() + except: + raise RuntimeError, "The chosen kernel does not exist" + if not_really: bootcfg["kernel"] = "" % chosencfg["kernel"] else: - data = fs.open_file(chosencfg["kernel"]).read() (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.", dir=output_directory) os.write(tfd, data)