How to remount .img as rw and repack

Hi fellas!
I make a sh script which the following:

sudo mkdir Temp
sudo mount -o loop output.img Temp

The command mounts the img.Thats fine.But it moun s it as read only.But I need to edit/delete some files inside it and repack it as ext4 using this command:

sudo ./mkuserimg.sh -s Temp factoryfs.img ext4 ./temp 893386752B

The part I'm lacking is,How do I remount the .img as rw and edit the files inside that???
And yeah...I need to remount the partition again with the default permissions again after editing/deleting files....
Thanks for your help...

---------- Post updated 09-19-12 at 11:42 AM ---------- Previous update was 09-18-12 at 02:42 PM ----------

Bump!!!Please guys..Some help on this...:slight_smile:

I don't think this can be done. You can look at iso images as archives of sort, and can't modify it. Mounting just makes it accessible, but the archive is set.
What I'd do is copy the mounted filesystem tree somewhere else (provided you have enough space), then make the changes and then make the new iso image.

Any Ideas on how to do this???
Edit:I tried this but got errors on chown part....

mkdir extracted
sudo cp -rfv TempDir/* extracted
user=$user
sudo chown -R $user extracted

What did you try to achieve with this line?

user=$user

I'd bet $user is not set. You probably want to do any of these equivalent ways to get the current user:

chown -R $USER extracted
chown -R $(whoami) extracted
chown -R $(id -un) extracted
1 Like