How to Migrate CasaOS Data to a New Drive and Mount It Permanently

When you’re upgrading your storage or adding additional space to your CasaOS setup, you’ll need to copy existing data to a temporary directory before mounting the new drive. This process involves identifying the new drive, formatting it, and ensuring all your data remains intact and accessible. Here’s a step-by-step guide to doing just that.

Step 1: Identifying the New Drive

Before you can format and mount your new drive, you need to identify it. The lsblk -f command is a simple way to do this:

  1. Open your terminal.
  2. Type the command:
lsblk -f
  1. Look for a drive without a filesystem type — likely your new, unformatted drive.

Step 2: Copying Existing Data to a Temporary Directory

Before formatting the new drive, ensure that you have a backup of your existing data. Use the following commands to copy your data:

  1. Create a temporary directory to hold your data:
sudo mkdir /tmp/appdata_backup
  1. Copy the data from /DATA/AppData to the temporary directory:
sudo cp -a /DATA/AppData/. /tmp/appdata_backup/

The -a option in the cp command preserves the permissions and ownership of the files.

Step 3: Formatting the New Drive

With your data safely backed up, it’s time to format the new drive:

  1. Format the drive with ext4 filesystem:
sudo mkfs.ext4 /dev/[your-drive-name]

Warning: Double-check the drive identifier to avoid data loss.

Step 4: Mounting the New Drive

Now, mount the new drive to the original location of your data:

  1. Mount the drive:
sudo mount /dev/[your-drive-name] /DATA/AppData
  1. Restore the data from the temporary directory back to /DATA/AppData:
sudo cp -a /tmp/appdata_backup/. /DATA/AppData/

Step 5: Automating the Mount at Boot

To ensure your drive mounts automatically on boot:

  1. Add an entry to /etc/fstab:
echo "/dev/[your-drive-name] /DATA/AppData ext4 defaults 0 0" | sudo tee -a /etc/fstab
  1. Test the entry to avoid boot issues:
sudo mount -a

Step 6: Cleanup

With your data now safely on the new drive and mounted at the correct location, don’t forget to remove the temporary backup:

  1. Remove the temporary directory:
sudo rm -rf /tmp/appdata_backup

Conclusion

You’ve successfully upgraded your CasaOS’s storage capabilities without losing data. It’s always a good idea to back up your data before performing such operations, and remember to verify each step along the way to ensure that everything is proceeding smoothly.

Happy computing with your newly expanded CasaOS setup!

FAQ’s

Does this change where the OS or any other files are located?

No, the process outlined only changes the storage location for the data associated with Docker containers, specifically the bound or mounted data that containers use to persist information. This includes any volumes or bind mounts that you’ve set up within Docker to store application data outside of the container’s writable layer. It does not affect the location of the operating system files, system configurations, or other non-container files on your system. This ensures that your OS and personal or system-wide files remain intact and in their original locations, providing a seamless transition for your Docker container storage without impacting the rest of your system’s setup.