Report abuse

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
In preseed:

d-i preseed/early_command string wget http://URL/autopart -P /tmp ; chmod 755 /tmp/autopart ; echo /tmp/autopart installer >> /var/lib/dpkg/info/download-installer.postinst


Contents of URL/autopart:

#!/bin/sh
#
# Manually create LVM configuration
#
# Partman does not currently support multi-disk lvm
#
# Designed to be run after download-installer but before partman-base
# This allows us to modify partman-base.postinst after it's been dropped
# in by anna
#
# Partman appears to be entirely an external program, removing the call
# to partman from partman-base.postinst prevents it from running.

# -x is useful for debugging
set -ex

# doesn't work
# exec 2>&1 | logger -t autopart

case "$1" in
    installer)
	# We should have d-i downloaded by now.  partman comes in a udeb
	# from the network so we have to hook here and replace the
	# partman-base.postinst file

	anna-install lvm2-udeb
	sed -i 's/partman/\/tmp\/autopart partman/' \
	    /var/lib/dpkg/info/partman-base.postinst
	logger -t autopart modified partman-base.postinst
	;;

    partman)
	. /usr/share/debconf/confmodule

	# do filesystem stuff: detect our config, fdisk, lvms, mount /target
	logger -t autopart Partition configuration starting
	modprobe dm_mod
	# Did I ask you to activate exising VGs and LVs? No. So fuck off.
	/sbin/vgchange -aln --ignorelockingfailure	
	for vg in $(vgdisplay |grep 'VG Name' |sed 's/.*VG Name *//'); do
	    echo y | vgremove $vg
	done

	size_sda=`sed -n 's/.* \([0-9]*\) sda$/\1/p' /proc/partitions`
	size_sdb=`sed -n 's/.* \([0-9]*\) sdb$/\1/p' /proc/partitions`
	size_hda=`sed -n 's/.* \([0-9]*\) hda$/\1/p' /proc/partitions`
	size_hdb=`sed -n 's/.* \([0-9]*\) hdb$/\1/p' /proc/partitions`

	# If we've got SCSI, it's probably used for booting.
	if [ -n "$size_sda" ]; then
	    boot_device=sda

	    # SCSI needs a delay for LVM to work
	    db_get debian-installer/add-kernel-opts
	    kopt="${RET:+$RET } rootdelay=5"
	    db_set debian-installer/add-kernel-opts "$kopt"
	else
	    boot_device=hda
	fi
	logger -t autopart Boot device is $boot_device

	if [ -n "$size_sda" ]; then
	    devices="${devices:+$devices }sda"
	fi

	if [ -n "$size_sdb" ]; then
	    devices="${devices:+$devices }sdb"
	fi

	if [ -n "$size_hda" ]; then
	    devices="${devices:+$devices }hda"
	fi

	if [ -n "$size_hdb" ]; then
	    devices="${devices:+$devices }hdb"
	fi

	for device in $devices; do
	    # Wipe any existing partition tables.  This action is
	    # COMPLETELY, UNAMBIGUOUSLY DESTRUCTIVE. So DON'T DO IT.
	    logger -t autopart Wiping /dev/$device
	    dd if=/dev/zero of=/dev/$device bs=512 count=1

	    # Create a single partition for lvm.
	    # If device == boot_device, create a partition at the
            # beginning for /boot

            if [ $device = $boot_device ]; then
                cyl=$(sfdisk -g /dev/$device | cut -d\  -f2)
                eval dev_size=\$size_$device
                # (Usually?) KB
                cyl_size=$(($dev_size/$cyl))
                sfdisk="${sfdisk:+$sfdisk },$(((128*1024)/$cyl_size)),L,*"
		pv=/dev/${device}2
	    else
		pv=/dev/${device}1
            fi

	    logger -t autopart Partitioning /dev/$device
            sfdisk="${sfdisk:+$sfdisk },,8e"
            for line in $sfdisk; do
                echo "$line"
            done | sfdisk /dev/$device
	    unset sfdisk

	    logger -t autopart Creating PV $pv
	    pvcreate $pv
	    lvm="${lvm:+$lvm }$pv"
	    dev_count=$((${dev_count:-0}+1))
        done

	logger -t autopart Creating VG
	vgcreate vgsys $lvm

	# Create and activate swap first. One for each PV.
	if [ $dev_count -gt 4 ]; then
	    swapsize=128M
	elif [ $dev_count -gt 2 ]; then
	    swapsize=256M
	else
	    swapsize=512M
	fi
	for device in $lvm; do
	    swap=$((${swap:--1}+1))
	    logger -t autopart Creating swap sw$swap on $device
	    lvcreate -L $swapsize -n sw$swap -C y vgsys $device
	    mkswap /dev/vgsys/sw$swap
	    swapon /dev/vgsys/sw$swap
	done
	unset swap

	# Then create other core filesystems
	logger -t autopart Creating LVs
	lvcreate -L 384M -n root vgsys
	lvcreate -L 256M -n tmp  vgsys
	lvcreate -L 3G   -n usr  vgsys
	lvcreate -L 1.5G -n var  vgsys

	# And format them
	logger -t autopart Formatting
	mke2fs    -L boot /dev/${boot_device}1

	mke2fs -j -L root /dev/vgsys/root
	mke2fs    -L tmp  /dev/vgsys/tmp
	mke2fs -j -L usr  /dev/vgsys/usr
	mke2fs -j -L var  /dev/vgsys/var

	# Create directory structure
	logger -t autopart Mounting
	mkdir -p /target
	mount -t ext3 /dev/vgsys/root /target
	mkdir -p /target/boot
	mount -t ext2 /dev/${boot_device}1 /target/boot
	for mountpoint in tmp usr var; do
	    mkdir -p /target/$mountpoint
	    mount /dev/vgsys/$mountpoint /target/$mountpoint
	done

	db_get debian-installer/add-kernel-opts
	# 'twould be nice to detect exist rootflags and append
	kopt="${RET:+$RET } rootflags=data=journal"
	db_set debian-installer/add-kernel-opts "$kopt"

	# Create fstab
	logger -t autopart Creating fstab
	mkdir -p /target/etc
	(
	    echo \# /etc/fstab: static file system information.
	    echo \#

	    echo
	    echo proc /proc proc defaults 0 0

	    echo
	    for device in $lvm; do	
		swap=$((${swap:--1}+1))
		echo /dev/vgsys/sw$swap none swap sw,pri=0 0 0
	    done
	    unset swap

	    echo
	    echo /dev/vgsys/root / ext3 \
		defaults,noatime,sync,data=journal,errors=remount-ro 0 1
	    echo /dev/${boot_device}1 /boot ext2 \
		defaults,ro,noatime,nodev,nosuid,sync 0 2
	    echo /dev/vgsys/tmp /tmp ext2 \
		defaults,noatime,nodev,nosuid,errors=continue 0 2
	    echo /dev/vgsys/usr /usr ext3 \
		defaults,ro,noatime,nodev,errors=remount-ro 0 2
	    echo /dev/vgsys/var /var ext3 \
		defaults,noatime,nodev,nosuid,errors=remount-ro 0 2
	) > /target/etc/fstab
	    
	;;
    *)

	echo $0: This script is destructive and should only be run as
	echo part of the debian-installer process
	;;
esac