forked from emmett1/lfs-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-mkiso
More file actions
executable file
·160 lines (136 loc) · 4.42 KB
/
03-mkiso
File metadata and controls
executable file
·160 lines (136 loc) · 4.42 KB
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
#!/bin/bash -e
chroot_run() {
mount_pseudofs
cp -L /etc/resolv.conf $LFS/etc/
chroot $LFS $@
retval=$?
umount_pseudofs
return $retval
}
mount_pseudofs() {
mount --bind /dev $LFS/dev
mount -t devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -t proc proc $LFS/proc
mount -t sysfs sysfs $LFS/sys
mount -t tmpfs tmpfs $LFS/run
}
umount_pseudofs() {
unmount $LFS/dev/pts
unmount $LFS/dev
unmount $LFS/run
unmount $LFS/proc
unmount $LFS/sys
}
unmount() {
while true; do
mountpoint -q $1 || break
umount $1 2>/dev/null
done
}
interrupted() {
die "Abort by user."
}
cleanup() {
rm -fr $ISODIR
}
die() {
[ "$@" ] && printerror $@
umount_pseudofs
cleanup
exit 1
}
printstep() {
echo -e "\e[0;36m::\e[0m $*"
}
printerror() {
echo -e "\e[0;31mERROR:\e[0m $*"
}
if [ $(id -u) != 0 ]; then
echo "$0 script need to run as root!"
exit 1
fi
CWD=$PWD
if [ -f $CWD/config ]; then
source $CWD/config
fi
ISODIR="$CWD/iso"
LABEL="LFSLIVECD"
OUTPUT="lfs-livecd-$(date +"%Y%m%d").iso"
FILEDIR="$CWD/files"
LFS="${LFS:-$CWD/lfs-rootfs}"
PKGDIR="${PKGDIR:-$CWD/pkg}"
SRCDIR="${SRCDIR:-$CWD/src}"
WORKDIR="${WORKDIR:-$CWD/work}"
isolinux_files="chain.c32 isolinux.bin ldlinux.c32 libutil.c32 reboot.c32 menu.c32 libcom32.c32 poweroff.c32"
rm -fr $ISODIR
mkdir -p $ISODIR
printstep "Preparing isolinux files..."
mkdir -p $ISODIR/{lfs,isolinux,boot}
for file in $isolinux_files; do
cp $LFS/usr/share/syslinux/$file $ISODIR/isolinux || die "failed copying '$file'"
done
#cp isolinux/splash.png $ISODIR/isolinux
cp $FILEDIR/isolinux.cfg $ISODIR/isolinux
[ -d rootfs ] && cp -Ra rootfs $ISODIR
printstep "Make squash filesystem..."
mksquashfs $LFS $ISODIR/lfs/root.sfs \
-b 1048576 -comp xz -Xdict-size 100% \
-e $LFS/var/lib/pkg/src/* \
-e $LFS/var/lib/pkg/pkg/* \
-e $LFS/var/lib/pkg/work/* \
-e $LFS/tools/ \
-e $LFS/tmp/* 2>/dev/null || die "failed create squashed filesystem"
printstep "Preparing kernel and initramfs..."
cp $LFS/boot/vmlinuz-lfs $ISODIR/boot/vmlinuz || die "failed copying kernel"
cp files/livecd.hook $LFS/etc/mkinitramfs.d
kernver=$(file $LFS/boot/vmlinuz-lfs | cut -d ' ' -f9)
chroot_run mkinitramfs -k $kernver -a livecd -o /boot/initrd-live.img || die "failed create initramfs"
mv $LFS/boot/initrd-live.img $ISODIR/boot/initrd || die "failed copying initrd"
printstep "Setup UEFI mode..."
mkdir -p $ISODIR/boot/grub/{fonts,x86_64-efi}
mkdir -p $ISODIR/EFI/boot
if [ -f $LFS/usr/share/grub/unicode.pf2 ];then
cp $LFS/usr/share/grub/unicode.pf2 $ISODIR/boot/grub/fonts
fi
if [ -f $ISODIR/isolinux/splash.png ]; then
cp $ISODIR/isolinux/splash.png $ISODIR/boot/grub/
fi
echo "set prefix=/boot/grub" > $ISODIR/boot/grub-early.cfg
cp -a $LFS/usr/lib/grub/x86_64-efi/*.{mod,lst} $ISODIR/boot/grub/x86_64-efi || die "Failed copying efi files"
cp $FILEDIR/grub.cfg $ISODIR/boot/grub/
if [ -x /usr/bin/grub-mkimage ]; then
grub-mkimage -c $ISODIR/boot/grub-early.cfg -o $ISODIR/EFI/boot/bootx64.efi -O x86_64-efi -p "" iso9660 normal search search_fs_file linux reboot
elif [ -x /usr/bin/grub2-mkimage ]; then
grub2-mkimage -c $ISODIR/boot/grub-early.cfg -o $ISODIR/EFI/boot/bootx64.efi -p "" -O x86_64-efi part_gpt part_msdos disk fat exfat ext2 ntfs xfs appleldr hfs iso9660 normal search_fs_file configfile linux chain loopback echo efi_gop efi_uga video_bochs video_cirrus file gfxmenu gfxterm gfxterm_background gfxterm_menu halt reboot help jpeg ls png true
#grub2-mkimage -c $ISODIR/boot/grub-early.cfg -o $ISODIR/efi/boot/grubx64.efi -O x86_64-efi -p "" iso9660 normal search search_fs_file linux reboot
else
echo "grub is not founded on system";
exit
fi
modprobe loop
dd if=/dev/zero of=$ISODIR/boot/efiboot.img count=4096
mkdosfs -n LFS-UEFI $ISODIR/boot/efiboot.img || die "Failed mkdosfs"
mkdir -p $ISODIR/boot/efiboot
mount -o loop $ISODIR/boot/efiboot.img $ISODIR/boot/efiboot || die "Failed mount efiboot.img"
mkdir -p $ISODIR/boot/efiboot/EFI/boot
cp $ISODIR/EFI/boot/bootx64.efi $ISODIR/boot/efiboot/EFI/boot
umount $ISODIR/boot/efiboot
rm -fr $ISODIR/boot/efiboot
printstep "Making the iso..."
rm -f $OUTPUT
xorriso -as mkisofs \
-isohybrid-mbr $LFS/usr/share/syslinux/isohdpfx.bin \
-c isolinux/boot.cat \
-b isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e boot/efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-volid $LABEL \
-o $OUTPUT $ISODIR || die "failed create iso"
printstep "Cleaning up..."
cleanup
exit 0