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.
Grail, so am I right when I say
/dev/sda=>hd0
/dev/sdb=>hd1
/dev/sdc=>hd2
/dev/sdd=>hd3
?
Now I have only 2 disks. It is not probable I will have more then 2 disk because I have only 2 SATA channels and 2 IDE channels. But I asked just to be clear.
Yes menu.lst is long because it has more systems bargaining for drive can exchange or one disk can be unplugged. I have already script mechanism to exclude drive mapping.
This words o'you I don't understand:
"Meaning, root (/) will be assigned a UUID and the same for any other systems on the single machine, but, the UUID for root
would always be the same (as it is unique and only assigned to one value) and therefore you could now parse the entire file
for that UUID and change it and so on for the other UUIDs."
Maybe you speak about mechanism to exchange old UUID for new UUID. But that's that what I prepare. This script we write now should do the think later. 1st step is to get UUID form to HD(x,y) form. Then I can shift the numbers ++x,++y,--x,--y (correct assignment if necessary). And I could to convert back from HD(x,y) to UUID form.
Now the main think I wait is solution of the last code o'mine. I don't know how to test x value and to conversion to number a=>0, b=>1, etc.
So it does not matter if this line is in the file once or a hundred times but it will ALWAYS be the same. What I am saying is that you need to only find it once (not 20+ times) and make the change for all
Never mind. I want both methods. It is fact (U R right) that if I would need to do all the steps* for about 10 items that is too slow work.
* Which steps I mean - step like from hd0,2 make hd1,2 or 1,3, then convert to uuid (maybe just because I want to check if the uuid is correct... if is in blkid list... )... and then maybe to convert it back to hd(?,?)... Yeah it is too long. But...
But later I can give it in function and to make this call for whole file...
If I something change I want to have a control over every item what is in it. That means, I still need to process every item through the main loop mentioned above. The main loop gives me ability to work with every item (title rename, set hdx.y, set uuid ). I could do one thing and it is to apply the function on whole file.
Therefor I still need the code to solve. It is not important if I apply the code on 1 block or on whole file. I need the basic form of code, and later I can to adjust it or expend it.
Quote:
Originally Posted by grail
Now something else I noticed is that some of the entries already have the entry - (hdx,y) in them, like:
(hd0,2)/boot/vmlinuz
Maybe this can also be used for the conversion??
The script needs to unify the form. (hd0,2) never minds. Because I convert the /dev/sda3 uuid to (hd0,2). So the form will be unified.
Realize. If i reinstall system then I have new uuid. So can't be found in blkid. This is next thing. If the uuid is not found I will call blkid again and output will go to select. I will select disc which uuid I would use.
But still... for me is important the code to convert /dev/something to hd(x,y)
I think I follow where you are going, but I have come up with an alternative anyway, which you can change as you need.
The following code will assume that the block_new loop has also been removed:
Code:
#!/bin/bash
uuids=($(awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");if(!_[$0]++)print}' menu.lst))
for uuid in ${uuids[@]}
do
dev=$(blkid -U $uuid)
drive=$(echo -n ${dev:7:1} | od -A n -t dC)
((drive -= 97))
partition=${dev:8}
((partition--))
echo "(hd${drive},${partition})"
done
Let me know what you think and if you don't understand any of it?
+ for uuid in '${uuids[@]}'
++ blkid -U eab515e9-bc3e-4024-9f01-55fddaa0fb1c
+ dev=/dev/sda3
++ echo -n a
++ od -A n -t dC
+ drive=' 97'
+ (( drive -= 97 ))
+ partition=3
+ (( partition-- ))
+ echo '(hd0,2)'
(hd0,2)
What means the od arguments?
Code:
-A, --address-radix=RADIX
decide how file offsets are printed
-t, --format=TYPE
select output format or formats
-d same as -t u2, select unsigned decimal 2-byte units
What means -A n ? What means adress radix?
What means the last letter C ?
I am pleased to know new command.
Edit:
I think about how to use this code. I think I will work with the block_new to proceed every item separately. However there is one thing about awk I'd like to know. If I have somethenig in variable x throught the gensub fnc. Ho can I do the comparation.
I have a awk command with this:
BEGIN{...} {
x=gensub(...)
# now I want e.g. to do something like:
if x<=n x=0 # how should be correct syntax?
print x
}
Edit:
One more thing I don't understand. U use this form of increase ((n++)) an I use this: i=$((i+1));
What is better? What is more reliable?
RADIX is d for decimal, o for octal, x for hexadecimal or n for none.
Quote:
What means the last letter C ?
d[SIZE] signed decimal, SIZE bytes per integer
SIZE is a number. For TYPE in doux, SIZE may also be C for sizeof(char)
The nice thing about the code I presented is that in the for loop you can use a very simple sed statement to replace the UUID throughout the entire
menu.lst. For example in the menu.lst you provided me, this would generate 5 sed scripts to update ALL stanzas in the file.
Quote:
# now I want e.g. to do something like:
if x<=n x=0 # how should be correct syntax?
U use this form of increase ((n++)) an I use this: i=$((i+1));
What is better? What is more reliable?
Neither or both. I prefer the "++" method as have used it in other languages for years and I recognize it immediately, but other bash programmers may say they prefer the one you have used. Each to their own
The nice thing about the code I presented is that in the for loop you can use a very simple sed statement to replace the UUID throughout the entire
menu.lst. For example in the menu.lst you provided me, this would generate 5 sed scripts to update ALL stanzas in the file.
I don't like this "all at once" solution. Because man needs to proceed every system's device reference separately. If you would get file into memory, then you would proceed Mandriva Linux and change data in the file, then you want to continue to viewing other systems in the file but you read it from the memory.... Now file is changed but data in memory are not changed. I work out my own solution with use of your code.
Can you to explain simply what the command od does in your code? As much as it is possible to be simple. Edit: I know that it converts character to ord value but how you got it
So we are looking at the device in /dev and all hard drives come in the form hdXY or sdXY where X is a letter of the alphabet representing which drive
we are looking at (a=1, b=2, and so on) and Y is which partition of that drive.
We also know that the characters a-z are numerically matched in the ASCII table to 97-122 inclusive.
Therefore when we use:
Quote:
echo <letter> | od -A n -t dC
We get the numerical value for the letter we have removed from the second last position of the device.
We then know that grub likes to be a bit different and start its numbering for both the device and the partition from 0.
Therefore, we subtract 97 (the ASCII value for 'a') from the drive number and take 1 from the partition number so we get a mapping like:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.