Typo
[linux_from_scratch_hints.git] / OLD / lfs-from-osx.txt
blobc2de23dbb61712b775eb651a9b573ee875ef0744
1 AUTHOR: Martin Schaffner <schaffner@gmx.li>
2 DATE: 2004-03-28
3 LICENSE: GPL
4 VERSION: 1.0
6 SYNOPSIS: Cross-compiling LFS 5.0 from a Mac OS X 10.3 host system
8 DESCRIPTION: This hint lets you install LFS on a (newworld) Macintosh without first installing a binary distribution. This is accomplished by cross-compiling everything in chapter 5, and then rebooting instead of chrooting. This hint doesn't repeat anything from the LFS 5.0 book, it only tells what to do differently. Maybe it is also helpful if someone tries to compile LFS from another system (MinGW and Cygwin come to mind), I'm interested to know if you try.
10 PREREQUISITES:
11 * Mac OS X 10.3 on a partitioned hard disk
12 * Use fink (http://fink.sourceforge.net/) to install "gawk", "sed", "wget". You'll also want "fileutils", so you can do "ls foo -al".
13 * ext2fsx (http://sourceforge.net/projects/ext2fsx), latest version
14 * crosstool (http://kegel.com/crosstool/), at least 0.28-rc1: http://kegel.com/crosstool/crosstool-0.28-rc1.tar.gz
15 * yaboot: http://penguinppc.org/projects/yaboot/yaboot-1.3.11.tar.gz
16 * hfsutils (http://www.mars.org/home/rob/proj/hfs/): ftp://ftp.mars.org/pub/hfs/hfsutils-3.2.6.tar.gz
17 * powerpc-utils (http://packages.debian.org/stable/base/powerpc-utils): download http://ftp.debian.org/debian/pool/main/p/powerpc-utils/powerpc-utils_1.1.3.orig.tar.gz and http://ftp.debian.org/debian/pool/main/p/powerpc-utils/powerpc-utils_1.1.3-5.diff.gz
18 * the following patches from the lfs-patches project:
19     bash-2.05b-crosscompile.patch
20     coreutils-5.0-remove_du.patch
21     linux-2.4.23-nognuexpr.patch
22     sed-4.0.7-cross_hack_for_powerpc_linux_gnu.patch
23     yaboot-1.3.11-crosscompile.patch
26 HINT:
28 Partitioning
29 ------------
31 I don't know of any tool which lets you resize HFS/HFS+ partitions, so after repartitioning, any data on such partitions, including installed Mac OS systems, will be lost.  Also, Apple's partitioning tools formats all partitions when repartitioning, even those whose layout doesn't change. To partition with Apple's tool, use a boot CD. On the OS X installer disk, the partitioning tool (part of "disk tools") can be found in the "Installer" menu.
33 Recommended partitions for GNU/Linux on a newworld mac:
34 * a 800k bootstrap partition (HFS format) for yaboot (this is the minimum size for HFS partitions).
35 * a swap partition of approx. the amount of RAM in the machine
36 * a root partition of type Apple_UNIX_SVR2. Apple's disk utility can create those.
37 Of course, you need also a HFS+ partition with Mac OS X from where to install LFS.
38 Maybe you want to create an exchange partition with the FAT32 format. To do this, create a partition in any format, and once LFS is installed, use mac-fdisk to change its type to Windows_FAT_32, then format it.
40 When the hard disk is partitioned and OS X re-installed, write down the partition map, which can be optained with:
41 echo "L" | sudo pdisk
43 Install ext2fsx in OS X. Create the ext2 filesystems for the GNU/Linux root partition with "newfs_ext2". To label ext2 partitions, unmount them with "disktool -p disk?s?", then run /usr/local/sbin/e2label. Remount with "disktool -m disk?s?".
45 You can't create the linux swap partition from Mac OS X. Do this after having installed util-linux in chapter 6.
48 Chapters 1 to 4
49 ---------------
51 Make sure you have the 3.3 compiler selected: "sudo gcc_select 3.3".
53 On the Mac, volumes are mounted automatically. The mount point for volumes is: /Volumes/label_of_volume
55 To create a user, use the "Accounts" control panel.
58 Chapter 5
59 ---------
61 To create the temporary system, we can't just follow the book. The new system we build in /tools has to be bootable, because we can't just "chroot" into it, since the kernel of the host system is the Mac OS X kernel.
63 After setting up the environnement, instead of installing pass 1 of gcc and binutils, we create a cross-compiler in /opt, on the Mac OS X partition. The PATH variable shouldn't contain "/tools/bin", since Mac OS X can't execute those programs. After creating the cross-compiler, we install linux and the linux headers, and then we continue, cross-compiling everything in this chapter.
65 All GNU packages use the autotools (autoconf, automake, libtool), which makes it easier to cross-compile them. The autotools were used by the package maintainers to create a "configure" script, which is run before running "make".
66 To allow cross-compiling, the configure scripts can take the arguments are --build, --host, and --target.
67 The build triplet tells the configure script what machine the "make" command will be run on.
68 The host triplet tells the configure script what machine the compiled program will run on.
69 For programs creating programs (gcc and binutils), the target triplet tells what machine the program's output will run on.
70 Mac OS X 10.3 is called powerpc-apple-darwin7.2.0
71 GNU/Linux on a G3 processor is called powerpc-750-linux-gnu
73 To install the cross-compiler, use crosstool.
74 As root, "mkdir -p /opt/crosstool", and "chown <your_login>.<your_login> /opt/crosstool".
75 As user, in the crosstool directory, run "bash demo-ppc750.sh". This gives you a cross-compiler in /opt/crosstool. It takes some time: on my ibook@600Mhz, it took:
76   real    275m1.076s
77   user    128m25.250s
78   sys     52m41.810s
80 For me, one SBU was:
81   real    10m3.755s
82   user    4m50.220s
83   sys     3m12.140s
85 After installing crosstool, set the PATH variable to include the cross-compiler:
86 export PATH=/opt/crosstool/powerpc-750-linux-gnu/gcc-3.3.3-glibc-2.3.2/bin:$PATH
87 You may want to put this into your ~/.bash_profile file.
88 Next, you need to "lock" the cross-compiler to the glibc library which will be in /tools: Edit /opt/crosstool/powerpc-750-linux-gnu/gcc-3.3.3-glibc-2.3.2/lib/gcc-lib/*/*/specs by putting "/tools" in front of all occurences of "/lib/".
90 Next, you need to install linux and the linux headers. I used linux-2.4.25, which has HFS+ support. linux-2.6.4 also has that, but has some problems compiling on Mac OS X.
91 Apply linux-2.4.23-nognuexpr.patch
92 For all invocations of "make", append: 
93 CROSS_COMPILE=powerpc-750-linux-gnu- ARCH=ppc
94 Follow the book's section "installing linux headers".
95 make menuconfig, keeping in mind that the temporary system will not be able to load modules, nor to mount partitions (it is OK to configure with modules, as long as they are not necessary in chapter 6). You can just use the defaults, that should work.
96 make
97 cp vmlinux $LFS/tools/
98 mkdir $LFS/dev
100 Since we are cross-compiling everything in chapter 5, append to all invocations of a configure script:
101 --build=powerpc-apple-darwin7.2.0 --host=powerpc-750-linux-gnu
102 Further, you can't do any testing in chapter 5.
103 Below is a list of packages to install from chapter 5, together with notes where special care is required.
105 * glibc: prefix the configure command with BUILD_CC=gcc CC=powerpc-750-linux-gnu-gcc AR=powerpc-750-linux-gnu-ar RANLIB=powerpc-750-linux-gnu-ranlib (still suffix with --target=... of course). remove "--with-binutils" flag. Don't install the locales.
106 * gcc (pass 2): "expect" is not installed so the test at the beginning does not work. Only enable-languages=c (no c++). After installing, change the specs file in /tools/lib/gcc-lib/*/*/specs by removing all occurences of "/tools", and changing the number after "cross-compile" to 0 instead of 1.
107 * binutils (pass 2): append "--disable-nls" to the configure command. Don't prepare for re-adjusting.
108 * gawk
109 * coreutils: apply coreutils-5.0-remove_du.patch before running configure.
110 * bzip2: append to the make command: CC=powerpc-750-linux-gnu-gcc AR=powerpc-750-linux-gnu-ar RANLIB=powerpc-750-linux-gnu-ranlib
111 * gzip
112 * diffutils
113 * findutils
114 * make
115 * grep
116 * sed: apply sed-4.0.7-cross_hack_for_powerpc_linux_gnu.patch before running configure
117 * gettext
118 * patch: remove "setmode" from the configure script, append to make: CC=powerpc-750-linux-gnu-gcc
119 * tar
120 * bash: apply bash-2.05b-crosscompile.patch and run "autoconf" before running "configure", ignore error for make and make install, don't reload bash
121 * util-linux: prepend configure with CC=powerpc-750-linux-gnu-gcc CFLAGS=-I/opt/crosstool/powerpc-750-linux-gnu/gcc-3.3.2-glibc-2.3.2/include/ and don't build or install "more". You can use "tail -n <line_count> <file>" if you want to see a part of a file.
123 It is not necessary to install tcl, expect, dejagnu, ncurses, perl, texinfo
127 Before getting to chapter 6, we need to make our system in $LFS/tools bootable.
128 Unpack yaboot, and apply: yaboot-1.3.11-crosscompile.patch
129 Compile and install with:
130 make yaboot CROSS=powerpc-750-linux-gnu-
131 cp second/yaboot /
132 Create a file /yaboot.conf similar to the following example, adjusting the partition numbers; in this example, I have Mac OS Classic on partition 15, Mac OS X and yaboot on partition 13, and LFS on partition 12 (you can find out partition numbers of volumes with "mount"):
133 macosx=hd:13
134 macos=hd:15
135 enablecdboot
136 enableofboot
137 defaultos=macosx
138 ofboot=hd:13
139 delay=30
140 default=linux
141 timeout=50
142 image=hd:12,/tools/vmlinux
143   label=linux
144   root=/dev/hda12
145   read-write
146   append="devfs=mount init=/tools/bin/bash"
147 image=hd:12,/tools/vmlinux
148   label=nodevfs
149   root=/dev/hda12
150   read-write
151   append="init=/tools/bin/bash"
154 Chapter 6
155 ---------
157 Don't bother removing the debuggin symbols
159 Instead of doing "chroot", you have to reboot into your minimal but (hopefully) working bootstrap GNU/Linux system.
160 Warning: the system does no file system check, it just mounts the root partition. It directly executes bash, without any init system. To reboot, you have to hit ctrl-command-power, but be sure to do "sync" first!!!. If you don't, you will have an inconsistent file system!
161 After such a reboot, it is a good idea to boot into Mac OS X' single user mode (hit command-s after the chime, until you get text mode), and then type: "fsck_ext2 /dev/disk0s12" (or whatever the ext2 partition is).
162 Further, you will not have virtual terminals, and "ctrl-c" will not work.
164 To boot into the minimal system, reboot, and right after the chime hit command-alt-o-f, and at the open firmware prompt, type (changing the number to the partition number where you installed yaboot):
165 boot hd:13,yaboot
166 Then type:
167 linux
169 After booting, type:
170 export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
171 export HOME=/root
173 When creating devices, we can't do that in /dev, since /dev is handled by devfs. Instead, we do:
174 mkdir /dev2; cd /dev2
175 There we expand MAKEDEV, and execute:
176 ./MAKEDEV -v generic
177 ./MAKEDEV -v nvram
178 After that, we sync, then reboot into Mac OS X (single user mode), where we fsck_ext2 our LFS partition, mount_ext2 it, then move $LFS/dev to $LFS/dev-old, then move $LFS/dev2 to $LFS/dev. After that, we do "reboot", and tell yaboot to boot "nodevfs". After booting, we set $PATH and $HOME again.
180 Unfortunately, since we couldn't cross-compile all packages in chapter 5, we can't install the linuxthread man pages at the beginning of chapter 6, and some tests will fail (e.g. because perl is not installed). These things have to wait until the packages left out from chapter 5 have been installed. Also, since "expect" is not installed, the test on the first line of the binutils section will not work.
182 When re-adjusting the toolchain, we can't do the first step, adjusting the linker.
184 Instead of grub, we install yaboot. yaboot requires:
185 * hfsutils. install with:
186     ./configure --prefix=/usr && make && make install
187 * nvsetenv. install with:
188     tar xvzf powerpc-utils_1.1.3.orig.tar.gz
189     cd pmac-utils
190     zcat ../src/powerpc-utils_1.1.3-5.diff.gz | patch
191     make nvsetenv
192     cp nvsetenv /sbin/
193 Install yaboot:
194     make install
196 As soon as you have util-linux installed, you can create your swap filesystem, with "mkswap".
198 For the keymap, take one from /usr/share/kbd/keymaps/mac/all/
201 Chapters 7 to 9
202 ---------------
204 To make the system bootable, edit /etc/yaboot.conf:
205 * change all partition numbers
206 * add lines "macos=hd:15", "macosx=hd:13" and "defaultos=[linux|macos|macosx]" if you wish to be able to boot into Mac OS after executing ybin
207 * remove "local/" from the pathnames
208 Execute (replacing "9" with your bootstrap partition number):
209 mount proc /proc -t proc
210 hformat /dev/hda9
211 /usr/sbin/ybin
213 At the end, instead of logging out, do "sync", followed by a forced reboot (ctrl-command-power).
215 CHANGELOG: