You should make sure, if there is any doubt, that the system is not actually rebooting due to brown-out as implied by other commentators (check
uptime if you are unsure).
I always use
tmux when initiating updates. In a nutshell, this is a tool that allows you to (amongst other things) start a command, send it to the background, then check in on it later even after logging out.
Of course, you can background and foreground processes using the
jobs protocol in the shell, but the "even after logging out part" can be a gotcha, meaning, it may work, but don't expect consistency in this regard. Conversely,
tmux is very safe.
There are lots of introductions, etc., to
tmux online (and no you do not need one written for Raspberry Pi users, it is the same
tmux as anywhere1). I will only demonstrate this particular task.
sudo apt install tmux
tmux new-session -s updates
Here "updates" is just a label, you can use anything. You will probably now see a solid bar across the bottom of the terminal (
ssh or otherwise) with that label on the left.
sudo apt update && sudo apt upgrade
The usual will happen. While that's going on, hit Ctrl-b, then d. The output and bar will disappear and you will be back at the prompt where you entered the
Do whatever. Log out. Come back tomorrow. As long as the system hasn't rebooted, you should be able to enter:
And see a line about the "update" session from before.
tmux attach-session -t update
Where "update" is the actual label. You'll be back at the scene of the
apt upgrade. If it's still proceeding, you can Ctrl-b, then d to leave again.
If not, and you want to close the session, just enter
Two quick tips about
Normal scrolling doesn't work; if you want to scroll back, you have to Ctrl-b (all the tmux commands are entered this way) and [. To exit that mode just hit q.
The default mode is not the same 256 or 16M colour mode used by most contemporary terminal interfaces, which can be irritating if you use tools that exploit such. To counter that:
echo "set -g default-terminal 'xterm-256color'" >> ~/.tmux.conf
- But there is one such thing from our now defunct blog: https://raspberrypise.tumblr.com/post/143463394889/tmux-102-getting-to-know-tmux There's also a very in depth