To Unpack-Modify-Pach the system.img, I have followed the following procedure:
a) Unpacking
Run file system.img and make sure that system.img is Android Sparse Image.
Rename system.img to system.img.ext4. // Not required if you will use other name for raw image in below steps.
simg2img system.img.ext4 system.img
you will get a raw image file named system.img
mkdir system
create directory to mount system.img
sudo mount -t ext4 -o loop system.img system/
you will get all files of system.img in system folder
b) Modifying
ls -l system/init.rc
note permissions: 750
sudo chmod 777 system/init.rc
give write permissions
sudo echo "#MODIFICATION " >> system/init.rc
done some modification in init.rc
sudo chmod 750 init.rc
reset init.rc to the noted permissions
c) Calculate system sector size
tune2fs -l system.img | grep "Block size\|Block count"
you will get block size and count
echo $((1553064 * 4096))
multiply both results. I got 6361350144
d) Packing
sudo make_ext4fs -s -l 6361350144 -a system system_new.img sys/
you will get system_new.img “Android Sparse Image” that has all changes