Typo
[linux_from_scratch_hints.git] / OLD / one-partition-hint.txt
blobfe59dfc4370424c4998e1b7bc14129e33a67c74b
1 TITLE:          One Partition HINT
2 LFS VERSION:    2.x-4.0*
3 AUTHOR:         Alex Kloss (LX) <l.x.@gmx.de>
5 SYNOPSIS:
6         Install LinuxFromScratch using only 1 bootable Linux-partition
7         on which is your actual distribution.
9 HINT:
10 ________________________________________________________________________________
12 The following text describes the changes you have to make to the normal LFS 
13 installing procedere when using only 1 bootable partition. It's not complete
14 without the LFS Book. It is just a description of the things you ought to do
15 in a different way than declared in the LFS book. It splits up into 2 parts
16 that differ from the Book: first, of course, the making of partition, which is
17 replaced by the making and setup of a loop device file, and next, the deletion
18 of the previous system due to the need of diskspace for the new one and the
19 installation and boot setup, that differs a bit, too.
20 ________________________________________________________________________________
22 *: A certain Version of LFS is not really necessary. You can perform the 
23    following tricks with any recent LFS Version known to me. The only thing 
24    that really depends on the LFS version are the Chapter Names and Numbers.
25 ________________________________________________________________________________
27 HISTORY:
29 Summer 2000: After doing this little trick on my own notebook, I urged
30 myself to write a hint (after all, I had a lot fun with LFS and wanted to 
31 help spread that fun).
33 Somewhen later 2000: While using my own hint when I tried to make a LFS BootCD 
34 without using the hint (I'll never do that again), I stumbled over a nice 
35 information about losetup, which opens a better way to handle loop devices and
36 added it to that hint.
38 14. Dec. 2001: After a few month, I wanted 1. to do a new LFS using my hint 
39 again (not only for the fun of it, I also wanted the System as new as possible),
40 2. try to reorganise this hint and 3. make the scripts on the end a bit nicer.
41 Note: I had to enlarge the lfs.disk file a bit, due to the fact that on some 
42 systems, during glibc compilation in chapter 6 the disk usage conquers 800MB.
44 19. Dec. 2001: Corrected a bad typo
46 30. Mar. 2002: I'm trying to keep this hint up to date, so another 
47 installation is about to take place. I want to go a bit beyond the current 
48 version, so I'll try to use gcc-3.0.4 and another few versions not yet used by
49 the book. Wish me luck!
51 31. Oct. 2002: Currently testing LFS 4.0 on a One Partition Build. Since
52 the chapters have a new structure and the static utils are stored in a
53 separate directory, the advantages should be used in this hint, too.
55 ________________________________________________________________________________
57 THANKS:
58 Many thanks goes to Gerard, without his book, developing this hint had never 
59 been possible.
60 Thanks to the whole bunch of people that usually idles the whole day on 
61 #lfs@irc.linuxfromscratch.org for helping me in so many ways.
62 And thanks to all the people not mentioned here for not minding it...
63 ________________________________________________________________________________
65 REISERFS WARNING:
67 If you're using reiserfs, this hint is almost unusable for you due to
68 deletion errors on a recursive mounted volume with reiserfs (the files
69 will be deleted, but the space wouldn't be freed). You could still use
70 the hint to make everything ready for a transfer using a bootdisk/CD,
71 but don't try the "Delete the previous System" section or further.
72 You've been warned!
74 RECOMMENDATION:
76 Make yourself a bootdisk or bootCD, whatever is sufficient on your
77 system. You can prevent a lot of damage to your system. 
79 If you don't know how to make a bootdisk or bootCD, look at the hints,
80 the BLFS section about it or search for bootdisk on freshmeat. Be sure
81 that the bootdisk/CD is able to read/write your root partition, e.g. a
82 tomsrtbt is currently not able to mount reiserfs.
84 INSTALLATION:
86 When you come to the part of the LFS Book which is called:
88 Part II, Paragraph 4
89 ====================
91 Preparing a new partition
93 You don't want to create a new partition! That's why you're trying to use this 
94 hint. Therefore, this should be replaced with:
96 Making a loop device file and setting it up
98 Be sure to be superuser and that you have all variables ($LFS) set up like
99 you're told in the book. Then make a file containing enough MB of
100 nothing using:
102         dd if=/dev/zero of=/tmp/lfs.disk bs=1M count=XXX
104 This file /tmp/lfs.disk will become our loop device file afterwards. The newer
105 versions of software you use, the more space you need for compiling; you might
106 want to replace XXX with 800 for LFS 2.x, 900-1000 for LFS 3.x and
107 1100-1300 for LFS 4.x or even more to be on the safe site.
109 LFS 4.0 allows to put all the static stuff to another directory, so it
110 would be cool to part the loopback volumes, too:
112         dd if=/dev/zero of=/tmp/lfs.disk bs=1M count=450 &&
113         dd if=/dev/zero of=/tmp/static.disk bs=1M count=750
115 This makes one volume for the finished LFS and one for the static stuff
116 you'll delete afterwards.
118 ________________________________________________________________________________
120 Command explanations
122 dd: 
124 data dump utility - a small utility to read from an input file/device and dump 
125 the data into an output file.
127 if=/dev/zero: 
129 defining /dev/zero as Input file. We don't need nor want any input. The Zero 
130 device contains as much "0" as we want to read from it.
132 of=/tmp/lfs.disk: 
134 we dump a choosed amount full of nothing into the Output File called
135 "lfs.disk" in the directory /tmp. It's not necessary to call it like
136 that. You can even put it into any directory you got read/write-rights
137 for. But if you call it otherwise, you'll better remind to change this
138 filename within the later instructions.
140 bs=1M: 
142 Blocksize is set to 1 MegaByte.
144 count=XXX: 
146 We want XXX blocks each containing 1MB, so our file will be XXX MB big.
147 Version 2.x can be build with about 800MB, Version 3.x with about 1GB,
148 Version 4.x with about 1.2GB. If you want to be on the safe site, you
149 might want to take 100MB more. Even if it the size written in the
150 book works, when installing glibc, you may reach the limits faster than
151 you thought.
152 ________________________________________________________________________________
154 Finding out wether the loop device is available and install it if not
156 For this hint, you need the loop device to be installed in your kernel,
157 either as module or included. To find out wether it is available, simply
160         dmesg | grep loop
162 if you get something like 
164         loop: loaded (max 8 devices)
165         Calibrating delay loop... XXXX.XX BogoMIPS
167 The driver is already loaded. If you don't get it, try
169         modprobe loop
171 If modprobe complains about the module not to be found, it's possible,
172 that you haven't compiled it into your kernel. If not, you can skip the
173 following section.
174 ________________________________________________________________________________
176 Command Explanation
178 dmesg:
180 Giving the kernel messages (like these you see every bootup - if you
181 ever see one, actually) to the standard output.
185 A so-called "pipe". Gives the standard output from one command to the
186 standard input of another one.
188 grep loop:
190 print only the lines with "loop" in it, e.g. the one about the loop
191 device driver.
192 ________________________________________________________________________________
194 Setting up the loop device in your kernel
196 First, we check again, if there's really no loop device support in your kernel
197 (there are few chances that depmod didn't run properly or that you're running
198 the wrong kernel):
200         cat /usr/src/linux/.config | grep CONFIG_BLK_DEV_LOOP
202 If you get something like
204 CONFIG_BLK_DEV_LOOP=Y 
206 meaning the support is compiled into the kernel, or
208 CONFIG_BLK_DEV_LOOP=M
210 stating that loop device support is compiled as module.
211 If you get something like
213 #CONFIG_BLK_DEV_LOOP is not set
215 you could change the necessary option by typing (or copy and paste - X
216 is great!)
218         sed s/\#\ CONFIG_BLK_DEV_LOOP\ is\ not\ set/CONFIG_BLK_DEV_LOOP=m/ \
219         /usr/src/linux/.config > conf && mv conf /usr/src/linux/.config &&
220         cd /usr/src/linux && make modules modules_install && insmod loop
222 After some minutes (depending on the speed of your system) you should be
223 able to use the loop device.
224 ________________________________________________________________________________
226 Command Explanation:
228 cat /usr/src/linux/.config: 
230 writes the kernel configuration to the standard output.
232 | grep CONFIG_BLK_DEV_LOOP: 
234 searches the output for the loop-device-option.
236 sed...: 
238 replaces the "is not set" instruction with the instruction for making a module
239 to use the loop device. For further explanation, please read the LFS book.
241 insmod loop: 
243 loading the module for mounting loop devices
245 mount lfs.disk /mnt/lfs -o loop: 
247 mounting the disk image file to the directory /mnt/lfs using the loop device 
248 driver (-o loop).
249 ________________________________________________________________________________
251 If your loop device was already available, you should get on with things
252 right here:
254 Setting up the loop device
256 You load the file you made to the loop device with the command
258         losetup /dev/loop0 /tmp/lfs.disk
260 And if you're using LFS 4.x with splitting of lfs and static, add
262         losetup /dev/loop1 /tmp/static.disk
264 If you get an error: /dev/loop0 device file not found, it so seems that
265 you're missing the device file (which is really unusual), but you could
266 make it easily by typing
268         mknod b 7 0 /dev/loop0
270 And for the splitting again
272         mknod b 7 1 /dev/loop1
274 and perform the losetup again.
275 ________________________________________________________________________________
277 Command Explanations
279 losetup /dev/loop0 /tmp/lfs.disk:
281 Attaching the file /tmp/lfs.disk to the loop device on /dev/loop0. This
282 is somewhat like mounting, only there's no filesystem on a device to
283 mount to a directory, but a file that gets "mounted" to a device for
284 later mounting.
286 mknod b 7 0 /dev/loop0:
288 Making a block device with major/minor nr. 7/0 using the filename
289 /dev/loop0. You could read the mknod manpage and the devices.txt of
290 the kernel Documentation for further informations on the issue.
291 ________________________________________________________________________________
293 Creating a ext2 file system on the new partition
295 We don't have a new partition. But we have our file "lfs.disk" (or whatever you 
296 called it). on the /dev/loop0 device So instead of creating the file system 
297 on /dev/hda2 or any other partition, we're using the command on the
298 loop device our file is attached to:
300         mke2fs /dev/loop0
302 And if you made a static.disk you should also
304         mke2fs /dev/loop1
306 You could also use mkreiserfs or any other filesystem that's capable of
307 unix-style attributes, but I should warn you that e.g. reiserfs produces
308 grossiping amounts of overhead, so prepare yourself in patience for a
309 slow installation. I hear your questions why reiserfs should be slower
310 than ext2fs at a loop device. This is because the reiserfs uses a
311 journal which is accessed every time at write accesses, so you have to
312 write almost any data twice vs. once using ext2fs.
314 If you haven't got any idea about what I was writing about the last
315 paragraph, just believe me using ext2fs is the best method.
316 ________________________________________________________________________________
318 Command explanations
320 mke2fs /dev/loop0: 
322 creating an ext2 file system through /dev/loop0 into the file lfs.disk
323 instead of an block device 
324 (like e.g. /dev/hda1).
325 ________________________________________________________________________________
327 Mounting the new partition
329         mount /dev/loop0 /mnt/lfs
331 And again the static part:
333         mkdir /mnt/lfs/static
334         mount /dev/loop1 /mnt/lfs/static
335 ________________________________________________________________________________
337 Command explanations
339 You don't really expect me to explain commands like that, hm?
340 ________________________________________________________________________________
342 Where to put the sources
343 ========================
345 When using this hint, you're possibly about to have space problems. You
346 can reduce such by putting the sources to your usual partitions, using
347 an extra terminal to extract the source package you intend to compile
348 and apply the patches by using the following commands
350         cd /mnt/lfs/<sourcedir>/<packagedir> &&
351         bzcat <patch> | patch -Np1
353 Of course you can delete every packagedir after installation.
356 Halting the Building of LFS
357 ===========================
359 So you found that building LFS using this hint takes too long to do it
360 in one pass? Never mind. All you have to do is save the system in a
361 secure state so you can shut down safely. When in chroot'ed mode, first
363         umount /proc
365 Then exit the chrooted mode. If you got a static volume, you sure want
368         umount /mnt/lfs/static
370 before you
372         umount /mnt/lfs
374 Now you can set back the loop devices:
376         losetup -d /dev/loop0
378 and for the static part
380         losetup -d /dev/loop1
382 Now you can safely shut down your system. When you start again, you need
383 to perform those steps "backwards", like you already did in the
384 beginning:
386         losetup lfs.disk /dev/loop0
387         losetup static.disk /dev/loop1
388         mount /dev/loop0 /mnt/lfs
389         mount /dev/loop1 /mnt/lfs/static
391 chroot and mount proc if necessary (use the commands you find in the LFS
392 Book, they may differ from version to version). Omit the "/dev/loop1"
393 stuff (every 2nd line) if you've not using a static volume.
395 ________________________________________________________________________________
398 Go on with LFS
399 ============== 
401 The following steps are quite the same. The only differences starts again when 
402 you want to make this drive bootable:
404 Part II, Chapter 8
405 ==================
407 Making the LFS System bootable.
409 A thought on making the kernel in LFS: why reconfigure everything? Even
410 if you've got an old kernel, most of the things you've chosen (or not)
411 during kernel configuration have not changed a bit. You could fasten up
412 this if instead of
414         make menuconfig
416 using out of the chroot'ed environment
418         cp /usr/src/linux/.config $LFS/usr/src/linux
419         <enter chroot>
420         make oldconfig
422 Now you only get asked on the things that weren't configured with your
423 new kernel (which should be somewhat less work than choosing every
424 menu). If you're unsure, you could still check it with "make menuconfig".
426 Make your kernel and /etc/lilo.conf in the chroot'ed environment as described 
427 in the LFS book. Don't try to start lilo now! Stop here! I hope you're
428 still in the chroot'ed environment, otherwise go back there.
430 The only bootable partition you've got is the one your current distro is 
431 running on. 
433 If you want to use the /tmp/lfs.disk file for anything else than
434 installing LFS over your distribution, you'll probably not need the
435 following part.
437 You're about to install LFS on the partition, deleting the distro. But
438 before you get started, read the following warning carefully:
440 --------------------------------------------------------------------------------
441                 Do yourself a real big favour and get a bootdisk! 
442 --------------------------------------------------------------------------------
444 If you delete your distribution and have a power failure, you would lose
445 your whole system (including the lfs.disk file that you can't access
446 anymore without a bootable linux system).
447 ________________________________________________________________________________
449 Mounting the main partition
451 Mount the main partition to "/mnt" in the chroot'ed environment suggesting your 
452 main partition is /dev/hda1, otherwise fill in what is necessary:
454         mount /dev/hda1 /mnt
456 Explanations of the command shouldn't be necessary. Just to help your 
457 imagination. The main partition is now mounted to a directory in a file 
458 attached to a block device which is mounted on the main partition (that is 
459 mounted to a directory...). This is a nice example for recursion. And this 
460 could get another nice example of an almost infinite loop (depending on your 
461 harddisk's size), if you try to copy everything to mount. Or an destructive 
462 loop, if you try to delete everything in /mnt (because this also holds the 
463 file currently working as your root environment). If you're asking what I'm
464 talking about, never mind, just follow the next instructions very carefully.
465 ________________________________________________________________________________
467 Making sure init finds his getty
469 If you're not completely puzzled about that headline, you could go
470 straight to the following paragraph. "init" is the process that is
471 started by the kernel to start everything else during the bootup.
472 Everything else, that is, all calls that are in /etc/inittab. In this
473 inittab, you should find some version program getty, for example agetty
474 or mgetty, but maybe only getty. This program is used to load the
475 programs that allow you to login into your system. Now imagine you
476 delete the whole old stuff including the old getty. Imagine further the
477 LFS's agetty is different from the distro's version, or in a different
478 directory (Debian, for example, uses getty). The inittab should remain
479 in the memory. Init would try (on your next login) to use a getty that's
480 not there, meaning you wouldn't be able anymore to login into your
481 system.
483 Before you logout of the chroot'ed system you should be sure that the
484 init process will find the version of getty named in the inittab,
485 otherwise you would be unable to access the system anymore and need the
486 the bootdisk! A short
488         cat /mnt/etc/inittab | grep getty
490 shows wether your previous system is using getty, agetty, mgetty or any
491 other version possible. If it's using any other version than agetty
492 (that's what Linux From Scratch is using), you should do a symlink like
494         ln -s /sbin/agetty /sbin/<the previous getty version>
496 Now you can safely replace the old system.
497 ________________________________________________________________________________
499 Command Explanations
501 cat /mnt/etc/inittab | grep getty:
503 Writes the content of /mnt/etc/inittab (your previous' systems inittab) to the
504 standard output, piping it to grep, which filters out all lines not bearing 
505 "getty" in it.
507 ln -s /sbin/agetty /sbin/<the previous getty version>:
509 Making a symbolic link that init will follow from the old getty version to the
510 new one.
511 ________________________________________________________________________________
513 Deleting the previous System
515 You'll have to get the main partition entirely clean from everything that is not
516 /tmp/lfs.disk (and proc, which holds another file system).
518         for dirname in `ls -1 /mnt | sed -e /tmp/d -e /proc/d -e /mnt/d`; 
519         do rm -r /mnt/$dirname; done &&
520         for filename in `ls /mnt/tmp | sed s/lfs.disk//`; do 
521         rm $filename; done
523 Now it's clean enough for copying the LFS system. 
524 ________________________________________________________________________________
526 Command explanations
528 for dirname/filename in <list>; do <command>; done:
530 performing <command> in a bash loop for every entry of <list>. The command in 
531 this case is simply deleting the directory or file named in the entry.
533 'ls -1 /mnt ...':
535 These kind of apostrophs let bash execute the commands inside and giving the 
536 result back as string, so we could use it as a <list> for our bash loop.
537 ls -1 /mnt lists all files in /mnt using 1 line per entry for easier editing 
538 with sed.
540 '... | sed -e /tmp/d -e /proc/d -e /mnt/d':
542 We are piping the result of "ls" to sed. -e states the following string to be
543 a (regular) expression. /.../d deletes the first line to have the expression 
544 ... in it. So we're taking /mnt/tmp, /mnt/proc and /mnt/mnt out of the list.
545 ________________________________________________________________________________
548 Now we may copy the new system. Everything but the /mnt directory, to which 
549 the device that we are filling with LFS is mounted and the directory /proc, in 
550 which are dynamic files written by the kernel.
552         for dirname in `ls -1 / | sed -e /mnt/d -e /proc/d -e /tmp/d`; do 
553         cp -a $dirname /mnt; done
554 ________________________________________________________________________________
556 Command explanations
558 cp -a ... /mnt:
560 copies in "archive" mode, so the whole directories are copies with their 
561 content and all subdirs and all filemodes are kept, if possible. For the 
562 for ...; do; done constructions look at the previous command explanation.
563 ________________________________________________________________________________
565 Now the LFS is on your primary partition logout of the chroot'ed environment 
566 into the new system. Now you can perform lilo and this stuff.
568         logout (or exit)
569         cd /
570         umount /mnt/lfs/proc
571         umount /mnt/lfs
572         losetup -d /dev/loop0
573 ________________________________________________________________________________
575 Command explanations
577 logout/exit:
579 Get out of 1. a bash, 2. a chroot'ed environment.
581 cd /
583 we change to the root dir not to have former access on the device we're
584 about to unmount.
586 umount...
588 First we need to unmount the proc device from the loop device, so you
589 can unmount this.
591 losetup -d /dev/loop0
593 delete the binding from /dev/loop0 to /tmp/lfs.disk.
594 ________________________________________________________________________________
596 You may now delete lfs.disk, unless you don't want to use it otherwise.
598 After doing LFS another few times I found out that booting on an loop
599 device is quite unpractical due to the lack of speed and memory (I don't 
600 think that everyone has 1GB+ of RAM). What you can do is use gparted or 
601 any similar program to resize your actual partition, make another bootable 
602 partition on the PC you want to install the LFS on, and then
604         dd if=/tmp/lfs.disk of=/dev/hda2
606 Use the node of the new partition instead of /dev/hda2.
608 You could also pipe the disk dump to install over network. If anybody is
609 planning an LFS installation like that I beg you to contact me via
610 irc.linuxfromscratch.org to 1. get further support and 2. let me share
611 your experience.
613 Then you can get back to the book (installing LILO and all that stuff).
615 Good luck!
618 The Future of this Hint
619 =======================
621 First of all, LFS, Linux and this hint are hobbies to me, so I can only
622 hope for spare time to test, correct and complement this hint. Even
623 then, a few additions would be of interest:
625 - maybe you could make sort of a bootdisk image (rootfs only), copy it
626   to a ramdisk and use this to work on the main partition - which would
627   be especially useful for a reiserfs installation!
629 - it could be helpful to be able to resize the lfs.disk file if
630   necessary. dd could be used to add size to the file, resize2fs will be
631   needed for the filesystem.
633 - same goes for a decrease in size of those files.
635 Since I use my systems for serious work, I'm not all eager to play
636 around with them that much. If you got a system you want to use for such
637 testing (to help me? How nice!), please contact me.
639 ________________________________________________________________________________
641 Alex [LX]
642 (alex@22-music.com) - hope to meet you at #lfs on irc.linuxfromscratch.org