Local APK cache: Difference between revisions
Dubiousjim (talk | contribs) (delete Category:Development) |
Dubiousjim (talk | contribs) (add older text (commented out)) |
||
Line 56: | Line 56: | ||
[[Category:Package Manager]] | [[Category:Package Manager]] | ||
<!-- | |||
== Enabling Package Caching (Older) == | |||
{{Note|This document applies to Alpine 1.9 and later versions only}} | |||
Package caching is useful when the need arises to upgrade packages on read-only media. Package caching allows you to store newer packages in a location on writable media, which Alpine checks for when loading packages on start-up. | |||
This can be enabled either from the console or through the ACF. | |||
{{Tip|For package upgrades, it is useful to point Alpine Package Manager to repositories on the internet, to easily obtain package upgrades when they become available.}} | |||
{{:Include:Using_Internet_Repositories_for_apk-tools}} | |||
== Enable caching from either console or ACF == | |||
Choose one of the two methods below to enable, either from the console or from the ACF web interface. | |||
=== Option 1: Enable caching from the console === | |||
''Substitute 'sda1' in the example below for the actual device you will use to store the caching directory.'' | |||
First upgrade apk-tools: | |||
{{Cmd|apk add –u apk-tools}} | |||
Now enable package caching: | |||
{{Cmd|mkdir –p /media/sda1/cache | |||
ln –s /media/sda1/cache /etc/apk/cache}} | |||
=== Option 2: From the ACF === | |||
Browse to '''System > Packages > Cache''' | |||
''Edit Cache Settings:'' | |||
Tick '''Enable Cache''' | |||
Specify the '''Cache Directory''', for example: | |||
/media/sda1/cache | |||
Click '''Save''' | |||
--> |
Revision as of 03:12, 29 October 2012
Alpine Linux needs to be able to pull packages from local media on boot. (You can't download packages from the net before you have a network connection.) Using remote repositories presents a problem. If the config files have been modified for a newer version of a package, and the older package is on local media, all sorts of fun can result.
The solution is a local cache of updated packages. This cache can be stored on any r/w media, typically the same location as the apkovl.
The cache is enabled by creating a symlink named /etc/apk/cache that points to the cache directory.
To enable local cache run:
setup-apkcache
To enable Local Cache on releases prior v2.3
Alpine Linux version prior to v2.3 does not have the setup-apkcache tool so the symlink needs to be set up manually.
To Manually Enable Local Cache on HDD install
If you've installed Alpine to your hard drive (as 'sys'), then create a cache dir and then an /etc/apk/cache symlink pointing to that dir:
mkdir -p /var/cache/apk ln -s /var/cache/apk /etc/apk/cache
You normally don't need apk cache on HDD 'sys' installs but it might be handy if you re-install from net to have the packages cached.
To Manually Enable Local Cache on run-from-RAM installs
- Create a cache directory on the device you store your lbu backups (typically,
/dev/sda1
.)mkdir /media/sda1/cache
mount -o remount,rw /media/sda1
and then don't forget to runmount -o remount,ro /media/sda1
when you are done with the following commands- Create a symlink to this directory from
/etc/apk/cache
.ln -s /media/sda1/cache /etc/apk/cache
- Run an lbu commit to save the change (
/etc/apk/cache
is in/etc
and is automatically backed up.)lbu commit
- Done. Now whenever you run an apk command that pulls a new package from a remote repository, The package is stored on your local media. On startup, Alpine Linux will check the local cache for new packages, and will install them in preference.
So you now have a run-from-RAM distro that can do a yum upgrade or apt-get dist-upgrade
Cache Maintenance
Over time, newer packages will replace older ones; the cache directory will contain all older versions of packages.
Delete Old Packages
To clean out older versions of packages, run the clean command.
apk cache clean
or to see what is deleted
apk -v cache clean
Download Missing Packages
If you accidentally delete packages from the cache directory, you can make sure they are there with the download command,
apk cache download
Delete and Download In One Step
You can combine the two steps into one with the sync command - this cleans out old packages and downloads missing packages.
apk cache -v sync
Automatically Cleaning Cache on Reboot
To automatically attempt to validate your cache on reboot, you can add the above command to the /etc/conf.d/local
script, in the stop
stanza:
local_stop() { # This is a good place to unload any misc. # programs you started above. # verify the local cache on shutdown apk cache -v sync # We should always return 0 return 0 }