LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-21-2018, 08:47 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
Using tar to cold backup the root file system - strange error


My normal method to do a cold backup of the root fs is with Clonezilla. The only downside is that Clonezilla will not write an image to a smaller drive - even if there is plenty of room for the files.

I am playing with a couple of Raspberry Pi3 computers. They use a microSD card as their "hard drive." Rather cool. Problem is... all 16GB microSD cards are not the same size. Even a few KB difference will prevent Clonzilla from moving the OS to a smaller card. So...

I have figured out the necessary switches to allow rsync to copy files to a smaller microSD card (once it is properly partitioned and formatted.) I decided to give tar a try - just for the heck of it. In this case I am attempting to write a tar file from a microSD card mounted in my CentOS 7 workstation.
Code:
[ken@taylor20 Desktop]$ sudo tar --acls -cpvzf /xtra/store_root/pi_root.tar.gz /run/media/ken/PI_ROOT
[sudo] password for ken: 
tar: Removing leading `/' from member names
/run/media/ken/PI_ROOT/
/run/media/ken/PI_ROOT/tmp/
/run/media/ken/PI_ROOT/tmp/.ICE-unix/
/run/media/ken/PI_ROOT/tmp/config-err-U5UlJ9
/run/media/ken/PI_ROOT/tmp/.X11-unix/
/run/media/ken/PI_ROOT/tmp/.XIM-unix/
/run/media/ken/PI_ROOT/tmp/.Test-unix/
/run/media/ken/PI_ROOT/tmp/.font-unix/
...
/run/media/ken/PI_ROOT/dev/fd/3/tmp/.ICE-unix/
...
/run/media/ken/PI_ROOT/dev/fd/3/dev/fd/3/dev/fd/3/tmp/.ICE-unix/
...
Segmentation fault
The errors which I captured show
Quote:
tar: Removing leading `/' from member names
tar: /run/media/ken/PI_ROOT/tmp/.ICE-unix/1290: socket ignored
tar: Removing leading `/' from hard link targets
tar: /run/media/ken/PI_ROOT/dev/fd/1: file changed as we read it
tar: /run/media/ken/PI_ROOT/dev/fd/3/tmp/.ICE-unix/1290: socket ignored
tar: /run/media/ken/PI_ROOT/dev/fd/3/dev/fd/3/tmp/.ICE-unix/1290: socket ignored
tar: /run/media/ken/PI_ROOT/dev/fd/3/dev/fd/3/dev/fd/3/tmp/.ICE-unix/1290: socket ignored
tar: /run/media/ken/PI_ROOT/dev/fd/3/dev/fd/3/dev/fd/3/dev/fd/3/tmp/.ICE-unix/1290: socket ignored
It appears that I have some sort of recursive mischief going on. This started when I added the -h option to attempt to preserve links. However, it seems that I am trying to save the files linked to (according to the man pages.)
My question is... How do I save the LINKS so that they will be restored to my cloned "hard drive" and used when the Pi boots?

TIA,

Ken
 
Old 11-21-2018, 10:27 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Not sure what is happening either.

What distribution are you running on your Pi's? I run Raspbian which uses a tmpfs for /dev.
 
Old 11-21-2018, 10:33 AM   #3
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,569
Blog Entries: 19

Rep: Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451
Have you thought of using fsarchiver? Unlike clonezilla, it only copies the occupied part of the disk. I have used it to move filesystems to partitions that were not the same size.
 
1 members found this post helpful.
Old 11-21-2018, 10:55 AM   #4
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks michaelk,

I am running Ubuntu Mate 16.04 and 18.04. I think I will try tar without the -h and see if links are in fact added to the tarball by default. I spent two days figuring out that I needed to add -A to my rsync command. It worked, the Pi booted but I could not mount a USB flash drive. Seems that /mount/ken had an ACL set. When that was not present I could not mount the flash drive

Thanks hazel,

I will check out fsarchiver. It is always good to have more tools in the toolbox

Ken
 
Old 11-21-2018, 05:49 PM   #5
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Update...

I did a tar without the "a" option and it seemed to work OK. At least no errors. When I did an un-tar I found that the permissions do not carry forward as they should. Here are my commands
Quote:
sudo tar --acls -cpvzf /xtra/store_root/pi_root.tar.gz /run/media/ken/PI_ROOT >> run.log 2> errors.txt

sudo tar --acls -xpvf /xtra/store_root/pi_root.tar.gz -C /
When I examine the resultant file system I find for example that /home has the permissions
Code:
drwx------.  3 root root 4096 Nov 21 18:40 home
which should be something like
Code:
drwxr-xr-x   3 root root  4096 Sep  9 14:50 home/
Obviously the users will not be able to access their home directories

Oh never mind - but this is rather interesting! I was writing this post as the process was running. I was viewing the / directory of the target file system. As the process completed I observed the little [x] symbols disappear from the various directories. I can now access my home directory and files. Perhaps restoring permissions is a final step to the un-tar process?

Ken
 
Old 11-21-2018, 05:54 PM   #6
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
But of course the Pi does not boot Kernel panic. Missing links perhaps?

Ken
 
Old 11-23-2018, 06:15 AM   #7
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by taylorkh View Post
My normal method to do a cold backup of the root fs is with Clonezilla. The only downside is that Clonezilla will not write an image to a smaller drive - even if there is plenty of room for the files.

I am playing with a couple of Raspberry Pi3 computers. They use a microSD card as their "hard drive." Rather cool. Problem is... all 16GB microSD cards are not the same size. Even a few KB difference will prevent Clonzilla from moving the OS to a smaller card. So...

I have figured out the necessary switches to allow rsync to copy files to a smaller microSD card (once it is properly partitioned and formatted.)
May I ask what file system? Since you are already partitioning and formatting the microSD card, why not just use dump/restore or xfsdump/xfsrestore (depending on filesystem)?
 
1 members found this post helpful.
Old 11-23-2018, 06:44 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Do not use the -h.

That causes tar to make a copy of the original file, not the link. In a restore the file would be copied back.

As for keepting the owners and such - I use "tar --one-file-system --selinux --acls --xattrs -z" to create the backup.

Then use the --same-owner (which is the default for the super user).

The --selinux --acls and --xattrs are because they are used on Fedora/RH kit, so they need to be preserved. The --one-file-system is to prevent tar from walking into other mounted filesystems.
 
1 members found this post helpful.
Old 11-23-2018, 07:00 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
segfault is caused because of the loop. As you see there is a symbolic link which will make a recursion. It will cause a variable overflow inside tar and finally a crash. You need to avoid following those links.
 
1 members found this post helpful.
Old 11-24-2018, 10:23 AM   #10
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thank you jpollard - that did the trick! I tar(ed) the root partition from a microSD card, deleted all files from that partition and (un)tar(ed) the files back. The microSD card successfully booted the Pi and it seems to be working fine. As to the -h. I did not want to follow the links, just to save them to the tarball. I have a working recipe now.

Thanks pan64, I realize that the segmentation fault was caused by the looping until tar exploded or imploded or whatever. Again, I did not want to follow the links, just save them. My bad.

Thanks dc.901,

The partition is ext4. I will look into dump and restore. It is always good to have options.


Ken

Last edited by taylorkh; 11-24-2018 at 10:28 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
"Invalid tar magic" error msg. when I try to tar ldmud *.tar file in DSL pixxi451 Linux - Newbie 4 07-04-2010 08:32 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
How do I un tar a .tar, .tar.z, .tar.gz file vofkid Linux - Newbie 4 03-15-2002 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration