----- Original Message ----- | Cheers, I'll walk you through how I came up with the augeas commands. | | Opening augtool and printing /files/boot/grup/menu.lst shows how the | lense has constructed the augeas tree (edited for brevity): | | augtool> print /files/boot/grub/menu.lst/ | /files/boot/grub/menu.lst | /files/boot/grub/menu.lst/#comment[1] = "grub.conf generated by | anaconda" | ... | /files/boot/grub/menu.lst/default = "0" | /files/boot/grub/menu.lst/timeout = "0" | /files/boot/grub/menu.lst/splashimage = "(hd0,0)/grub/splash.xpm.gz" | ... | /files/boot/grub/menu.lst/title[2] = "Fedora (2.6.40.4-5.fc15.x86_64)" | /files/boot/grub/menu.lst/title[2]/root = "(hd0,0)" | /files/boot/grub/menu.lst/title[2]/kernel = "/ | vmlinuz-2.6.40.4-5.fc15.x86_64" | /files/boot/grub/menu.lst/title[2]/kernel/ro | ... | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | Looks like each boot option is created as in array format in the title | branch of the tree, with a value of the actual title of the boot | option. That makes finding just the Windows one very easy, however it | depends on you knowing the title of the kernel option, which I'm going | to assume you do. | | augtool> print /files/boot/grub/menu.lst/title[.="Windows"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | The period in the path expression /files/boot/grub/menu.lst/ | title[.="Windows"] is a shortcut for self::*, which is tree node | 'title' in this case, so in laymans terms "print title where title = | Windows". | | As a learning exercise lets assume we don't know the title of the | Windows Grub option, but we assume that anything that has | "chainloader= | +1" we need to do something with, we can use this path expression, | which says "child tree nodes of the name 'chainloader' with the value | '+1'". | | augtool> print /files/boot/grub/menu.lst/ | title[child::chainloader="+1"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | It can be simplified by dropping the "child::" bit, which is an augeas | shortcut: | | augtool> print /files/boot/grub/menu.lst/title[chainloader="+1"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | Back to your example, adding the savedefault node: | | augtool> ins savedefault after /files/boot/grub/menu.lst/ | title[.="Windows"]/chainloader | augtool> print /files/boot/grub/menu.lst/title[.="Windows"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | /files/boot/grub/menu.lst/title[4]/savedefault | augtool> save | Saved 1 file(s) | augootl> quit | [root@biguml-laptop ~]# tail -n 4 /boot/grub/grub.conf | title Windows | rootnoverify (hd0,0) | chainloader +1 | savedefault | | Looks good. | | You piqued my interest with the savedefault option though so I looked | it up. Are you sure you don't want it on every kernel boot option so | if you change into different Linux kernels it remembers them as well? | | You can do that with augeas too, using a combination of setm and | clearm (set multiple and clear multiple). | | First use setm to create the 'savedefault' node as a child of all | 'title' nodes and then clear the value of these node, as the | 'savedefault' option doesn't have a value: | | augtool> setm /files/boot/grub/menu.lst/title savedefault 1 | augtool> clearm /files/boot/grub/menu.lst/title savedefault | augtool> save | Saved 1 file(s) | | [root@biguml-laptop ~]# cat /boot/grub/grub.conf | # grub.conf generated by anaconda | # | # Note that you do not have to rerun grub after making changes to this | file | # NOTICE: You have a /boot partition. This means that | # all kernel and initrd paths are relative to /boot/, eg. | # root (hd0,0) | # kernel /vmlinuz-version ro root=/dev/mapper/vg_root-lv_root | # initrd /initrd-[generic-]version.img | #boot=/dev/sda | default=0 | timeout=0 | splashimage=(hd0,0)/grub/splash.xpm.gz | hiddenmenu | title Fedora (2.6.40.6-0.fc15.x86_64) | root (hd0,0) | kernel /vmlinuz-2.6.40.6-0.fc15.x86_64 ro root=/dev/mapper/vg_root- | lv_root rd_LUKS_UUID=luks-08041027-ab79-4f45-87b0-756d1eeb26e5 | rd_LVM_LV=vg_root/lv_root rd_NO_MD rd_NO_DM LANG=en_GB.UTF-8 | SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet | initrd /initramfs-2.6.40.6-0.fc15.x86_64.img | savedefault | title Windows | rootnoverify (hd0,0) | chainloader +1 | savedefault | | | There we go. | | You might run into a problem using setm in Puppet, probably clearm as | well, as I don't think ruby-augeas supports it properly (I can't | remember the error). In my manifests I call augtool in an Exec | resource. In Fedora at least, augtool -s "<command>" wasn't saving the | files either so I had to get even more hacky and use a temporary file | (urgh...). This is from one of my modules: | | $aug_tmp_file = "/tmp/.puppet_base_augeas_cmd_file" | exec { "set elevator=deadline in $grub_menu": | command => "echo 'setm /files${grub_menu}/title kernel/elevator | deadline' > ${aug_tmp_file} && /usr/bin/augtool -s -f ${aug_tmp_file} | && rm -f ${aug_tmp_file}", | onlyif => "grep 'kernel /vmlinuz-2' ${grub_menu} | grep -v | elevator=deadline", | require => Package["augeas"], | } | | Hope that helps, | | -Luke |
Thanks for the detailed reply Luke. I've come up with the following class and it works, however, keeps adding savedefault to the end so I'm going to have to add an onlyif statement to stop that from happening. I'm still trying to work out that onlyif statement right now, but this was incredibly helpful. class windows_default_boot { augeas{ "set_windows_to_default" : context => "/files/etc/grub.conf", changes => [ "ins savedefault after /files/etc/grub.conf/title[.='Windows']/chainloader", ], } } -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpelt...@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.