WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Can a Pi update its own piCore?  (Read 2558 times)

Offline DrRob

  • Jr. Member
  • **
  • Posts: 60
Can a Pi update its own piCore?
« on: June 13, 2017, 04:01:11 PM »
I'm wondering if a Pi can update its own piCore installation by downloading the zip, unzipping the image file, copying extensions into ramfs, copying anything that's changed in /mnt/mmcblk0p2/tce/ into ramfs, unmounting /mnt/mmcblk0p2, dd the new image to /dev/mmcblk0, remount /mnt/mmcblk0p2 and copy saved stuff back to it?  It would save me from having to jump through hoops to reinstall the files required for a wifi connection on the Pi Zero W...

I'd be happy to give it a go, but someone might be able to say, "Don't be daft, that'll never work because X" and save me hours of pulling my hair out.

One thing (probably of many) that could prevent this working is if the new version has different size partitions to the old version.  During the normal installation method, the Pi has to be rebooted after changing the partition size with fdisk before the kernel knows about it, and we can't do that here or the things saved in RAM would be lost.

Rob.

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Can a Pi update its own piCore?
« Reply #1 on: June 13, 2017, 04:19:17 PM »
In order for the partition holding the  tce-dir  to be un-mountable, no extensions can be mounted.
By creating an empty file  /etc/sysconfig/tcedir/copy2fs.flg , all extensions are copied to the filesystem in RAM after being mounted and the extensions then get unmounted. This way the partition holding the  tce-dir  can be un-mounted if not used by anything else.

I just mount the img from the zip and copy files over to the RPi's boot media. No  dd  involved.
Also, I don't need files for the other RPis (kernel, initrd, bcm-xxx.dtb) which saves some space for backups.
Before reboot though, I fetch some kernel modules in order to be able to update extensions after reboot if needed.
Download a copy and keep it handy: Core book ;)

Offline DrRob

  • Jr. Member
  • **
  • Posts: 60
Re: Can a Pi update its own piCore?
« Reply #2 on: June 15, 2017, 03:45:31 AM »
Ah, I see, and now that I've read the instructions* about "Copy mode" I see that it's useful to avoid corruption during power loss, which is the reason I switched to piCore in the first place.

* radical move, eh?

Thanks for the tips!
Rob.

Offline DrRob

  • Jr. Member
  • **
  • Posts: 60
Re: Can a Pi update its own piCore?
« Reply #3 on: June 15, 2017, 04:24:11 PM »
That worked a treat, thanks!  The steps I took were:

scp piCore-9.0.1.zip pi:/mnt/mmcblk0p2/ to get the updated image onto the Pi (I could have wget it from the Pi, but I'd already downloaded it onto my computer)

ssh pi

cd /mnt/mmcblk0p2

sudo unzip piCore-9.0.1.zip

sudo mkdir /mnt/update1
sudo mkdir /mnt/update2

fdisk -ul piCore-9.0.1.img
Disk piCore-9.0.1.img: 49 MB, 51380224 bytes, 100352 sectors
49 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device          Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
piCore-9.0.1.img1    4,0,1       37,63,32          8192      77823      69632 34.0M  c Win95 FAT32 (LBA)
piCore-9.0.1.img2    38,0,1      48,63,32         77824     100351      22528 11.0M 83 Linux

sudo mount -v -o offset=$(expr 512 \* 8192) -t vfat piCore-9.0.1.img /mnt/update1
sudo mount -v -o offset=$(expr 512 \* 77824) -t ext4 piCore-9.0.1.img /mnt/update2

cp -af /mnt/update1/* /mnt/mmcblk0p1/
cp -af /mnt/update2/tce/optional/* /mnt/mmcblk0p2/tce/optional/

sudo exitcheck.sh reboot

...and then reapplied the changes I'd made to config.txt and cmdline.txt, that I forgot I'd done, and overwrote with the default versions above (oops).

Rob.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 714
Re: Can a Pi update its own piCore?
« Reply #4 on: June 16, 2017, 03:15:00 PM »
Just a tip to bash.

I think you can use in bash to calc like this, just add more parentheses.

From:
Code: (bash) [Select]
sudo mount -v -o offset=$(expr 512 \* 8192) -t vfat piCore-9.0.1.img /mnt/update1

To:
Code: (bash) [Select]
sudo mount -v -o offset=$((512*8192)) -t vfat piCore-9.0.1.img /mnt/update1


I have done something like this:

Code: (bash) [Select]
TEMPWORKDIR=$(WORKDIR)TEMP/
PICOREIMGFILE=piCore-8.1.5.img
SECTORSIZE=512
PARTFATBEGIN=$(shell LANG=C parted -s $(TEMPWORKDIR)$(PICOREIMGFILE) unit s print |  awk '/^Number/{p=1;next} p{p++} {if (p==2) printf("%i",$$2)}')
PARTFATEND=$(shell LANG=C parted -s $(TEMPWORKDIR)$(PICOREIMGFILE) unit s print |  awk '/^Number/{p=1;next} p{p++} {if (p==2) printf("%i",$$3)}')
PARTEXTBEGIN=$(shell LANG=C parted -s $(TEMPWORKDIR)$(PICOREIMGFILE) unit s print |  awk '/^Number/{p=1;next} p{p++} {if (p==3) printf("%i",$$2)}')
PARTEXTEND=$(shell LANG=C parted -s $(TEMPWORKDIR)$(PICOREIMGFILE) unit s print |  awk '/^Number/{p=1;next} p{p++} {if (p==3) printf("%i",$$3)}')
PARTFATBEGINOFFSET=$(shell echo $$(($(PARTFATBEGIN)*$(SECTORSIZE))))
PARTEXTBEGINOFFSET=$(shell echo $$(($(PARTEXTBEGIN)*$(SECTORSIZE))))
PARTFATENDOFFSET=$(shell echo $$(($(PARTFATEND)*$(SECTORSIZE))))
PARTEXTENDOFFSET=$(shell echo $$(($(PARTEXTEND)*$(SECTORSIZE))))


Offline DrRob

  • Jr. Member
  • **
  • Posts: 60
Re: Can a Pi update its own piCore?
« Reply #5 on: June 17, 2017, 11:52:26 AM »
Yes, that's neater, thanks.