Auto-update for TinyCore Linux
I got myself in a bit of a pickle sorting this one out, but I got there in the end.
The issue:
To update TinyCore extensions (packages), you need to boot into a special mode (base norestore). Then, you need to run tce-update.
This is a piece of cake to do manually, but a pain to automate.
How I did it (overview):
How I did it (details):
1 - First, I backed up my .../tce/boot/extlinux/extlinux.conf so I didn't lose it.
cp /mnt/sda2/tce/boot/extlinux/extlinux.conf /mnt/sda2/tce/boot/extlinux/extlinux.conf.bak
(/mnt/sda2/ is where I mounted the hard drive on which TinyCore was installed - this may be different for you)
2 - Then, to change bootmodes, I swapped out /mnt/sda2/tce/boot/extlinux/extlinux.conf for a copy to which I'd added the 'boot norestore' options.
I put this swap-out process into a script I called setbootupdate.sh.
#!/bin/sh
touch /opt/performupdate
EXTLINUX_DIR=/mnt/sda2/tce/boot/extlinux
mv $EXTLINUX_DIR/extlinux.conf $EXTLINUX_DIR/extlinux.normal.conf
cp $EXTLINUX_DIR/extlinux.update.conf $EXTLINUX_DIR/extlinux.conf
The line 'touch /opt/performupdate' is to create a marker file to be picked up on the subsequent boot.
3 - I also created a script to switch back. I called this script setbootnormal.sh
#!/bin/sh
EXTLINUX_DIR=/mnt/sda2/tce/boot/extlinux
mv $EXTLINUX_DIR/extlinux.normal.conf $EXTLINUX_DIR/extlinux.conf
4 - I then added this to my /opt/bootlocal.sh:
if [ -e /opt/performupdate ]
then
rm /opt/performupdate
tce-update /mnt/sda2/tce
su tc -c "sh /mnt/sda2/tce/boot/setbootnormal.sh"
filetool.sh -b
reboot -d 20
fi
This checks every boot to see if the file /opt/performupdate exists (created in setbootupdate.sh above). If it does exist, the script removes the file, performs the update, swaps back the extlinux.conf to the normal boot parameters, backs up the file changes (IMPORTANT!) and reboots after 20s (giving me enough time to see the display to check it worked).
5 - As root ('sudo su' from tc prompt), I editted the crontab table by typing 'crontab -e' at the command prompt. I then added the following:
30 23 * * * sh /opt/rebootandupdate.sh
I then added /var/spool/cron to my .filetool.sh (to make sure the crontab table is backed up).
the rebootandupdate.sh script is merely:
#!/bin/sh
/mnt/sda2/tce/boot/setbootupdate.sh
reboot -d 10
(REMEMBER: you need the 'cron' boot option in extlinux.conf to start the cron daemon at boot)
What went wrong in the setup:
I had originally made /opt/bootlocal.sh check if /opt/performupdate.sh was executable and, if it was, execute it. (then the tce-update was in performupdate.sh).
The stupid mistake I made was putting a reboot command in the performupdate.sh.
This made the machine reboot BEFORE performupdate.sh was made non-executable, so the machine was stuck in a cycle, rebooting after every reboot!
To fix it, I had to:
- boot from install CD
- edit /mnt/sda2/opt/bootlocal.sh (with opt=sda2 in the normal boot options)
- change /mnt/sda2/tce/boot/extlinux/extlinux.conf to have the norestore option
- reboot from the normal hard drive
- copy /mnt/sda2/tce/mydata.tgz to / and expand it manually (tar -xvf mydata.tgz)
- edit /opt/bootlocal.sh to NOT reboot
- run filetool.sh -b
- reboot normally now the reboot-cycle is fixed
What I plan to add next:
- logging for the update boot so I can check it actually worked as expected when unattended
The issue:
To update TinyCore extensions (packages), you need to boot into a special mode (base norestore). Then, you need to run tce-update.
This is a piece of cake to do manually, but a pain to automate.
How I did it (overview):
- backup extlinux.conf
- create extlinux.conf and script to switch to boot into 'update mode'
- create script to switch back to normal boot
- add check to /opt/bootlocal.sh to see if the system is booting normally, or into 'update mode'
- create crontab job to regularly reboot into 'update mode'
How I did it (details):
1 - First, I backed up my .../tce/boot/extlinux/extlinux.conf so I didn't lose it.
cp /mnt/sda2/tce/boot/extlinux/extlinux.conf /mnt/sda2/tce/boot/extlinux/extlinux.conf.bak
(/mnt/sda2/ is where I mounted the hard drive on which TinyCore was installed - this may be different for you)
2 - Then, to change bootmodes, I swapped out /mnt/sda2/tce/boot/extlinux/extlinux.conf for a copy to which I'd added the 'boot norestore' options.
I put this swap-out process into a script I called setbootupdate.sh.
#!/bin/sh
touch /opt/performupdate
EXTLINUX_DIR=/mnt/sda2/tce/boot/extlinux
mv $EXTLINUX_DIR/extlinux.conf $EXTLINUX_DIR/extlinux.normal.conf
cp $EXTLINUX_DIR/extlinux.update.conf $EXTLINUX_DIR/extlinux.conf
The line 'touch /opt/performupdate' is to create a marker file to be picked up on the subsequent boot.
3 - I also created a script to switch back. I called this script setbootnormal.sh
#!/bin/sh
EXTLINUX_DIR=/mnt/sda2/tce/boot/extlinux
mv $EXTLINUX_DIR/extlinux.normal.conf $EXTLINUX_DIR/extlinux.conf
4 - I then added this to my /opt/bootlocal.sh:
if [ -e /opt/performupdate ]
then
rm /opt/performupdate
tce-update /mnt/sda2/tce
su tc -c "sh /mnt/sda2/tce/boot/setbootnormal.sh"
filetool.sh -b
reboot -d 20
fi
This checks every boot to see if the file /opt/performupdate exists (created in setbootupdate.sh above). If it does exist, the script removes the file, performs the update, swaps back the extlinux.conf to the normal boot parameters, backs up the file changes (IMPORTANT!) and reboots after 20s (giving me enough time to see the display to check it worked).
5 - As root ('sudo su' from tc prompt), I editted the crontab table by typing 'crontab -e' at the command prompt. I then added the following:
30 23 * * * sh /opt/rebootandupdate.sh
I then added /var/spool/cron to my .filetool.sh (to make sure the crontab table is backed up).
the rebootandupdate.sh script is merely:
#!/bin/sh
/mnt/sda2/tce/boot/setbootupdate.sh
reboot -d 10
What went wrong in the setup:
I had originally made /opt/bootlocal.sh check if /opt/performupdate.sh was executable and, if it was, execute it. (then the tce-update was in performupdate.sh).
The stupid mistake I made was putting a reboot command in the performupdate.sh.
This made the machine reboot BEFORE performupdate.sh was made non-executable, so the machine was stuck in a cycle, rebooting after every reboot!
To fix it, I had to:
- boot from install CD
- edit /mnt/sda2/opt/bootlocal.sh (with opt=sda2 in the normal boot options)
- change /mnt/sda2/tce/boot/extlinux/extlinux.conf to have the norestore option
- reboot from the normal hard drive
- copy /mnt/sda2/tce/mydata.tgz to / and expand it manually (tar -xvf mydata.tgz)
- edit /opt/bootlocal.sh to NOT reboot
- run filetool.sh -b
- reboot normally now the reboot-cycle is fixed
What I plan to add next:
- logging for the update boot so I can check it actually worked as expected when unattended
Comments
Post a Comment