1

Note: I am doing this to learn more about linux. I understand there are other tools that can be used with simple interfaces.

Note: I am using Fedora 23. I have it installed physically on an SSD and my goal is to move it into a virtual machine.

Before using tar, I have successfully used rsync. I would rsync my entire file system directly onto a partition formatted with ext4. I would then set up a virtual machine and boot with a liveCD, mount the partition, and rsync the files back. After that, I update my fstab, re-install grub and generate the grub configuration file, and finally generate a new initramfs using dracut

I would like to use tar now so I can store backups of my system in a single archive file and have it compressed.

I use this command to create the tar: tar -czpf /path/to/backup.tar.gz /path/to/fs/

Note that the path to the FS I am archiving is the same files that I rsynced to a temp directory. It does not include folders such as proc, dev, sys, etc.

And then I boot up the VM using a livecd, mount the partitions, and then use this command to extract the tar as root user:

tar -xzpf /path/to/backup/file -C /path/to/new/partition

When I update the same files as I did with rsync, I reboot and get to the login screen. However, logging in as root (using tty) or as my user does not work. It simply sends me back to the login screen -- I am stuck in a login loop.

I found out that when tar extracts files owned by amoghrabi, it will replace the user as liveuser. This is because tar uses the file system's passwd file to match users. If it cannot find the user name, it will match by UID and GID.

As a possible solution, I have tried updating the live system's passwd file and group file with the ones from my original filesystem. This does not work.

I have read about using the flag --same-owner, but this does not work in my case because the passwd file of the livecd filesystem does not contain the original users of the system I am restoring.

What are my options here to successfully restore my system as I did with rsync?

EDIT:

To avoid confusion, I am booting from a liveCD and mounting /dev/sda1, the partition I want to restore my backup to. I am un-taring the backup to this partition and then chrooting (while still in the liveCD environment) to modify /etc/fstab, reinstall grub, and re-generate the initramfs file. After the process of un-taring my backup to /dev/sda1 is complete, it appears that amoghrabi, my user in my backup, no longer owns its files (e.g. /home/amoghrabi/ and instead, the files are owned by liveuser. I believe this is because the /etc/passwd file on the liveCD has UID of 1000, which is the same UID for amoghrabi.

What can I do in this case? I have already tried restoring my /etc/passwd and /etc/group file to the liveCD environment before un-taring my backup. This fixed the issue where the user amoghrabi home directory is owned by amoghrabi, but I still get stuck in a login loop which I believe is the cause of something not having the correct permissions from the un-taring process.

My end goal here is to be able to boot into /dev/sda1 and have a working copy of my system, with the use of tar to store my backups.

migrated from stackoverflow.com May 24 '16 at 12:46

This question came from our site for professional and enthusiast programmers.

0

Pass the --numeric-owner option to tar either when making the archive or when extracting it (or both). This causes the files to be extracted with the same UIDs and GIDs that they were archived under, regardless of user names on the system where you extract. Since you're restoring the user database alongside the rest, the files will end up owned by the correct user on the restored system.

If you look at your restored backup from the live CD, it's normal that users appear with a different name. What identifies a user in the filesystem is the numerical user ID, not the user name. The user ID of liveuser is the first number in the range for physical users; the user ID of amoghrabi is presumably the same number, if this was the first user created during or after the installation. I think Fedora starts at UID 500, so the files in /home/amoghrabi are owned by UID 500. When seen from the live CD, user 500 has the name liveuser. When seen from the original system or from the restored system, user 500 has the name amoghrabi.

If you want to use the restored backup from the live CD, you'll need to do a little more than chroot into it. You need to mount a number of filesystems (to be done as root outside the chroot):

mount --rbind /dev /media/sda1/dev
mount --rbind /proc /media/sda1/proc
mount --rbind /sys /media/sda1/sys
mount -t tmpfs tmpfs /media/sda1/run
mount -t tmpfs tmpfs /media/sda1/tmp

Then start a display manager in the chroot if you want to run a GUI session from a GUI login. You may need to start some additional services in the chroot, I'm not sure about that.

  • Thanks for your response @Gilles, however this did not work. I only tried extracting it using the --numeric-owner option. I end up in the same login loop. I noticed that the user of my home directory is liveuser, not amoghrabi. Does it matter if I also need to create the tar file using the same flag, as you stated? I also plan to doing this while booting into livecd + replacing /etc/passwd, /etc/group, and /etc/shadow from my original backup. I'll get back to you tomorrow to see if that worked. – AMoghrabi May 25 '16 at 5:38
  • @AMoghrabi I thought you were using the live CD to restore your backup, and then booting or chrooting into the restored system. If you want to use the data of the account from the backup together with the system configuration (including the user database) from the livesystem, that's different. But I don't see this indicated in your question, you say that you're rebooting into the restored system. – Gilles May 25 '16 at 6:21
  • @AMoghrabi Please clarify what you're doing and include user IDs in your description, not just user names, because you seem to mix up user name lookups from different databases (e.g. a file that belongs to liveuser when you look at it from the live system belongs to amoghrabi when you look at it from the restored system, if they both have the same user ID). – Gilles May 25 '16 at 6:21
  • Sorry for the confusion. I've updated my answer. – AMoghrabi May 25 '16 at 17:49
  • @AMoghrabi Ok. According to your description, file ownership is correct. You don't mention mounting /dev, /proc, etc. which may be the cause of the problem. If that doesn't help, look for logs somewhere. I'm not sure about the location of the logs, on Debian it's ~/.xsession-errors but I don't know if Fedora uses the same configuration. In what program are you logging in (e.g. text mode login, xdm, lightdm, gdm, kdm, …), and what type of session do you start (gnome3, kde4, fvwm, custom, …)? – Gilles May 25 '16 at 21:03
0

I'm wondering if part of your issue is that tar doesn't capture all of the special files. Have you looked at using dd?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.