Jump to content











Photo
- - - - -

Need help for rename a file in syslinux


Best Answer Wonko the Sane , 25 October 2014 - 10:42 AM

Are you really SURE that (once you have completed the translation) syslinux.cfg, mylinux1.cfg and mylinux2.cfg are the EXACT SAME size (in bytes)?

In (say) Windows 7, open a command prompt and do a DIR of the volume.

Are the size (in bytes) EXACTLY the same? :dubbio:

Usually when using this approach files in use are "padded" to a given size by adding excess bytes at the end (in a plain text file such as these you normally add SPACEs at the end of the file until you reach the intended size, and usually multiples of a "standard" sector or "block" of 512 bytes are used).

 

 

No, there is no "/i" switch in cat, but there is actually no *need* for it, as you actually know that what you wrote in syslinux.cfg (i.e. in mylinux1.cfg and mylinux2.cfg) is all in small letters, even if the switch would exist, it would be an unneeded complication to use it, even if it would not apply to the specific case, when you do a find/replace your scope is to "narrow" the result as much as you can, NOT to "expand" it.

 

:duff:

Wonko

Go to the full post


  • Please log in to reply
42 replies to this topic

#26 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 October 2014 - 01:35 PM

Generally speaking if you are going to make a "complex" conditional kind of script, it would be better to make a grub4dos batch (as opposed to a set of commands in a menu.lst).
 
But it's the whole concept of your snippet that is "the other way round" :w00t: :ph34r:
 
You want to ONLY dd mylinux2.cfg over syslinux.cfg IF mylinux2.cfg exist (whether mylinux1.cfg exists or not is irrelevant) and, NO matter if the dd command is executed or not proceed with a chainloader /syslinux.bin command.
 
That would be:
 
find --set-root /syslinux.cfg
if not exist  /mylinux2.cfg echo File mylinux2.cfg is missing && echo Second line && echo Third line && pause
if exist /mylinux2.cfg dd if=()/mylinux2.cfg of=()/syslinux.cfg
chainloader /syslinux.bin
but we can do "better" with:


find --set-root /syslinux.cfg
if exist /mylinux2.cfg dd if=()/mylinux2.cfg of=()/syslinux.cfg || echo File mylinux2.cfg is missing && echo Second line && echo Third line && pause
chainloader /syslinux.bin
Remember that the boot command is NOT needed in a menu.lst entry (as it is implied) while it is needed on command line.
 
:duff:
Wonko
  • imnothing likes this

#27 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 25 October 2014 - 02:00 PM

 

You want to ONLY dd mylinux2.cfg over syslinux.cfg IF mylinux2.cfg exist (whether mylinux1.cfg exists or not is irrelevant) and, NO matter if the dd command is executed or not proceed with a chainloader /syslinux.bin command.

 

 

 

Thanks, Wonko.

But I want to check the existence of mylinux1.cfg (english). This file must be exist to return English lang when needed. And I want if this file does not exist, grub will display message like

Warning! If you continuing change your language setting, you'll can not back to English language later.

And if it's possible, I want to add Yes/No prompt that allow choose continuing or not.

 

If mylinux1.cfg exist, grub will check mylinux2.cfg. If mylinux2.cfg exist, lang setting will be changed. If not, we'll get message

your language configuration file that you selected does not exist. Your language setting will not change.


#28 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 25 October 2014 - 02:30 PM

here my code and it did not work.

find --set-root /syslinux.cfg
if not exist /mylinux2.cfg clear && echo "cannot change your lang setting" && pause && chainloader /syslinux.bin
if not exist /mylinux1.cfg clear && echo "Warning ...." && set /p /u Answer = Are you want to continue? (Y/N):
if /i "%answer%=="n" chainloader /syslinux.bin || dd if=()/mylinux2.cfg of=()/syslinux.cfg && echo Your language setting was changed && echo But you cannot back to English && pause
chainloader /syslinux.bin

So, I think I made something wrong and I need your help. Thanks


Edited by congnt92, 25 October 2014 - 03:09 PM.


#29 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 October 2014 - 03:03 PM

here my code and it work but not completely. Ex, in case mylinux1.cfg does not exist, and I press N, grub not chainloader to syslinux.bin. And maybe still other error.

Well, at first sight you have "unbalanced" double quotes here:

if /i "%answer%"=="n" chainloader /syslinux.bin

 

but most probably you need:

if /i "%answer%"=="n" chainloader /syslinux.bin && boot

 

 

But you have still not yet focused fully on the "logic" behind.

 

If mylinux1.cfg exists (and mylinux2.cfg also exists) there is NO sense in echoing "Your language setting was changed  But you cannot back to English", that should be echoed ONLY if mylinux1.cfg does NOT exist BUT mylinux2.cfg exists AND you did NOT enter "n" at the prompt. (BTW *any* key will proceed in your code, usually *any* key will NOT proceed and ONLY the "explicit" Y/y would proceed)

 

As said, if you are going to write a whole set of conditions you'd better go for a batch file, where you can have labels and goto/call commands.

 

I would use:

find --set-root /syslinux.cfg

set answer=n
if not exist /mylinux1.cfg clear && echo "Warning ...." && echo You won't be able to get back to English && set /p /u answer = Proceed? (Y/N):
if /i not "%answer%"=="y" echo Language was not changed && pause && chainloader /syslinux.bin && boot

if exist /mylinux2.cfg dd if=()/mylinux2.cfg of=()/syslinux.cfg || echo Language was NOT changed. && pause && chainloader /syslinux.bin && boot

echo Your language setting was changed to Vietnamese
 pause

chainloader /syslinux.bin

If mylinux1.cfg does not exist the user can choose to proceed or not (no way back).

If mylinux2.cfg does not exist the user is told that the language has NOT been changed.

If BOTH mylinux1.cfg AND mylinux2.cfg  exist the user gets the message of success.

 

:duff:

Wonko



#30 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 25 October 2014 - 03:53 PM

Thanks Wonko,

Your code work fine except in case both mylinux1.cfg and mylinux2.cfg exist, then I get this message "language was not changed".

Seem

if /i not "%answer%"=="y"  ...

will always run even if linux1.cfg exists.



#31 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 25 October 2014 - 04:25 PM

I have made new code, seem it work fine but I want to report it here to you re-check. I'm not good at DOS command.

find --set-root /syslinux.cfg
if not exist /mylinux2.cfg clear && echo mylinux2.cfg missing && pause && chainloader /syslinux.bin && boot
if exist /mylinux1.cfg clear && dd if=()/mylinux2.cfg of=()/syslinux.cfg && echo lang changed && pause && chainloader /syslinux.bin && boot
echo "Warning ...."
echo You won't be able to get back to English
set /p /u answer = Proceed? (Y/N): 
if /i not '%answer%'=='y' if /i not '%answer%'=='n' clear && echo error input && pause && chainloader /syslinux.bin && boot
if /i "%answer%"=="n" clear && echo Language was not changed && pause && chainloader /syslinux.bin && boot
dd if=()/mylinux2.cfg of=()/syslinux.cfg 
clear
echo lang changed but you can't back to english
pause
chainloader /syslinux.bin

Edited by congnt92, 25 October 2014 - 04:39 PM.


#32 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 October 2014 - 01:50 PM

Yep, my bad, the first line should be set answer=y

find --set-root /syslinux.cfg

set answer=y
if not exist /mylinux1.cfg clear && echo "Warning ...." && echo You won't be able to get back to English && set /p /u answer = Proceed? (Y/N):
if /i not "%answer%"=="y" echo Language was not changed && pause && chainloader /syslinux.bin && boot

if exist /mylinux2.cfg dd if=()/mylinux2.cfg of=()/syslinux.cfg || echo Language was NOT changed. && pause && chainloader /syslinux.bin && boot

echo Your language setting was changed to Vietnamese
pause

chainloader /syslinux.bin

But of course is just one of the ways it can be written :), if you like your version and it works, it's fine, your version adds (good) input control (i.e. only y or n are accepted), this is a typical case where a batch would have been useful, as in your script, if you fail to input any of y/n you go back to the Syslinux, while in a normal batch you could have gone to a label just before the input request.

 

Or you could think of using [iftitle]:

http://www.rmprepusb...c-grub4dos-menu

 

Something *like* this might be useful :unsure: :

iftitle [if /i exist ()/mylinux1.cfg && if /i exist ()/mylinux2.cfg] Everything is OK Change language English/Vietnamese
root ()

iftitle [if /i exist ()/mylinux1.cfg && if /i not exist ()/mylinux2.cfg] Only available language English Change language
root ()

iftitle [if /i exist ()/mylinux2.cfg && if /i not exist ()/mylinux1.cfg] Only available language Vietnamese Change language
root ()

:duff:

Wonko


  • imnothing likes this

#33 steve6375

steve6375

    Platinum Member

  • Developer
  • 6954 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 26 October 2014 - 05:11 PM

No, there is no "/i" switch in cat, 

 

:duff:

Wonko

 

actually there is a case-insensitive switch -  use  --locatei=xyz


  • imnothing likes this

#34 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 October 2014 - 06:00 PM

actually there is a case-insensitive switch -  use  --locatei=xyz

Yep :),and the presence of of it is (though scarcely :ph34r:) documented alright in "help cat", but the point was only about it being unneeded in the specific case and  to underline how it could be potentially "abused" for - say - finding commas :w00t:
http://www.rmprepusb...orials/grub4dos
 
 

# check iso file is contiguous...
set ISO=\test.iso
blocklist %ISO% | set check=
set c=%check:~7,18%
echo %c% > (md)2800+1
echo Checking for comma in && cat (md)2800+1
cat --locatei="," (md)2800+1 > nul && echo WARNING: %ISO% is not contiguous - please run WinContig.exe on the drive! && pause

;)
 
Now, seriously, and as a side note, apart the use of locatei, are you sure that set ISO=\test.iso would work? :dubbio:
 
 
:duff:
Wonko
  • imnothing likes this

#35 steve6375

steve6375

    Platinum Member

  • Developer
  • 6954 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 26 October 2014 - 06:27 PM

I was just pointing it out for the sake of others who were reading the thread.

I appreciate you taking the time to look through my site pages and picking out every little typo - thanks, I have corrected it now. I hope it didn't take you too much time to find it... <_<


  • imnothing likes this

#36 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 October 2014 - 06:55 PM

I was just pointing it out for the sake of others who were reading the thread.
I appreciate you taking the time to look through my site pages and picking out every little typo - thanks, I have corrected it now. I hope it didn't take you too much time to find it... <_<

Actually, it was one of the first result googling for "locatei", which is bad news, as the only other meaningful reference was:
http://code.google.c...b-2011-11-03.7z
but also very good :) news, it means that the scarcely documented feature is actually present in an example on your site, which comes out among the first results :fine:, but I find very important that even little typo's in code examples (when found by chance) are swiftly corrected :thumbsup:, a newbie with grub4dos would have probably lost a lot of time in finding the slash/backslash little typo :ph34r:.

Really (again, seriously) I find the use of the locatei to locate a comma a form of "abuse" (though it will of course work fine, unlike the typo) of the fuction :dubbio:, but I was just pulling your legs a bit ;).


:duff:
Wonko



#37 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 27 October 2014 - 02:21 AM

Yep, my bad, the first line should be set answer=y

find --set-root /syslinux.cfg

set answer=y
if not exist /mylinux1.cfg clear && echo "Warning ...." && echo You won't be able to get back to English && set /p /u answer = Proceed? (Y/N):
if /i not "%answer%"=="y" echo Language was not changed && pause && chainloader /syslinux.bin && boot

if exist /mylinux2.cfg dd if=()/mylinux2.cfg of=()/syslinux.cfg || echo Language was NOT changed. && pause && chainloader /syslinux.bin && boot

echo Your language setting was changed to Vietnamese
pause

chainloader /syslinux.bin

If you fail to input any of y/n you go back to the Syslinux, while in a normal batch you could have gone to a label just before the input request.

 

Or you could think of using [iftitle]:

http://www.rmprepusb...c-grub4dos-menu

 

Something *like* this might be useful :unsure: :

iftitle [if /i exist ()/mylinux1.cfg && if /i exist ()/mylinux2.cfg] Everything is OK Change language English/Vietnamese
root ()

iftitle [if /i exist ()/mylinux1.cfg && if /i not exist ()/mylinux2.cfg] Only available language English Change language
root ()

iftitle [if /i exist ()/mylinux2.cfg && if /i not exist ()/mylinux1.cfg] Only available language Vietnamese Change language
root ()

:duff:

Wonko

 

Thanks Wonko,

My code is base on your suggestion. Even it work fine, I don't want to use it, I prefer using your code. Both of code work fine but your code is simply and easy to use while too much character was use in my code.

Now, my problems is completely solved.

Thanks again Wonko

God bless u :)



#38 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 27 October 2014 - 08:40 AM

Hi,
After completely resolved my problems with your help, I formated my USB to re-created USB multiboot.
And I get new problem when using cat command.
Cannot write resident/small file! Enlarge it to 2KB and try again
I'm try to make size of syslinux.cfg bigger by adding some lines with # in front then try cat command again and it work fine.
I'm not sure but I guess this problem come from allocation unit size option when format USB with NTFS.
So my question is: Which parameter can be use to cat command run always success, not depend which format option that we choose?

Edited by congnt92, 27 October 2014 - 08:45 AM.


#39 steve6375

steve6375

    Platinum Member

  • Developer
  • 6954 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars, www.easy2boot.com
  •  
    United Kingdom

Posted 27 October 2014 - 08:45 AM

grub4dos cannot write to small NTFS files. It is a major and annoying limitation.

Make sure the file is larger than approx 900 bytes (somewhere there is a thread on this and the size of file necessary).

The problem is that the first 900 bytes or so of an NTFS file is in the $MFT record and grub4dos does not support writes to a file that has no clusters.


  • imnothing likes this

#40 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 October 2014 - 09:13 AM

Well, you cannot claim that you weren't given some hints about the possible issue ;):

Imagine that you have THREE files:

  • syslinux.cfg (sized - say - 2048 bytes or however larger than the lower size limit for a file to exit the internal $MFT storage on NTFS)
  • my1linux.cfg (the exact same size of the above)
  • my2linux.cfg (the exact same size of the above) 

Here it is :):
http://reboot.pro/to...testers-wanted/
http://www.forensicf...wtopic/t=10403/
 
Theoretically (if all that is needed is to replace a fixed number of characters with the same number of characters) one could hexedit/cat replace directly the $MFT, BUT besides needing experimenting, finding the right "location" where to do the replace would be definitely more complex.
 
:duff:
Wonko

 

P.S.: Should anyone want to play with this, the file has been re-uploaded/attached here:

http://reboot.pro/to...edisk/?p=184432


  • imnothing likes this

#41 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 27 October 2014 - 10:03 AM

grub4dos cannot write to small NTFS files. It is a major and annoying limitation.

Well, you cannot claim that you weren't given some hints about the possible issue ;):

Oh, I'm sorry.
I didn't get this problem because I using dd command. And with dd command, I have 3 .cfg file which have quite many label. So their size approximately 4k.
Today, I format USB and re-create USB Multi boot and using cat command (not dd command like before).
And with cat commad, as your suggestion, I have a small syslinux.cfg with only 4 lines

TIMEOUT 1
DEFAULT othermenu
LABEL othermenu
CONFIG /mylinux1.cfg

Only 4 lines, so size of this file only about 90 bytes (On USB NTFS with default allocation unit size). This is reason why before I didn't get this error.
I'd like using cat command. It's very simple in my case.

if exist mylinux2.cfg >> change to my lang. if not, echo "lang not change".

Not check the existence of mylinux1.cfg needed. Because mylinux1.cfg must be exist on USB to syslinux.cfg config.
But with only 4 lines, it's impossible to make size of syslinux.cfg bigger. (Or I must type very very many white spaces)
So in my case, maybe I should choose dd command instead cat command. With many label, size of syslinux.cfg, mylinux1.cfg, mylinux2.cfg always "big" NTFS files. I don't want to add many lines to syslinux.cfg which not necessary just to make it's size bigger.
Anw, Thanks for your help Wonko and Steve6375.

And I'm a newbie with DOS, grub4dos and syslinux commands and with my poor English, so surely, you got many trouble to help me. I'm so sorry about that.
God bless u :)


Edited by congnt92, 27 October 2014 - 10:12 AM.


#42 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14793 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 October 2014 - 11:08 AM

congnt92, on 27 Oct 2014 - 11:03 AM, said:
But with only 4 lines, it's impossible to make size of syslinux.cfg bigger. (Or I must type very very many white spaces)

Well, you can easily make it automated, even in a poor man's way:
http://www.911cd.net...showtopic=14189
in your case you make a file in Notepad with ONLY a space in it, let's say you call it to1024.txt, then you open a command prompt (in a Windows NT OS) and execute in it:
FOR /L %A IN (1,1,10) DO TYPE to1024.txt>>to1024.txt
then you write in it the syslinux menu commands you want, rename it to syslinux.cfg (or whatever) and then either manually or using fsz (part of the DSFOK utilities):
http://members.ozema...ware/index.html
you trim it again to 1024 bytes (or you leave it slightly bigger than that).
You can also try simply using the fsz to resize (enlarging it) the file, but it has to be tested if syslinux "likes" the 00's that fsz adds. :unsure:
That would be:
fsz syslinux.cfg 1024
Strictly speaking, you don't even need Notepad, you can use COPY CON, like this:

COPY CON to1024.txt
[SPACE]
[CTRL+Z]
[ENTER]

you actually type COPY CON to1024.txt, then press the [SPACE] key, then you press together the [CTRL] and the [z] keys (they will show as "^Z" on screen and then you press the [ENTER] key.
 

congnt92, on 27 Oct 2014 - 11:03 AM, said:
And I'm a newbie with DOS, grub4dos and syslinux commands and with my poor English, so surely, you got many trouble to help me. I'm so sorry about that.

Naah, don't worry, you are very welcome :), everyone has been a newbie (and still is :w00t: :ph34r:) at something, the whole idea is to not remain one forever, and you are clearly showing the "right" attitude to soon become familiar with these thingies :thumbsup:.

:duff:
Wonko
  • imnothing likes this

#43 imnothing

imnothing

    Member

  • Members
  • 37 posts
  •  
    Vietnam

Posted 27 October 2014 - 12:28 PM

Great! Big thank to you, Wonko. :D






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users