1

Topic: Scripting, Command Parameters, Etc.

hello,

first off, do forgive me for being such a dummy when it comes to unix/linux...dos/windows..a wiz....linux...duh...  wink

my question(s) is/what i was wondering if it could be done is:

i have an app that determines the sizes needed to partition a hdd into 3 partitions.  it writes the sizes to the C drive.

right now, the user has to boot up to the live cd, and manually put in this info.

how might this be automated?

my thoughts would be something like:
1 - use the win app to figure out sizes, write this info to file on C root (already have this)
2 - boot to live cd, gparted starts with some parameters which read in a script file and the info from the C drive file
3 - gparted performs those tasks, exits out/reboots

the tasks are:
take main partition, resize it to a smaller patition - 500m -> 250m
take unalloc part spilt it into 2 halfs, partitions 1 part and sets to ntfs and labels it, 2nd half is left alone

i read thru the dox and really didnt see anything about using parameters.  i also didnt know if using some sort of linux 'keyboard macro' app could be used in place of scripts/parameters.

also, if such items are possible, how might i put this items into the default live cd image?

many thanks to yall for any/all help on this!
smile

2

Re: Scripting, Command Parameters, Etc.

GParted is a graphical user interface that uses a library from the parted project for the partition operations.

If you wish to develop a script to create partitions, my suggestion would be to use parted directly because it uses a command line interface.  You can read more about parted at:
http://www.gnu.org/software/parted/index.shtml

3

Re: Scripting, Command Parameters, Etc.

dear gedakc,

thank you VERY much for that link...it had what i need to perform the automation.

however, how would i use this info?

?1 - what is the format for the script? 1 command/file?  multi commands in a single file?
?2 - what should the file ext be?  in dos for example, all 'scripts' have the ?.bat ext.
?3 - how would i get linux to mount/read the script which i would create on the C drive in dos/windows?
i know i would use the 'mount' command, but that is about all i know of it, ie no idea of what params to use, though i think it would be /dev/hda/ 

what i do know is it (script) would be something like:

on the live cd-

mount C drive
gparted C:\script.nam
reboot

also where would i insert this script at on the live cd?  here again, in dos, it would be put in/appended to the autoexec.bat file.

i am so sorry that i am a moron when it comes to linux/unix stuff...

thank you and to any others that might be able to help me!  smile

4 (edited by cmdr 2009-07-30 20:18:50)

Re: Scripting, Command Parameters, Etc.

Hello z80cpu (... I loved it in my early computer days !),

?1 - what is the format for the script? 1 command/file?  multi commands in a single file?
?2 - what should the file ext be?  in dos for example, all 'scripts' have the ?.bat ext.
?3 - how would i get linux to mount/read the script which i would create on the C drive in dos/windows?

first of all - don't underestimate the effort, you have to expend, for realizing your program. Since Windows is your primary OS, I would do as much as possible with Windows for a maximum of compatibility ( e.g. Boot Records from "parted" are NOT bootable with Windows !). You don't need "parted" to create a new partition in an unallocated region; use Windows "diskpart" commandline tool. Limit the use of "parted" to resizing an existing partition.

?1 : Bash script files contain a sequence of commands as they would be typed at the prompt; lines are terminated with 0x0A (= LineFeed), NOT 0x0D 0x0A (Carriage Return / LineFeed with Windows), but there is a converting Linux program ("dos2unix"). It's much the same as with DOS-Batch files ( except for jumps; use procedures instead ).

?2 : Linux does NOT depend on file extensions. If they are used, it's for your convenience (e.g. images or media files).

?3 : That's a really big point ! You don't need neither desktop nor GUI at all, you only need console mode, but "GParted Live" automatically starts the desktop (unattended with the appropriate kernel parameters !) and runs "GParted" ( bash script file "startX" ). You therefore have to create and integrate a new "startX", which does NOT start X-Graphic, but stays in console mode, mounts the drive, where your actual task script is stored, copies it to Linux,  unmounts the drive, so that parted may also work on it... and finally starts the just loaded script. Perhaps it makes sense to use an USB pendrive instead of the involved harddisk for the task script, if you want to have a logfile even if something went wrong.

The crunchpoint is, that you have to adapt "filesystem.squashfs", where "startX" resides ! You need "unsquashfs"/"mksquashfs" V 4.0". Both are NOT contained in "GParted" ( but in "PartedMagic" ) and you have to recreate the ISO image with the new "filesystem.squashfs" ( use "ISO master" or "mkisofs"/"genisoimage" or a Windows burning software).

If you need man-pages (short manuals for most Linux commands), look here.

I would suggest, that you start to play around with "GParted's" Terminal console mode and a blank USB stick to resize an existing partition (NTFS NOT with "parted", but "ntfsresize" !). Mount the stick (FAT or FAT32 formatted, NOT NTFS!) with mkdir /mnt/usb -next line- mount /dev/< name > /mnt/usb, where < name > must be replaced with the stick's device name, e.g. sdc1 (= first primary partition). To have a good editor under "GParted" use the built-in editor of "mc" (=Midnight Commander). Type mc at the prompt and confirm, then press [F9] - o - i and confirm to activate the internal editor. To create an empty file in folder /home type touch /home/myfirstscript, highlight it with arrow keys (sorry, mouse isn't working !) and press [F4], then type as first line #!/bin/sh (the shell, which will operate the script). Now type your first script commandline ( classical echo "Hello World !", press [F2] to save it and confirm the highlighted script name to run it. If the script should not be marked with an asterisk, it won't run. Then type chmod +x /home/myfirstscript to make it executable.

What always helps in learning a new programming language is to inspect existing files. Look in folder /usr/bin for "gl-..." files for example or "MC_HxEd" (my "baby"). "mc" is your filemanager, it's worth to learn how to master it !

Have fun with Linux !
cmdr

PS:
1. A big pitfall for Windows user : Linux is case-sensitive  "mc" is not the same as "MC"
2. If you start a script from the folder, where it's stored, typing  "myscript" is not enough, use "./myscript" instead or the absolute path.

5

Re: Scripting, Command Parameters, Etc.

hello, cmdr,

i just wanted to thank you for your response to my posting!  smile

i also appreciate GREATLY the amount of time you put into your posting too!  smile


i guess all i really need is just a tad of help with some of the linux stuff on the live cd.

to put it in terms that i know and hopefully you do to, this is all i am after:

1 - make dos bootable cd

2- cd boots and loads OS boot files

3 - then it loads autoexec.bat
contents:
gparted -s c:\somename.txt
reboot command

thats it.

i just do not know where on the live cd to put the 'autoexec' file and what the command is to mount the c drive

what i would do is to replace the original 'autoexec' on the cd with mine

example:

from:
gpartedgui
exit/reboot

to:
mount c drive
gparted -script c:\somefile.txt
exit/reboot

i just do not know how to do this.  i am a wiz at dos/win programming, just an idiot when it comes to linux.  sad

also, i noted (if i read correct) that when the command line ver of gparted is done, there is no 'reboot' command.  if this is so, is there a linux command/app that would do this?  i am sure that an app exist.  again, i am a big dummy on this..  wink

i just need 4 simple things:

1 - what file i need to modify for the 'autoexec'
2 - how to mount the c drive (which is the boot drive) via the 'autoexec'
3 - how to reboot the computer at the end of gparted  via the 'autoexec'
4 - if i need to create a separate file for each gparted command

example:
file #1 - resize partition
file #2 - create new partition
file #3 - label new partition
OR
one file with all 3 commands in it
file #1:
resize
create
label


and what i am doing is:
1 - resizing a windows partition (making smaller and at the front)
2 - taking the unalloc part, creating 2 new parts
3 - taking one new part, making it ntfs and lableing it
4 - leaving 2nd new part alone

i am doing this by hand now, and for me to do it, it is no problem.  the problem is having OTHERS doing it.  you know, the regular users who think that their cd-rom tray is a cup holder..hehehehe  wink

thus why i am trying to automate the process.  i already have written an app in vb6 that generates the disk sizes for the resize and new parts, and it is stored on the c drive.

everything works, just be hand.  and there are no 'freeware' apps (at least that i am aware of) that will do a dos/win based resize on a ntfs drive.  now..hehe...if you know of one that will do a resize let me know!  wink 

that would make my life a WHOLE lot easier!  smile

as far as replacing the original 'autoexec' file with my new one, i had intended to use an app like power iso or win iso to do the 'swap' using those type of apps and re-burn it.

and thank you for mentioning using 'diskpart' from MS, for that partition that is 'left alone', that is what i use in a later step.  smile

also, the reason i prefer to use the live cd is that it appears that a lot of drivers are present for many types of systems.  i would hate to create a 'base' linux boot cd and it not work on most systems.  i am shooting for near 100% 'boot availability' on all p3+ machines. 

any/all help for those 'simple' 4 things would be greatly appreciated!  smile

again thank you very much for the help that you have offered!

6

Re: Scripting, Command Parameters, Etc.

Hello z80cpu,
I think, i have to correct some of your ideas concerning Linux as they are too much Windows based. And my further intention is to alter as less as possible on the GParted distro ( GP from now on) to match your needs. With my approach, you only have to exchange TWO files to get it working standalone ( provided, that there is no crash by a fault), i.e. boot - do its work - shutdown / reboot without interaction of the user. We need no graphical interface ( = NO gparted / gpartedbin !). We have much more hardware information accessible for scripts in Linux than in Windows. Let the script decide, whether "parted" or "ntfsresize" is used, no problem !

Let's have a closer look at GP. GP uses "isolinux" as bootmanager (the menu selection at the beginning!). The menu script is readable text in "isolinux.cfg". This is the first file to be altered : timeout for default item down to 3 seconds; default item with additional parameters for unattended further boot. "vmlinuz", the (DOS) Linux virtual machine is started and loads a first filesystem on a ramdisk (initrd1.img) to prepare switching to the main filesystem "filesystem.squashfs". The latter contains file "startX", which launches the graphical interface. This is counterproductive to what you want, because graphical gparted needs manual interaction. Keep in mind, that it's only an interface for the underlying commandline filesystem tools ( parted and ntfsprogs for Windows filesystems). We use them directly, so we don't need a graphical interface ("swinging block"). We exchange "startx" with a synonym script (your "autorun" file) , which

stays in console mode, mounts the drive, where your actual task script is stored, copies it to Linux,  unmounts the drive, so that parted may also work on it... and finally starts the just loaded script.

This new script is YOUR task. Your Windows software has to create it due to the actual needs and values. Therefore you must have experiences with the appropriate commandline tools in Linux ( my suggestion in my last post).

1 - resizing a windows partition (making smaller and at the front)
2 - taking the unalloc part, creating 2 new parts

3 - taking one new part, making it ntfs and lableing it
4 - leaving 2nd new part alone

Task 1 is a must for GP, Task 2 may be done by Linux or Windows (diskpart). Task 3 should be done by Windows. Task 4 : I don't know, what you mean -- just unallocated space(=nothing to do, neither partitioning) ?

if you know of one that will do a resize let me know!

that would make my life a WHOLE lot easier!

I think it's better, that Windows is NOT running, while working on its harddisk or you need an ultra-big RAM(DISK), an external harddisk or else to keep the whole stuff working. GP fits and works even on a small USB pendrive, which would make it easier to store your generated script file or even your whole VB6-program on it.

the reason i prefer to use the live cd is that it appears that a lot of drivers are present for many types of systems.  i would hate to create a 'base' linux boot cd and it not work on most systems.  i am shooting for near 100% 'boot availability' on all p3+ machines.

A very strong argument !

As I suggested, experiment with resizing an USB stick from a "parted" script. Your VB6-program should submit the ready Linux Bash script with all correct parameters, so you have to know them !

Regards
cmdr