2

I've got questions about how the Linux mount command works when used multiple times.

Through an unfortunate series of events (multiple crashes in Ubuntu), I've decided that I wish to simply back up my data and start afresh. So, after booting with a bootable USB, I have thus far mounted an external disk and the first partition of two which I wish to back up. However, I noticed something odd. After some difficulties, I found that I was able to mount the two drives with the following command line:

sudo mount /dev/sdxx /mnt

replacing the "xx" with the correct letter and number. I first mounted the partition to be backed up, and then navigated to the home directory in that drive (the one I needed to back up). I then opened a second terminal window and mounted the external disk. I've been led to believe that the /mnt bit at the end of the command line tells the computer in which directory I wish to mount the drive; this would explain why the /mnt directory now has only the stuff from the external disk. However, in my first terminal window, I was still able to navigate around the 1st drive I mounted, even though the path (/mnt/home/user/) no longer existed, according to the second window.

  1. Why does the first terminal window still allow me to navigate around what appears to be a non-existent directory?

Furthermore, I've started backing up the files to the external drive by using a simple zip command, run from the first terminal within the directory containing everything which I need to back up: zip -r9 /mnt/backup.zip *. It seems to be doing fine; the second terminal is showing the partial zip file growing in the /mnt directory on the external disk.

  1. Is there any reason that you would expect this to go wrong at any point whatsoever, or is this perfectly logical behavior?
0

Question 1

From the mount man page:

Description

All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again.

The trunk or root of the tree is the /, hence the name root filesystem. In linux, it is possible to mount a bigger disk as smaller chunks, as you have found out. In order to preserve your directories, you have to options:

  1. Choose smaller chunks, ie:

    sudo mkdir -v /mnt/home-backup  
    sudo mount -v /dev/sdX/home/username /mnt/home-backup
    
  2. Use the --bind option

    sudo mkdir -v /mnt/entire-usb
    sudo mount -v /dev/sdX /mnt/entire-usb
    sudo mkdir -v /mnt/home-backup
    sudo mount --bind /mnt/entire-usb/home/username /mnt/home-backup
    

While bind mounts seem confusing, they aren't. They are used to make parts of the same file system writable in two places, so that the updates I do in one place are reflected in both places... In my example above, in the first two lines i mounted my entire usb stick, thinking I would back up the entire disk. Realizing my mistake, I binded a smaller subset of the entire disk to a new mount point.

Note that it's a lot easier to use sudo umount /dev/sdX and then remount it using option 1.


Question 2

There are some directories you don't want to backup, since they will be recreated during a reinstall, namely /sys /dev /usr and /etc. Also possibly, /tmp and /root so using * in your zip file is considered by some, to be a bad idea. You either need to:

  1. Start over, and mount each directory using option 1 from above, using a separate zip file for each.
  2. Learn something new, and use tar instead of zip. Tar includes the -X option.

Consider:

$ cat exclude.lst   
/usr
/dev
/sys
#Other Directories to exclude

tar -cvzf /mnt/backup.tar.gz /path/to/mount/point/ -X exclude.lst

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.