1

I accidentally ran the command chown -R MY_ACCOUNT / and now I can't start my computer anymore. It shows the Ubuntu logo, but gets stuck before showing the login prompt.

I've seen this question asked here before, and people have been recommended to reinstall Ubuntu with the option to keep all files.

However, when I try to reinstall from a USB, I am only given the option to install and delete all files, or to install a new Ubuntu 22.04 parallel to my previous Ubuntu 22.04. So I have the following questions:

  1. Can I run a suitable chown from a live version of Ubuntu so that I can log in again?

  2. If 1. is not possible, can I at least do something from the live version that allows me to reinstall Ubuntu and keep my files?

  3. If a new install is really necessary, is it safe to restore my files from the backup on my external drive, or are the changed ownerships stored in some files there, so that restoring will get me back to where I am now?

I'm grateful for any help.

  • Not all files have the same attributes; so it's not a single chown command you'd have to run, but what could be hundreds of commands that vary on what packages you have installed (unless you create a script from a backup to return stats back to what they were) – guiverc Jan 31 '23 at 12:36
  • 1
  • FYI: You only mention re-installing Ubuntu, but not which Ubuntu product you're asking about; eg. Desktop? Server? Core?... so adjust for your unstated Ubuntu product. – guiverc Jan 31 '23 at 12:41
  • @guiverc the question you linked is not exactly the same as mine. Apart from my home folder, I'd also like to keep all installed programs in folders like opt, usr/local etc., and at the same time have the "default" ownerships of them restored. It's Ubuntu Desktop, by the way. – andyfaber Jan 31 '23 at 13:44
  • @guiverc Even though the question you referred to is not about also keeping all installed software, your answer to it seems to answer my question as well. I assume that my problems are due to the new ownerships in folders other than those that are kept by this type of reinstall. – andyfaber Jan 31 '23 at 14:19
  • You can re-install and manually installed packages (from Ubuntu repositories) get auto-reinstalled. Applications you add yourself post install are marked as manually installed by the system which is why I use that term. I provided a link to the Understanding Lubuntu testcases where I use apps like clementine (the music app I use) that isn't installed on a clean Lubuntu install, as one of my examples; ie. after re-install that non-default app should exist & on play continue my playlist (ie. the app was re-installed; the playlist wasn't touched nor was music files on local system).. – guiverc Jan 31 '23 at 22:55
  • ps: if it's 3rd party apps; those may or may not be installed depending on a number of factors that I try to avoid (complications) none of which apply with Quality Assurance for Ubuntu (I'm involved with) as that is a matter for the 3rd party apps to deal with themselves; some do & some don't. If the 3rd party app packager cared about their product, it'll work for those apps too if your sources are setup correctly (this can vary on release & installer though; ie. more complications I prefer to avoid). – guiverc Jan 31 '23 at 23:02
  • @guiverc thanks for this explanation. I'll try this reinstall as soon as I know what to do with the "lacking EFI System Partition" issue. I only have two partitions from my original installation: one of type ext4, that I'll set as the root partition, and one of type swap. So, I don't understand the EFI warning as everything has worked just fine for years. – andyfaber Feb 01 '23 at 06:28

1 Answers1

1
  1. Not really. There are methods and I had to do this twice myself where I used the permissions from another system to copy those over to the broken system but the end result was never really perfect; it always needed manual adjustment and that makes it very time consuming.

  2. Yes, you need to pick "something else", add the partitions, name and set the same filesystem as you have now and then -not- select "format". I used this method several times and it works very well. Just need to make sure you do it correctly as a mistake will be fatal so always make sure you have a backup when you do this.

If a new install is really necessary, is it safe to restore my files from the backup on my external drive,

Yes, but this yes is only valid for personal files.

or are the changed ownerships stored in some file there, so that restoring will get me back to where I am now?

No but it is very easy to restore permissions for personal files. Those are in their own directories outside of the system and all have the same permissions unless you have more than 1 user.

=== Do not do this on directories that are system related ===

Dirs:

find /dir -type d -print0 | xargs -0 chmod 0755

Files:

find /dir -type f -print0 | xargs -0 chmod 0644

where "/dir" is the location of your personal files for instance "/home/$USER/Desktop/" or any of the other directories in /home/$USER/. /dir can also be a partition if you have that. Also: this only applies to Linux filesystems like ext and not for NTFS, or FAT.

Rinzwind
  • 299,756
  • Thank you very much for your answer. I'd just like to ask if the reinstall process you suggested will reset the ownerships of program folders like opt and usr to default. – andyfaber Jan 31 '23 at 13:40
  • I tried to follow your advice and selected "something else". Then, the partitions /dev/sda1 (Type ext4) and /dev/sda5 (Type swap) are listed. I set the first one as "Ext 4 journaling file system" and '/' as mount point. (I found that other people had been recommended this.) So far I haven't set the second one as anything. When I try to proceed, I am warned that I need an "EFI System Partition". Should I set /dev/sda5 as this? – andyfaber Jan 31 '23 at 15:22
  • ehm you should already have one. and no sda5 if that is swap if not an efi. That should be another one. can you add the current disk partition layout to the question? – Rinzwind Jan 31 '23 at 15:40
  • Sorry, I took a screenshot, but I'm not able to past it here. The sda5 of swap type has a size of 8504 MB. It's "used" value is "unknown". – andyfaber Jan 31 '23 at 15:56
  • I checked that I don't have the folder /sys/firmware/efi, so my current system should be BIOS. It seems that the reinstallation from the USB wants it to be UEFI. Can I change this to BIOS somehow? My bootable USB was created with Rufus, so I wonder if I made some choices there that only allow UEFI installation. – andyfaber Feb 01 '23 at 09:12
  • You should use the installer you used to install the system and the choice to install using bios/efi is made during boot on how the installer is made iirc. A newer installer will prob. use efi and that will never work on a bios system. – Rinzwind Feb 01 '23 at 09:53
  • I don't have that old installer any more (if I ever had). The computer came with Ubuntu 12.04 installed many years ago, then I have upgraded multiple times. Is it not possible to create a bootable USB with Ubuntu 22.04 for bios? (I have access to Ubuntu on another bios system, if that makes any difference.) – andyfaber Feb 01 '23 at 10:02
  • I never used rufus but acc. to https://askubuntu.com/a/1407229/15811 you need to pick partition scheme mbr and then bios. – Rinzwind Feb 01 '23 at 10:06
  • Thanks again. I'll try mkusb. Does it matter whether I create it on a bios- or uefi system? – andyfaber Feb 01 '23 at 10:27
  • I followed the steps in the link you provided, selected mbr and bios, and mounted the existing ext4 partition on /. The reinstall did work this time. However, I can't start the computer. I still get stuck before arriving at the login prompt. Are you sure that the bad ownerships don't remain and cause the same problems as before? – andyfaber Feb 01 '23 at 15:53
  • I should add that the computer starts if the bootable USB is connected, otherwise not. The home folder has been preserved, but all installed software is gone. – andyfaber Feb 02 '23 at 07:18