Stay organized with collections
Save and categorize content based on your preferences.
Copy the source machine's file system
Modernization of an application component requires
creating a copy of the source machine's file system.
This page describes the steps required to copy the source machine's file system
along with some specifications for reducing the size of the copied file system.
Create a local copy of the Linux source machine file system
The Migrate to Containers CLI supports access to source machines using either direct
SSH connection or by using gcloud.
Direct SSH
To copy using direct SSH access, run the following command:
After the copy is complete, a copy of the source machine's file system is
available in the specified output directory.
Reduce the size of the copied file system
Depending on the source machine, the copied file system might be very large. The
larger the copy, the longer it takes for each operation to complete and, if
there's not enough space, the copy operation fails.
The Migrate to Containers CLI applies filters to reduce the size of the copy,
but with the given knowledge of the application component, you can modify the
filters to further reduce the size of the copy.
When you run the copy command again with the modified filters, the contents of
the output directory are updated according to the changes you applied in the
filter file.
To modify the default filters, follow these steps:
Get a list of the default filters:
./m2c copy default-filters > filters.txt
Edit the file filters.txt to remove irrelevant directories. The file uses
the rsync filter rule format, as specified in the rsync documentation page.
Use the --filters flag to specify the filter file with the copy command.
Create a local copy of the Windows source machine file system
For Windows source machines, you need to copy the disk images in VHD or VHDX
format for the migration process. However, Migrate to Containers CLI does not support
exporting disk images from your source platform to your local machine.
To export a Compute Engine virtual machine (VM) instance disk, first
create an image from the disk
and then export the image to the local machine.
To export an image from Compute Engine, perform the following steps:
To export VMware VM disk images, first complete the steps to
export an image to a VMDK file. Then, convert the VMDK file to
a VHD file using third-party tools such as qemu-img.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[],[],null,["# Copy the source machine's file system\n=====================================\n\nModernization of an application component requires\ncreating a copy of the source machine's file system.\n\nThis page describes the steps required to copy the source machine's file system\nalong with some specifications for reducing the size of the copied file system.\n\nCreate a local copy of the Linux source machine file system\n-----------------------------------------------------------\n\nThe Migrate to Containers CLI supports access to source machines using either direct\nSSH connection or by using `gcloud`.\n**Note:** The user that you use to access the source machine must be a sudoer to be able to access all files and directories relevant to modernization. If sudo is disabled for all users including root, use the root user and use the flag `--remote-sudo=false`. \n\n### Direct SSH\n\nTo copy using direct SSH access, run the following command: \n\n ./m2c copy ssh [\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e@]\u003cvar translate=\"no\"\u003eHOSTNAME\u003c/var\u003e \\\n -i \u003cvar translate=\"no\"\u003ePATH_TO_PRIVATE_KEY\u003c/var\u003e \\\n -o \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: your username\n- \u003cvar translate=\"no\"\u003eHOSTNAME\u003c/var\u003e: the hostname\n- \u003cvar translate=\"no\"\u003ePATH_TO_PRIVATE_KEY\u003c/var\u003e: the path to private key\n- \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e: the path for the output directory on your local machine where you want to copy the source machine's file system\n\n### gcloud\n\nIf the source machine has a public IP, run the following command: \n\n ./m2c copy gcloud \\\n -p \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n -z \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e \\\n -n \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n -o \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project ID\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone of your VM\n- \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name of the source VM\n- \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e: the path for the directory output on your local machine where you want to copy the source machine's file system\n\nIf the source machine doesn't have a public IP, you can do one of the following:\n\n- If you are running the Migrate to Containers CLI from a machine in the same internal network, Use the `--internal-ip` flag.\n- If you are running on a different network, use the `--tunnel-through-iap` flag.\n\nFor more information about these flags, see the\n[gcloud documentation](/sdk/gcloud/reference/compute/ssh#:%7E:text=can%20be%20specified%3A-,%2D%2Dinternal%2Dip,-Connect%20to%20instances).\n\nAfter the copy is complete, a copy of the source machine's file system is\navailable in the specified output directory.\n\n### Reduce the size of the copied file system\n\nDepending on the source machine, the copied file system might be very large. The\nlarger the copy, the longer it takes for each operation to complete and, if\nthere's not enough space, the copy operation fails.\n\nThe Migrate to Containers CLI applies filters to reduce the size of the copy,\nbut with the given knowledge of the application component, you can modify the\nfilters to further reduce the size of the copy.\n\nWhen you run the `copy` command again with the modified filters, the contents of\nthe output directory are updated according to the changes you applied in the\nfilter file.\n\nTo modify the default filters, follow these steps:\n\n1. Get a list of the default filters:\n\n ./m2c copy default-filters \u003e filters.txt\n\n2. Edit the file `filters.txt` to remove irrelevant directories. The file uses\n the `rsync` filter rule format, as specified in the [`rsync` documentation page](https://linux.die.net/man/1/rsync#Filter%20Rules).\n\n3. Use the `--filters` flag to specify the filter file with the `copy` command.\n\n ### Direct SSH\n\n ./m2c copy ssh [\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e@]\u003cvar translate=\"no\"\u003eHOSTNAME\u003c/var\u003e \\\n -i \u003cvar translate=\"no\"\u003ePATH_TO_PRIVATE_KEY\u003c/var\u003e \\\n -o \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e \\\n --filters filters.txt\n\n ### gcloud\n\n ./m2c copy gcloud \\\n -p \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n -z \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e \\\n -n \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n -o \u003cvar translate=\"no\"\u003eOUTPUT_FILESYSTEM_DIR\u003c/var\u003e \\\n --filters filters.txt\n\nCreate a local copy of the Windows source machine file system\n-------------------------------------------------------------\n\nFor Windows source machines, you need to copy the disk images in VHD or VHDX\nformat for the migration process. However, Migrate to Containers CLI does not support\nexporting disk images from your source platform to your local machine.\n\n- To export a Compute Engine virtual machine (VM) instance disk, first\n [create an image from the disk](/compute/docs/instances/windows/creating-windows-os-image)\n and then export the image to the local machine.\n\n- To export an image from Compute Engine, perform the following steps:\n\n 1. Export the image to Cloud Storage using the [`gcloud compute images export` command](/sdk/gcloud/reference/compute/images/export):\n\n ```\n gcloud compute images export \\\n --export-format vhdx \\\n --destination-uri DESTINATION_URI \\\n --image IMAGE_NAME\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDESTINATION_URI\u003c/var\u003e: the Cloud Storage URI destination for the exported image file.\n - \u003cvar translate=\"no\"\u003eIMAGE_NAME\u003c/var\u003e: the name of the disk image to export.\n 2. Download the image on your local machine:\n\n ```\n gcloud storage cp DESTINATION_URI LOCAL_PATH\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDESTINATION_URI\u003c/var\u003e: the Cloud Storage URI destination of the exported image file\n - \u003cvar translate=\"no\"\u003eLOCAL_PATH\u003c/var\u003e: the path to the local folder where you want to download the image\n\n For more information, see [Export a custom image to Cloud Storage](/compute/docs/images/export-image).\n- For more information on exporting Amazon EC2 images, see\n [Exporting an instance as a VM using VM Import/Export](https://docs.aws.amazon.com/vm-import/latest/userguide/vmexport.html).\n\n | **Note:** When you create the JSON file for exporting an image, omit the `ContainerFormat` field, and set `DiskImageFormat` to `\"VHD\"`.\n- For more information on exporting Azure Cloud Compute images, see\n [Download a Windows VHD from Azure](https://learn.microsoft.com/en-us/azure/virtual-machines/windows/download-vhd?tabs=azure-portal).\n\n- To export VMware VM disk images, first complete the steps to\n [export an image to a VMDK file](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere-lifecycle-manager.doc/GUID-A3E9D4BA-CAAC-4F2C-B97F-C0904ECE5E14.html). Then, convert the VMDK file to\n a VHD file using third-party tools such as [qemu-img](https://cloudbase.it/qemu-img-windows/).\n\nWhat's next\n-----------\n\n- Learn how to [create a migration plan](/migrate/containers/docs/m2c-cli/create-a-migration-plan)."]]