Jump to: navigation, search

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...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
#!/usr/bin/env python
+
'''Note:''' This content is likely out of date. Ironic has supported local boot of Bare metal nodes for quite some time, and this page was likely posted when that work was still under development. For the latest ironic documentation, see https://docs.openstack.org/ironic/latest
import os
+
 
 +
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
 
   
 
   
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)
        open(old_grub_file, 'r') as reader:
+
  cmdline_existed = False
        for line in reader:
+
  with open(grub_file, 'w') as writer, \
            key = line.split('=')[0]
+
          open(old_grub_file, 'r') as reader:
            if key == grub_cmd:
+
          for line in reader:
                #If there is already some value:
+
              key = line.split('=')[0]
                if line.strip()[-1] == '"':
+
              if key == grub_cmd:
                    line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"'
+
                  #If there is already some value:
                cmdline_existed = True
+
                  if line.strip()[-1] == '"':
            writer.write(line)
+
                      line = line.strip()[:-1] + ' ' + ' '.join(kernel_parameters) + '"'
        if not cmdline_existed:
+
                  cmdline_existed = True
            line = grub_cmd + '=' + '"' + ' '.join(kernel_parameters) + '"'
+
              writer.write(line)
            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')

Latest revision as of 17:21, 3 May 2021

Note: This content is likely out of date. Ironic has supported local boot of Bare metal nodes for quite some time, and this page was likely posted when that work was still under development. For the latest ironic documentation, see https://docs.openstack.org/ironic/latest

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')