LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   changing default to zero (https://www.linuxquestions.org/questions/linux-newbie-8/changing-default-to-zero-716694/)

ramjgn 04-03-2009 08:43 PM

changing default to zero
 
hi, i need to change the default boot order from any number to zero via a script. let me assume the following
# 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/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=1
timeout=10
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.27.5-117.fc10.i686)
root (hd0,2)
kernel /vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=108b1257-bc22-48d6-afab-2666b96d0dc8 rhgb quiet
initrd /initrd-2.6.27.5-117.fc10.i686.img
title Microsoft Windows Vista Ultimate
rootnoverify (hd0,0)
chainloader +1


here, the default boot order is 1. i need a script that would change it from 1 to 0 . i tried sed 's/default=[0-9]*/default=0/' /boot/grub/grub.conf
but it only displays the boot order changed to zero but in reality the boot order is the same . please help me.

mjmwired 04-03-2009 08:53 PM

Why aren't you saving the output?

# sed 's/default=[0-9]*/default=0/' /boot/grub/grub.conf > /boot/grub/grub.conf

(make sure you keep an update of the original when doing this)

ramjgn 04-03-2009 08:53 PM

it makes the file empty.

i92guboj 04-03-2009 09:02 PM

Quote:

Originally Posted by ramjgn (Post 3497882)
here, the default boot order is 1. i need a script that would change it from 1 to 0 . i tried sed 's/default=[0-9]*/default=0/' /boot/grub/grub.conf
but it only displays the boot order changed to zero but in reality the boot order is the same . please help me.

You would need to redirect this to a file to save it, like in:

Code:

sed -e 's/default=[0-9]*/default=0/' /boot/grub/grub.conf > grub.new
Then rename it. You can also make the mods on the fly, but then, make sure you make a backup of the relevant file(s) before, because there's no chance to go back of something goes wrong and your file is wiped or corrupted.

Code:

sed -e 's/default=[0-9]*/default=0/' -i /boot/grub/grub.conf

i92guboj 04-03-2009 09:03 PM

Code:

# sed 's/default=[0-9]*/default=0/' /boot/grub/grub.conf > /boot/grub/grub.conf
Quote:

Originally Posted by ramjgn (Post 3497888)
it makes the file empty.

Yes. That's wrong. You need to save to another file, or use -i as I told you above.

ramjgn 04-03-2009 09:11 PM

the new file is also empty. i tried both the options you stated , well before posting the thread,but couldn`t do it . it doesn`t work. only empty file is created. may be a c program that will make use of array to check "default" and change the value from any number to zero would work. i should try it, if shell fails.
if you have some other suggestions or options, do post me.

i92guboj 04-03-2009 09:18 PM

Quote:

Originally Posted by ramjgn (Post 3497899)
the new file is also empty. i tried both the options you stated , well before posting the thread,but couldn`t do it . it doesn`t work. only empty file is created. may be a c program that will make use of array to check "default" and change the value from any number to zero would work. i should try it, if shell fails.
if you have some other suggestions or options, do post me.

There's no reason why shell should fail. It works for everyone else. There's an error somewhere.

PS. If this command shows the correct output:

Code:

sed 's/default.*[0-9]*/default 0/' /boot/grub/grub.conf
Then, this one will write that output to a file as long as the input and output file are not the same:

Code:

sed 's/default.*[0-9]*/default 0/' /boot/grub/grub.conf > grub.new
And this one will edit the file in place:

Code:

sed 's/default.*[0-9]*/default 0/' /boot/grub/grub.conf -i

ramjgn 04-03-2009 11:20 PM

thanks for ur reply!!!! though the first two failed, last one, sed 's/default.*[0-9]*/default 0/' /boot/grub/grub.conf -i
successfully did the job. thank you


All times are GMT -5. The time now is 01:43 PM.