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?
5 Answers
/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.
Debian gnu/Linux12 config.txt moved and is read only after updates. I checked UI assuming it's locked because I should use it and found a nicely named Raspberry PI Config app. Tab interfaces gives me all the little toggles for my cameras which defaulted to off.
- 1
If you are new to RPi & Linux, you might find the Leafpad editor more friendly... :-)
sudo leafpad /boot/config.txt
- 156
- 3
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.
- 291
- 1
- 2
- 6
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