Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Wrong file ownerships after moving HDD to another computer

  1. #11
    Join Date
    Apr 2010
    Beans
    81

    Re: Wrong file ownerships after moving HDD to another computer

    Originally Posted by SeijiSensei
    Not if the source and target are from the same distribution. The system users remain the same across Ubuntu machines.
    No, unfortunately they are not the same. Even though I installed Ubuntu 10.04 server on both machines following (almost) the same procedure, the UIDs of system users are different. I probably didn't install all the packages in the same order. For example:
    mysql (UID): 106 -> 104
    clamav (UID): 110 -> 106 (so mysql data on Comp1 is owned by clamav on Comp2)
    etc.

    I don't see why your approach includes both chown and juggling passwd and shadow files.
    I want to match UIDs and GIDs on both machines. To do that I first need to copy them (passwd, group, shadow) from Comp1 to Comp2. Afterwards I need to change ownerships of the files on Comp2 to match the changes in passwd, group and shadow files.
    That way I will also be able to move the HDD in the future without any needed adjustments because the UIDs and GIDs will be the same on both machines (unless I add new users).

    The one thing you need to look out for is this:
    say you chown from 1300 to 1400
    say you also need to change files from 1400 to something else
    how do you distinguish between 'real 1400' and '1400 that were 1300 previously' ?
    Very good point. Hmm... I could use a temporary random UID and use it as an intermediary:
    1300 -> 1500(temporary UID)
    1400 -> 1300
    1500 -> 1300
    I just tried it and the temporary UID doesn't even have to belong to any user in passwd file.

  2. #12
    Join Date
    May 2007
    Location
    NY's first capital
    Beans
    2,868
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Wrong file ownerships after moving HDD to another computer

    I think from reading this thread one can gather this is not a pretty situation.

    I'm wondering how many users are actually impacted. You say this is a second drive added after install. What type of data is stored?

    How many users are owning files on this drive? A recursive ls may show you how many users own files.

    Output to a text file for easy reading/query.

    Code:
    ls -lR /mnt/secondhd > ownership.txt
    I think chmod owner:group of the second drive should be all that is needed if this system were to replace the original.

    If this second drive needs to move from machine to machine, I would suggest a reinstall of your backup server. Create an image of the primary disk of system 1 using something like dd or clonezilla. In my opinion this will be a better starting ground and likely less work.
    Nothing is ever easy, but if it is difficult you must be doing it wrong.

  3. #13
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,918
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by Kljuka View Post
    I've installed Ubuntu server on Computer1 a while ago and added an additional Hdd to it.

    Now I want to create a backup server of Computer1. I've installed new Ubuntu server on Computer2 with the same packages, and users. The last step is to move the Hdd from Computer1 to Computer2.

    And here is the problem:
    the users on Computer2 were not created in the same sequence as on Computer1 so when I mount the Hdd to Computer2 the files have wrong ownerships (www-data becomes mysql, etc.).

    Is there a script to change ownersip of all files of particular user to another user? Or is there a better way of moving files to another computer?
    maybe i missunderstood the issue but instead of installing ubuntu on pc 2,why did't you copy the / partition from pc1 to pc 2?? mybe with dd with a live cd, so that all the conf files and user/group id are all the same?
    and then you can mount the back up files easily.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  4. #14
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by Kljuka View Post
    No, unfortunately they are not the same. Even though I installed Ubuntu 10.04 server on both machines following (almost) the same procedure, the UIDs of system users are different.
    That's terrible packaging if true, and another reason for me to continuing running only CentOS on servers. The "apache" user is always UID 48 on RedHat-flavored distributions no matter when it is installed.

    Can anyone else confirm this? If so, there should be a bug filed against the server version to correct this problem.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #15
    Join Date
    Apr 2010
    Beans
    81

    Re: Wrong file ownerships after moving HDD to another computer

    maybe i missunderstood the issue but instead of installing ubuntu on pc 2,why did't you copy the / partition from pc1 to pc 2??
    Unfortunately the Comp1 is a server that must always stay online. Comp2 will be it's backup in case of Comp1 failure. That's why I need to move all those files (and hdd).
    As I understand I can't use dd or Clonezilla to clone mounted system.

    The "apache" user is always UID 48 on RedHat-flavored distributions no matter when it is installed.
    I checked on 5 of my Ubuntu computers. The Apache (www-data) has a consistent UID of 33. But other processes that are UID 102+ don't.: postfix, sshd, mysql, ntp. It seems to me they get it based on the time they get installed. I don't know whether this is a bug or not.

    Thank you all for your help. You've shown me a way to configure my backup server. It's not the easiest solution but it should work (and hopefully this posts will also be useful to others).

  6. #16
    Join Date
    Apr 2010
    Beans
    81

    Re: Wrong file ownerships after moving HDD to another computer

    I'm wondering how many users are actually impacted. You say this is a second drive added after install. What type of data is stored?
    This second drive contains Apache www-data and is mounted to /var/www. Apache is configured to use mpm-itk which forces separate UID:GID for each user. So there are quite some users/groups.

    Slightly off the topic quiestion:
    I was wondering if I can manually create a new user on Ubuntu by only adding an appropriate line to passwd, group and shadow files without using useradd command?

    Do you think there is a better way to create a clone of a live server than fresh-installing it, changing UIDs and ownerships to be the same as on the original server and afterwards copying the data to it?

  7. #17
    Join Date
    May 2006
    Location
    Boston
    Beans
    1,918
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by Kljuka View Post
    Do you think there is a better way to create a clone of a live server than fresh-installing it, changing UIDs and ownerships to be the same as on the original server and afterwards copying the data to it?
    if you cannot copy the partition / i'd chande the UID and GID (of the user that i need)of the files contained in the backup of pc-1.
    Code:
    find /media/mybackup -mount -user UID-of-pc-1 -exec chown UID-of-pc-2  {} \;
    find /media/mybackup -mount -group GID-of-pc-1 -exec chgrp newgroup GID-of-pc-2 {} \;
    change the uid and the GID of the files in the back up to the uid & gid of the system in pc-2. You should run the command with a live section (it is adviced not to be logged as the old/new user while doing it.)

    reference http://blogging.dragon.org.uk/index....d-gid-on-files
    Last edited by fdrake; December 24th, 2012 at 03:26 AM.

    blog
    Donations BTC : 12FwoB7uAM5FnweykpR1AEEDVFaTLTYFkS
    DOUBLEPLUSGOOD!!

  8. #18
    Join Date
    May 2007
    Location
    NY's first capital
    Beans
    2,868
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Wrong file ownerships after moving HDD to another computer

    Quote Originally Posted by Kljuka View Post
    ...

    Do you think there is a better way to create a clone of a live server than fresh-installing it, changing UIDs and ownerships to be the same as on the original server and afterwards copying the data to it?
    You can use dd as previously mentioned. I have applied dd image to a live system and rebooted into the new system. It is very powerful. Here is a good start on learning some dd magic.

    After applying dd to a new drive you may have some minor tweaks such as fixing ../persistent-net-rules (fix or remove mac address from old system), ../fstab (fix/change uuids and mount points), and possibly Grub 2 may need to be reinstalled to find correct disk uuid.
    Nothing is ever easy, but if it is difficult you must be doing it wrong.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •