43

First is simply an oddity with the command cd. If I type in cd, then a space, then press Tab to view the available directories, I get this error message:

bash: cannot create temp file for here-document: Read-only file system

The more troublesome issue has been random closings of the terminal window. It has happened while testing the cd oddity, and also while ssh'd into another server doing simple things like git status and such. [Edit] It seems if I press enter exactly 31 times it triggers the auto closing of the terminal window (verified 3 times now).

I recently upgraded from 12.04 to 14.04 late last week, and this behavior did not occur the entire day I used it after upgrading. This is the first time attempting anything on this computer since that day.

Please advise any other information I can provide, and what I need to do to resolve this.

5
  • Just a friendly reminder to make the question title more descriptive, which helps get better responses: "odd terminal behaviour" is not very descriptive. Aug 26, 2014 at 3:41
  • I appreciate it.
    – Takamuffin
    Aug 26, 2014 at 3:43
  • In order to better diagnose your problem, can you tell me if you are using the default partitioning that Ubuntu set up, are you using whole disk encryption or LVM, and have you done anything to your fstab? What is the output of the mount command? Aug 26, 2014 at 3:47
  • mount output: gist.github.com/anonymous/74dc62ccd5602d1e9742
    – Takamuffin
    Aug 27, 2014 at 4:31
  • Thanks for providing that - it looks like no issue with the way the mounts are configured and no problems at mount time but maybe errors with the / (root) mount encountered since then? The remount-ro specifies that the root partition will be remounted as read-only in the event of certain filesystem errors. Doing a fsck from recovery or a Live CD would be good. Aug 27, 2014 at 5:15

6 Answers 6

22

I rebooted in recovery mode and followed the instructions the system gave me. I ran fsck on /dev/sda2, and that fixed the problem.

1
  • How do you reboot into recovery mode without a live-cd? Jul 15, 2022 at 19:38
14

The Read-only file system error is the major clue here. I would guess that your home directory, where bash tries to store your command history and so forth, is inside a read-only partition.

I would guess that it tries to update your recent command history on disk once every 32 commands, which is why it's failing on the 32nd command you type in a session.

Now, a partition may be mounted as read-only if you do it deliberately, but it may also be mounted as read-only if there was an error - this latter behaviour is usually the default for the root partition.

I'd be surprised if you weren't experiencing other problems if your root partition is mounted read-only.

You can try rebooting and checking the disk from the recovery menu. Press and hold shift as the computer boots, right after the BIOS screen disappears and right before the Ubuntu logo appears.

1
  • 2
    Had the same problem. Rebooting worked. Thanks.
    – whitehat
    Jun 27, 2016 at 14:29
5

This exact issue happened to me too.

It occurs intermittently.

So I finally had enough with it and decided to reinstall OS - ubuntu-gnome 14.04 (clean).

It fixed it! At least for a few days.. Then that exact same problem occurred again...

So I went to Fry's and got a new hdd (Seagate).

So far so good ( 6 months & counting ).

side note: stock hdd was Toshiba

6
  • Welcome to Ask Ubuntu. Since this is not a proper answer to the question, please delete it. Oct 9, 2015 at 8:55
  • 2
    That's my answer. What's your answer?
    – phtn458
    Oct 9, 2015 at 9:36
  • 2
    What I wanted to say is that reinstalling OS or buying a new hard disk is not a proper solution. You may want to comment on other posts and you will be able to comment when you have enough reputation (15). Oct 10, 2015 at 13:23
  • 11
    @ArchismanPanigrahi "the disk is bad, get a new one" is an answer.
    – Seth
    Dec 12, 2015 at 19:44
  • 1
    wow. So all those upvoted the answer went and bought new hdd (?)
    – Pawan
    Jan 10, 2017 at 12:38
3

As others have pointed out, a read-only /tmp filesystem causes further problems.

As for the 31 lines, it's related to gnome-terminal's internals.

It keeps a certain amount of lines in memory, in a so-called "ring". The rest, lines that scroll out of this ring are placed in a "stream". In older versions of gnome-terminal the stream was pretty much directly written into a file under /tmp, in newer versions there's buffering, compression and encryption before it's written out. (I can't remember off the top of my head whether the file under /tmp is opened when the first chunk of data is written into the stream, or when the stream first tries to actually write to /tmp; it's a minor implementation detail.)

The size of the ring is always a power of two (each slot containing 1 line of the terminal; except for 1 slot is not used due to technical reasons), and is doubled every time it's required due to the growth of the terminal height (but never shrinks back). E.g., with the default height of 24 lines the ring contains the last 31 lines of output, the rest goes to the stream (eventually to /tmp). If you increase the window's height to let's say 40 lines, the in-memory ring will grow to accommodate at most 63 entries at a time.

What you experience is that gnome-terminal tries to open a file in /tmp to store the stream, and exits because of the unexpected failure here. Try with a taller window than the default; it'll crash after pressing Enter 63 (or maybe 127) times.

That being said, /tmp should be fixed to be writable (with permissions 1777).

1

My problem was that a process was running with 100% CPU and probably took all disk resources (Some backup process: Ur-Backup).

Once i killed it, all went well. So I would think that a bottle-neck on the IO could cause this error even if there is enough space and you have write permission.

(Raspberry Pi with Jessy 18/03/16)

0

Ubuntu 18

Strangely enough, I had a read-only /tmp filesystem.

I hardened my /tmp directory and bash-completion worked as it should. Make sure you do not have any processes using the /tmp folder or moving the /tmp folder might be denied to you.

dd if=/dev/zero of=/var/TMP bs=2048 count=1048576
mke2fs -j /var/TMP
mv /tmp /tmp_backup
mkdir /tmp
mount -o loop,noexec,nosuid,rw /var/TMP /tmp
chmod 1777 /tmp
cp -R /tmp_backup/* /tmp/
rm -rf /tmp_backup

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .