Linux clone disk
Using dd (device dump) to clone/copy the entire disk
Disk to Disk
- Source: /dev/sda (not mounted), size=4GB
- Target: /dev/sdb (not mounted), size=8GB
- View source details
root@raspberrypi:~ # fdisk -l /dev/sda Disk /dev/sda: 3.75 GiB, 4026531840 bytes, 7864320 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4808f986 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/sda2 532480 7864286 7331807 3.5G 83 Linux
- Copy /dev/sda/ to /dev/sdb
root@raspberrypi:~ # dd if=/dev/sda of=/dev/sdb 7864320+0 records in 7864320+0 records out 4026531840 bytes (4.0 GB, 3.8 GiB) copied, 1118.79 s, 3.6 MB/s
- Compare the result
root@raspberrypi:~ # fdisk -l /dev/sdb Disk /dev/sdb: 7.4 GiB, 7948206080 bytes, 15523840 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4808f986 Device Boot Start End Sectors Size Id Type /dev/sdb1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/sdb2 532480 7864286 7331807 3.5G 83 Linux
Disk to Image
- Source: /dev/sda (not mounted), size=4GB
- Target: /dev/sdb (mounted), size=8GB
- View source details
root@raspberrypi:~ # fdisk -l /dev/sda Disk /dev/sda: 3.75 GiB, 4026531840 bytes, 7864320 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4808f986 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/sda2 532480 7864286 7331807 3.5G 83 Linux
- Create and mount the filesystem
root@raspberrypi:~ # mkfs.vfat /dev/sdb1 mkfs.fat 4.2 (2021-01-31)
root@raspberrypi:~ # mount/dev/sdb /mnt
root@raspberrypi:~ # df -h | grep mnt /dev/sdb1 7.4G 4.0K 7.4G 1% /mnt
- Clone to Image
root@raspberrypi:~ # dd if=/dev/sda of=/mnt/clonetest.iso 7864320+0 records in 7864320+0 records out 4026531840 bytes (4.0 GB, 3.8 GiB) copied, 432.071 s, 9.3 MB/s
- View the result
root@raspberrypi:~ # ls /mnt -allh total 3.8G drwxr-xr-x 2 root root 4.0K Jan 1 1970 . drwxr-xr-x 19 root root 4.0K Mar 12 18:55 .. -rwxr-xr-x 1 root root 3.8G May 28 20:30 clonetest.iso
Disk to Network/Image
- Source: /dev/sda (not mounted), size=4GB
- Target: sshfs /dev/mnt (mounted)
- View source details
root@raspberrypi:~ # fdisk -l /dev/sda Disk /dev/sda: 3.75 GiB, 4026531840 bytes, 7864320 sectors Disk model: STORAGE DEVICE Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4808f986 Device Boot Start End Sectors Size Id Type /dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA) /dev/sda2 532480 7864286 7331807 3.5G 83 Linux
- Prepare SSH Filesystem
root@raspberrypi:~ # apt-get install sshfs
- Mount filesystem
root@raspberrypi:~ # sshfs -o allow_other,default_permissions vmadmin@192.168.178.67:/ /mnt vmadmin@192.168.178.67's password:
- Clone the running OS Disk
root@raspberrypi:~ # dd if=/dev/mmcblk0 of=/mnt/data/clonetest.iso 3901440+0 records in 3901440+0 records out 1997537280 bytes (2.0 GB, 1.9 GiB) copied, 278.75 s, 7.2 MB/s