Commands.page Logo

How to Create Compressed Archive of Mounted Drive Ubuntu

This guide explains how to create a compressed archive of a mounted drive in Ubuntu. You will learn the necessary commands to safely backup data without unmounting the drive, ensuring file integrity while saving storage space using standard Linux tools like tar and gzip.

Identify the Mount Point

Before creating the archive, confirm the path where your drive is mounted. Open the terminal and use the df -h command to list all mounted filesystems. Locate your specific drive in the output and note the path listed under the “Mounted on” column, such as /mnt/data or /media/username/drive.

Execute the Tar Command

Use the tar utility to compress the contents. Navigate to a directory with sufficient storage space to hold the new archive, ideally on a different physical drive to prevent data loss. Run the following command, replacing the placeholder paths with your actual mount point and desired archive name:

sudo tar -czvf /path/to/backup/archive_name.tar.gz /mount/point

The -c flag creates a new archive, -z compresses it using gzip, -v displays progress in the terminal, and -f specifies the filename. Using sudo ensures you have permission to read all files within the mounted drive.

Verify the Archive

Once the command completes, verify the integrity of the compressed file. You can list the contents of the archive without extracting it to ensure all files were captured. Run the following command:

tar -tzvf /path/to/backup/archive_name.tar.gz

If the file list displays correctly without errors, your mounted drive has been successfully archived and compressed.