-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy path02-base
executable file
·176 lines (149 loc) · 3.94 KB
/
02-base
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
#!/bin/bash
lfs_dirs() {
mkdir -pv $LFS/dev
mknod -m 600 $LFS/dev/console c 5 1 || true
mknod -m 666 $LFS/dev/null c 1 3 || true
mkdir -pv $LFS/bin $LFS/usr/{lib,bin} $LFS/etc || true
ln -svf /tools/bin/{bash,cat,chmod,dd,echo,ln,mkdir,pwd,rm,stty,touch} $LFS/bin
ln -svf /tools/bin/{env,install,perl,printf} $LFS/usr/bin
ln -svf /tools/lib/libgcc_s.so{,.1} $LFS/usr/lib
ln -svf /tools/lib/libstdc++.{a,so{,.6}} $LFS/usr/lib
ln -svf bash $LFS/bin/sh
ln -svf /proc/self/mounts $LFS/etc/mtab
cat > $LFS/etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
daemon:x:6:6:Daemon User:/dev/null:/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
cat > $LFS/etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
input:x:24:
mail:x:34:
kvm:x:61:
wheel:x:97:
nogroup:x:99:
users:x:999:
EOF
# pkgutils
mkdir -p $LFS/var/lib/pkg/{pkg,src,work}
touch $LFS/var/lib/pkg/db
}
mount_pseudo() {
mkdir -p $LFS/{dev,run,proc,sys}
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
if [ -h $LFS/dev/shm ]; then
mkdir -p $LFS/$(readlink $LFS/dev/shm)
fi
}
umount_pseudo() {
unmount $LFS/dev/pts
unmount $LFS/dev
unmount $LFS/run
unmount $LFS/proc
unmount $LFS/sys
}
mountbind_srcpkg() {
mount --bind $SRCDIR $LFS/var/lib/pkg/src
mount --bind $PKGDIR $LFS/var/lib/pkg/pkg
}
unmountbind_srcpkg() {
unmount $LFS/var/lib/pkg/src
unmount $LFS/var/lib/pkg/pkg
}
unmount() {
while true; do
mountpoint -q $1 || break
umount $1 2>/dev/null
done
}
runinchroot() {
pushd $LFS &>/dev/null
mount_pseudo
mountbind_srcpkg
cp -L /etc/resolv.conf $LFS/etc/
chroot "$LFS" $ENVLFS -i \
HOME=/root \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin $@
retval=$?
unmountbind_srcpkg
umount_pseudo
popd &>/dev/null
return $retval
}
interrupted() {
die "script $(basename $0) aborted!"
}
die() {
[ "$@" ] && printerror $@
unmountbind_srcpkg
umount_pseudo
exit 1
}
printerror() {
echo -e "ERROR: $@"
}
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
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
MAKEFLAGS="${MAKEFLAGS:--j$(nproc)}"
LFS="${LFS:-/mnt/lfs}"
PKGDIR="${PKGDIR:-$CWD/pkg}"
SRCDIR="${SRCDIR:-$CWD/src}"
WORKDIR="${WORKDIR:-/tmp}"
if [ -x $LFS/usr/bin/env ]; then
ENVLFS=/usr/bin/env
else
ENVLFS=/tools/bin/env
fi
PKGS="filesystem linux-api-headers man-pages glibc tzdata zlib bzip2 file readline m4 bc binutils gmp mpfr mpc attr acl shadow gcc
pkg-config ncurses libcap sed psmisc iana-etc bison flex grep bash libtool gdbm gperf expat inetutils
perl perl-xml-parser intltool autoconf automake xz kmod gettext elfutils libffi openssl python3 coreutils
diffutils gawk findutils groff fuse2 grub less gzip iproute2 kbd libpipeline make patch man-db tar texinfo vim procps-ng
util-linux e2fsprogs sysklogd sysvinit eudev lfs-bootscripts linux-firmware libarchive mkinitramfs linux libtasn1 p11-kit ca-certificates
wget pkgutils libnl dbus libxml2 dhcpcd wpa_supplicant lzo lz4 squashfs-tools popt efivar pciutils efibootmgr libpng which freetype2 dosfstools grub-efi
curl ports httpup gpm libevent links mtools syslinux"
if [ ! -f $LFS/var/lib/pkg/db ]; then
lfs_dirs
fi
rm -fr $LFS/usr/ports
mkdir -p $LFS/usr/ports/
echo "==> Copying ports"
cp -Ra ports/* $LFS/usr/ports/
for pkg in $PKGS; do
case $pkg in
filesystem|gcc|bash|perl|coreutils) runinchroot pkgin -i -ic $pkg || die;;
*) runinchroot pkgin -i $pkg || die;;
esac
done
exit 0