{"id":1808,"date":"2026-01-29T18:21:49","date_gmt":"2026-01-29T18:21:49","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=1808"},"modified":"2026-01-29T19:39:31","modified_gmt":"2026-01-29T19:39:31","slug":"usb-drive-apt-get-cache-raspberrypi-install","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/experimental\/usb-drive-apt-get-cache-raspberrypi-install\/","title":{"rendered":"Use USB drive as apt-get cache for frequent Raspberry PI reinstalls"},"content":{"rendered":"<p>I work on a configuration script for a Raspberry Pi, and as I debug it, more often than not I need to run reinstall over and over. On a metered connection it may be a problem, as not only it's slow, it also uses your data plan.<\/p>\n<p>A way around this would be having a local apt-get cache on a removable USB drive. On every install, apt will only fetch the .deb packages from the internet if they're not in the cache, and it will of course save a copy into the cache for future use.<\/p>\n<p>Your USB drive is not a part of the system, so you can safely reinstall your main OS as many times as you want - see <a href=\"\/blog\/tools\/mac-os\/clone-raspberry-pi-micro-sd\/\">\/blog\/tools\/mac-os\/clone-raspberry-pi-micro-sd\/<\/a><\/p>\n<h2>0. Format the USB drive<\/h2>\n<p>On a Linux machine, simply create <code>ext4<\/code> partition.<\/p>\n<p>On a Mac, you may need to format into something both Mac and Linux (your Raspberry OS) will understand, such as ExFAT.<\/p>\n<p>Open Disk Utility and right click your drive, click Erase. Choose:<\/p>\n<ul>\n<li>Format: ExFAT<\/li>\n<li>Scheme: GUID Partition Map<\/li>\n<li>Label (optional): <code>apt-archives<\/code>, just for fun - yours can be any<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: If you use ExFAT, apt will show permission errors. A hotfix is to force it to run as root.<\/p>\n<pre><code>echo &#039;APT::Sandbox::User &quot;root&quot;;&#039; &gt; \/etc\/apt\/apt.conf.d\/99no-apt-sandbox<\/code><\/pre>\n<h2>1. Permanently mount your USB drive to apt's cache location<\/h2>\n<p>Get the UUID for your USB drive. Run <code>lsblk -f<\/code> and look for the UUID column for your drive. Identify your drive using the label column you defined in the previous step.<\/p>\n<pre><code>mkdir -p \/mnt\/usb\nmkdir -p \/mnt\/usb\/apt-archives\necho &#039;UUID=697B-9DE4  \/mnt\/usb  exfat  defaults,nofail,uid=0,gid=0,umask=022,x-systemd.automount  0  0&#039; &gt;&gt; \/etc\/fstab\necho &#039;\/mnt\/usb\/apt-archives  \/var\/cache\/apt\/archives  none  bind,nofail,x-systemd.automount  0  0&#039; &gt;&gt; \/etc\/fstab<\/code><\/pre>\n<h2>2. Tell apt to NOT clear the cache<\/h2>\n<pre><code>echo &#039;APT::Keep-Downloaded-Packages &quot;true&quot;;&#039;  &gt; \/etc\/apt\/apt.conf.d\/99keep-debs<\/code><\/pre>\n<h2>3. Reboot and enjoy<\/h2>\n<p>To test:<\/p>\n<ol>\n<li>run <code>ls -la \/var\/cache\/apt\/archives<\/code> - note the contents of the folder<\/li>\n<li>run <code>apt-get install something<\/code><\/li>\n<li>return to <code>ls -la \/var\/cache\/apt\/archives<\/code> - see the .deb file for your package appear<\/li>\n<li>shut down your RPI and insert the USB drive into your laptop, ensure you can see the .deb package file<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I work on a configuration script for a Raspberry Pi, and as I debug it, more often than not I need to run reinstall over and over. On a metered connection it may be a problem, as not only it&#8217;s slow, it also uses your data plan. A way around this would be having a&hellip; <a class=\"more-link\" href=\"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/experimental\/usb-drive-apt-get-cache-raspberrypi-install\/\">Continue reading <span class=\"screen-reader-text\">Use USB drive as apt-get cache for frequent Raspberry PI reinstalls<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[811],"tags":[775,1272,791],"class_list":["post-1808","post","type-post","status-publish","format-standard","hentry","category-experimental","tag-debian","tag-fstab","tag-raspberry-pi","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":2,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"predecessor-version":[{"id":1811,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1808\/revisions\/1811"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}