Page MenuHomePhabricator

Netboot Imaging
Updated 2,145 Days AgoPublic


Please Look at Cloning for single machines and Multicast for cloning a entire lab

Quick Clone

sudo /var/local/ecc/120G/ #Clone resizes the windows partition to TOTAL_SPACE * 0.95.
sudo /var/local/ecc/120G/  #Does not resize partition.

Manual Clone


dd if=/dev/zero of=/dev/sda count=256 bs=1M #Zero out the first 256MiB.
dd if=/var/local/ecc/120G/mbr.bin of=/dev/sda bs=512 count=1 #Copy the MBR, which includes the partition table.
sync #Sync writes

hdparm -z /dev/sda #Notify the kernel of the partition table changes.

dd if=/var/local/ecc/120G/ecc-p1.dd of=/dev/sda1 status=progress bs=1M #Copy the first parition, the windows bootloader

dd if=/var/local/ecc/120G/ecc-p2.dd of=/dev/sda2 status=progress bs=1M #Copy the second partition, the root filesystem

#Calculate the amount of reserved space. TOTAL_SPACE  - (TOTAL_SPACE * 0.5)
FREE_SPACE=`parted /dev/sda unit B print free | grep 'Free Space' | tail -n1 | awk '{print $3}' | sed 's/.$//'`
TOTAL_SPACE=`parted /dev/sda unit B print free | grep 'Free Space' | tail -n1 | awk '{print $2}' | sed 's/.$//'`
RESERVED_SPACE=`awk "BEGIN {printf \"%.0f\n\", $TOTAL_SPACE*0.05}"`

echo "Total Space: ${TOTAL_SPACE}"
echo "Reserved Space: ${RESERVED_SPACE}"

PART_TWO=`awk "BEGIN {printf \"%.0f\n\", $TOTAL_SPACE-$RESERVED_SPACE}"`

echo "Partition size: ${PART_TWO}"

#Resize partition 2
parted -s /dev/sda "resizepart 2 ${PART_TWO}B"

#Resize the filesystem to match the partition.
ntfsresize -ff -v /dev/sda2


#Zero out drive
ansible labd_linux -m shell -u root -a "dd if=/dev/zero of=/dev/sda bs=1M count=1024"

#Copy MBR
ansible labd_linux -m shell -u root -a "dd if=/var/local/ecc/mbr.bin of=/dev/sda bs=512 count=1"

#Sanity Check
ansible labd_linux -m shell -u root -a "fdisk -l /dev/sda"

#Copy partition 1
ansible labd_linux -m shell -u root -a "ntfsclone --restore-image --overwrite /dev/sda1 /var/local/ecc/ecc-p1.img"

#Copy partition 2
ansible labd_linux -m shell -u root -a "ntfsclone --restore-image --overwrite /dev/sda2 /var/local/ecc/ecc-p2.img"
Last Author
Last Edited
Jul 5 2018, 2:41 PM