1 Title: Debian APT upgrade without enough free space on the disk...
5 <p>Quite regularly, I let my Debian Sid/Unstable chroot stay untouch
6 for a while, and when I need to update it there is not enough free
7 space on the disk for apt to do a normal 'apt upgrade'. I normally
8 would resolve the issue by doing 'apt install <somepackages>' to
9 upgrade only some of the packages in one batch, until the amount of
10 packages to download fall below the amount of free space available.
11 Today, I had about 500 packages to upgrade, and after a while I got
12 tired of trying to install chunks of packages manually. I concluded
13 that I did not have the spare hours required to complete the task, and
14 decided to see if I could automate it. I came up with this small
15 script which I call 'apt-in-chunks':</p>
20 # Upgrade packages when the disk is too full to upgrade every
21 # upgradable package in one lump. Fetching packages to upgrade using
22 # apt, and then installing using dpkg, to avoid changing the package
23 # flag for manual/automatic.
35 for p in $(apt list --upgradable | ignore "$@" |cut -d/ -f1 | grep -v '^Listing...'); do
38 apt install --download-only -y $p
39 for f in /var/cache/apt/archives/*.deb; do
41 dpkg -i /var/cache/apt/archives/*.deb
46 </pre></blockquote></p>
48 <p>The script will extract the list of packages to upgrade, try to
49 download the packages needed to upgrade one package, install the
50 downloaded packages using dpkg. The idea is to upgrade packages
51 without changing the APT mark for the package (ie the one recording of
52 the package was manually requested or pulled in as a dependency). To
53 use it, simply run it as root from the command line. If it fail, try
54 'apt install -f' to clean up the mess and run the script again. This
55 might happen if the new packages conflict with one of the old
56 packages. dpkg is unable to remove, while apt can do this.</p>
58 <p>It take one option, a package to ignore in the list of packages to
59 upgrade. The option to ignore a package is there to be able to skip
60 the packages that are simply too large to unpack. Today this was
61 'ghc', but I have run into other large packages causing similar
62 problems earlier (like TeX).</p>
64 <p>Update 2018-07-08: Thanks to Paul Wise, I am aware of two
65 alternative ways to handle this. The "unattended-upgrades
66 --minimal-upgrade-steps" option will try to calculate upgrade sets for
67 each package to upgrade, and then upgrade them in order, smallest set
68 first. It might be a better option than my above mentioned script.
69 Also, "aptutude upgrade" can upgrade single packages, thus avoiding
70 the need for using "dpkg -i" in the script above.</p>
72 <p>As usual, if you use Bitcoin and want to show your support of my
73 activities, please send Bitcoin donations to my address
74 <b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>