Score:-1

After Live USB boot on system with broken grub, how do I gain permission to read/write files from old Ubuntu OS?

gf flag

When trying to format a USB key in the Disks tool I broke grub on a dual-boot system by accidentally formatting partition 1 of the HDD instead.

I haven't had any luck fixing it because I'm quite new to Ubuntu/Linux. Boot repair doesn't work because I'm on a UEFI system with no legacy bios. I get warnings to boot into legacy mode but can't.

I can boot using a Ubuntu Live CD. In the Disks tool I can see the old Ubuntu Filesystem. The Disks tool confirms that the filesystem is intact. When I mount the partition which it is installed to, I can navigate to see the names of the files and folders stored on the system (the files in my old Ubuntu Home folder for example). However when I try to open them, I get a permission denied error. Natural enough given that the old system had a username and password I suppose.

How do I gain permission to view these old files from the Live USB OS environment? Is there a way to enter my old password somewhere to gain access?

Apologies if the terminology I use isn't correct, I am not a regular Ubuntu user.

ChanganAuto avatar
us flag
It seems you misunderstood almost everything 2 experts tried to make you understand in comments of your other question: https://askubuntu.com/questions/1443288/grub-boot-partition-repair-on-dual-boot-uefi-system . But it's a moot point anyway, at least for the moment, because you decided not to try to re-create the ESP and reinstall GRUB. Now, indeed you may have permissions and ownership issues when trying to backup your files from a live session, you need to `chown` (self-explanatory) the new mount point. Soo........
ChanganAuto avatar
us flag
1. Check the mount point in Disks and then run `sudo chown $USER: (mount point)`. More info here: https://askubuntu.com/questions/628896/chown-difference-between-user-and-useruser
casperso avatar
gf flag
@changanAuto yes as I noted I am not a regular Ubuntu user and if you look at the comments for that post I have asked questions to try and understand what they are saying. Also I have actually spent 2 days trying to re-create the ESP and reinstall GRUB but have not yet succeeded. Hence why I am trying an alternative route to get the data.
casperso avatar
gf flag
@ChanganAuto please don't get angry if I misunderstood you too here as I am new, if you can elaborate just a little it would be helpful. In the Live USB O/S I mounted the old Ubuntu filesystem- let's say it was at /media/ubuntu/xyz. I wasn't sure if you meant to literally write $USER or that I should use my username so I tried both, neither worked. I think the default username in Live USB is ubuntu so the text I typed (no wildcards here) was "sudo chown ubuntu: /media/ubuntu/xyz". There was no change however. Would I not need to enter the old Ubuntu OS password to get access to the files?
ChanganAuto avatar
us flag
Yes, literally `$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 be `sudo chown -R $USER: /media/ubuntu/xyz` (of course adjust for the actual mount point).
casperso avatar
gf flag
@ChanganAuto in fact I did read the link. It doesn't specify whether they're using $USER literally or to denote the actual username either actually. Members considering whether to use the -R flag in the chown command on a root directory should read @ mook765's comment to my answer below before doing so. Doing so may make it difficult or impossible to later restore the broken OS.
ChanganAuto avatar
us flag
*may make it difficult or impossible to later restore the broken OS* Yes, of course. But aren't we beyond that point, by your own decision?
casperso avatar
gf flag
@ChanganAuto - yes but perhaps others who find this page are not so I wanted to make the consequences of taking these steps unambiguous.
Score:1
gf flag
  • 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:
  1. Boot to Ubuntu Live CD

  2. In the graphical user interface, open the "Disks" tool

  3. In the left panel, select the disk that the the old Ubuntu filesystem which you can't boot was installed to

  4. In the right panel, select the partition on that disk which the old Ubuntu filesystem is installed to.

  5. Optional: Click the 'wheel'to access additional partition options and 'Check filesystem' to ensure there is nothing wrong with the old Ubuntu filesystem

  6. Click 'play' to mount the partition which the old Ubuntu filesystem is installed to.

  7. 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.

  8. 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

  9. 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.

  1. 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.

mook765 avatar
cn flag
You should not use the `-R`-option in the `chown`-command since it will change the ownership for all files of your installed Ubuntu and that will break your system which you want to repair. Only change the ownership of the mount-point.
casperso avatar
gf flag
@mook765 thank you for your message. Could you please share if it is possible to change ownership of the mount-point while allowing access to the files in the directory? This would be useful for attempts to recover files if repair is impossible.
casperso avatar
gf flag
@mook765 I guess to gain access to your files in a situation where repair is impossible or where you wanted to copy the files off to backup storage before attempting repair, one could then selectively mount with recursion for just the directory of interest? For example to gain access to the Documents folder without breaking the system, after mount could one run `chown $USER: -R /media/ubuntu/xyz/home/$OLDUSER/Documents` in the live OS? Then if successfully repaired the same could be run from the repaired OS to regain permissions over the Documents folder in the repaired system again?
mook765 avatar
cn flag
You only need to ommit the -R-option in your chown-command, you don't want to change ownership of the files in the mounted partition. If you ran the command you suggested already, the system you want to repair is heavily damaged already and you likely have to reinstall. Only change the owner for the mountpoint (`sudo chown $USER: /media/ubuntu/xyz`). I don't see a reason why one would repair a file in the Documents-folder using a live system, but `chown $USER: -R /media/ubuntu/xyz/home/$OLDUSER/Documents` wouldn't be dangerous, ownership has to be restored afterwards.
casperso avatar
gf flag
@mook765 thank you, I wouldn't want to repair those files in the Documents folder, just gain access to them. I do not think the files themselves are damaged. Just I couldn't access them before because the boot partition was wiped accidentally. Perhaps I'm missing something - could you please share why you thought I was trying to repair those? My attempts to repair boot for that system over the last 2 days were unsuccessful so I think the system was never coming back. I'm happy to just have access to the files that were on it!
mook765 avatar
cn flag
I couldn't know that you don't want to repair the OS anymore. If you just want to gain access to copy files then also your first command method is ok. If you want to repair the OS, then it's not ok. Apologies if I misunderstood your question in this point.
casperso avatar
gf flag
@mook765 it was very helpful to know that -R on the root would complicate repair of the OS, thank you. Also good to know that it's possible to gain access to copy files and the safe way to do that if the -R flag is used is to target the specific folder in the chown command. Do you think though that there is another way to gain access to copy the files using just `sudo chown $USER: (mount point)` - i.e. without using the -R flag? I'm asking because when I try it, I still don't have permission to access the files in subfolders at the mounted point. I'm wondering if I'm missing something.
mook765 avatar
cn flag
There are some. As the superuser (`sudo`) you have access everything. You could use `chmod` to fine-tune the permissions of the directory you want to access. Remind that changes made with `chmod` or `chown` are persistent on that filesystem and the changes may be difficult to reverse. If you just want to copy some files, use `sudo cp source destination`, that will not make any changes on that filesystem. Comments are not for extended discussion, so we should stop here.
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.