ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
title Sata Mandriva
e12487ff-6d6f-44c4-9e03-33f545b3b798
initrd (hd0,2)/boot/initrd.img
Instead:
e12487ff-6d6f-44c4-9e03-33f545b3b798
But How can you be sure it gives correct number? I need to specify what (or what type of device) is there. So "UUID=" before hexadecimal digit expression.
Next thing - in this case I need to get uuid, not whole block
Grail
Quote:
Originally Posted by grail
Assuming the format remains the same for all stanzas you could use:
I am sorry, I thought the point was to replace the current root=UUID=<blah> with root=(hd0,2):
I tryied to explain situation. But first I need to get correct uuid. I don't know location of system at this point. I will replace it later. Can you explain me where is the fault my awk pattern doesn't cut out (remove) beginning?
PS:
Does anyone know if a uuid always has the same number of characters? If so, that could be incorporated into the regex.
Look at the uuid of a fat32 filesystem. It will be short.
Here are examples for uuids from the /dev/disk/by-uuid/ directory on my laptop. The first one is from an NTFS filesystem. The second is for a fat32 filesystem. A Linux filesystem or swap partition follows the last pattern.
Grail,
I don't know what you mean "4+ fields"?
Do you speak about the resume argument?
"I do use grub, but am not sure of all the possible combinations?"
I use configuration of Mandriva Linux auto generated.
Originaly I wanted awk pattern to return uuid.
But now situation is such that I would reather return all uuids to one string. Then I will check if the uuids is in blkid output. I will replace the existing UUID=uuid to hd(?,?). I will reinstall my system and change target partitions. So this script will be usefull after reinstalling system.
So if we know we always will have at a minimum, 4 fields in this order then we can simply deal with field $4 or if you want resume as well and it is always
there then field $5.
I have found the simplest way to get the first uuid to be 2 simple subs:
So if we know we always will have at a minimum, 4 fields in this order ...
No. This is changable. In menu.lst are more systems and configurations, depending on installer of distribution. So this is not sure. Therefor I want all uuids to one string. Then I will do some type of replace with help of loop.
Quote:
Originally Posted by grail
I have found the simplest way to get the first uuid to be 2 simple subs:
This is interesting (clever), but as I say. There can be situation, that there will be more uuids on one line and in block, as installer creates such configuration. So putting all uuids to one string "... ... ... ..." will be better to fix all possibilities.
I continue. I have this code. In case that 1 of uuids is not found in your system it should echo warning. But the if cond. is not right. What is in the d var if awk nothing found?
Code:
uuid=($(echo "$block_new" | awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");print}'))
for d in ${uuid[@]}; do
dev=$(blkid | grep $d | awk 'BEGIN{FS=":"} {print $1}');
if [[ "$dev" != "" ]] && [[ "$dev" != "\n" ]]; then
echo $dev
else
echo "uuid $uuid not found in list of devices"
fi;
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.