3

I am new to raspberry pi, and to linux. When I am trying to follow tutorials online, they sometimes require me to change /boot/config.txt. I am using the Jessie Version or Raspbian. (I am trying to change the file on the pi itself.) Whenever I try to save my edits, however, I get an error saying "Can't open file to write." How can I edit config.txt?

3
  • Do you use Linux or Windows to change the file?
    – MadMike
    Aug 19, 2017 at 15:09
  • I am using the Jessie Version or Raspbian. (I am trying to change the file on the pi itself.) Aug 19, 2017 at 15:12
  • 1
    Hello and welcome. Please use the edit function to add requested information directly to the question itself instead of putting it in comments. This ways readers of your question will get the whole picture much easier without going through the comments too. Thanks.
    – Ghanima
    Aug 19, 2017 at 15:21

4 Answers 4

5

/boot mounted as read-only

Issue a

mount | grep /boot

if the the output is

/dev/mmcblk0p1 on /boot type vfat (ro,relatime, ... ,errors=remount-ro)

it is mounted read-only (see the ro). You can remount it with the following command:

sudo mount -o remount,rw /boot

Sometimes there are errors on the boot-filesystem which triggers the system to mount it read-only. Issue a

sudo fsck -y /boot

to try and correct errors.

Edit your file with root rights

/boot/config.txt isn't editable by the pi user. So you need to start your editor with sudo to gain root rights:

sudo nano /boot/config.txt

You can check the file right with ls -l. Here an example:

ls -al /boot/config.txt 
-rwxr-xr-x 1 root root 1590 Jul  5 10:53 /boot/config.txt

root root means that the file is owned by the user root and by the group root. -rwxr-xr-x shows who has which rights. The first part -rwx means that the user has the right to read, write and execute the file. The next part r-x means that other user of the group root can read and execute the file. The last r-x the other users. Which are allowed read and execute the file.

3
  • I am using a micro-sd card... Aug 19, 2017 at 15:09
  • I tried remounting, and it still wouldn't save, then I tried "sudo fsck -y /boot" but it till wouldn't save. Aug 19, 2017 at 15:32
  • I removed the part about the SD card lock which is not connected to anything on a Raspberry and has no effect. Mar 26, 2020 at 6:26
0

If you are new to RPi & Linux, you might find the Leafpad editor more friendly... :-)

sudo leafpad /boot/config.txt
0

You can also edit the file from another operating system. It is very handy if you cannot boot up the raspberry pi anymore. Plug the sdcard into your computer (using an adapter). You will find two partitions on the sdcard. Go into the folder boot. There you will find the file config.txt. Edit it with a text editor like Notepad++. Then save it. Put it back into the raspberry and boot.

-1

I also encountered this message Can't open file to write as I attempted to edit the config.txt file from within Raspbian.
I had just clicked on it and it opened in whatever Raspbian has as the default editor. That editor doesn't run with root privileges and therefore was not allowed to write to the config.txt file.
The easiest solution found here is was to run an alternate editor with root privileges.
Thanks, Folks.

From the terminal run:

sudo leafpad /boot/config.txt
2
  • 1
    This doesn't add anything new, it just clutters the question with a useless picture. Mar 26, 2020 at 6:21
  • I made my comment to confirm that this actually does allow one to accomplish what the original inquiry was about, editing config.txt from WITHIN the Raspbian that is running. I read through a number of answers that involved using another machine, and on Windows, before finding the Leafpad solution. I wish it had been the first answer I saw. Theres probably a lot of people finding there way here as they try to add those touchscreen displays to their Pi. They will waste their time reading through all the same stuff.....unless my pic catches their eye. Ill not bloviate here in the future. Mar 28, 2020 at 5:25

Your Answer

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

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