7

I have linux installed on SD card, I used this command to install the rootfs

tar xpjf rootfs.tar.bz -C /mnt/rootfs/

Now, I made some changes to the rootfs and I would like to create a backup that I can use with the same command above, I tried using:

tar cpjf rootfs.tar.bz2 /mnt/rootfs
and
tar cpjf rootfs.tar.bz2 -C / mnt/rootfs
I also tried
tar cpjf rootfs.tar.bz2 /mnt/rootfs/*

And tried:

cd /mnt/rootfs
tar -cvpjf rootfs.tar.bz2 --exclude=/rootfs.tar.bz2 .
tar: ./rootfs.tar.bz2: file changed as we read it

but I end up with an archive that has two levels before the file system i.e mnt/rootfs/files What am I doing wrong ?

1

1 Answer 1

14

That's because it starts from current working directory, you can do:

cd /mnt/rootfs
tar cpjf /rootfs.tar.bz2 .

And that should create an archive at /rootfs.tar.bz2 with its root at the contents of /mnt/rootfs/

10
  • 2
    Don't use *. That might fail with files named like "--filename". Instead, use ./* . Jul 9, 2012 at 12:41
  • Also, it might be worth noting that ./* (and *) might not pick up files whose names begin with a dot. Jul 9, 2012 at 12:43
  • Thanks for the tip, i used * as the user posted the question with that, corrected the answer ;)
    – alex88
    Jul 9, 2012 at 12:43
  • 1
    @mux tar cjpf /rootfs.tar.bz2 . Jul 9, 2012 at 12:53
  • 10
    tar cpjf /rootfs.tar.bz2 -C /mnt/rootfs . Where -C means "cd into <path> then ...." Is simpler.
    – sabgenton
    Aug 14, 2013 at 4:16

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