0

I want to copy my Ubuntu's root file system into another folder (perhaps /home/rootfs). I am not trying to copy /, which is the root file directory, but am trying to copy the root file system. Does anyone know the proper way of doing this?

I am doing this because I am trying to create a container using Go (https://www.youtube.com/watch?v=Utf-A4rODH8) and in the video she already has a root file system copied. I would also like to do the same.

Thank you!

1

2 Answers 2

2

You can use dd.

dd if=/dev/sdXX of=/home/rootfs.img where /dev/sdX is the block device you're looking to copy (input).

your root filesystem is likely /dev/sda1 if you have a standard installation, but you will be able to tell by running 'df' and picking the device mounted on '/'.

the argument of indicates where the image will be saved when you're done.

You may have to run this as root.

4
  • I'm getting this error: dd: unrecognized operand 'if'. How can I fix this?
    – Melissa
    Jun 26, 2018 at 17:55
  • @Melissa sorry, type-o. I edited my answer to fix it and to be a bit more clear. Jun 26, 2018 at 17:58
  • Okay thank you! Just a question, why is it of=/home/rootfs.img and not of=/home/rootfs? Wanted to know if there is a difference because the video tutorial had the copy named rootfs.
    – Melissa
    Jun 26, 2018 at 22:15
  • @Melissa I don't know if you've found the answer yet, but the of= argument is just where you specify the output location. The .img extension is pretty much meaningless, it's just convention. You can name it anything you like and have similar results. Jun 27, 2018 at 11:03
2

Perhaps this answer will not be relevant to you anymore, but it might be useful for anyone also following that demo through.

Trick is to use rsync but excluding the directories that are not needed, as well as the directory into which the root folder is being cloned to avoid endless, recursive copying.

Command:

rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*"} /home/rootfs

Explanation:

rsync is a file transfer program that is more sophisticated than cp. You can read more about it and its capabilities by typing man rsync in your shell.

  • -a flag: shortcut for 'archive' mode. This preserves symlinks, devices, etc.
  • -A flag: Preserves permissions
  • -X flag: Preserves extended attributes
  • -v flag: Verbose

    --exclude=... flag: This excludes (not copies) the directories listed inside the flag value. Note the last entry: we are excluding the /home/* folder, avoiding endless recursive copying.

Finally, the last parameter is the destination directory. In your case, it is /home/rootfs (demo stores the clone in /vagrant/ubuntu-fs/)

After running this, I was able to follow through with the demo. Hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .