Reinstall osmc without removing sdcard

Is there a way to reinstall osmc without removing the sdcard ?
I mean, the os is still running, but kodi gets corrupted, in this case it would be good to be able to reinstall the complete image. But as i’ve set-up a media center, the pi is inside an enclosure and it’s hard to take it apart…

You can try and run the following commands (substitute rbp2 for rbp1 if necessary):

sudo systemctl stop mediacenter
wget -O- | gunzip -c | sudo dd if=/dev/mmcblk0 bs=1M conv=fdatasync

Once this is done, power cycle the device.

Thanks Sam.
I see that you do not unmount the partition before writing the image.
I know DD will write it, but isn’t there a risk this way ?

If your filesystem gets corrupted often, you really care about risks?

Fix the underlying issue!

The risk is that dd will write the image, but meanwhile the OS will also write to the partition, rendering the newly written image corrupted.

Fix the real issue of your filesystem corruption!
Then you don’t have to do risky things.

Get a good powersupply or power off your device correctly.
A dying sdcard should also be replaced sooner than later.

You’ll find it pretty hard to unmount the root partition when it is in use :wink:

In the end I’ve separated the commands as putty was fore some reason outputting everything it receied to stdout.

gunzip OSMC_TGT_rbp2_20160910.img.gz
dd if=OSMC_TGT_rbp2_20160910.img.gz of=/dev/mmcblk0 bs=1M conv=fdatasync

That won’t work reliably, and if it does work, there is no guarantee of success.

You need to pipe directly as you cannot reliably read from the SD card when you are performing block level write operations.

I made a slight typo in my command above, the correct command is:

wget -O- | gunzip -c | sudo dd of=/dev/mmcblk0 bs=1M conv=fdatasync

You can mount your file systems read-only before writing the image.

To do so, edit /etc/fstab

/dev/mmcblk0p1  /boot    vfat     defaults,noatime,ro    0   0
/dev/mmcblk0p2  /    ext4      defaults,noatime,ro    0   0

and reboot.

You would struggle to get a bootable system with that!

In a quick test the system booted and ssh worked. For sure, that is no clean way (as the whole thread) :wink:

Thanks @sam_nazarko it works!! I was confuse since i’m trapped in remote are while COVID situation and i don’t bring SDCard adapter. Thanks again