Score:1

Trouble reinstalling Ubuntu after accidentally changing ownership

va flag

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.

guiverc avatar
cn flag
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 avatar
cn flag
Does this answer your question? [How to reinstall Ubuntu in the easiest way?](https://askubuntu.com/questions/446102/how-to-reinstall-ubuntu-in-the-easiest-way)
guiverc avatar
cn flag
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.
andyfaber avatar
va flag
@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 avatar
va flag
@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.
guiverc avatar
cn flag
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 avatar
cn flag
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*).
andyfaber avatar
va flag
@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.
Score:1
cn flag
  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.

andyfaber avatar
va flag
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 avatar
va flag
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?
cn flag
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?
andyfaber avatar
va flag
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 avatar
va flag
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.
cn flag
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.
andyfaber avatar
va flag
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.)
cn flag
I never used rufus but acc. to https://askubuntu.com/a/1407229/15811 you need to pick partition scheme mbr and then bios.
andyfaber avatar
va flag
Thanks again. I'll try mkusb. Does it matter whether I create it on a bios- or uefi system?
andyfaber avatar
va flag
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 avatar
va flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.