-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustom.sh
executable file
·186 lines (150 loc) · 5.64 KB
/
custom.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
#! /bin/bash
set -x
KERNEL=${1}
if [ -z $KERNEL ]
then
printf "Please specify a kernel package (deb) as the first parameter."
exit
fi
# Set the Ubuntu release here
RELEASE=${2:-kinetic}
WORK_DIR=$HOME/$RELEASE-custom
mkdir $WORK_DIR
# Bootstrap the arm64 port of the requested Ubuntu release
debootstrap \
--arch=arm64 \
--variant=minbase \
$RELEASE \
$WORK_DIR/chroot \
http://ports.ubuntu.com/ubuntu-ports/
mount --bind /dev $WORK_DIR/chroot/dev
mount --bind /run $WORK_DIR/chroot/run
# Copy kernel with support for new hardware
# e.g.
cp $KERNEL $WORK_DIR/chroot/
# copy modules specific to Lenovo ThinkPad X13s
cp $PWD/modules_x13s $WORK_DIR/chroot/
# copy initramfs-tools hook for platform firmware files
cp $PWD/qcom-soc-firmware $WORK_DIR/chroot/
# for Qualcomm based laptops copy debian packages from aarch64-laptops/debian-cdimage repo
cp $PWD/debs/*.deb $WORK_DIR/chroot/
cp $PWD/chroot.sh $WORK_DIR/chroot/
# setup the live environment under chroot
chroot $WORK_DIR/chroot /bin/bash -c "RELEASE=$RELEASE ./chroot.sh"
# unmount dev/run
umount $WORK_DIR/chroot/run
umount $WORK_DIR/chroot/dev
mkdir -p $WORK_DIR/image/{casper,isolinux,install}
# copy kernel from chroot
cp $WORK_DIR/chroot/boot/vmlinuz-* $WORK_DIR/image/casper/vmlinuz
cp $WORK_DIR/chroot/boot/initrd.img-* $WORK_DIR/image/casper/initrd
# copy UEFI shell
mkdir $WORK_DIR/image/tools
cp $PWD/Shell.efi $WORK_DIR/image/tools/
# for Qualcomm based laptops copy DtbLoader as bootaa64.efi
# (this program will chainload the grub binary in the same directory)
cp $PWD/DtbLoader.efi $WORK_DIR/image/isolinux/bootaa64.efi
# copy grub from debian cdimage for Qualcomm laptops
cp -R $PWD/grub-arm64-efi $WORK_DIR/chroot/grub-arm64-efi
touch $WORK_DIR/image/ubuntu
# create grub configuration
cat <<EOF > $WORK_DIR/image/isolinux/grub.cfg
search --set=root --file /ubuntu
insmod all_video
set default="0"
set timeout=30
menuentry "Ubuntu $RELEASE live - Lenovo ThinkPad X13s" {
linux /casper/vmlinuz boot=casper pd_ignore_unused clk_ignore_unused modprobe.blacklist=msm nopersistent toram loglevel=9 ---
initrd /casper/initrd
}
menuentry "UEFI Shell" {
chainloader /tools/Shell.efi
}
EOF
#menuentry "Ubuntu $RELEASE live - Apple MacBook Pro 16-inch M1 Max" {
# devicetree /isolinux/dtb/t6001-j316c.dtb
# linux /casper/vmlinuz boot=casper nopersistent toram loglevel=9 ---
# initrd /casper/initrd
#}
#
#menuentry "Ubuntu $RELEASE live - Apple Mac mini M1" {
# devicetree /isolinux/dtb/t8103-j274.dtb
# linux /casper/vmlinuz boot=casper nopersistent toram loglevel=9 ---
# initrd /casper/initrd
#}
# create package manifest
chroot $WORK_DIR/chroot dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee $WORK_DIR/image/casper/filesystem.manifest
cp -v $WORK_DIR/image/casper/filesystem.manifest $WORK_DIR/image/casper/filesystem.manifest-desktop
sed -i '/ubiquity/d' $WORK_DIR/image/casper/filesystem.manifest-desktop
sed -i '/casper/d' $WORK_DIR/image/casper/filesystem.manifest-desktop
sed -i '/discover/d' $WORK_DIR/image/casper/filesystem.manifest-desktop
sed -i '/laptop-detect/d' $WORK_DIR/image/casper/filesystem.manifest-desktop
sed -i '/os-prober/d' $WORK_DIR/image/casper/filesystem.manifest-desktop
# create live filesystem
mksquashfs $WORK_DIR/chroot $WORK_DIR/image/casper/filesystem.squashfs
printf $(sudo du -sx --block-size=1 $WORK_DIR/chroot | cut -f1) > $WORK_DIR/image/casper/filesystem.size
# create diskdefines
cat <<EOF > $WORK_DIR/image/README.diskdefines
#define DISKNAME Ubuntu arm64 custom
#define TYPE binary
#define TYPEbinary 1
#define ARCH arm64
#define ARCHamd64 1
#define DISKNUM 1
#define DISKNUM1 1
#define TOTALNUM 0
#define TOTALNUM0 1
EOF
# create standalone grub binary
(
cd $WORK_DIR/image/ &&
grub-mkstandalone \
--format=arm64-efi \
--output=isolinux/grubaa64.efi \
--directory=../chroot/grub-arm64-efi \
--locales="" \
--fonts="" \
"boot/grub/grub.cfg=isolinux/grub.cfg"
)
# copy needed device trees installed with kernel
mkdir $WORK_DIR/image/isolinux/dtb
#cp $WORK_DIR/chroot/usr/lib/linux-image-*/apple/*.dtb $WORK_DIR/image/isolinux/dtb
#cp $WORK_DIR/chroot/usr/lib/linux-image-*/apple/*.dtb $WORK_DIR/image/isolinux/dtb
#cp $WORK_DIR/chroot/usr/lib/linux-image-*/apple/*.dtb $WORK_DIR/image/isolinux/dtb
cp $WORK_DIR/chroot/usr/lib/linux-image-*/qcom/sc8280xp-lenovo-thinkpad-x13s.dtb $WORK_DIR/image/isolinux/dtb/f249803d-0d95-54f3-a28f-f26c14a03f3b.dtb
# copy kernel
cp $WORK_DIR/chroot/boot/vmlinuz-* $WORK_DIR/image/casper/vmlinuz
cp $WORK_DIR/chroot/boot/initrd.img-* $WORK_DIR/image/casper/initrd
# create efi system partition
(
cd $WORK_DIR/image/isolinux && \
dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
sudo mkfs.vfat efiboot.img && \
LC_CTYPE=C mmd -i efiboot.img dtb efi efi/boot && \
LC_CTYPE=C mcopy -i efiboot.img ./dtb/f249803d-0d95-54f3-a28f-f26c14a03f3b.dtb ::dtb/ && \
LC_CTYPE=C mcopy -i efiboot.img ./grubaa64.efi ::efi/boot/ && \
LC_CTYPE=C mcopy -i efiboot.img ./bootaa64.efi ::efi/boot/
)
# create md5sum
(
cd $WORK_DIR/image &&
/bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v -e 'md5sum.txt' -e 'efiboot.img' > md5sum.txt)"
)
# create iso image
(
cd $WORK_DIR/image &&
xorriso \
-as mkisofs \
-iso-level 3 \
-full-iso9660-filenames \
-volid "Ubuntu arm64 custom" \
-output "../ubuntu-$RELEASE-arm64-custom.iso" \
-eltorito-alt-boot \
-e EFI/efiboot.img \
-no-emul-boot \
-append_partition 2 0xef isolinux/efiboot.img \
-m "isolinux/efiboot.img" \
-graft-points \
"/EFI/efiboot.img=isolinux/efiboot.img" \
"."
)