How to use dump and recovery to clone a Linux OS disk

You can find a lot of information on the Internet about using ddOS cloning discs.

Do not listen! It is much faster to use dumpand restorebecause you are copying only the data, and not copying all the blocks (empty or not).

Part 1: find out where the source and target drives are in the device list

lsscsi | grep sd*

will show you a list of scsi devices and their associated letters. If you are fortunate enough to work with a hot-swappable box, you can simply run this command before and after you insert the disk - the newest display device is, of course, the disk you just inserted.

Part 2: Get Ready for a Dump

  • Security Tip: Assign variables to destination devices and source. (Also, if you do this several times, the variable allows you to reuse commands.)

SOURCE=/dev/sdx DEST=/dev/sdy

  1. Note on the source disk (the one you are copying from). If you copy the current OS drive, it will (duh) already be installed. If you are copying another disk, it does not actually need to be mounted.
  2. Copy the partition table of your source disk to a file: sfdisk -d $SOURCE > part_table

  3. Copy part_table already saved to file sfdisk --force $DEST < part_table

  4. Extract boot sector: dd if=/dev/zero of=${DEST}1 bs=512 count=1

  5. Make your file system (one partition at a time): mkfs -t ext4 ${DEST}1 mkswap ${DEST}2

  6. Take a look: parted $DEST --script print

  7. Copy the label of all sections without replacement. Example:tune2fs -L "/" /${DEST}1

Part 3: Landfill | recovery moment

  1. Create a directory to mount the target dump device | reestablish. (As mentioned above, the source device does not need to be mounted.) mkdir -p /mnt/${DEST}1
  2. Install the target device: mount -t ext4 ${DEST}1 /mnt/${DEST}1

  3. cd : cd /mnt/${DEST}1

  4. : dump -a0f - /dev/${SOURCE}1 | restore -rf - ( : a = autosize; 0 () = 0; f = , - = stdout; : r = rebuild; f = file; - = stdout)

  5. dump | restore .

4: grub

  1. , (.. , ), .

  2. Grub hd #, 0 (NOT 1). :/dev/sda = hd0,/dev/sdb = hd1 ..

     [root@drive-toaster /]# grub
    
     grub> root (hd1,0)  # use correct number for your disk!  
     root (hd1,0)   
     Filesystem type is ext2fs, partition type 0x83
    
     grub> setup (hd1) # use correct number for your disk!  
     setup (hd1)   
     Checking if "/boot/grub/stage1" exists... yes
     Checking if "/boot/grub/stage2" exists... yes
     Checking if "/boot/grub/e2fs_stage1_5" exists... yes
     Running "embed /boot/grub/e2fs_stage1_5 (hd1)"...  27 sectors are     embedded.
     succeeded
     Running "install /boot/grub/stage1 (hd1) (hd1)1+27 p
     (hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
     Done.
    
     grub> quit
    
+4

All Articles