Sponsored Content
Top Forums Shell Programming and Scripting Help with UUID replacement in fstab and menu.lst Post 302512036 by mirni on Friday 8th of April 2011 08:25:26 AM
Old 04-08-2011
This is the script to modify menu.txt. It modifies the file in-place. It'd be safer to omit sed's '-i' switch in the second line, and let it print out the new version of menu.txt (redirect it into a new file); so that the original is kept untouched.
Code:
miro@miro-ntb:Downloads$ cat test.sh
#!/bin/bash

root_uuid=$(sed -n ' s/[^ ]* "// ;/\/[\r]*$/  s/".*//p' partlist.txt) #extract root UUID
sed -i 's/root=[^ ]*/root=UUID='$root_uuid'/' menu.txt #this file will get modified

Code:
miro@miro-ntb:Downloads$ cat menu.txt 
# 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/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-71.el6.i686)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-71.el6.i686 ro root=/dev/mapper/VolGroup-lv_root rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
    initrd /initramfs-2.6.32-71.el6.i686.img
miro@miro-ntb:Downloads$ ./test.sh
miro@miro-ntb:Downloads$ cat menu.txt 
# 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=UUID=f75b104c-678e-4f80-a618-70d4bf4a3ede
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-71.el6.i686)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-71.el6.i686 ro root=UUID=f75b104c-678e-4f80-a618-70d4bf4a3ede rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
    initrd /initramfs-2.6.32-71.el6.i686.img


Last edited by mirni; 04-08-2011 at 09:31 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

menu.lst, boot options?

Hi all, I would like to have some details on menu.lst!! the reason is ,if i am trying to add my own boot option where do i need to add it? is it in menu.lst only or elsewere(am referring to unix os) because i tried adding a unique boot option and it was not reflected when the system booted?... (8 Replies)
Discussion started by: wrapster
8 Replies

2. Shell Programming and Scripting

shell script to alter grub menu.lst

Hi folks, I have a dual-boot Ubuntu/Windows machine and I wanted to create a script to change the menu.lst file so it will change the default boot partition (this is so I can reload the machine remotely and allow it to boot to the Windows partition). Today I have to sudo cp a template file I... (1 Reply)
Discussion started by: ppucci
1 Replies

3. UNIX for Advanced & Expert Users

Generate UUID for a host

Hello Experts, Is there a way to generate Universally Unique identifiers on all Unix flavours such as Solaris, RHELinux,Suse Linux, MacOS,HP UX etc? If i can get a system command or a system call or an algorithm/script/program to generate a unique identifier, it will be helpful. Thanks in... (1 Reply)
Discussion started by: GajendraSharma
1 Replies

4. SuSE

Need to edit the menu.lst so it can work

I am trying to install three OS (Windows VISTA, OpenSUSE 11.3 & Solaris 11 Express) on a single drive of a laptop. However when I go to edit the /rpool/boot/grub/menu.lst to put the entry so it can boot the OpenSUSE 11.3 I get errors some of which result into starting all over again. I have also... (0 Replies)
Discussion started by: Tenyhwa
0 Replies

5. Solaris

Need to create a menu.lst for Solaris 11 Express, OpenSUSE 11.3 & Windows Vista

I have partitioned and installed Windows Vista, OpenSUSE and Solaris 11 Express on a LapTop hardDrive. However I am not able to boot OpenSUSE 11.3 although I have it in menu.lst which I put in a Solaris partition directory /rpool/boot/grub. Could someone tell me how to go about it. See what I did... (2 Replies)
Discussion started by: Tenyhwa
2 Replies

6. Boot Loaders

Help Me edit the menu.lst !

I am trying to install three OS (Windows VISTA, OpenSUSE 11.3 & Solaris 11 Express) on a single drive of a laptop. However when I go to edit the /rpool/boot/grub/menu.lst to put the entry so it can boot the OpenSUSE 11.3 I get errors some of which result into starting all over again. I have also... (3 Replies)
Discussion started by: Tenyhwa
3 Replies

7. UNIX for Dummies Questions & Answers

Missing menu.lst file in Ubuntu

I am not able to find menu.lst in /boot. During the Linux Kernel Compilation I installed the kernel using make install. Next I created an initrd image. I had to modify the Grub configuration file - /boot/grub/menu.lst which I am not able to find. Any resolution for the issue? (3 Replies)
Discussion started by: rupeshkp728
3 Replies

8. Shell Programming and Scripting

Script to unmount and mount by UUID

Hi, Need a bit of help on this one as I am a scripting noob. I have a linux based NAS that mounts USB hard drives in an inconsistent location and to make matters worse, seems to lose the mount for an unknown reason and doesn't remount automatically unless the drive is removed and re-inserted.... (4 Replies)
Discussion started by: gtr33m
4 Replies

9. BSD

Find Partition/Slice UUID

I thought I had figured this out at one point, but I can't remember. Is there a way/command to get the UUIDs of a disk's partitions/slices in FreeBSD? Linux has the blkid command, which doesn't seem to be available. (2 Replies)
Discussion started by: AntumDeluge
2 Replies
GRUBBY(8)						      System Manager's Manual							 GRUBBY(8)

NAME
grubby - command line tool for configuring grub, lilo, and elilo SYNOPSIS
grubby [--add-kernel=kernel-path] [--args=args] [--bad-image-okay] [--boot-filesystem=bootfs] [--bootloader-probe] [--config-file path] [--copy-default] [--default-kernel] [--grub] [--info=kernel-path] [--initrd=initrd-path] [--lilo] [--make-default] [-o path] [--remove-kernel=kernel-path] [--set-default=kernel-path] [--title=entry-title] DESCRIPTION
grubby is a command line tool for updating and displaying information about the configuration files for the grub, lilo, elilo (ia64), and yaboot (powerpc) boot loaders. It is primarily designed to be used from scripts which install new kernels and need to find information about the current boot environment. On Intel x86 platforms, grub is the default bootloader and the configuration file is in /boot/grub/grub.conf. On Intel ia64 platforms, elilo mode is used and the default location for the configuration file is /boot/grub/grub.conf. On PowerPC platforms, yaboot parsing is used and the configuration file should be in /etc/yaboot.conf. There are a number of ways to specify the kernel used for --info, --remove-kernel, and --update-kernel. Specificying DEFAULT or ALL selects the default entry and all of the entries, respectively. If a comma separated list of numbers is given, the boot entries indexed by those numbers are selected. Finally, the title of a boot entry may be specified by using TITLE=title as the argument; all entries with that title are used. OPTIONS
--add-kernel=kernel-path Add a new boot entry for the kernel located at kernel-path. --args=kernel-args When a new kernel is added, this specifies the command line arguments which should be passed to the kernel by default (note they are merged with the arguments from the template if --copy-default is used). When --update-kernel is used, this specifies new arguments to add to the argument list. Multiple, space separated arguments may be used. If an argument already exists the new value replaces the old values. The root= kernel argument gets special handling if the configuration file has special handling for specifying the root filesystem (like lilo.conf does). --bad-image-okay When grubby is looking for a entry to use for something (such as a template or a default boot entry) it uses sanity checks, such as ensuring that the kernel exists in the filesystem, to make sure entries that obviously won't work aren't selected. This option over- rides that behavior, and is designed primarily for testing. --boot-filesystem=bootfs The grub boot loader expects file paths listed in it's configuration path to be relative to the top of the filesystem they are on, rather then relative to the current root filesystem. By default grubby searches the list of currently mounted filesystems to deter- mine this. If this option is given grubby acts as if the specified filesystem was the filesystem containing the kernel (this option is designed primarily for testing). --bootloader-probe grubby tries to determine if grub or lilo is currently installed. When one of those bootloaders is found the name of that bootloader is displayed on stdout. Both could be installed (on different devices), and grubby will print out the names of both bootloaders, one per line. The probe for grub requires a commented out boot directive grub.conf identical to the standard directive in the lilo configuration file. If this is not present grubby will assume grub is not installed (note that anaconda places this directive in grub.conf files it creates). This option is only available on ia32 platforms. --config-file=path Use path as the configuration file rather then the default. --copy-default grubby will copy as much information (such as kernel arguments and root device) as possible from the current default kernel. The kernel path and initrd path will never be copied. --default-kernel Display the full path to the current default kernel and exit. --elilo Use an elilo style configuration file. --grub Use a grub style configuration file instead of lilo style. This is the default on ia32 platforms. --info=kernel-path Display information on all boot entries which match kernel-path. I --initrd=initrd-path Use initrd-path as the path to an initial ram disk for a new kernel being added. --lilo Use a lilo style configuration file. --make-default Make the new kernel entry being added the default entry. --remove-args=kernel-args The arguments specified by kernel-args are removed from the kernels specified by --update-kernel. The root argument gets special handling for configuration files that support separate root filesystem configuration. --remove-kernel=kernel-path Removes all boot entries which match kernel-path. This may be used along with --add-kernel, in which case the new kernel being added will never be removed. --set-default=kernel-path The first entry which boots the specified kernel is made the default boot entry. --title=entry-title When a new kernel entry is added entry-title is used as the title (lilo label) for the entry. If entry-title is longer then maximum length allowed by the bootloader (15 for lilo, unlimited for grub and elilo) the title is shortened to a (unique) entry. --update-kernel=kernel-path The entries for kernels matching kernel-path are updated. Currently the only items that can be updated is the kernel argument list, which is modified via the --args and --remove-args options. --version Display the version of grubby being run and then exit immediately. --yaboot Use an yaboot style configuration file. BUGS
The command line syntax is more then a little baroque. This probably won't be fixed as grubby is only intended to be called from shell scripts which can get it right. SEE ALSO
grub(8), lilo(8), yaboot(8), mkinitrd(8) AUTHOR
Erik Troan <ewt@redhat.com> 4th Berkeley Distribution Thu Jun 21 2002 GRUBBY(8)
All times are GMT -4. The time now is 04:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy