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

On Oct 13, 11:17 pm, "James A. Peltier" <[email protected]> wrote:
> ----- Original Message -----
> | On Thu, Oct 13, 2011 at 1:24 AM, Luke Bigum <[email protected]>
> | wrote:
> |
> | > Can you give me an example of a grub.conf file that you want to
> | > achieve? I don't have a dual boot windows system so not exactly sure
> | > what option you mean.
> |
> |
> |
> |
> | > # 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,2)
> | > # kernel /vmlinuz-version ro root=/dev/ROOTDISK/root
> | > # initrd /initrd-version.img
> | > #boot=/dev/sda
> | > default=0
> | > timeout=15
> | > splashimage=(hd0,2)/grub/splash.xpm.gz
> | > hiddenmenu
> | > password --md5 $1$CgIXv$laSfgcbmFW62.Y7PWbtBB0
> | > title CentOS (2.6.18-274.3.1.el5)
> | >         root (hd0,2)
> | >         kernel /vmlinuz-2.6.18-274.3.1.el5 ro
> | >         root=/dev/ROOTDISK/root rhgb
> | > quiet
> | >         initrd /initrd-2.6.18-274.3.1.el5.img
> | > title Windows
> | >         rootnoverify (hd0,0)
> | >         chainloader +1
> | >
> | >
> |
> | default= should be set to saved
> | davedefault should be appended after chainloader +1
>
> savedefault should be appended after chainloader +1
>
> --
> James A. Peltier
> IT Services - Research Computing Group
> Simon Fraser University - Burnaby Campus
> Phone   : 778-782-6573
> Fax     : 778-782-3045
> E-Mail  : [email protected]
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to