LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Using parted in a script (https://www.linuxquestions.org/questions/linux-software-2/using-parted-in-a-script-621354/)

jjhunt 02-15-2008 08:23 AM

Using parted in a script
 
I am having to re-image Windows XP Embedded machines that are formatted with fat32. This needs to be unattended, and I am having a problem with parted.

Since we don't know how big the hard drive may be on all the different controllers, the image will be just large enough to hold WinXPE, after imaging the controller, we need to expand the fat32 file system to fill the partition.

The problem is that sometimes parted comes back with an error that says "Warning: File system is reporting XXXXX clusters, not XXXXX clusters." When you use the --script flag, it simply cancels out of this warning instead of continuing with the resize. parted will do the resize correctly when you select ignore, but there in lies the problem. Does anyone know how to script this to always ignore the warning????

I've tired a here-document like this:

parted << eof


ignore
q
eof

It only works when parted does not throw the error. This error does not show up everytime, even on the same machine with the same image over and over again.

Thanks to anyone who may be able to help.

homey 02-16-2008 06:10 PM

I don't know about your problem with parted but, I would be inclined to use scriptable fdisk ( sfdisk ) and tell it to make one partition to fill the drive. For example:
Code:

# For vfat, use C
sfdisk -D /dev/sda1 << EOF
,,C,*
EOF

# For ntfs, use 7
sfdisk -D /dev/sda1 << EOF
,,7,*
EOF

# Format the partition as vfat
/sbin/mkfs.vfat /dev/sda1

# Format the partition quickly for ntfs
/sbin/mkfs.ntfs -Q /dev/sda1 >/dev/null


jjhunt 02-16-2008 11:24 PM

Thanks Homey, but the issue isn't with the hard drive partitioning, but rather the new image file system v. the partition size.

The controllers are already functioning with WinXP Embedded. But not all of the machines have the same hardware. Depending on the controller, my script will pull the correct image from the server and replace the current WinXP image with our software updates. Because we don't know how big each hard drive is in advance, the new images will be just big enough to hold the Windows image and our software. Once it is on the hard drive, the image file system will have to be re-sized to fill the partition. This is done simply by using parted to "resize" to current size. Done simply if you have someone sitting there re-imaging hundreds of machines by hand.

I think I have it working now, though. I re-ordered some things in my script and using the Here-Document I have had 100% success rate during the initial testing. Before it was 5 of 10 tries. With no real rhyme or reason why it would fail half the time.

It seems odd to me that parted was written to safely resize a partition and has a scripting option, but there is no way to ignore known warnings, and it defaults to "Cancel" in script mode. The machines and images that are formatted NTFS are no problem, because when you use ntfsresize and pass no size arguments, it forces the file system to fill the partition. Why can't parted work that simply? Oh well.

Anyways, thanks again man.


All times are GMT -5. The time now is 07:26 AM.