summaryrefslogtreecommitdiff
path: root/examples/hooks/lenny_binary_live-installer-usbfix.sh
blob: ded8b80edcf46c4826ffe1159b42a68bcad8ea26 (plain)
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
#!/bin/sh

echo "BINARY-HOOK: fix install from USB in Lenny."

# This is a *binary-hook* to allow disk installations from USB for
# Debian 5.0.x Lenny. Place this file in config/binary_local-hooks/,
# make it executable and rebuild your live image (binary only).

# This workaround for debian-installer was adapted from Chris Lamb
original patch:
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498143#5

# It works by fooling apt-setup. With an existing /hd-media directory
# apt-setup will not try to umount /cdrom. Enable live installer with
# lh_config:
#
# lh_config --debian-installer "live"
#
# Rebuild your binary image. No options needed on boot.

cat > cdrom-detect.postinst.patch << 'EOF'
@@ -44,6 +44,30 @@ do
 		fi
 	done
 
+	# Try disk partitions masquerading as Debian CDs for Debian Live
+	# "usb-hdd" images. Only vfat and ext are supported.
+	modprobe vfat >/dev/null 2>&1 || true
+	for device in $(list-devices partition); do
+		if mount -t vfat -o ro,exec $device /cdrom ||
+		   mount -t ext2 -o ro,exec $device /cdrom; then
+			log "Pseudo CD-ROM mount succeeded: device=$device"
+
+			# Test whether it's a Debian CD
+			if [ -e /cdrom/.disk/info ]; then
+				mounted=1
+				db_set cdrom-detect/cdrom_device $device
+				# fake hd-media install so that apt-setup doesn't break.
+				mkdir /hd-media
+				break
+			else
+				log "Ignoring pseudo CD-ROM device $device - it is not a Debian CD"
+				umount /cdrom 2>/dev/null || true
+			fi
+		else
+			log "Psuedo CD-ROM mount failed: device=$device"
+		fi
+	done
+
 	if [ "$mounted" = "1" ]; then
 		break
 	fi

EOF

# for the syslinux installer
mkdir usb-install-syslinux
cd usb-install-syslinux
zcat ../binary/install/initrd.gz | cpio -iv
patch ./var/lib/dpkg/info/cdrom-detect.postinst < ../cdrom-detect.postinst.patch
PATCH_ERROR=${?}
if [ "${PATCH_ERROR}" != 0 ]
then
	# if there was an error, say it and undo everything.
	echo "ERROR: error while patching cdrom-detect.postinst."
	cd ..
	rmdir -rf usb-install-syslinux
	exit 0
fi
# rebuild the initrd
find . -print0 | cpio -0 -H newc -ov | gzip -c > ../initrd-new.gz
cd ..
mv initrd-new.gz binary/install/initrd.gz
rm -rf usb-install-syslinux

# for the gtk installer
mkdir usb-install-gtk
cd usb-install-gtk
zcat ../binary/install/gtk/initrd.gz | cpio -iv
patch ./var/lib/dpkg/info/cdrom-detect.postinst < ../cdrom-detect.postinst.patch
PATCH_ERROR=${?}
if [ "${PATCH_ERROR}" != 0 ]
then
	# if there was an error, say it and undo everything
	echo "ERROR: error while patching cdrom-detect.postinst."
	cd ..
	rmdir -rf usb-install-gtk
	exit 0
fi
# rebuild the initrd
find . -print0 | cpio -0 -H newc -ov | gzip -c > ../initrd-new.gz
cd ..
mv initrd-new.gz binary/install/gtk/initrd.gz
rm -rf usb-install-gtk

rm cdrom-detect.postinst.patch