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?
/boot mounted as read-only
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
-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.
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
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.
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.
From the terminal run:
sudo leafpad /boot/config.txt