1 AUTHOR: Alex Kloss <alex@22-music.com>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: Install LinuxFromScratch using only 1 bootable Linux-partition
10 If you got no spare partition to build your LFS on, you could turn a file into
11 a partition, using the so-called loop-device. The transfer of the system to
12 the root partition is a bit tricky, though.
15 You need to have loop device support compiled into your kernel (if you're
16 unsure, run "grep LOOP /usr/src/linux/.config"; if the last letter is y or
17 m, the kernel compiled with that options has loop device support enabled),
20 sed s/\#\ CONFIG_BLK_DEV_LOOP\ is\ not\ set/CONFIG_BLK_DEV_LOOP=m/ \
21 usr/src/linux/.config > conf && mv conf /usr/src/linux/.config &&
22 cd /usr/src/linux && make modules modules_install && insmod loop &&
23 cd /dev && ./MAKEDEV loop
25 Now your kernel should have loop device support through a module. Other
26 than that, you need about 1GB (rather make it a bit more, the filesystem is
27 stored in the file as well and adds up to some MB of data) of free space on
28 your root partition (or any other partition you intend to store your loop
29 file on). The commands "cd /dev && ./MAKEDEV loop should be omitted on systems
30 which are using devfs).
33 The following text describes the changes you have to make to the normal LFS
34 installing procedere when using only 1 bootable partition. It's not complete
35 without the LFS Book. It is just a description of the things you ought to do
36 in a different way than declared in the LFS book. It splits up into 2 parts
37 that differ from the Book: first, of course, the making of partition, which is
38 replaced by the making and setup of a loop device file, and next, the deletion
39 of the previous system due to the need of diskspace for the new one and the
40 installation and boot setup, that differs a bit, too.
43 If you're using reiserfs, this hint is almost unusable for you due to deletion
44 errors on a recursive mounted volume with reiserfs (the files will be deleted,
45 but the space wouldn't be freed). You could still use the hint to make every-
46 thing ready for a transfer using a bootdisk/CD, but don't try the "Delete the
47 previous System" section or further. You've been warned!
50 Make yourself a bootdisk or bootCD, whatever is sufficient on your system. You
51 can prevent a lot of trouble when rebooting fails.
53 If you don't know how to make a bootdisk or bootCD, look at the hints, the BLFS
54 section about it or search for bootdisk on freshmeat. Be sure that the bootdisk
55 or -CD is able to read/write your root partition, e.g. a tomsrtbt is currently
56 not able to mount reiserfs.
58 When you come to the part of the LFS Book which is called:
60 "Creating a new partition"
62 You don't want to create a new partition! That's why you're trying to use this
63 hint. Therefore, this should be replaced with:
65 Making a loop device file:
67 Be sure to be superuser and that you have all variables ($LFS) set up like
68 you're told in the book. Then make a file containing enough MB of
71 dd if=/dev/zero of=/tmp/lfs.disk bs=1M count=XXX
73 "dd" is short for "disk dump"; it will dump the contents of an device or file
74 into another device or file. We dump from input file "/dev/zero", so everything
75 in the new output file "lfs.disk" will be empty space. This file /tmp/lfs.disk
76 will become our loop device file soon. The newer versions of software you use,
77 the more space you will probably need for compiling; you might want to replace
78 XXX with 800-900 MB for LFS 2.x, 900-1000 MB for LFS 3.x and 1000-1100 MB for
79 LFS 4.x/5.x or even more to be on the safe site.
81 Setting up the loop device:
83 You load the file you made to the loop device with the command
85 losetup /dev/loop0 /tmp/lfs.disk
87 which will bind /tmp/lfs.disk to the loop device /dev/loop0; everything
88 written to /dev/loop0 will go directly into /tmp/lfs.disk.
90 Creating a ext2 file system on the new partition:
92 We don't have a new partition. But we have our file "lfs.disk" (or whatever
93 you called it) on the /dev/loop0 device. So instead of creating the file
94 system on /dev/hda2 or any other partition, we're using the command on the
95 loop device our file is attached to:
99 This will write an ext2 filesystem to our /tmp/lfs.disk file using the loop
100 device. You could also use mkreiserfs or any other filesystem that is capable
101 of handling unix-style attributes (So dosfs/vfat doesn't count, but umsdos
102 does), but be warned that a journalling filesystem like reiserfs produces
103 grossiping amounts of overhead, so prepare yourself in patience for a slow
104 installation. I hear your questions why reiserfs should be slower than ext2fs
105 at a loop device. This is because the reiserfs uses a journal which is
106 accessed every time at write accesses, so you have to write almost any data
107 twice vs. once using ext2fs.
109 If you haven't got any idea about what I was writing about the last paragraph,
110 just believe me using ext2fs is the best method. If your main system uses a
111 journalling filesystem, the data is safe anyway, because lfs.disk will be
112 included in the journal, too.
114 Mounting the new partition:
116 mount /dev/loop0 /mnt/lfs
118 Instead of mount e.g. /dev/hda2 to /mnt/lfs, we're using our loop device. From
119 now on, the installation may proceed as in the book.
121 Before entering the chrooted environment (which usually happens in Chapter 6),
122 you can safely put the sources in your /home/lfs directory and unpack them
123 directly there. When entering the chrooted environment, you can reduce the
124 needed space by unpacking the sources from another login in which you do not
125 enter the chrooted environment.
127 Of course you can delete every packagedir (even the kernel) after installa-
128 tion, unless the book tells otherwise.
130 Halting the Building of LFS:
132 So you found that building LFS using this hint takes too long to do it in one
133 pass? Never mind. All you have to do is save the system in a secure state so
134 you can shut down safely. When in chroot'ed mode, first umount everything
135 that's mounted to /mnt/lfs, then get every shell away from /mnt/lfs and umount
138 Then exit the chrooted mode. Now unmount the lfs "partition":
143 exit # the chrooted environment
144 cd # get out of /mnt/lfs
147 Now you can safely set back the loop devices:
149 losetup -d /dev/loop0
151 Now you can safely shut down your system. When you start again, you need to
152 perform those steps "backwards", like you already did in the beginning:
154 losetup lfs.disk /dev/loop0
155 mount /dev/loop0 /mnt/lfs
157 Now chroot and mount proc if necessary (use the commands you find in the LFS
158 Book, they may differ from version to version).
160 The following steps are quite the same. The only differences starts again when
161 you want to make this drive bootable:
163 Making the LFS System bootable:
165 A thought on making the kernel in LFS: why reconfigure everything? Even
166 if you've got an old kernel, most of the things you've chosen (or not)
167 during kernel configuration have not changed a bit. You could fasten up
172 using out of the chroot'ed environment:
174 cp /usr/src/linux/.config $LFS/usr/src/linux
178 Now you only get asked on the things that weren't configured with your new
179 kernel (which should be somewhat less work than choosing every menu). If
180 you're unsure, you could still check it with "make menuconfig".
182 Make your kernel and grub (or lilo, if you are using an version < 5.x) in the
183 chroot'ed environment as described in the LFS book. Don't try to start grub or
184 lilo now! Stop here! I hope you're still in the chroot'ed environment, other-
187 The only bootable partition you've got is the one your current distro is
190 If you want to use the /tmp/lfs.disk file for anything else than installing
191 LFS over your distribution, you'll probably not need the following part.
193 You're about to install LFS on the partition, deleting the distro. But before
194 you get started, read the following warning carefully:
196 -------------------------------------------------------------------------------
197 Do yourself a real big favour and get a bootdisk!
198 -------------------------------------------------------------------------------
200 If you delete your distribution and have a power failure, you would lose
201 your whole system (including the lfs.disk file that you can't access
202 anymore without a bootable linux system unless you get a bootdisk).
204 Mounting the main partition:
206 Mount the main partition to "/mnt" in the chroot'ed environment suggesting
207 your main partition is /dev/hda1, otherwise fill in what is necessary:
211 The main partition is now mounted to a directory in a file attached to a block
212 device which is mounted on the main partition (that is mounted to a directory
213 and so on...). This is a really nice example for recursion. And this could get
214 another nice example of an almost infinite loop (depending on your harddisk's
215 size), if you try to copy everything to mount. Or an destructive loop, if you
216 try to delete everything in /mnt (because this also holds the file currently
217 working as your root environment). If you're asking what I'm talking about,
218 never mind, just follow the next instructions very, very carefully.
220 Making sure init finds his getty:
222 If you know what I'm talking about, you could go straight to the following
223 paragraph. Anyone else may read the explanation: "init" is the process that is
224 started by the kernel to start everything else during the bootup.
226 Everything else, that is, all calls that are in /etc/inittab. In this inittab,
227 you should find some version program getty, for example agetty or mgetty, but
228 maybe only getty. This program is used to load the programs that allow you to
229 login into your system. Now imagine you delete the whole old stuff including
230 the old getty. Imagine further the LFS's agetty is different from the distro's
231 version, or in a different directory (Debian, for example, uses getty). The
232 inittab should remain in the memory. Init would try (on your next login) to
233 use a getty that's not there, meaning you wouldn't be able anymore to login
234 into your system, which could be fatal in the current state.
236 Before you logout of the chroot'ed system you should be sure that the init
237 process will find the version of getty named in the inittab, otherwise you
238 would be unable to access the system anymore and need the the bootdisk! A
241 cat /mnt/etc/inittab | grep getty
243 shows wether your previous system is using getty, agetty, mgetty or any
244 other version possible. If it's using any other version than agetty
245 (that's what Linux From Scratch is using), you should do a symlink like
247 ln -s /sbin/agetty /sbin/<the distro's getty version>
249 Now you can safely replace the old system.
251 Deleting the previous System:
253 To repeat the previous warning: That DOESN'T WORK well with reiserfs. I've
254 double-checked if the issue would be resolved in the current reiserfs
255 version, but the result was negative: the deletion of recursive mounted
256 file systems leaves the emptied space unusable, because it's not cleared in
257 the journal! So don't try the next steps if you are using reiserfs! If you are
258 using an ext3 partition, you may mount it as ext2 and covert it back after you
259 copied the new LFS to your main partition. Anyone using reiserfs should create
260 a boot-CD with the new LFS in a .tar.gz file. You'll find a short description
261 at the end of this hint
263 You'll have to get the main partition entirely clean from everything that is
264 not /mnt, /tmp/lfs.disk and proc, which holds another file system:
266 for dirname in `ls -1 /mnt | sed -e /tmp/d -e /proc/d -e /mnt/d`; do
267 rm -r /mnt/$dirname; done &&
268 for filename in `ls /mnt/tmp | sed s/lfs.disk//`; do
271 You may omit other directories at will by adding "-e /<directory>/d" to the
272 first sed command. The second line is only needed if you want to clear the /tmp
275 Now the partition should be clean enough for copying the LFS system. If you
276 want to keep other files and are not so sure about your shell scripting skills,
277 better delete all unnecessary files by hand (don't touch /tmp, /proc or /mnt).
279 Copying the system to the root partition:
281 Now we may copy the new system. Everything but the /mnt directory, to which
282 the device that we are filling with LFS is mounted and the directory /proc, in
283 which are dynamic files written by the kernel.
285 for dirname in `ls -1 / | sed -e /mnt/d -e /proc/d -e /tmp/d`; do
286 cp -a $dirname /mnt; done
292 copies in "archive" mode, so the whole directories are copies with their
293 content and all subdirs and all filemodes are kept, if possible. For the
294 for ...; do; done constructions look at the previous command explanation.
296 Now the LFS is on your primary partition logout of the chroot'ed environment
297 into the new system. Now you can perform grub/lilo and this stuff.
303 losetup -d /dev/loop0
309 Get out of 1. a bash, 2. a chroot'ed environment.
313 we change to the root dir not to have former access on the device we're
318 First we need to unmount the proc device from the loop device, so you
321 losetup -d /dev/loop0
323 delete the binding from /dev/loop0 to /tmp/lfs.disk.
325 You may now delete lfs.disk, unless you don't want to use it otherwise.
327 You could e.g. pipe the disk dump to install over network. If anybody is plan-
328 ning an LFS installation like that I beg you to contact me via IRC in #lfs on
329 irc.linuxfromscratch.org to 1. get further support and 2. let me share your
332 Then you can get back to the book (installing grub/lilo and all that stuff).
334 Now for those who are using reiserfs and need to make a bootcd to copy the new
335 system over: 1. make a bootdisk (like in the BLFS section), add all utilities
336 you may need (like reiserfsprogs) 2. make a .tar.gz archive of your new LFS
337 (of course after exiting the chrooted environment):
341 tar czfv /tmp/lfscd/LFS-<version>-<date>.tar.gz
343 Now create an isofs which uses the bootdisk image as El-Torito bootimage:
345 mkdir /tmp/lfscd/boot
346 cp <bootimg> /tmp/lfscd/boot
348 mkisofs -r -o /tmp/lfscd.iso -b /tmp/lfscd/boot/<bootimg> \
349 -c /tmp/lfscd/boot/catalog
351 Now use cdrecord to write the iso image on a CD. The LFS on this CD may not run
352 on other Systems, especially older systems will need an cross-compiled version
353 of LFS (see cross-compiling hint).
357 * After doing this little trick on my own notebook, I urged myself to write
358 a hint (after all, I had a lot fun with LFS and wanted to help spread it).
360 [Somewhen later 2000]
361 * While using my own hint when I tried to make a LFS BootCD without using
362 the hint (I'll never do that again), I stumbled over a nice information
363 about losetup, which opens a better way to handle loop devices and added
367 * After a few month, I wanted 1. to do a new LFS using my hint again (not
368 only for the fun of it, I also wanted the System as new as possible),
369 2. try to reorganise this hint and 3. make the scripts on the end a bit
371 Note: I had to enlarge the lfs.disk file a bit, due to the fact that on
372 some systems, during glibc compilation in chapter 6 the disk usage con-
376 * Corrected a bad typo
379 * I'm trying to keep this hint up to date, so another installation is about
380 to take place. I want to go a bit beyond the current version, so I'll try
381 to use gcc-3.0.4 and another few versions not yet used by the book. Wish
385 * Currently testing LFS 4.0 on a One Partition Build. Since the chapters
386 have a new structure and the static utils are stored in a separate
387 directory, the advantages should be used in this hint, too.
390 * Updating to the new format, removed unnecessary stuff, checking for
391 LFS 5.0-pre1 (test build).
394 * Further updates to 5.0-pre2 (since pre1 had some show-stopper bugs),
398 * Finished testing with 5.0-pre2 (successfully), minor changes to
399 match the new book style (command explanations after each command), added a
400 short section about the bootcd stuff for reiserfs users.
403 Many thanks goes to Gerard, without his book, developing this hint had never
405 Thanks to the whole bunch of people that usually idles the whole day on
406 #lfs@irc.linuxfromscratch.org for helping me in so many ways.
407 And thanks to all the people not mentioned here for not minding it...