Copying a Disk Over SSH
Updated by Linode Written by Linode
You can use SSH to copy a Linode’s disk to a system that resides on a different network. This is an effective way to back up your Linode’s disks to a personal computer or another server. In this guide, you’ll learn how to use SSH to copy a Linode’s disk to a local system.
Prepare the Receiving Computer
Verify that the receiving computer has SSH installed. (Most Linux/Unix-like systems have it installed by default.) If you’re running Windows locally, you may wish to set up the Cygwin compatibility layer to provide a reasonably complete Unix-like environment. Instructions on setting up Cygwin are located here, at the bottom of the guide.
Start Your Linode in Rescue Mode
Before you initiate the transfer, start your Linode in Rescue Mode and start SSH by following these guides:
- Start your Linode in Rescue Mode.
- Connecting to a Linode Running in Rescue Mode via LISH.
- Start the SSH server on your Linode.
Copy the Disk
Now that the Linode is running in Rescue Mode, you can transfer the disk from the Linode to the receiving machine over SSH:
Enter the following command on the receiving machine. Replace
18.104.22.168with the Linode’s IP address and
/home/archive/linode.imgwith the path where you want to store the disk:
ssh email@example.com "dd if=/dev/sda " | dd of=/home/archive/linode.img
/dev/sdais used for Linodes running on top of KVM. If you Linode is still using XEN, then throughout this guide you must use
The receiving machine will connect to the Linode. Type
yesand press Enter to continue connecting:
The authenticity of host '22.214.171.124 (126.96.36.199)' 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)? yes
Enter the root password for the Linode:
Warning: Permanently added '188.8.131.52' (RSA) to the list of known hosts. firstname.lastname@example.org's password:
The transfer starts, and you’ll see output similar to the following:
4096000+0 records in 4096000+0 records out 2097152000 bytes (2.1 GB) copied, 371.632 seconds, 5.6 MB/s 4096000+0 records in 4096000+0 records out 2097152000 bytes (2.1 GB) copied, 364.002 s, 5.8 MB/s
NoteCopying your disk can take a while. Please be patient. If you have a slow internet connection, add the
-Coption to the SSH command; this enables gzip compression for data transfer. If you receive a
Write failed: Broken pipeerror, repeat this step.
Verify the Disk
Once the copy has completed, you can verify it by mounting the image on the receiving machine.
Log in to the receiving machine as
rootby entering the following command and entering the
Make a directory on the receiving machine by entering the following command:
Mount the disk by entering the following command, replacing
linode.imgwith the name of the disk:
mount -o loop linode.img linode
View the directories stored on the disk by entering the following command:
You should see the directories on the disks, similar to the ones shown below, indicating that everything has transferred:
bin dev home lost+found mnt proc sbin srv tmp var boot etc lib media opt root selinux sys usr
You have successfully transferred your Linode’s disk to another host using SSH.
Upload the Disk
Once you have a copy of your Linode’s disk you may want to upload that copy from your local machine to a Linode in the future.
Prepare your empty Linode by creating a new disk. Access your Linode through the Linode Manager and select Create a new disk:
Enter a descriptive name in the Label field, and be sure the Size is large enough to hold the contents of the disk you are uploading. Click Save Changes.
From your receiving machine issue the following command, replacing
/home/archive/linode.img/with your disk image’s path, and
184.108.40.206with your Linode’s IP.
dd if=/home/archive/linode.img | ssh email@example.com "dd of=/dev/sda"
When the transfer is done, you will see an output similar to this:
49807360+0 records in 49807360+0 records out 25501368320 bytes transferred in 9468.878375 secs (2693177 bytes/sec) 49807360+0 records in 49807360+0 records out 25501368320 bytes (26 GB) copied, 9462.12 s, 2.7 MB/s
NoteCopying your disk can take a while. Please be patient. If you receive a
Write failed: Broken pipeerror, repeat this step.
Verify the Disk
As above, you will want to verify the disk by mounting it on the receiving Linode. Log in to your Linode through SSH.
Make a new directory for the disk:
Mount the disk:
mount /dev/sda linode
View the directories in the disk:
The output should be similar to below:
bin dev home lib64 media opt root sbin srv tmp var boot etc lib lost+found mnt proc run selinux sys usr
Expand the Filesystem
If the disk you created on the receiving Linode is larger than the source disk (for example you’re transferring a disk from a smaller Linode to a larger Linode), you’ll have to resize the filesystem in order to make use of the new space.
You can check if this is necessary by comparing the space reported by the filesystem:
# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda 24G 19G 4.0G 83% /
To the space reported by the disk:
# 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 30GB (the Linode Manager will also show the disk as 30GB), the filesystem can only see 24G. To use all available space on the new disk, execute the following from Rescue Mode:
e2fsck -f /dev/sda resize2fs /dev/sda
Create the Swap Disk
If your Linode still has enough space for a swap disk, simply create one from your Linode’s Dashboard by selecting
swap from the Type drop down menu. A swap disk is typically between 256MB and 512MB in size, but can be made larger or smaller depending upon your needs. If all of the free space on your Linode is assigned to the disk you created previously, resize the disk to make enough room for the swap disk, and then follow the steps to create it.
Boot from the Disk
You will now need to create a new configuration profile on the receiving Linode to boot from.
From within your Linode Manager, select your Linode and select Create a New Configuration Profile.
Enter the name for the configuration profile in the Label field, and in the Block Device Assignment section set the
/dev/sdato the new disk you created earlier in this section of the guide. Set
/dev/sdbto the swap image. Save changes.
Return to the Linode’s dashboard manager, and select the configuration profile that you just created. Click Reboot to start the Linode using the disk you just transferred.
Windows Cygwin Instructions
Download and install Cygwin
Install the OpenSSH package, by clicking on the Cygwin install after the install succeeds.
opensshinto the search bar, and press install.
- Test if the
sshfunction of Cygwin works:
Join our Community
This guide is published under a CC BY-ND 4.0 license.