-
Notifications
You must be signed in to change notification settings - Fork 44
/
mkboot
executable file
·48 lines (42 loc) · 1.44 KB
/
mkboot
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
#!/usr/bin/env bash
# $1=model $2=version
MODEL="$1"
VER="$2"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT=$(dirname ${SCRIPT_DIR})
MV=${MODEL}_${VER}
WORKDIR=$ROOT/$MV
PAT=$ROOT/pat/$MV
fallocate -l 50M $WORKDIR/synoboot.img
sgdisk -o -n 0:0:+15M -t 1:EF00 -n 0:0:+30M -n 0:0: -t 3:EF02 -c 1:boot -c 2:image -c 3:legacy $WORKDIR/synoboot.img
kpartx -as $WORKDIR/synoboot.img
loopdev=`sudo kpartx -l $WORKDIR/synoboot.img | tr ' ' '\n' | fgrep -m1 /dev/loop `
parts=`kpartx -l $WORKDIR/synoboot.img |cut -d: -f1`
for part in $parts;do
mkfs.vfat "/dev/mapper/$part"
done
part1=`echo $parts | cut -d\ -f1`
part2=`echo $parts | cut -d\ -f2`
mkdir $WORKDIR/bl
mount -o noexec,nosuid,nodev "/dev/mapper/$part1" $WORKDIR/bl
grub-install --target=x86_64-efi --efi-directory=$WORKDIR/bl --removable --no-nvram -s --no-bootsector --boot-directory=$WORKDIR/bl
grub-install --target=i386-pc -s --boot-directory=$WORKDIR/bl $loopdev
cp $WORKDIR/grub.cfg $WORKDIR/bl/grub/
umount $WORKDIR/bl
rm -rf $WORKDIR/bl
mkdir $WORKDIR/img
mount -o noexec,nosuid,nodev "/dev/mapper/$part2" $WORKDIR/img
cp $PAT/rd.gz $WORKDIR/img/rd.gz
if [ -f $WORKDIR/bzImage ]; then
cp $WORKDIR/bzImage $WORKDIR/img/
fi
cp $PAT/zImage $WORKDIR/img/
if [ -f $WORKDIR/jun.lzma ]; then
cp $WORKDIR/jun.lzma $WORKDIR/img/extra.lzma
fi
if [ -f $WORKDIR/info.txt ]; then
cp $WORKDIR/info.txt $WORKDIR/img/
fi
umount $WORKDIR/img
rm -rf $WORKDIR/img
kpartx -d $WORKDIR/synoboot.img