- Here is how I ended up gaining access via a Ubuntu Live
USB OS to files on the original Ubuntu
OS which wasn't booting since its grub /boot partition was broken:
Boot to Ubuntu Live CD
In the graphical user interface, open the "Disks" tool
In the left panel, select the disk that the the old Ubuntu filesystem which you can't boot was installed to
In the right panel, select the partition on that disk which the old Ubuntu filesystem is installed to.
Optional: Click the 'wheel'to access additional partition options and 'Check filesystem' to ensure there is nothing wrong with the old Ubuntu filesystem
Click 'play' to mount the partition which the old Ubuntu filesystem is installed to.
Still in the Disks tool, look at the 'Contents' field below the partition which you have selected in the right panel. Copy the location it is mounted at. Say for example it is mounted at /media/ubuntu/xyz . When you navigate to that location in the Ubuntu GUI file manager, you should now see the folders that were contained on your old Ubuntu OS. However the folders will have a little lock icon next to them because ownership of the files remains with the old Ubuntu OS user.
Navigate to the specific location of the files that you want to gain access to – for example /media/ubuntu/xyz/home/$OLDUSER/Documents and copy the folder path for use in step 10
Open terminal
Check what user you are logged in as by running whoami
The default for a Ubuntu Live USB user is ubuntu so I will use that in the command below. However if you get a different username you should use that instead.
NB: before running the next step, the following should be noted as pointed out by @mook765:
i. Best to target only a sub-folder that contains user files which you want to gain access to in the Live OS (e.g. to copy them to a USB key before attempting to restore your system)
ii. If you successfully recover your operating system, it may be difficult or impossible to reverse the change in priviliges. That may render it impossible to repair the broken OS. Therefore think carefully about whether to do this. An alternative may be to just copy the files using sudo cp source destination
.
iii. Don’t target root with this command or it is likely to make repair of the original system impossible due to priviliges for system files being removed from the original user on that system.
- Gain ownership/priviliges to read/write the files contained in the folder which contains the files you want to recover from the partition which you mounted:
sudo chown ubuntu: -R /media/ubuntu/xyz/home/$OLDUSER/Documents
Now in the Ubuntu GUI file manager when you navigate back to that location where the Old Ubuntu OS files are mounted (/media/ubuntu/xyz/home/$OLDUSER/Documents in this example), you should see that the little lock icon has been removed from the files and folders there. You should be able to read/write, copy the files etc. given you have now obtained permission to do so.
P.S. Thanks to @ChanganAuto for suggesting to use chown to do this. When I first tried the sudo chown $USER: (mount point) code he suggested I thought it didn't work because I still could not open any of the files within subfolders of that directory. So in addition to what they mentioned, I also had to target the specific folder where the files I wanted to recover were stored and use the -R flag to recursively gain permissions over the files and subfolders contained within that directory in order to be able to open the files.
Thanks also to @mook765 for clarifying exactly how to gain priviliges to access to specific user files without changing priviliges relating to system files of the original OS. You don't want to change priviliges for system files because doing so would break the original system and complicate any further repair attempts that you may want to carry out.
chown
(self-explanatory) the new mount point. Soo........ – ChanganAuto Dec 01 '22 at 19:20sudo chown $USER: (mount point)
. More info here: https://askubuntu.com/questions/628896/chown-difference-between-user-and-useruser$USER:
(the ":" is also important) and you would have know this is you read the link I provide above. Now, MY mistake: It also need a recursive argument - -R - so the full command should besudo chown -R $USER: /media/ubuntu/xyz
(of course adjust for the actual mount point). – ChanganAuto Dec 02 '22 at 19:12