-
Notifications
You must be signed in to change notification settings - Fork 5
/
partgen.sh
executable file
·246 lines (231 loc) · 6.59 KB
/
partgen.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
# needed uuencode/decode (sharutils)
#
usage(){
cat <<EOF >&2
partgen.sh -d DISKS [-v yes|no] -l [1|10|none]
-d [DISKS|manual] - the number of disks for the system raid, starting from sda, default: 1
Use "manual" for manual layout.
-v - create /var partition (default are the root and swap partitions only)
-l [LEVEL|none] - create RAID1/5/6/10 with lvm xenvg and xenvg/system-stuff
LEVEL is the number, default: 1.
If DISKS=1 then simple partition will be created instead of RAID.
Use "none" if you wish to create LVM manually later - the "sci-setup xenvg"
will offer you some options for this.
EOF
}
partvar=no
partlvm=yes
disks=1
while getopts "hp:d:v:l:" opt; do
case $opt in
h)
usage
exit 1
;;
d)
disks=$OPTARG
;;
v)
partvar=$OPTARG
;;
l)
partlvm=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument" >&2
usage
exit 1
;;
esac
done
test "$partvar" = "yes" || partvar=""
case $disks in
manual)
cat <<EOF
d-i grub-installer/only_debian boolean true
# Have manual partitioning
EOF
;;
1)
cat <<EOF
d-i grub-installer/only_debian boolean false
d-i grub-installer/with_other_os boolean false
d-i grub-installer/bootdev string /dev/sda
EOF
if [ "$partlvm" = "none" ]; then
partlvm=""
fi
cat <<EOF
d-i partman-auto/method string regular
d-i partman-auto/disk string /dev/sda
d-i partman-auto/expert_recipe string root :: \\
10240 10 10240 ext4 \\
\$lvmignore{ } \\
\$primary{ } \$bootable{ } method{ format } \\
format{ } use_filesystem{ } filesystem{ ext4 } \\
mountpoint{ / } \\
. \\
1024 20 1024 linux-swap \\
\$lvmignore{ } \\
\$primary{ } method{ swap } format{ } \\
EOF
if [ -n "$partvar" ]; then
lvmvol=sda4
cat <<EOF
. \\
10240 20 10240 ext4 \\
\$lvmignore{ } \\
\$primary{ } method{ format } \\
format{ } use_filesystem{ } filesystem{ ext4 } \\
mountpoint{ /var } \\
EOF
else
lvmvol=sda3
fi
cat <<EOF
. \\
500 100 1000000000 lvm \\
\$primary{ } \\
use_filesystem{ } \\
filesystem{ lvm } \\
method{ keep } \\
EOF
cat <<EOF
.
#d-i partman-auto/choose_recipe select root
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/alignment select cylinder
d-i partman/confirm boolean true
EOF
if [ -n "$partlvm" ]; then
cat <<EOF
# was unable to do in-target mount /stuff, so it woll done in postinst.sh
d-i preseed/late_command string vgcreate xenvg /dev/$lvmvol && lvcreate -L 20G -n system-stuff xenvg && mkfs.ext4 /dev/xenvg/system-stuff && echo "/dev/xenvg/system-stuff /stuff ext4 errors=remount-ro 0 0" >>/target/etc/fstab && mkdir /target/stuff
EOF
fi
;;
*)
devices=`echo /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh|cut -d' ' -f-$disks`
grub_devices=`echo '(hd0,0) (hd1,0) (hd2,0) (hd3,0) (hd4,0) (hd5,0) (hd6,0) (hd7,0)'|cut -d' ' -f-$disks`
if [ -z "$devices" ]; then
echo "-d expects the number of disks"
usage
exit 1
fi
cat <<EOF
d-i grub-installer/only_debian boolean false
d-i grub-installer/with_other_os boolean false
d-i grub-installer/bootdev string $devices
EOF
if [ "$partlvm" = "none" ]; then
partlvm=""
elif [ "$partlvm" = "yes" ]; then
partlvm=1
fi
# XXX needs check against no raid on one disk and sufficient disks for raid levels
cat <<EOF
d-i partman-auto/method string raid
# Specify the disks to be partitioned. They will all get the same layout,
# so this will only work if the disks are the same size.
d-i partman-auto/disk string $devices
EOF
if [ -n "$partlvm" ]; then
cat <<EOF
d-i partman-lvm/confirm boolean true
d-i partman-auto-lvm/new_vg_name string xenvg
EOF
fi
cat <<EOF
# Next you need to specify the physical partitions that will be used.
d-i partman-auto/expert_recipe string multiraid :: \\
10240 10 10240 raid \\
\$primary{ } method{ raid } \\
. \\
1024 20 1024 raid \\
\$primary{ } method{ raid } \\
EOF
if [ -n "$partvar" ]; then
cat <<EOF
. \\
10240 20 10240 raid \\
\$primary{ } method{ raid } \\
EOF
fi
# we'll create the restful partition, but will not assemble it to the raid unless LVM is used
cat <<EOF
. \\
500 100 1000000000 raid \\
\$primary{ } method{ raid } \\
EOF
if [ -n "$partlvm" ]; then
cat <<EOF
. \\
20480 20 20480 ext4 \\
\$defaultignore{ } \\
\$lvmok{ } \\
lv_name{ system-stuff } \\
method{ format } \\
format{ } \\
use_filesystem{ } \\
filesystem{ ext4 } \\
mountpoint{ /stuff } \\
. \\
500 100 1000000000 ext4 \\
\$defaultignore{ } \\
\$lvmok{ } \\
lv_name{ removeit } \\
use_filesystem{ } \\
filesystem{ ext4 } \\
method{ keep } \\
EOF
fi
cat <<EOF
.
# Last you need to specify how the previously defined partitions will be
# used in the RAID setup. Remember to use the correct partition numbers
# for logical partitions. RAID levels 0, 1, 5, 6 and 10 are supported;
# devices are separated using "#".
# Parameters are:
# <raidtype> <devcount> <sparecount> <fstype> <mountpoint> \\
# <devices> <sparedevices>
EOF
(echo -n d-i partman-auto-raid/recipe string" "
echo -n 1 $disks 0 ext4 / `echo $devices|awk -vn=1 'BEGIN{OFS="#";ORS=""}{for(i=1; i<=NF; i++){$i=$i n}; print}'`.
echo -n 1 $disks 0 swap - `echo $devices|awk -vn=2 'BEGIN{OFS="#";ORS=""}{for(i=1; i<=NF; i++){$i=$i n}; print}'`.
if [ -n "$partvar" ]; then
echo -n 1 $disks 0 ext4 / `echo $devices|awk -vn=3 'BEGIN{OFS="#";ORS=""}{for(i=1; i<=NF; i++){$i=$i n}; print}'`.
lvmpartno=4
else
lvmpartno=3
fi
if [ -n "$partlvm" ]; then
echo $partlvm $disks 0 lvm / `echo $devices|awk -vn=$lvmpartno 'BEGIN{OFS="#";ORS=""}{for(i=1; i<=NF; i++){$i=$i n}; print}'`.
fi)
cat <<EOF
# For additional information see the file partman-auto-raid-recipe.txt
# included in the 'debian-installer' package or available from D-I source
# repository.
# This makes partman automatically partition without confirmation.
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman/alignment select cylinder
EOF
if [ -n "$partlvm" ]; then
cat <<EOF
d-i preseed/late_command string lvremove -f /dev/xenvg/removeit
EOF
fi
;;
esac