Skip to content Skip to main navigation Skip to footer

Linux:重走LFS之路:(七) 基础系统编译准备

Linux:重走LFS之路:(七) 基础系统编译准备
Linux:重走LFS之路:(七) 基础系统编译准备

(题图来自: techradar.com)

准备虚拟内核文件系统

建立系统挂载目录

mkdir -pv $LFS/{dev,proc,sys,run}

创建初始设备节点

sudo mknod -m 600 $LFS/dev/console c 5 1
sudo mknod -m 666 $LFS/dev/null c 1 3

挂载并填充设备目录

sudo mount -v –bind /dev $LFS/dev

挂载虚拟内核文件系统

mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run

建立一个符号链接

if [ -h $LFS/dev/shm ]; then
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi

这时候就可以chroot到lfs的工具环境里面来进行基础系统的编译,但是在这之前需要先在$LFS中建立root目录,然后再chroot进去编译。

进入chroot环境

sudo chroot “$LFS” /tools/bin/env -i
HOME=/root
TERM=”$TERM”
PS1=’${debian_chroot:+($debian_chroot)}[33[01;31m][A][33[01;33m]u[33[00m]@[33[01;32m]h:[33[01;34m]w[33[00m]$ ‘
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
/tools/bin/bash –login +h

建立必要目录、符号链接与文件

mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{1..8}
case $(uname -m) in
x86_64) ln -sv lib /lib64
ln -sv lib /usr/lib64
ln -sv lib /usr/local/lib64 ;;
esac
mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}

建立基本文件和符号链接

ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
sed ‘s/tools/usr/’ /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
ln -sv bash /bin/sh
ln -sv /proc/self/mounts /etc/mtab

创建用户存储文件passwd

cat > /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

创建用户组文件group

cat > /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:
systemd-journal:x:23:
input:x:24:
mail:x:34:
nogroup:x:99:
users:x:999:
EOF

这时候可以把用户名位置那讨厌的“I have no name!”去掉了

exec /tools/bin/bash –login +h

用户名成功变身root

再建立一些必要的日志文件,就可以进行系统编译啦

touch /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664 /var/log/lastlog
chmod -v 600 /var/log/btmp

来源:http://www.haopingrui.cn/?p=113

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.