lintpkgsrc comes from pkgtools/lintpkgsrc
[ikiwiki.git] / docs / howtos / HowToBuildKernelFromLiveCD.mdwn
1 This article describes the way to build a kernel right after installation, before the very first reboot. This has been performed on the request of the project leader, Matthew Dillon.
2
3
4
5 I used a dual PIII-450MHz machine, and I have built an SMP kernel with pf, vlan and ALTQ features compiled-in. I used the latest PREVIEW ISO to date (20061228). No additional tools are needed. I performed a fresh installation. Prerequisities: you have to know how to create a custom kernel config and build a kernel.
6
7
8
9 ## Part 1: Mounting the necessary filesystems, copying kernel sources, chroot-ing. 
10
11 First, boot the machine with the CD and perform a regular installation, but after configuring the system, do not reboot, just leave the installer and log in as root. Then you should mount the root filesystem to the ***/mnt*** mount point:
12
13     # mount /dev/ad0s1a /mnt
14
15 In ***/mnt***, you will have the root of your HD installation mounted. If you have enough space, you can copy ***/usr/src-sys.tar.bz2*** to ***/mnt***, or you can mount additional 'partitions'. Try this:    
16
17     # cat /mnt/etc/fstab
18
19 You'll get an output like this:
20
21     # Device                Mountpoint      FStype  Options         Dump    Pass#
22     /dev/ad0s1a             /               ufs     rw              1       1
23     /dev/ad0s1b             none            swap    sw              0       0
24     /dev/ad0s1d             /var            ufs     rw              2       2
25     /dev/ad0s1e             /tmp            ufs     rw              2       2
26     /dev/ad0s1f             /usr            ufs     rw              2       2
27     /dev/ad0s1g             /home           ufs     rw              2       2
28     proc                    /proc           procfs  rw              0       0
29
30 To mount the new home directory into ***/mnt/home***:
31
32     # mount /dev/ad0s1g /mnt/home
33
34 Then copy the kernel source tarball to the HDD:
35
36     # cp /usr/src-sys.tar.bz2 /mnt/
37
38 There we go. But now the root is the CD's top-level filesystem and it does confuse the kernel installation (FIXME). Luckily, we can tell the operating system to use another mountpoint (or even a folder) as root. We just tell the system to use /mnt as root.
39
40
41
42     
43
44     # chroot /mnt
45
46 Now your ***/*** is the root of your new installation. Then mount all the remaining partitions:
47
48
49
50     
51
52     # mount -a
53
54 We are done with the first part. Let's just build the new kernel!
55
56
57
58 ## Part 2: Unpacking the kernel source, building and installing the new kernel 
59
60 Go into ***/usr*** and unpack the kernel source tarball located in /:
61
62
63
64     
65
66     # cd /usr && tar xyfv /src-sys.tar.bz2
67
68 Then your kernel sources will be in ***/usr/src***. Now create a custom kernel config, I named it SMP and placed it into ***/root'. After you are done with configuring, comes the trickier part. To make sure the kernel and userland are in sync from a developmental point of view, you usually have to ***make buildworld*** before trying to ***make buildkernel***, and the tools from the freshly built world (# userland) are used to build the new kernel. But now you don't have the necessary source files to do the buildworld and if you are on a slower connection, it can take ages to fetch, let alone the build time (takes 4x or 5x of the kernel build time). Luckily you can build a kernel with the toolchain of your current system - the kernel and userland from the CD are in sync, aren't they? :)
69
70
71
72     
73
74     # cd /usr/src && make nativekernel KERNCONFDIR#/root KERNCONFSMP
75
76     <kernel build message flood>
77
78     # make installkernel KERNCONFDIR#/root KERNCONFSMP
79
80 Note: the ***nativekernel*** target can of course be used anytime, but the kernel and userland have to be in sync, otherwise if you make a kernel on top of an older userland, your system may become unusable.
81
82 Done. Now get outta the chroot:
83
84
85
86     
87
88     # exit
89
90 and reboot. Make sure to remove the install CD.
91
92
93
94 Hint: you can perform this on a faster machine and place the HDD into the original machine afterward if you are in a hurry. Be aware of the fact that SMP kernels won't boot on UP machines, though.
95
96