Changeset 8dfb4e04
- Timestamp:
- 03/10/2023 03:04:05 AM (3 months ago)
- Branches:
- xry111/kcfg-revise
- Parents:
- 74d4d5e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chapter10/kernel.xml
r74d4d5e r8dfb4e04 97 97 <ulink url="http://www.kroah.com/lkn/"/> </para> 98 98 99 <caution> 100 <para>A good starting place for setting up the kernel configuration is to 101 run <command>make defconfig</command>. This will set the base 102 configuration to a good state that takes your current system architecture 103 into account.</para> 104 105 <para>Do not disable any option enabled by <command>make 106 defconfig</command> unless the following note explicitly makes it 107 disabled or you really know what you are doing.</para> 108 </caution> 99 <para> 100 Set up a minimal base configuration: 101 </para> 102 103 <screen role="nodump"><userinput>cat > lfs.config << EOF<literal> 104 # Many packages expect SysV IPC or POSIX message queue 105 CONFIG_SYSVIPC=y 106 CONFIG_POSIX_MQUEUE=y 107 108 # Mainstream x86 system contains multiple CPU cores. This is needed to use 109 # all the cores. 110 CONFIG_SMP=y 111 112 # Many packages expect the basic network functionality is available, even 113 # if the system has no NIC at all. 114 CONFIG_NET=y 115 CONFIG_PACKET=y 116 CONFIG_UNIX=y 117 CONFIG_INET=y 118 CONFIG_IPV6=y 119 120 # Mainstream x86 system use PCIe as the system bus for peripherals. 121 CONFIG_PCI=y 122 CONFIG_PCIEPORTBUS=y 123 124 # Enable devtmpfs which is necessary for udev, and mount it at early boot 125 # stage so we don't need to create static device nodes in /dev. 126 CONFIG_DEVTMPFS=y 127 CONFIG_DEVTMPFS_MOUNT=y 128 129 # LFS uses ext4 file system. Don't set it to m or you'll need an initramfs. 130 # Also Enable Access Control List feature needed by the Acl package. 131 CONFIG_EXT4_FS=y 132 CONFIG_EXT4_FS_POSIX_ACL=y 133 134 # Allow to execute ELF executables and scripts. All executables in a LFS 135 # system are either ELF or a script. 136 CONFIG_BINFMT_ELF=y 137 CONFIG_BINFMT_SCRIPT=y 138 139 # Allow to use framebuffer console if your BIOS provides a framebuffer. 140 # Otherwise the VGA console (forced to y with CONFIG_EXPERT=n) can be used 141 # as a fallback. Some of them can be set to m, but doing so may cause debug 142 # difficulties in case the boot fails before loading modules. 143 CONFIG_SYSFB_SIMPLEFB=y 144 CONFIG_FB=y 145 CONFIG_DRM=y 146 CONFIG_DRM_FBDEV_EMULATION=y 147 CONFIG_DRM_SIMPLEDRM=y 148 149 # Enable NVME disk and disk controller support, SATA disk support, and AHCI 150 # SATA controller support. They should be enough for accessing the disk 151 # for a mainstream x86 system. Do not set them to m, or an initramfs will 152 # be needed for boot. 153 CONFIG_BLK_DEV_NVME=y 154 CONFIG_SCSI=y 155 CONFIG_BLK_DEV_SD=y 156 CONFIG_ATA=y 157 CONFIG_SATA_AHCI=y 158 159 # Enable kernel modules. If you think it's not necessary, you can omit it 160 # and change all "m" below to "y". 161 CONFIG_MODULES=y 162 163 # Enable PS/2 and USB keyboards, and the USB controllers on mainstream x86 164 # systems. 165 CONFIG_INPUT_KEYBOARD=y 166 CONFIG_KEYBOARD_ATKBD=m 167 CONFIG_USB_SUPPORT=y 168 CONFIG_USB=m 169 CONFIG_USB_PCI=y 170 CONFIG_USB_HID=m 171 CONFIG_HID_GENERIC=m 172 CONFIG_USB_XHCI_HCD=m 173 CONFIG_USB_EHCI_HCD=m 174 CONFIG_USB_OHCI_HCD=m 175 CONFIG_USB_OHCI_HCD_PCI=m 176 CONFIG_USB_UHCI_HCD=m 177 178 # Enable ASLR and SSP for the kernel. We've already protected the entire 179 # userspace with them (via --enable-default-{pie,ssp} in GCC configuration) 180 # so it does not make too much sense to leave the kernel alone. 181 CONFIG_RELOCATABLE=y 182 CONFIG_RANDOMIZE_BASE=y 183 CONFIG_STACKPROTECTOR=y 184 CONFIG_STACKPROTECTOR_STRONG=y 185 186 # Enable ACPI or the system will not shutdown or reboot correctly. 187 CONFIG_ACPI=y 188 189 # Enable CMOS RTC shipped in mainstream x86 systems, so the system time 190 # will be correct once LFS is boot. 191 CONFIG_RTC_CLASS=y 192 CONFIG_RTC_INTF_DEV=y 193 CONFIG_RTC_DRV_CMOS=y 194 195 # Not strictly needed, but it seems a nice optimization. 196 CONFIG_JUMP_LABEL=y 197 198 </literal>EOF</userinput></screen> 199 200 <para> 201 Now enable some additional settings depending on if you are building 202 a 32-bit or 64-bit system: 203 </para> 204 205 <screen role='nodump'><userinput>if [ $(uname -m) = x86_64 ]; then 206 cat >> lfs.config << EOF<literal> 207 # Enable building a 64-bit kernel. 208 CONFIG_64BIT=y 209 210 # Enable x2apic which is recommended by Intel on supported systems. 211 # It also prevents a kernel panic when the BIOS forcefully enables x2apic. 212 CONFIG_PCI_MSI=y 213 CONFIG_IOMMU_SUPPORT=y 214 CONFIG_IRQ_REMAP=y 215 CONFIG_X86_X2APIC=y 216 217 </literal>EOF 218 else 219 cat >> lfs.config << EOF<literal> 220 # Enable using more than 4GB memory because mainstream x86 systems often 221 # contains more. 222 CONFIG_HIGHMEM64G=y 223 224 # Enable the system calls with 32-bit time_t. This is necessary until the 225 # year 2037 problem solved in all packages. 226 CONFIG_COMPAT_32BIT_TIME=y 227 228 </literal>EOF 229 fi</userinput></screen> 230 231 <para revision='systemd'> 232 Enable some features needed by Systemd: 233 </para> 234 235 <screen role="nodump" revision="systemd"><userinput>cat >> lfs.config <<EOF<literal> 236 CONFIG_PSI=y 237 CONFIG_CGROUPS=y 238 CONFIG_MEMCG=y 239 CONFIG_SECCOMP=y 240 CONFIG_NETDEVICES=y 241 CONFIG_DMIID=y 242 CONFIG_INOTIFY_USER=y 243 CONFIG_AUTOFS_FS=m 244 CONFIG_TMPFS=y 245 CONFIG_TMPFS_POSIX_ACL=y 246 247 </literal>EOF</userinput></screen> 248 249 <para> 250 Now create the <filename>.config</filename> file with our settings 251 in <filename>lfs.config</filename>, but other options disabled: 252 </para> 253 254 <screen role="nodump"><userinput>KCONFIG_ALLCONFIG=lfs.config make allnoconfig</userinput></screen> 255 256 <para> 257 Check if our settings are set correctly: 258 </para> 259 260 <screen role="nodump"><userinput>for i in $(sed '/^#/d' lfs.config); do 261 grep $i .config -q || echo "$i is not set correctly" 262 done</userinput></screen> 263 264 <para> 265 Enable mitigations against hardware vulnerabilities in mainstream x86 266 systems. Even if you want to disable them (only do so if you know 267 what you are doing), it would be better to use 268 <option>mitigations=off</option> in the kernel command line instead of 269 disabling them at build time: 270 </para> 271 272 <screen role="nodump"><userinput>echo "CONFIG_SPECULATION_MITIGATIONS=y" >> .config 273 make olddefconfig</userinput></screen> 109 274 110 275 <note> 111 <para>Be sure to enable/disable/set the following features or the system might 112 not work correctly or boot at all:</para> 113 114 <screen role="nodump" revision="sysv">Processor type and features ---> 115 [*] Build a relocatable kernel [CONFIG_RELOCATABLE] 116 [*] Randomize the address of the kernel image (KASLR) [CONFIG_RANDOMIZE_BASE] 117 General setup ---> 118 [ ] Compile the kernel with warnings as errors [CONFIG_WERROR] 119 < > Enable kernel headers through /sys/kernel/kheaders.tar.xz [CONFIG_IKHEADERS] 120 [ ] Configure standard kernel features (expert users) [CONFIG_EXPERT] 121 General architecture-dependent options ---> 122 [*] Stack Protector buffer overflow detection [CONFIG_STACKPROTECTOR] 123 [*] Strong Stack Protector [CONFIG_STACKPROTECTOR_STRONG] 124 Device Drivers ---> 125 Graphics support ---> 126 Frame buffer Devices ---> 127 <*> Support for frame buffer devices ---> 128 Console display driver support ---> 129 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE] 130 Generic Driver Options ---> 131 [ ] Support for uevent helper [CONFIG_UEVENT_HELPER] 132 [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS] 133 [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs [CONFIG_DEVTMPFS_MOUNT]</screen> 134 135 <screen role="nodump" revision="systemd">Processor type and features ---> 136 [*] Build a relocatable kernel [CONFIG_RELOCATABLE] 137 [*] Randomize the address of the kernel image (KASLR) [CONFIG_RANDOMIZE_BASE] 138 General setup ---> 139 [ ] Compile the kernel with warnings as errors [CONFIG_WERROR] 140 [ ] Auditing Support [CONFIG_AUDIT] 141 CPU/Task time and stats accounting ---> 142 [*] Pressure stall information tracking [CONFIG_PSI] 143 < > Enable kernel headers through /sys/kernel/kheaders.tar.xz [CONFIG_IKHEADERS] 144 [*] Control Group support [CONFIG_CGROUPS] ---> 145 [*] Memory controller [CONFIG_MEMCG] 146 [ ] Enable deprecated sysfs features to support old userspace tools [CONFIG_SYSFS_DEPRECATED] 147 [ ] Configure standard kernel features (expert users) [CONFIG_EXPERT] 148 General architecture-dependent options ---> 149 [*] Enable seccomp to safely compute untrusted bytecode [CONFIG_SECCOMP] 150 [*] Stack Protector buffer overflow detection [CONFIG_STACKPROTECTOR] 151 [*] Strong Stack Protector [CONFIG_STACKPROTECTOR_STRONG] 152 Networking support ---> 153 Networking options ---> 154 <*> The IPv6 protocol [CONFIG_IPV6] 155 Device Drivers ---> 156 Generic Driver Options ---> 157 [ ] Support for uevent helper [CONFIG_UEVENT_HELPER] 158 [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS] 159 [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs [CONFIG_DEVTMPFS_MOUNT] 160 Firmware Loader ---> 161 [ ] Enable the firmware sysfs fallback mechanism [CONFIG_FW_LOADER_USER_HELPER] 162 Firmware Drivers ---> 163 [*] Export DMI identification via sysfs to userspace [CONFIG_DMIID] 164 Graphics support ---> 165 Frame buffer Devices ---> 166 <*> Support for frame buffer devices ---> 167 Console display driver support ---> 168 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE] 169 File systems ---> 170 [*] Inotify support for userspace [CONFIG_INOTIFY_USER] 171 Pseudo filesystems ---> 172 [*] Tmpfs POSIX Access Control Lists [CONFIG_TMPFS_POSIX_ACL]</screen> 173 174 <para>Enable some additional features if you are building a 64-bit 175 system. If you are using menuconfig, enable them in the order of 176 <parameter>CONFIG_PCI_MSI</parameter> first, then 177 <parameter>CONFIG_IRQ_REMAP</parameter>, at last 178 <parameter>CONFIG_X86_X2APIC</parameter> because an option only 179 shows up after its dependencies are selected.</para> 180 181 <screen role="nodump">Processor type and features ---> 182 [*] Support x2apic [CONFIG_X86_X2APIC] 183 Device Drivers ---> 184 [*] PCI Support ---> [CONFIG_PCI] 185 [*] Message Signaled Interrupts (MSI and MSI-X) [CONFIG_PCI_MSI] 186 [*] IOMMU Hardware Support ---> [CONFIG_IOMMU_SUPPORT] 187 [*] Support for Interrupt Remapping [CONFIG_IRQ_REMAP]</screen> 276 <para> 277 In the instructions above, a <quote>mainstream x86 system</quote> 278 means a x86 system manufactured in 2010 or more recent. All these 279 systems should have 64-bit capability (though still compatible with 280 32-bit distros). 281 </para> 282 283 <para> 284 If your system is older, it may contain a non-AHCI ATA controller. 285 Then you need to set <option>CONFIG_ATA_SFF=y</option>, 286 <option>CONFIG_ATA_BMDMA=y</option>, and a suitable driver for the 287 ATA controller (for example, <option>CONFIG_ATA_PIIX=y</option> 288 for old Intel chipsets and QEMU virtual machines). 289 </para> 290 291 <para> 292 If your system is older and it contains 4GB or smaller RAM, and you 293 are building a 32-bit LFS system, remove 294 <parameter>CONFIG_HIGHMEM64G=y</parameter> or the kernel may fail 295 to boot. 296 </para> 188 297 </note> 189 298 190 <note revision="systemd"> 191 <para>While "The IPv6 Protocol" is not strictly 192 required, it is highly recommended by the systemd developers.</para> 299 <para> 300 The instructions above has created a minimal configuration enough 301 for booting LFS on a mainstream x86 system with a functional Linux 302 console. For other peripherals (NICs, mice, etc.), it's obviously 303 impossible to cover all the drivers for them here. And there are also 304 other configuation options you may want to tweak. Now you should run 305 <command>make menuconfig</command> to invoke a menu-driven 306 configuration interface and manually adapt the configuration for your 307 need, or run <command>make localmodconfig</command> to enable all 308 configuration options for kernel modules already loaded by the host 309 distro (they should likely cover the drivers for the peripherals 310 already connected onto the system). Some examples of kernel 311 configurations (for the systems of LFS editors) can be viewed at 312 <ulink url='about:blank'>TODO</ulink>. 313 </para> 314 315 <note> 316 <para> 317 Do not set <option>CONFIG_WERROR=y</option> or 318 <option>CONFIG_IKHEADERS=y</option>, or the kernel may fail to 319 build. Do not set <option>CONFIG_SYSFS_DEPRECATED=y</option>, 320 <option>CONFIG_UEVENT_HELPER=y</option>, or 321 <option>CONFIG_FW_LOADER_USER_HELPER=y</option>, or the system may 322 fail to boot. Do not set <option>CONFIG_EXPERT=y</option> 323 unless you really know what you are doing. 324 </para> 193 325 </note> 194 195 <para revision="sysv">There are several other options that may be desired196 depending on the requirements for the system. For a list of options needed197 for BLFS packages, see the <ulink198 url="&lfs-root;blfs/view/&short-version;/longindex.html#kernel-config-index">BLFS199 Index of Kernel Settings</ulink>200 (&lfs-root;blfs/view/&short-version;/longindex.html#kernel-config-index).</para>201 202 <note>203 <para>If your host hardware is using UEFI and you wish to boot the204 LFS system with it, you should adjust some kernel configuration205 following <ulink url="&blfs-book;postlfs/grub-setup.html#uefi-kernel">206 the BLFS page</ulink>.</para>207 </note>208 209 <variablelist>210 <title>The rationale for the above configuration items:</title>211 212 <varlistentry>213 <term><parameter>Randomize the address of the kernel image (KASLR)</parameter></term>214 <listitem>215 <para>Enable ASLR for kernel image, to mitigate some attacks based216 on fixed addresses of sensitive data or code in the kernel.</para>217 </listitem>218 </varlistentry>219 220 <varlistentry>221 <term>222 <parameter>223 Compile the kernel with warnings as errors224 </parameter>225 </term>226 <listitem>227 <para>This may cause building failure if the compiler and/or228 configuration are different from those of the kernel229 developers.</para>230 </listitem>231 </varlistentry>232 233 <varlistentry>234 <term>235 <parameter>236 Enable kernel headers through /sys/kernel/kheaders.tar.xz237 </parameter>238 </term>239 <listitem>240 <para>This will require <command>cpio</command> building the kernel.241 <command>cpio</command> is not installed by LFS.</para>242 </listitem>243 </varlistentry>244 245 <varlistentry>246 <term>247 <parameter>248 Configure standard kernel features (expert users)249 </parameter>250 </term>251 <listitem>252 <para>This will make some options show up in the configuration253 interface but changing those options may be dangerous. Do not use254 this unless you know what you are doing.</para>255 </listitem>256 </varlistentry>257 258 <varlistentry>259 <term><parameter>Strong Stack Protector</parameter></term>260 <listitem>261 <para>Enable SSP for the kernel. We've enabled it for the entire262 userspace with <parameter>--enable-default-ssp</parameter>263 configuring GCC, but the kernel does not use GCC default setting264 for SSP. We enable it explicitly here.</para>265 </listitem>266 </varlistentry>267 268 <varlistentry>269 <term><parameter>Support for uevent helper</parameter></term>270 <listitem>271 <para>Having this option set may interfere with device272 management when using Udev/Eudev. </para>273 </listitem>274 </varlistentry>275 276 <varlistentry>277 <term><parameter>Maintain a devtmpfs</parameter></term>278 <listitem>279 <para>This will create automated device nodes which are populated by the280 kernel, even without Udev running. Udev then runs on top of this,281 managing permissions and adding symlinks. This configuration282 item is required for all users of Udev/Eudev.</para>283 </listitem>284 </varlistentry>285 286 <varlistentry>287 <term><parameter>Automount devtmpfs at /dev</parameter></term>288 <listitem>289 <para>This will mount the kernel view of the devices on /dev290 upon switching to root filesystem just before starting291 init.</para>292 </listitem>293 </varlistentry>294 295 <varlistentry>296 <term><parameter>Framebuffer Console support</parameter></term>297 <listitem>298 <para>This is needed to display the Linux console on a frame299 buffer device. To allow the kernel to print debug messages at an300 early boot stage, it shouldn't be built as a kernel module301 unless an initramfs will be used. And, if302 <option>CONFIG_DRM</option> (Direct Rendering Manager) is enabled,303 it's likely <option>CONFIG_DRM_FBDEV_EMULATION</option> (Enable304 legacy fbdev support for your modesetting driver) should be305 enabled as well.</para>306 </listitem>307 </varlistentry>308 309 <varlistentry>310 <term><parameter>Support x2apic</parameter></term>311 <listitem>312 <para>Support running the interrupt controller of 64-bit x86313 processors in x2APIC mode. x2APIC may be enabled by firmware on314 64-bit x86 systems, and a kernel without this option enabled will315 panic on boot if x2APIC is enabled by firmware. This option has316 has no effect, but also does no harm if x2APIC is disabled by the317 firmware.</para>318 </listitem>319 </varlistentry>320 321 </variablelist>322 323 <para>Alternatively, <command>make oldconfig</command> may be more324 appropriate in some situations. See the <filename>README</filename>325 file for more information.</para>326 327 <para>If desired, skip kernel configuration by copying the kernel328 config file, <filename>.config</filename>, from the host system329 (assuming it is available) to the unpacked <filename330 class="directory">linux-&linux-version;</filename> directory. However,331 we do not recommend this option. It is often better to explore all the332 configuration menus and create the kernel configuration from333 scratch.</para>334 326 335 327 <para>Compile the kernel image and modules:</para>
Note:
See TracChangeset
for help on using the changeset viewer.