lfs(systemd版本)學習筆記-第3頁 的地址:http://www.javashuo.com/article/p-slhiylnx-g.htmlhtml
網絡配置node
1.網絡設備命名linux
cat > /etc/systemd/network/10-ether0.link << "EOF" [Match] # Change the MAC address as appropriate for your network device MACAddress=12:34:45:78:90:AB(更改成網卡的mac號,在主機使用ifconfig查看) [Link] Name=ether0(更改成網卡的名字,在主機使用ifconfig查看) EOF
2.靜態ip配置shell
cat > /etc/systemd/network/10-eth-static.network << "EOF" [Match] Name=<network-device-name> [Network] Address=192.168.0.2/24 Gateway=192.168.0.1 DNS=192.168.0.1(使用靜態/etc/resolv.conf文件,這個選項能夠去掉) Domains=<Your Domain Name> EOF
3.dhcp配置windows
cat > /etc/systemd/network/10-eth-dhcp.network << "EOF" [Match] Name=<network-device-name> [Network] DHCP=ipv4 [DHCP] UseDomains=true EOF
4.systemd-resolved配置bash
ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf
5.靜態resolv.conf配置網絡
cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf domain <Your Domain Name> nameserver 8.8.8.8 nameserver 8.8.4.4 # End /etc/resolv.conf EOF
6.配置主機名字app
echo "<lfs>" > /etc/hostname <lfs>更換爲主機名字
7.建立/etc/hosts文件dom
(1)使用dhcp自動分配ide
cat > /etc/hosts << "EOF"
# Begin /etc/hosts 127.0.0.1 localhost 127.0.1.1 <FQDN> <HOSTNAME> <192.168.1.1> <FQDN> <HOSTNAME> [alias1] [alias2 ...] ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters # End /etc/hosts EOF
(2)使用靜態地址
cat > /etc/hosts << "EOF" # Begin /etc/hosts 127.0.0.1 localhost 127.0.1.1 <FQDN> <HOSTNAME> <192.168.0.2> <FQDN> <HOSTNAME> [alias1] [alias2] ... ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters # End /etc/hosts EOF
若是電腦上面是多系統,而且有windows系統,就不要使用系統硬件時間做爲系統時間(會有時差)。若是沒有windows系統不須要更改。具體內容參見:個人linux時間綜述筆記地址:http://www.javashuo.com/article/p-toedddtb-en.html
硬件時間設置爲本地時間
cat > /etc/adjtime << "EOF" 0.0 0 0.0 0 LOCAL EOF
配置語言環境
運行如下命令獲取Glibc支持的全部語言環境的列表:
locale -a
結果:
C en_US.utf8 POSIX zh_CN.utf8
這裏咱們選擇en_US.utf8
如下是對對所選擇的語言的測試
LC_ALL=<locale name> locale charmap LC_ALL=<locale name> locale language LC_ALL=<locale name> locale charmap LC_ALL=<locale name> locale int_curr_symbol LC_ALL=<locale name> locale int_prefix
肯定正確的區域設置後,建立 /etc/profile
文件:
cat > /etc/locale.conf << "EOF" LANG=en_US.utf8 EOF
1.建立/etc/inputrc配置文件
cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc # Modified by Chris Lynn <roryo@roryo.dynup.net> # Allow the command prompt to wrap to the next line set horizontal-scroll-mode Off # Enable 8bit input set meta-flag On set input-meta On # Turns off 8th bit stripping set convert-meta Off # Keep the 8th bit for display set output-meta On # none, visible or audible set bell-style none # All of the following map the escape sequence of the value # contained in the 1st argument to the readline specific functions "\eOd": backward-word "\eOc": forward-word # for linux console "\e[1~": beginning-of-line "\e[4~": end-of-line "\e[5~": beginning-of-history "\e[6~": end-of-history "\e[3~": delete-char "\e[2~": quoted-insert # for xterm "\eOH": beginning-of-line "\eOF": end-of-line # for Konsole "\e[H": beginning-of-line "\e[F": end-of-line # End /etc/inputrc EOF
1.建立/etc/shells文件
cat > /etc/shells << "EOF"
# Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF
1.引導時禁用屏幕清除
mkdir -pv /etc/systemd/system/getty@tty1.service.d cat > /etc/systemd/system/getty@tty1.service.d/noclear.conf << EOF [Service] TTYVTDisallocate=no EOF
2.禁用/ tmp的tmpfs
ln -sfv /dev/null /etc/systemd/system/tmp.mount
1.更改成lfs所建立的分區到相應位置便可(這個文件是配置lfs開機自動掛載的分區)
cat > /etc/fstab << "EOF" EOF# Begin /etc/fstab # file system mount-point type options dump fsck # order /dev/<xxx>
/<fff>
defaults 1 1 /dev/<yyy>
swap swap pri=1 0 0 # End /etc/fstab<xxx><fff><yyy>
配置編譯安裝linux內核
1.首先進入sources目錄
cd /sources
2.解壓內核文件壓縮包
tar -xvf linux-4.20.12.tar.xz
3.進入內核包目錄
cd linux-4.20.12
4.準備編譯
make mrproper
5.設置默認內核配置狀態
make defconfig
6.設置內核也能夠經過修改.config文件來進行設置
make menuconfig
7.設置書中提供的如下選項
General setup --> [ ] Enable deprecated sysfs features to support old userspace tools [CONFIG_SYSFS_DEPRECATED] [ ] Enable deprecated sysfs features by default [CONFIG_SYSFS_DEPRECATED_V2] [*] open by fhandle syscalls [CONFIG_FHANDLE] [ ] Auditing support [CONFIG_AUDIT] [*] Control Group support [CONFIG_CGROUPS] Processor type and features ---> [*] Enable seccomp to safely compute untrusted bytecode [CONFIG_SECCOMP] Networking support ---> Networking options ---> <*> The IPv6 protocol [CONFIG_IPV6] Device Drivers ---> Generic Driver Options ---> [ ] Support for uevent helper [CONFIG_UEVENT_HELPER] [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS] [ ] Fallback user-helper invocation for firmware loading [CONFIG_FW_LOADER_USER_HELPER] Firmware Drivers ---> [*] Export DMI identification via sysfs to userspace [CONFIG_DMIID] File systems ---> [*] Inotify support for userspace [CONFIG_INOTIFY_USER] <*> Kernel automounter version 4 support (also supports v3) [CONFIG_AUTOFS4_FS] Pseudo filesystems ---> [*] Tmpfs POSIX Access Control Lists [CONFIG_TMPFS_POSIX_ACL] [*] Tmpfs extended attributes [CONFIG_TMPFS_XATTR] Kernel hacking ---> Choose kernel unwinder (Frame pointer unwinder) ---> [CONFIG_UNWINDER_FRAME_POINTER]
8.若是您的主機硬件使用UEFI,請自行添加此項設置
Processor type and features ---> [*] EFI stub support [CONFIG_EFI_STUB]
9.設置調整完保存退出便可
10.編譯內核映像和模塊
make -j8
11.安裝配置模塊
make modules_install
12.複製一些內核的啓動文件到boot分區
cp -iv arch/x86/boot/bzImage /boot/vmlinuz-4.20.12-lfs-8.4-systemd cp -iv System.map /boot/System.map-4.20.12 cp -iv .config /boot/config-4.20.12
13.安裝Linux內核的文檔:
install -d /usr/share/doc/linux-4.20.12 cp -r Documentation/* /usr/share/doc/linux-4.20.12
14.配置linux模塊加載順序
install -v -m755 -d /etc/modprobe.d cat > /etc/modprobe.d/usb.conf << "EOF" # Begin /etc/modprobe.d/usb.conf install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true # End /etc/modprobe.d/usb.conf EOF
15.返回sources目錄並刪除包目錄
cd $LFS/sources
rm -rf linux-4.20.12
安裝配置grub引導
1.安裝grub引導到MBR
grub-install /dev/sda
2.建立grub配置文件
cat > /boot/grub/grub.cfg << "EOF" # Begin /boot/grub/grub.cfg set default=0 set timeout=5 insmod ext2 set root=(hd0,2) 括號裏面更改成你所安裝lfs的分區或boot分區 例如/dev/sda2爲(hd0,2) menuentry "GNU/Linux, Linux 4.18.5-lfs-8.3" { linux /boot/vmlinuz-4.18.5-lfs-8.3 root=/dev/sda2 ro(這裏的/dev/sda2更改成你所安裝lfs的分區號 例如/dev/sda2) } (若是boot單獨分區,則把這裏的/boot刪除。)
EOF
多系統引導文件示例:
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg set default=0 set timeout=5 menuentry "GNU/Linux, Linux 4.18.5-lfs-8.3" { insmod ext2 set root=(hd0,5) linux /vmlinuz-4.18.5-lfs-8.3 root=/dev/sda6 ro } menuentry 'Manjaro Linux'{ insmod ext2 set root='hd0,msdos9' linux /vmlinuz-4.19-x86_64 root=/dev/sda10 ro initrd /intel-ucode.img /initramfs-4.19-x86_64.img } menuentry 'Windows 7 (on /dev/sda1)'{ insmod ntfs set root='hd0,msdos1' chainloader +1 } EOF
設置系統版本及版本號
cat > /etc/os-release << "EOF" NAME="Linux From Scratch" VERSION="8.4-systemd" ID=lfs PRETTY_NAME="Linux From Scratch 8.4-systemd" VERSION_CODENAME="<your name here>"(括號裏改成本身起的名字) EOF echo 8.3-systemd > /etc/lfs-release cat > /etc/lsb-release << "EOF" DISTRIB_ID="Linux From Scratch" DISTRIB_RELEASE="8.4-systemd" DISTRIB_CODENAME="<your name here>"(括號裏改成本身起的名字) DISTRIB_DESCRIPTION="Linux From Scratch" EOF
運行下面的命令,退出chroot,卸載lfs的分區
exit umount -v $LFS/dev/pts umount -v $LFS/dev umount -v $LFS/run umount -v $LFS/proc umount -v $LFS/sys umount -v $LFS umount -v $LFS/usr umount -v $LFS/home umount -v $LFS
重啓進入lfs系統
reboot
若是須要本機的grub引導lfs則在root用戶下運行如下命令建立lfs的引導項
須要安裝os-prober軟件包,並掛載lfs的分區,在運行下面命令,添加lfs的啓動項
grub-mkconfig -o /boot/grub/grub.cfg
肯定添加完lfs引導項後,重啓機器進入lfs選項,便可進入lfs操做系統。