Jump to content











Photo
- - - - -

Extract USB functionality from a linux distro.


  • Please log in to reply
32 replies to this topic

#1 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 02:56 AM

My strange agenda is this:

ttake a linux distro, say puppy 5.4; take the vmlinuz and initrd.gz files, and boot them using grub4dos. Without(in this case)

having the sfs file present, you are dropped to a most elementary command line. I wish to edit the sfs or replace it with a

package containing *only* the drivers,etc necessary to mount and download flash and other USB to an arbitrary partition

on the hard drive. There is a utility to edit puppy sfs files, but when I open the main sfs, I cannot see what to do; in fact,

without the sfs present, and playing at this elementary command console,  I tried mounting a cdrom and got the message:

"does not support old method of mounting. ",(mount /dev/sr0 /mnt/cdrom). What is the new way?.



#2 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2013 - 10:18 AM

Not quite sure what you want to do - boot to Puppy from USB?  Try Tutorial #72?

 

Or maybe for linux users here?



#3 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2013 - 10:37 AM

Here are some grub4dos men entries which may be of use to you?

# if get 'puppy_precise_5.4.3 not found. Dropping out to initial-ramdisk console' error - check name and case of the .sfs file!# Extract files to /precise (only vmlinuz, initrd.gz and sfs needed) 
# rename PUPPY_PR.SFS to lower case puppy_precise_5.4.3.sfs
title Puppy Precise 
kernel /precise/vmlinuz pmedia=usbflash psubdir=precise fix=fsck psavemark=1 
initrd /precise/initrd.gz 

# Extract sfs to /precise 
# rename PUPPY_PR.SFS to lower case puppy_precise_5.4.3.sfs and place in \precise folder 
title Puppy Precise boot from ISO 
map /_ISO/Linux/precise-5.4.3.iso (0xff) 
map --hook 
root (0xff) 
kernel /vmlinuz pmedia=usbflash psavemark=1 fix=fsck psubdir=precise 
initrd /initrd.gz

 



#4 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 11:28 AM

Steve,

It's from a dos point of view;good usb is still lacking. The Bret Johnson drivers still only work with uhci(no ehci/ohci) controllers. Conversely, usb functionality

in modern linux is first rate. Using an entire linux for some usb io is like using an aircraft carrier as a toaster. So step one was to chop out everything not

useful to usb from the sfs, lowering it's foot- print-on-disk, then call this micro-linux from dos using a batfile invoking the grub.exe of grub4dos:it's menu.lst would have minimum timeout set;but the linux needs to start without the x-gui, since it is slow. At the linux, a bash script could mount usb,copy,etc.;

then rewrite a different menu.lst back to the dos partition, and reboot. The different menu.lst would reboot the dos, and we are back at the calling point.


  • p0lychr0me likes this

#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2013 - 11:31 AM

Sounds complicated! Have you done any of that before successfully?



#6 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 11:41 AM

I have in fact done this stuff in dos mixing C programs with batfiles, generating the bat, executing it from C, then deleting it,etc. Can do it just as easily with the menu.lst; but I'm a bit intrigued by your previous reply. Renaming the sfs will not shrrink it's footprint on disk, but the pmedia wrinkle will cause mostly

 the usb-stuff to load in ram,ala "tsr"? Also(you seem very familiar with grub4dos), will repeated invocations of grub.exe of grub4dos pile up somewhere,in a stack,say, and gum up the works?



#7 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2013 - 11:48 AM

Sorry, I don't really understand what you are trying to achieve.

Writing C programs, bat files and DOS is fairly simple - it all runs under DOS. mixing a DOS environment with a grub4dos environment and linux code seems weird to me and highly complex - like fitting bicycle pedals and aeroplane wings to a submarine!

What is your objective?



#8 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 12:41 PM

The objective is to exploit,as efficiently as possible, the usb io functionality of linux;mixing dos with grub4dos is like falling off a log. Boot up freedos on a machine with grub4dos; from dos, you can execute grub.exe, and it will work from the "nearest available" menu.lst to bring the grub4dos menu right back up again. As for complex, I can mix C and bat in my sleep;have written an entire frontend for dos which preserves the dos screen format, but allows

mouse selection of entries, as well as other things. The design philosophy there is to *exploit* tne dos command functionality to the hilt, and there is another point:

Microsoft windows stopped putting windows on-top--of-dos with NT; supposedly a slick move, this actually destroyed the innate portability of windows.

  I remember that Mercedes Benz used to make their engines with wierd non-standard socket-wrench sizes so that your average repair shop could not work on them. This was at any rate a proprietary move; the beauty of dos is it's standard portability(like the national electrical code?),or for that matter,

standard C. This is why folks still use dos!.

BTW, does the renaming of the sfs hide the sfs to some extent, so that the use of the sfs is controllable from the grub4dos?



#9 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2013 - 12:46 PM

What do you mean by 'exploit.. the USB functionality of linux'?

What do you actually want to do?

Are you talking about adding USB drivers to DOS?

 

P.S. the sfs is not renamed, it is merely named back to what it should be! If you use 7zip to extract the sfs file from the iso then the name is preserved, if you mount the ISO as a drive volume using ImDisk or Virtual Clone Drive, then the sfs name gets converted to 8.3. So you just need to make sure the sfs filename is it's original filename and not the mangled 8.3 filename.



#10 Icecube

Icecube

    Gold Member

  • Team Reboot
  • 1063 posts
  •  
    Belgium

Posted 13 February 2013 - 01:00 PM

Probably what you are looking for, already exists (at least if I understood you correctly):

 

kexec-loader is a Linux based bootloader that uses kexec to start the kernel of your choice. It fits on a 1.44MB floppy, supports most block devices supported by Linux and is easy to use. kexec-loader supports reading GRUB configuration files, this allows kexec-loader to be used as a drop-in replacement for GRUB by merely setting the GRUB installation path.

kexec-loader is aimed at people who wish to boot Linux or any other kernel supported by multiboot off a device which the BIOS does not support. For example, you may wish to use it to boot from a CD-ROM drive or USB Hard Disk that the BIOS can not boot from for whatever reason.

 

http://www.solemnwar...t/kexec-loader/

 

 

PlopKexec is a Linux Kernel based boot manager for auto detecting and chain loading Linux distributions on USB drives. It fits on a 1.44MB floppy. Its also possible to start plopKexec from CD or any Linux loader/boot manager. You can boot Linux from USB even if there is no Bios USB support.

 

Its based on a Linux Kernel and can load only other Linux kernels! PlopKexec is not a fork of kexec-loader.

 

The current plopKexec version is 0.3. The Linux Distro detection works currently only with distros that are using Syslinux. When some config files are making problems, then it should be no problem to fix plopKexec. When people like plopKexec and they need support for grub and lilo config files, then its possible to add it. This program has a big potential for many features. The distros can be on FAT, EXT2/3 formatted USB drives and on USB CD/DVD's. You can easily boot the detected Linux Distro from a menu.

 

Compiled for i386, Linux Kernel 3.1.4

 

USB Host support:
USB 1.1: UHCI, OHCI
USB 2.0: EHCI
USB 3.0: xHCI (Linux experimantal)

 

http://www.plop.at/en/plopkexec.html

 

Note: Both of them can only load Linux like kernels.



#11 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 13 February 2013 - 01:03 PM

Well, the just for the record Georg Potthast's thingy can seemingly do USB 2.0 and USB 3.0 under DOS:

http://www.georgpotthast.de/usb/

(and yes, it is Commercial)

 

@dense

I am clearly missing something.

Why don't you get a very minimal Linux distro, just as an example Tinycore:

http://tinycorelinux.net/

everything is in the initrd, there is no actual sfs, everything is cool.

 

:cheers:

Wonko



#12 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 01:13 PM

Exploit;yes indeed: to "steal" the usb drivers and file io(including ability to see into and use other partitions) of the linux. That is, to "kind of" "port" these things to dos. Naturally, I would love to "really" port it to dos, in the same way that Delorie ported GNU C to dos; but that is a BIG job; being something

 of a hobo myself, I would prefer to pick it off a low hanging linux tree, however *tangential* the "porting* might be.

   I will try the kexec,etc stuff; right now have dialysis(ugh!) appointment. See you guys later.



#13 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 13 February 2013 - 01:17 PM

As for George's USB thingy, the current package is non-free, since George got ticked at non-licensed commercial users; He now wants sixty *euro* to

use it; but even the older free one would not work on many machines, similar to Bret Johnsons free drivers. I have not seen a modern linux that does not work on anything.



#14 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 21 February 2013 - 04:34 AM

Have gotten this far:

Deleted sfs file altogether;

using only initrd.gz and vmlinuz can boot that with grub4dos;

takes five seconds to boot, and contains the functionality to mount usb,cdrom, and other partitions on the hard drive!.

  The problem then is that I cannot do a warm reboot. "reboot' is present proforma, but does nothing, just returns to the prompt; tried inserting the reboot script, as well as 'rc.d' which it refers to into the initrd, but it has too many references

not satisfied by the directories present on the ramdisk.

   The command 'exit' does something: a kernel panic :"attempted to kill init!". 'cntrl-alt-del does nothing, neither cntrl-alt-backspace. Have to do a cold-boot, which on this machine is very cranky.

  Any ideas there?.



#15 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 21 February 2013 - 08:46 AM

@dense

We are not clairvoyants.

If you need help, you need to EXPLAIN in DETAIL what you are doing, you cannot expect that anyone is able to understand bits and pieces (or only that has the time or will to try doing so).

http://homepage.ntlw...ard-litany.html

 

In Linux use shutdown command, you cannot kill the kernel.

http://unixhelp.ed.a...-cgi?shutdown 8

 

:cheers:

Wonko



#16 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 21 February 2013 - 12:07 PM

I don.t know if this qualifies as a 'litany'. but as compactly and concisely as possible:

1) do a frugal install of puppy slacko(5.4),saving to vfat on c:\ drive, in a folder called "slackobo", and booting this with grub4dos;

2)in slackobo, delete the sfs file, leaving essentially 'initrd.gz' and 'vmlinuz';

3)booting this with the same menu.lst entry as before, it quickly drops to a minimal shell;

4)amazingly, this shell contains the functionality to mount usb,cdrom,and every partition on the hard drive, allowing copying,etc.;

5)problematically, this shell does not contain the functionality of a clean shutdown, to wit:

5a)has no functioning 'reboot' command;

5b)has no 'sys-req whatsoever in 'proc';

5c)has no 'shutdown' command function whatsoever.

 

   I don't know if this is peculiar to puppy linux. Perhaps the initrd from,say, mint would have this elementary capability in it's initrd?

This is all that is holding things up, and what is the objective?:

 

A)dos,at present, has very little usb capability with freeware limited to the Bret Johnson's "usbdos" package; it is severely limited to machines with UHCI

usb controller, and even there tends to break on machines with usb mouse(i.e. no ps2 hole);

  The older "dosusb" by George Potthast shared some of these problems. The newer Potthast package is non-free, requiring a license for sixty euro's;

 

B)linux, on the other had, has *superb* usb functionality, which it exhibits on just about any machine you have lying around.

 

C) so, there is a definite charm in starting with a full size linux, with substantial bootup time, and shrinking it(puplet,mintlet)to one twentieth or less of it.s original footprint on disk and in ram. And it boots *fast* in that form.

 

D)finally, it is straightfoward, if a bit tedious, to implement a function in dos which invokes a special menu.lst with zero timeout,so that when the dos function reboots, the grub4dos automatically boots the "microlinux; said microlinux will have a light frontend geared to the task(minipulate files,etc,including from usb); then, exiting from that, remanipulate to another menu.lst,reboot, and carry us back to dos.

 

 

 As you see, the problem is a clean, warm reboot from the microlinux.



#17 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 21 February 2013 - 12:38 PM

Yes, but basically you are taking "something big" and stripping parts that you don't need/want from it (not entirely unlike nlite or XPlite behave in the Windows world) why don't you try another distro that from the start has NOT any additional filesystem if not the initrd?

The "fallback" command line to which you get with puppy is aimed to be an emergency-emergency command prompt, useful to troubleshoot a problem (which in this case you provoked intentionally by removing large chunks of the "OS as it was designed to be").

 

Like (example):

http://distro.ibibli.../tinycorelinux/

http://distro.ibibli.../downloads.html

The "core" should what you are after. :unsure:

 

:cheers:
Wonko



#18 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 21 February 2013 - 02:40 PM

If you use pfix=nox  cheatcode then it will boot further (but not run startx)  but at least reboot works...



#19 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 21 February 2013 - 05:38 PM

I have tried tinycore before, and even in the normal fasion, it didn't seem to work. I will look at it again.



#20 COD11

COD11

    Member

  • Members
  • 63 posts
  •  
    Germany

Posted 22 February 2013 - 02:53 PM

Hello dense,

give http://download.geex...ox-3.0-i386.iso a try. Extract 'vmlinuz' and 'initrd'.

Use (in Grub4dos 'menu.lst') :

...

kernel /vmlinuz initshell vga=789

initrd /initrd

 

Rebooting from command shell works with 'reboot -f'.

 

It would be possible to put your copy code into 'init' (the initial ramdisk script). I can help to pack/unpack it from 'initrd'. All tools for that purpose are contained in http://exo.enarel.eu...or/partedmagic/ (choose latest version).



#21 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 22 February 2013 - 04:10 PM

Thanks cod11,

  I thought puppy was too peculiar in terms of standard linux, so tried the vmlinuz and initrd from mint 14 which initrd is 14 MB!.Even screwier-could not mount several partitions, not even with sudo;  Then tried the vm-ini from micro tinycore,

booting it with grub4dos. This works perfectly;one scary moment: 'reboot' returned "cannot reboot;! Then did "sudo reboot";

good!.

   Thing is, the tiny is still about 5.5 MB for the core.gz(initrd). I would like to strip out everything but the usb-cdrom-partition mounting capabilities, but I suspect there are so many shared dependencies that the process of cut-and-try has enormous

permutations.

   BTW, I have figured out how to use 'cpio' to edit the initrd. I will try your suggestion. Right now, I am off to dialysis-torture.



#22 COD11

COD11

    Member

  • Members
  • 63 posts
  •  
    Germany

Posted 25 February 2013 - 05:47 PM

Hello dense,
I hope, you didn't have to suffer too much from your therapy !


Last weekend I played around with 'initrd' ( 1.2 MiB ) from GeeXBoX. I eliminated all unnecessary GeeXBoX stuff, adapted initial script 'init' so that one can't accidentally leave the shell prompt ( no 'kernel panic') and modified 'shutdown' script. The latter automatically unmounts reliably all mounted drives before either reboot, halt or poweroff command is used (usage 'shutdown reboot' for your purpose). I introduced a new script 'fn' which contains at the moment two functions 'mnt' and 'umnt'. With 'fn mnt sdc1' device sdc1 gets mounted at the new created mountpoint '/mnt/sdc1', whereas 'fn umnt' unmounts all mounted devices in the same manner as shutdown does ( in fact it is now used by 'shutdown' !). The (kernel) commandline parsing sequence within script 'init' offers a simple method to pass new variables (e.g. source and target location of your copy task) from Grub4dos to 'init'.
BTW 'initrd' is so tiny because it lacks many common linux commands (such as 'awk', 'dd', which I sadly miss in 'busybox'). There are only a handful of external commands (generously 'ntfs-3g'). There is no easy way to identify a storage device by UUID or label (no '/dev/disk/by-uuid' or '/dev/disk/by-label') although you may of course use UUID in 'mount' command as distinct addressing method (not yet with my 'fn' wrapper). The best way to solve this problem IMHO is to use tag files on the root folder of the drives/partitions involved. Name should be drive/partition name, content drive/partition UUID. So, let Grub4dos 'find' the file, let the 'cat' catch the content and pass UUID to the kernel commandline.

BTW, I have figured out how to use 'cpio' to edit the initrd.


To unpack initrd(.xz) to initrd(.cpio) and finally the linux folder structure is one thing. To find the correct parameters for repacking it is the other. I needed two trials for the latter. I wrote scripts for these tasks, too.
Although it takes only ten seconds to boot, I wanted a little bit of luxury within the shell, so I added "GNU Midnight Commander" to have a file manager and an editor ( with mouse control !) for my experiments. I stole it from PartedMagic, don't you tell on me. Unfortunately this doubles the size of 'initrd'. BTW, keyword 'double size' : if you repack the linux folder structure to cpio format, and your output goes to the same folder, the packed file is added at last,too ... you wonder why it has grown so much ! I always use a mounted ext2 file (e.g. 500 MiB size) for unpacking linux structures, because Linux links and (hidden) dot files get lost on Windows filesystems. Therefore I need something like PartedMagic to have an appropriate environment for my work.

My offer still holds : if you need any help for your project, count on me.



#23 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 26 February 2013 - 07:27 PM

Thank you cod11 for the detailed reply, but first:

I had purloined(swiped) the vm and ini from tinycore minimal and was impressed with how tightly it works; was able to edit the ini with cpio.

Thought I had nailed how to change the first timeout with grubinst but it ignores the timeout specified and always puts timeout=1!?

   Went back to basics and used:

   bootlace --time-out=# (hdx,y);then executed grub.exe, which brought up the "main" menu.lst,but with a default t=1; scrolled to the "reboot" entry, rebooted and there was the timeout I had set. I don.t know yet if merely reexecuting bootlace can change the timeout, or if fresh copies of grldr and grub need to be inserted first(I think they get modified by bootlace). Tried the brute force method with a hex editor

without success.

  I will now digest your detailed entry above concerning geexbox,et al and let you know.



#24 dense

dense

    Member

  • Members
  • 56 posts
  •  
    United States

Posted 26 February 2013 - 08:34 PM

cod11,

  before I try the geexbox, a few points:

1) I have written a light gui(or a heavy front end) for dos in which tne basic screen is identical to a dos screen, but divided into an upper and lower panel; each panel displays a true dos-screen and can be scrolled independantly, and navigated;

    So you can navigate to a file/folder in each of them, and copy from one to the other, going either way. Can also invoke any dos program/command in either one if it it inserted into the 'hub', which is straightforward(I love dos!).

 

2) the new wrinkle there is that I incorprorated *mouseability* into it, so that the entries on the dos screen can be selected with the mouse!

 

3) I had thought to port this to linux,but the thing which stumps me is the mouse function.

  This is so easy to do in dos using int33-union regs-int86, etc. so that the entire thing with mouse function is a mere 180 kb or so; this means if you keep it off the path, you can put a copy in multiple folders, each an independant "micro desktop" for different projects.

  This is anything but easy to do in linux, at least in a modern distro. It seems that the only way to get a mouse function is to grab onto some huge thing involving ncurses-obscure libraries and crisscrossing dependancies whose include.h's are forever under going

"upgrades" with subtle differences. This is why I am extremely interested in how you extracted the mousing from the parted magic;

  Do you think a binary of such a thing could work on an elementary linux of choice?(again why I love dos.)

 

4) Back on point: If I understand you correctly, the gru4dos can pass variables to essentially direct the execution of a startup script in the initrd? If so, would these variables get passed in the main menu.lst of grub4dos?

 

5) You are scripting mounts,etc at a raw level, but I notice that tiny minimal, once it boots, lists the available devices/partitions in /dev;

the lovely thing is that it lists them as folders by the exact same names in /mnt, and this means you are ready to do:

                 "sudo mount /dev/xyz /mnt/xyz"

What is twice as lovely is that when you then plug in a usb device, the system automatically recognizes the device, inserts a dev-name into both /dev and /mnt and you are ready to mount it. As an analogy, in c, you can do raw-io or file-io and my little dos gui makes heavey use of schemes in which, say,

"dir name>name.txt";

read name.txt into an array;

parse the entries in name.txt as appropriate

write lines to a bat file;

execute the bat file using 'system()' in c.

  While it is true that 'system()' is a little hinky when trying to execute some dos commands directly, it never fails when executing a

script. I think this is also true when compiling c in linux(I use djgpp in dos.)

 

So my idea is to read the dev and mnt folders at a "higher level" and let the shell do the "heavy-lifting".

  Again, tnx; I will try the geexbox.



#25 COD11

COD11

    Member

  • Members
  • 63 posts
  •  
    Germany

Posted 26 February 2013 - 11:30 PM

Hello dense,
 

3) I had thought to port this to linux, but the thing which stumps me is the mouse function.
...
Do you think a binary of such a thing could work on an elementary linux of choice?


Yes, for the DOS-like shell the mouse driver is 'gpm'. Together with its single library file it needs approx. 100 kB.
 

4) Back on point: If I understand you correctly, the gru4dos can pass variables to essentially direct the execution of a startup script in the initrd? If so, would these variables get passed in the main menu.lst of grub4dos?


Yes. G4d may even identify automatically a definite drive in changing storage configurations (and with different Linux device names!) if tag files are used, and pass its UUID to 'init' for mounting.

 

5) You are scripting mounts,etc at a raw level, but I notice that tiny minimal, once it boots, lists the available devices/partitions in /dev; ...


.. as do all Linux distros. But there is a better source in '/proc/partitions' which shows only active storage devices (and their sizes ). Of course it gets updated when changes happen. For the mounting issue : there is no problem to have a 'fn mntall' for my script, but be aware that this may comprise recovery partitions, diagnostic partitions and other stuff, which should not be touched.
Linux has a very versatile filter technique to extract exactly the wanted information from an input stream or file. Parsing a file with 'cat' file1 | <filter A> | <filter B> > file2 is often used in scripts.

To get from theory to practice, I provide my modified 'initrd' for download : http://www.mediafire...58dfhuw94lj48fz


Extract the necessary 'vmlinuz' from the GeeXBoX ISO and use

...

kernel /vmlinuz initshell vga=789

initrd /initrd

 

PS: 'Midnight Commander' starts with 'mc -c'


Edited by COD11, 26 February 2013 - 11:44 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users