LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2009, 09:43 PM   #1
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Rep: Reputation: 0
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.
 
Old 04-03-2009, 09:53 PM   #2
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Rep: Reputation: 39
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)
 
Old 04-03-2009, 09:53 PM   #3
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Original Poster
Rep: Reputation: 0
it makes the file empty.
 
Old 04-03-2009, 10:02 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by ramjgn View Post
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
 
Old 04-03-2009, 10:03 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Code:
# sed 's/default=[0-9]*/default=0/' /boot/grub/grub.conf > /boot/grub/grub.conf
Quote:
Originally Posted by ramjgn View Post
it makes the file empty.
Yes. That's wrong. You need to save to another file, or use -i as I told you above.
 
Old 04-03-2009, 10:11 PM   #6
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Original Poster
Rep: Reputation: 0
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.
 
Old 04-03-2009, 10:18 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by ramjgn View Post
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

Last edited by i92guboj; 04-03-2009 at 10:26 PM.
 
Old 04-04-2009, 12:20 AM   #8
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
changing default editor zyphonic Linux - General 8 11-14-2005 08:35 AM
Changing default OS in Grub .95 gautcha Linux - Newbie 8 05-04-2005 12:30 AM
Changing Default Route civicsi Linux - Newbie 1 04-23-2004 02:15 PM
changing the default chmod KOmaSHOOTER Linux - General 3 07-16-2003 01:20 AM
changing default WM pmh6310 Linux - Newbie 5 06-11-2003 06:00 PM


All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration