3

I'm running into quite a frustrating problem with my Raspberry Pi Zero W. When I try to run apt or apt-get, having done nothing on the installation aside from modifying wpa_supplicant and changing the default hostname and password, the Pi will crash at some point during the installation. It doesn't kick me from the SSH session, my terminal will just freeze and the Pi will become unresponsive to ping. The only way to fix it is to remove power and plug it in again.

It doesn't matter whether it's apt-get update or apt install, whether it's a big package or just a couple megabytes. Every time I run this command the pi crashes.

I have tried fresh installs of RaspOS on different SD Cards, older versions of RaspOS, the desktop and lite versions, but the problem persists no matter what. I've been using this pi for about a year or so now and I've never run into this sort of issue before.

Does anyone know why this is happening? It's driving me nuts!

Output of df -h:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  1.7G   12G  13% /
devtmpfs        183M     0  183M   0% /dev
tmpfs           216M     0  216M   0% /dev/shm
tmpfs           216M  3.1M  213M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           216M     0  216M   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   48M  205M  19% /boot
tmpfs            44M     0   44M   0% /run/user/1000
3
  • my terminal will just freeze cool, is there an error message? perhaps run a second SSH and monitor the logs and you may catch something there - too bad you can't connect it to a TV though ... out of interest, what's the output of df -h before you do anything with apt Commented May 4, 2021 at 4:17
  • Thanks for the reply, I had a peek at the logs while trying to install a random package, but there was nothing in there to clue me in to what might be going on. I updated my post with the output of df -h but everything seems to be alright there as well :/ Commented May 4, 2021 at 7:40
  • Change the CONF_SWAPSIZE parameter in /etc/dphys-swapfile to 2048 and regen your swap space.
    – Dougie
    Commented May 30 at 10:37

4 Answers 4

5

I had exactly same issue and after spending days I found out that it has something to do with ipv6. so if you disable ipv6 or force apt to use ipv4 it will work just fine .

1
  • 1
    I never would've thought this had anything to do with it, but wow! This fixed it. I disabled it using these instructions. Thank you!! cwesystems.com/?p=231
    – sbonkosky
    Commented Dec 20, 2021 at 0:35
1

Run apt-get -y install mc > log.txt (or a package of your choice) to collect the actual error message. If the log turns out to be empty or incomplete, try using unbuffer or stdbuf -oL -eL to disable IO buffering for apt-get, so that it flushes STDOUT to disk after every line.

Also try downloading a package (e.g.  wget http://archive.raspbian.org/raspbian/pool/main/m/mc/mc_4.8.26-1_armhf.deb) and installing the package with dpkg to see if the crash is apt-related or dpkg-related.

Crashes with apt / dpkg are usually due to filesystem corruption, and the best fix often consists in running fsck and reinstalling the system if that didn't help.

3
  • 1
    Okay thanks, I tried piping the output into a log file but, as you said, upon rebooting the pi it turned out to be empty. So I then tried using stdbuf but that also proved unsuccessful. I was able to manually install some packages using dpkg however, so it seems the issue is with apt. Commented May 5, 2021 at 2:07
  • Forgive my ignorance, but given that I have installed multiple versions of raspbian on multiple SD cards, is it really likely to be filesystem corruption? Commented May 5, 2021 at 2:10
  • @bobbutnotbob Filesystem corruption has nothing to do with how careful you are when installing. It usually happens when the system crashes or powers down at the wrong moment. Also, if you run apt via SSH, you should bear in mind that it can be sporadically killed when the network disconnects. Commented May 5, 2021 at 7:00
0

Go to terminal and type

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n 

If you find any packages using high space , type

sudo apt-get purge -y (packagename)

packagename is the name of the package .

0

I had the same problem and solved this by creating a larger swapfile (rule of thumb: installed RAM * 2 - so 1GB on a Zero W).

Update /etc/dphys-swapfile with

CONF_SWAPSIZE=1024

And then running

sudo dphys-swapfile swapoff
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.