Difference between revisions of "Ironic-boot-kernel-parameters"
(Created page with "#!/usr/bin/env python import os grub_file = '/etc/default/grub' kernel_parameters = ['quiet', 'splash'] grub_cmd = 'GRUB_CMDLINE_LINUX' old_grub_file = grub_file+'~' os.rena...") |
|||
Line 1: | Line 1: | ||
− | #!/usr/bin/env python | + | This is a reference script to passing kernel paramters to ironic localboot instance using configdrive. |
− | import os | + | This only works with ubuntu image, so users should modify this script by their own use case: |
+ | |||
+ | #!/usr/bin/env python | ||
+ | import os | ||
− | grub_file = '/etc/default/grub' | + | # Default grub2 config file in Ubuntu |
− | kernel_parameters = ['quiet', 'splash'] | + | grub_file = '/etc/default/grub' |
− | grub_cmd = 'GRUB_CMDLINE_LINUX' | + | # Add parameters here to pass to instance. |
− | old_grub_file = grub_file+'~' | + | kernel_parameters = ['quiet', 'splash'] |
− | os.rename(grub_file, old_grub_file) | + | grub_cmd = 'GRUB_CMDLINE_LINUX' |
− | cmdline_existed = False | + | old_grub_file = grub_file+'~' |
− | with open(grub_file, 'w') as writer, \ | + | os.rename(grub_file, old_grub_file) |
− | + | cmdline_existed = False | |
− | + | with open(grub_file, 'w') as writer, \ | |
− | + | open(old_grub_file, 'r') as reader: | |
− | + | for line in reader: | |
− | + | key = line.split('=')[0] | |
− | + | if key == grub_cmd: | |
− | + | #If there is already some value: | |
− | + | if line.strip()[-1] == '"': | |
− | + | line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"' | |
− | + | cmdline_existed = True | |
− | + | writer.write(line) | |
− | + | if not cmdline_existed: | |
+ | line = grub_cmd + '=' + '"' + ' '.join(kernel_parameters) + '"' | ||
+ | writer.write(line) | ||
− | os.remove(old_grub_file) | + | os.remove(old_grub_file) |
− | os.system('update-grub') | + | os.system('update-grub') |
− | os.system('reboot') | + | os.system('reboot') |
Revision as of 09:13, 25 May 2016
This is a reference script to passing kernel paramters to ironic localboot instance using configdrive. This only works with ubuntu image, so users should modify this script by their own use case:
#!/usr/bin/env python import os # Default grub2 config file in Ubuntu grub_file = '/etc/default/grub' # Add parameters here to pass to instance. kernel_parameters = ['quiet', 'splash'] grub_cmd = 'GRUB_CMDLINE_LINUX' old_grub_file = grub_file+'~' os.rename(grub_file, old_grub_file) cmdline_existed = False with open(grub_file, 'w') as writer, \ open(old_grub_file, 'r') as reader: for line in reader: key = line.split('=')[0] if key == grub_cmd: #If there is already some value: if line.strip()[-1] == '"': line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"' cmdline_existed = True writer.write(line) if not cmdline_existed: line = grub_cmd + '=' + '"' + ' '.join(kernel_parameters) + '"' writer.write(line) os.remove(old_grub_file) os.system('update-grub') os.system('reboot')