3

Is there a way to clone the dmsetup configuration of a disk onto another disk and recreate the filesystems and mount points ? I do not need to copy the data of the file systems, only the configuration.

I am thinking of using the output of

dmsetup info -c --separator=',' 

from the source disk as input to create the same layout on a blank target disk having same size and partitions.

By way of example, if I have a system with two identically sized and partitioned disks, sda and sdb, and sda is divided using device mapper, then after the 'cloning' sdb has the same layout and ideally, empty filesystems:

Before:

chewbacca:/root # lsblk 
NAME                                     MAJ:MIN RM  SIZE RO TYPE     MOUNTPOINT
sr0                                       11:0    1 1024M  0 rom  
sda                                        8:0    0   64G  0 disk 
├─sda1                                     8:1    0  264M  0 part /boot
└─sda2                                     8:2    0 63.8G  0 part 
  ├─rootvg-rootlv (dm-0)                 253:0    0    2G  0 lvm  /
  ├─rootvg-paging00 (dm-1)               253:1    0   16G  0 lvm  [SWAP]
  ├─rootvg-auditlv (dm-4)                253:4    0  512M  0 lvm  /audit
  ├─rootvg-homelv (dm-5)                 253:5    0  512M  0 lvm  /home
  ├─rootvg-optlv (dm-6)                  253:6    0    4G  0 lvm  /opt
  ├─rootvg-tmplv (dm-7)                  253:7    0    4G  0 lvm  /tmp
   ...
sdb                                        8:16   0   64G  0 disk 
├─sdb1                                     8:17    0  264M  0 part
└─sdb2                                     8:18    0 63.8G  0 part 

After:

chewbacca:/root # lsblk 
NAME                                     MAJ:MIN RM  SIZE RO TYPE     MOUNTPOINT
sr0                                       11:0    1 1024M  0 rom  
sda                                        8:0    0   64G  0 disk 
├─sda1                                     8:1    0  264M  0 part /boot
└─sda2                                     8:2    0 63.8G  0 part 
  ├─rootvg-rootlv (dm-0)                 253:0    0    2G  0 lvm  /
  ├─rootvg-paging00 (dm-1)               253:1    0   16G  0 lvm  [SWAP]
  ├─rootvg-auditlv (dm-4)                253:4    0  512M  0 lvm  /audit
  ├─rootvg-homelv (dm-5)                 253:5    0  512M  0 lvm  /home
  ├─rootvg-optlv (dm-6)                  253:6    0    4G  0 lvm  /opt
  ├─rootvg-tmplv (dm-7)                  253:7    0    4G  0 lvm  /tmp
   ...
sdb                                        8:16   0   64G  0 disk 
├─sdb1                                     8:1    0  264M  0 part
└─sdb2                                     8:2    0 63.8G  0 part 
  ├─rootvg-rootlv (dm-0)                 253:10   0    2G  0 lvm  /
  ├─rootvg-paging00 (dm-1)               253:11   0   16G  0 lvm  [SWAP]
  ├─rootvg-auditlv (dm-4)                253:14   0  512M  0 lvm  /audit
  ├─rootvg-homelv (dm-5)                 253:15   0  512M  0 lvm  /home
  ├─rootvg-optlv (dm-6)                  253:16   0    4G  0 lvm  /opt
  ├─rootvg-tmplv (dm-7)                  253:17   0    4G  0 lvm  /tmp
   ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.