Copy a disk over SSH
Piping SSH commands to utilities such as dd, gzip, or rsync is an easy way to copy a Linode's data into a single file for later extraction. This can effectively back up your Linode's disk or migrate your installed system to other Linodes.
This guide demonstrates how to download a .img file to your computer over SSH containing a block-level copy of your Linode's disk device created with dd.
If the amount of data on your disk is much less than the size of the disk, then downloading a copy with
ddcan take longer than just downloading your files. If you're interested in downloading individual files or directories, review the options listed in our Download Files from Your Linode and Backing Up Your Data guides.
Download a disk over SSH
This guide shows you how to download a Linode's disk image over SSH to a separate receiving system, like a personal computer or another Linode. This is done by executing commands on both the origin system (the Linode where your disk is stored) and the destination system which will receive a copy of this image.
While this guide has been written to accommodate computers running Linux as their operating system, if the receiving system is instead running Microsoft Windows, there are multiple SSH solutions available such as Cygwin and PuTTY which can alternatively be used to complete this process.
Boot into Rescue Mode
-
Boot the origin Linode into Rescue Mode and connect to it using Lish.
-
Set a root password for the rescue system and start the SSH server:
passwd service ssh start
Copy and download the disk
-
Prepare the destination system to download the disk image by verifying that SSH is installed. Most Linux/Unix-like systems include OpenSSH in their package base by default.
-
Copy the disk over SSH from the origin system to the destination system. Run the following command on the destination system, replacing
192.0.2.9with the origin Linode's IP address and/home/archive/linode.imgwith the path where you want to store the disk.ssh root@192.0.2.9 "dd if=/dev/sda " | dd of=/home/archive/linode.img status=progress -
The destination system is now connected to the Linode, prompting you to verify that the SSH key fingerprints are valid. If valid, type
yesand press Enter to continue:The authenticity of host '192.0.2.9 (192.0.2.9)' can't be established. RSA key fingerprint is 39:6b:eb:05:f1:28:95:f0:da:63:17:9e:6b:6b:11:4a. Are you sure you want to continue connecting (yes/no)? -
The destination system is prompted to enter the root password you created for the origin Linode in Rescue Mode. Enter this password now:
Warning: Permanently added '192.0.2.9' (RSA) to the list of known hosts. root@192.0.2.9's password:When the transfer completes, you see a summary output similar to the output below:
4096000+0 records in 4096000+0 records out 2097152000 bytes (2.1 GB) copied, 371.632 seconds, 5.6 MB/sCopying your disk can take a while. If you have a slow internet connection, add the
-Coption to the SSH command to enable gzip compression of the disk image. If you receive aWrite failed: Broken pipeerror, repeat this process.
Verify the disk
Once the copy has completed, verify it by mounting the image on the receiving system with the following commands.
-
Switch to the
rootuser:su -
Make a directory to mount the disk:
mkdir linode -
Mount the disk in the directory created in the previous step. Replace
linode.imgwith the name of your Linode's disk.mount -o loop linode.img linode -
List the directories on the disk to indicate if everything has transferred. Your output of
lsis similar to below:ls linodebin dev home lost+found mnt proc sbin srv tmp var boot etc lib media opt root selinux sys usr
Upload a disk over SSH
In some cases, it is necessary to upload your disk image to a new server. For example, if you previously downloaded your Linode's disk and deleted the Linode to halt billing on it, you can create a new Linode at a later date and upload the disk to resume your services. This section of the guide assumes that you are creating a new Linode with the default primary and swap disk as outlined in Create a Linode.
A Linodecan have up to 50 disks.
-
Once you've created a Linode with enough disk space available to accommodate your disk image, prepare the new Linode to receive this image. This is completed by first deleting the primary disk created by default, and keeping the swap disk. A swap disk typically starts at 256 MB or 512 MB in size, but can be larger or smaller depending upon your needs.
-
Access your Linode through Cloud Manager. Click the Storage tab to navigate to the Disks section.
-
On the following page in the Disks menu, select the ellipsis next to any primary disks you are replacing and select Delete.
-
Next, select Add a Disk.
-
The Add a Disk panel appears. Select the Create Empty Disk option, enter a Label that you can use as a personal identifier, select the file system that matches the format of the disk that was downloaded over SSH, and enter a Size that is large enough to hold the contents of the disk you are uploading. Click Save Changes.
-
Reboot Your Linode into Rescue Mode and start the secure SSH server using the following commands:
passwd service ssh start -
Upload the disk image you have saved remotely over SSH to the new Linode. Replace
192.0.2.9with the Linode's IP address and/home/archive/linode.imgwith the disk images's path.dd if=/home/archive/linode.img | ssh root@192.0.2.9 "dd of=/dev/sda"When the transfer completes, you see a summary output similar to below:
49807360+0 records in 49807360+0 records out 25501368320 bytes (26 GB) copied, 9462.12 s, 2.7 MB/sCopying your disk can take a while. If you receive a
Write failed: Broken pipeerror, repeat this process.
Expand the filesystem
If the disk you created on the new server is larger than the source disk (for example you're transferring a disk from a smaller Linode to a larger Linode), you have to resize the file system to make use of the new space.
You can check if this is necessary by comparing the space of the file system to the space of the new disk:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda 24G 19G 4.0G 83% /
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk /
In the above example, the values in the Size column don't match. Although the disk is 30 GB, the file system can only see 24 GB.
To use all available space on the new disk, execute the following from Rescue Mode. Replace /dev/sdx with your system disk's device identifier (/dev/sda, /dev/sdb, etc.).
e2fsck -f /dev/sdx
resize2fs /dev/sdx
Boot from the disk
You now need to create a new configuration profile on the destination Linode.
-
Select your Linode, click the Configurations tab, then select Add a Configuration.
-
The Add Configuration panel appears.

-
Enter a name for the configuration profile in the Label field, and in the Block Device Assignment section set the
/dev/sdato the new system disk you created earlier in this section of the guide. Set/dev/sdbto the swap image. -
The Linode is now ready to reboot using the new system disk.
Updated 4 months ago
