1

Recently, my Raspberry Pi's permissions were butchered. I am now accessing the Pi's file system through a USB drive running Ubuntu. This is great, but my next step is to return to working on the Pi again with a fresh install of Raspbian OS (and fresh permissions). Also, I cannot edit some of the directories' files as they are read only (the Ubuntu user is not the owner).

What is the most efficient way to go about this and what are the steps involved?
The way I see it, I need to move the files to the fresh OS installation without copying:

  • messed up permissions
  • broken sudo
  • broken SSH
  • etc.

I imagine there's multiple ways to do this, some much better than others...

If any clarification is needed, please ask! :)

I can move this question to a different community if necessary...there's a lot of overlap, so I wasn't sure which was most appropriate.

Ctrl S
  • 165

1 Answers1

1

While I am not able to help with changing the messed up permissions, I believe I can help with an efficient restore process. Bear in mind that you'll need to perform most of the backup either AS root, or from a live cd/USB.

First, as far as I know, there is no way to keep the permissions from copying over. This seems bad at first, but think about what you really need to copy over. Do you really need to copy over everything to get a working system, or can you copy over just your configuration files? Do you not even need the config files? Maybe it's just one directory (/home, /usr, etc) that you need. If that's the case, copy just that directory over. The key here is to shrink down the amount of work you'll end up doing when it comes time to restore files.

Once you have your backup ready, do a reinstall of the base system. If you have config files that need to be restored, use echo to send the contents of the old files to the new files on the system.

echo <oldfile> > /etc/new/config/file

This should overwrite the new files with the contents of the old without changing the permissions to 777.

For any files that are staying in your home directory, place them in a folder and run

chown -R 644 <foldername> 
(Or chown -R 640 <foldername>) 

to make the permissions a little more sane. If they end up being owned by root, use chown to give yourself access to them again.

chown -R <username>:<group> <foldername>

If there are additional files/folders that need to be restored, check the permissions on the new filesystem and get them to match.

ephreal
  • 71
  • This looks like a great start. Yes, 97% of what I need is in /home/pi and the remaining 3% is in /etc (which is really all I should have modified permissions for, not / lol). Using echo to copy file contents is a smart move. Will try this out on Monday. – Ctrl S Jul 20 '18 at 22:16
  • I'm glad to help. It should also be possible to loop through the backup directory and echo the files to the appropriate place automatically. You'll just need to make sure the backup is the same as where you're restoring to. – ephreal Jul 20 '18 at 22:24
  • I've written Makefile and installation scripts in the past, so I might be able to make one for copying file contents...or I'll just play it safe for now and do it by hand. – Ctrl S Jul 20 '18 at 22:34
  • Good luck! I hope it goes smoothly for you. – ephreal Jul 20 '18 at 22:37
  • Thanks! This isn't the first obstacle I've hit and I know it won't be the last, haha – Ctrl S Jul 20 '18 at 22:45