-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_qnap_boot
179 lines (158 loc) · 5.65 KB
/
create_qnap_boot
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
#!/bin/sh
# This is developed by laojifuli to create QNAP boot disk
# This script was modified by Mojelly for QNAP 4.4.1.1000+ firmware.
# Define the model type and firmware by get patch name or hardcode
# I recommend to use the patch name, make sure you do correct patch
MODEL_TYPE="QY410_QY450_10_10"
PATCHED_FIRMWARE="TS-X82S_20191206-4.4.1.1146"
#PATCHED_FIRMWARE=$(ls *.patch | head -n1 | cut -d'.' -f1-4)
DOWNLOAD_URL="https://download.qnap.com.cn/Storage/TS-X82S/"
extract_initrd()
{
rm -f ./initrd.boot
rm -rf ./initrd
cp -f $1 ./
[ -f ./initrd.boot ] || return 1
if [ "$2" = "lzma" ]; then
mv ./initrd.boot ./initrd.boot.lzma
unlzma ./initrd.boot.lzma
else
mv ./initrd.boot ./initrd.boot.gz
gzip -d ./initrd.boot.gz
fi
if [ $? != 0 ]; then
echo "Decompress the ram disk failed."
rm -f ./initrd.boot.*
return 1
fi
[ -d ./initrd ] || mkdir ./initrd
cd ./initrd
cpio -id < ../initrd.boot 1>/dev/null 2>&1
cd ${WORKING_DIR}
rm -f ./initrd.boot
[ ! -f ./initrd/etc/model_${MODEL_TYPE}.conf ] || return 0
return 1
}
packing_initrd()
{
rm -f ./initrd.boot
cd ./initrd
find . | cpio -o -H newc | gzip > ../initrd.boot
}
repair_rootfs2()
{
echo $1
REPAIR_DIR=/home/tc/ROOTFS2
if [ -f /mnt/${BOOT_DRIVES}2/boot/rootfs2.bz ]; then
mkdir -p ${REPAIR_DIR}
cp /mnt/${BOOT_DRIVES}2/boot/rootfs2.bz ${REPAIR_DIR}/rootfs2.lzma
cd ${REPAIR_DIR}
unlzma rootfs2.lzma
bzip2 -z rootfs2
mv rootfs2.bz2 rootfs2.bz
cksum rootfs2.bz > rootfs2.bz.cksum
rm -f /mnt/${BOOT_DRIVES}2/boot/rootfs2.bz
rm -f /mnt/${BOOT_DRIVES}2/boot/rootfs2.bz.cksum
cp -f * /mnt/${BOOT_DRIVES}2/boot/
rm -rf ${REPAIR_DIR}
else
error_stop "Repair failed, please restart the system and try again."
fi
}
clear_boot()
{
echo $1
rm -rf /mnt/${BOOT_DRIVES}2/*
rm -rf /mnt/${BOOT_DRIVES}3/*
}
error_stop()
{
echo $1
umount /dev/${BOOT_DRIVES}2 1>/dev/null 2>&1
umount /dev/${BOOT_DRIVES}3 1>/dev/null 2>&1
exit 1
}
# Try to locate laojifuli boot disk
BOOT_DRIVES=$(./hal_app2)
WORKING_DIR=$(pwd)
IS_PATCHED="true"
if [ "x$BOOT_DRIVES" = "x" ]; then
echo "Could not found laojifuli's QNAP boot disk."
exit 1
fi
# mount the QNAP master boot partion and clear boot
[ -d /mnt/${BOOT_DRIVES}2 ] || mkdir /mnt/${BOOT_DRIVES}2
mount -t ext2 /dev/${BOOT_DRIVES}2 /mnt/${BOOT_DRIVES}2 1>/dev/null 2>&1
[ $? = 0 ] || error_stop "Try to mount /dev/${BOOT_DRIVES}2 failed."
[ -d /mnt/${BOOT_DRIVES}3 ] || mkdir /mnt/${BOOT_DRIVES}3
mount -t ext2 /dev/${BOOT_DRIVES}3 /mnt/${BOOT_DRIVES}3 1>/dev/null 2>&1
[ $? = 0 ] || error_stop "Try to mount /dev/${BOOT_DRIVES}3 failed."
clear_boot "Clear the boot, Please wait a while." #如果不需要清空boot目录,则将此行开头添加#注释掉。
# check if the boot partion already created, if not we will download
# the QNAP firmware which is defined by ${PATCHED_FIRMWARE}
# You can do the QNAP firmware patch choose which one you like and patch it by yourself
if [ -f /mnt/${BOOT_DRIVES}2/boot/initrd.boot ]; then
extract_initrd "/mnt/${BOOT_DRIVES}2/boot/initrd.boot"
if [ $? != 0 ]; then
rm -f ./${PATCHED_FIRMWARE}.zip
echo "Start to download the QNAP firmware. Please wait a while."
wget ${DOWNLOAD_URL}${PATCHED_FIRMWARE}.zip
[ $? = 0 ] || error_stop "Download the QNAP firmware failed."
fi
else
if [ ! -f ./${PATCHED_FIRMWARE}.zip ]; then
echo "Start to download the QNAP firmware. Please wait a while."
wget ${DOWNLOAD_URL}${PATCHED_FIRMWARE}.zip
[ $? = 0 ] || error_stop "Download the QNAP firmware failed."
fi
fi
if [ -f ./${PATCHED_FIRMWARE}.zip ]; then
IS_PATCHED="false"
rm -f ./initrd.boot
rm -rf ./initrd
unzip ./${PATCHED_FIRMWARE}.zip
rm -f ./${PATCHED_FIRMWARE}.zip
./pc1 d QNAPNASVERSION4 ./${PATCHED_FIRMWARE}.img ./decoded_firmware.tar.gz
[ $? = 0 ] || error_stop "Unable to decoded QNAP firmware."
rm -f ./${PATCHED_FIRMWARE}.img
tar -xvf decoded_firmware.tar.gz bzImage bzImage.cksum initrd.boot initrd.boot.cksum qpkg.tar qpkg.tar.cksum rootfs2.bz rootfs2.bz.cksum rootfs_ext.tgz rootfs_ext.tgz.cksum
rm -f decoded_firmware.tar.gz
[ -d /mnt/${BOOT_DRIVES}2/boot ] || mkdir -p /mnt/${BOOT_DRIVES}2/boot
mv -f bzImage bzImage.cksum initrd.boot initrd.boot.cksum qpkg.tar qpkg.tar.cksum rootfs2.bz rootfs2.bz.cksum rootfs_ext.tgz rootfs_ext.tgz.cksum /mnt/${BOOT_DRIVES}2/boot/
extract_initrd "/mnt/${BOOT_DRIVES}2/boot/initrd.boot" "lzma"
fi
[ -d ./initrd ] || error_stop "Unable to establish the QNAP RAM disk."
# patch the QNAP system
if [ ${IS_PATCHED} != "true" ]; then
rm -f ./initrd.boot
cp -f ./hal_app1 ./initrd/sbin/hal_app1
cp -f ./hal_app2 ./initrd/sbin/hal_app2
cd ./initrd/bin
ln -s busybox tail
cd ../etc
cp -f ./model_${MODEL_TYPE}.conf ./model.conf
[ $? = 0 ] || error_stop "Create model.conf failed."
cp -f ./hal_util_${MODEL_TYPE}.conf ./hal_util.conf
[ $? = 0 ] || error_stop "Create hal_tuil.conf failed."
cd init.d
patch -p1 < ../../../${PATCHED_FIRMWARE}.patch
[ $? = 0 ] || error_stop "Make patch failed."
fi
cd ${WORKING_DIR}
./hardware_check
echo "Re-packing the QNAP RAM disk. Please wait a while."
packing_initrd
cd ${WORKING_DIR}
if [ ! -f ./initrd.boot ]; then
error_stop "Re-packing the QNAP RAM disk failed."
fi
cksum initrd.boot > initrd.boot.cksum
mv -f ./initrd.boot /mnt/${BOOT_DRIVES}2/boot/
[ $? = 0 ] || error_stop "Transfor QNAP RAM disk failed."
mv -f ./initrd.boot.cksum /mnt/${BOOT_DRIVES}2/boot/
repair_rootfs2 "Repair the rootfs2.bz file. Please wait a while." #低于1000+版本的固件无需修复roofs2.bz文件,可以在此行开头添加#注释掉。
umount /dev/${BOOT_DRIVES}2 1>/dev/null 2>&1
umount /dev/${BOOT_DRIVES}3 1>/dev/null 2>&1
echo "Create QNAP boot disk successful."
echo "Now you can enter command ‘sudo reboot’, restart system to install QNAP."
echo