Ubuntu Pastebin

Paste from root at Tue, 21 Apr 2015 07:19:38 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

ls -al /dev/disk/by-id

read -p "Enter the destination drive to clone to (e.g. sdc): "
echo # Just to move to a new line


orig="/dev/sda"
dest="/dev/${REPLY}"




read -p "Clone system from ${orig} to ${dest}. Press Y to continue: "
echo # Just to move to a new line
if [[ ! "${REPLY}" =~ ^[Yy]$ ]]
then
    exit 1
fi




read -p "Copy partition layout from ${orig} to ${dest} (Y/N)? "
echo "When using an already partitioned drive, press 'N'"
echo # Just to move to a new line
if [[ ! "${REPLY}" =~ ^[Nn]$ ]]
then
    # Make partition layout
    sfdisk -d "${orig}" > "/tmp/part_table"
    sfdisk "${dest}" < "/tmp/part_table"
fi




# Grow, Clone, Shrink RAID devices
declare -A raidInfo
raidInfo[0]="1"
raidInfo[1]="2"




for i in "${!raidInfo[@]}"
do
    echo "mdadm --grow --force '/dev/md${i}' --raid-devices=2"
    mdadm --grow --force "/dev/md${i}" --raid-devices=2
    sleep 10
    echo "mdadm --zero-superblock '${dest}${raidInfo[$i]}'"
    mdadm --zero-superblock "${dest}${raidInfo[$i]}"
    sleep 10
    echo "mdadm --manage '/dev/md${i}' --add --write-mostly '${dest}${raidInfo[$i]}'"
    mdadm --manage "/dev/md${i}" --add --write-mostly "${dest}${raidInfo[$i]}"
    sleep 10
    echo "mdadm --wait '/dev/md${i}'"
    mdadm --wait "/dev/md${i}"
    sleep 10
    sync
done




sleep 10
sync
sleep 10
# Install GRUB to dest
grub-install "${dest}"
sleep 10




for i in "${!raidInfo[@]}"
do
    echo "mdadm '/dev/md${i}' --fail '${dest}${raidInfo[$i]}'"
    mdadm "/dev/md${i}" --fail "${dest}${raidInfo[$i]}"
    sleep 10
    echo "mdadm '/dev/md${i}' --remove '${dest}${raidInfo[$i]}'"
    mdadm "/dev/md${i}" --remove "${dest}${raidInfo[$i]}"
    sleep 10
    echo "mdadm --grow --force '/dev/md${i}' --raid-devices=1"
    mdadm --grow --force "/dev/md${i}" --raid-devices=1
    sleep 10
    echo ""
    echo "Finshed syncing /dev/md${i}"
    echo ""
    echo ""
    echo ""
done
Download as text