![]() | ![]() |
|
HOWTO Clone Disk Images on Linux Booted from a Network2002-09-09
1. Legal Notices1.2. CopyrightCopyright (c) 2002 Guilherme Tupynamb� Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License (GFDL), Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. The clone script is licensed in the terms of the GNU General Public License (GPL). 2. Introduction3. Setting up DHCP and TFTP servers3.1. Setting up DHCPInstall DHCP, if not installed, from the rpm package, normally found in Linux distributions:
3.2. Setting up TFTPSetting up TFTP is almost as easy as DHCP. First install from the rpm package:
Create a directory for the files:
Edit the file /etc/xinetd.d/tftp to look like the following:
4. Preparing boot files4.1. KernelIdentify the compressed kernel file:
4.2. Files on initrdNext, make the root file system image for the client. The full listing of the files is in Appendix A. These files have been taken from a working system as a minimum configuration for having powerful shell (bash), client network utilities (dhcpcd and tftp), and copying and compressing utilities (dd, gzip). Administrative commands (mknod, mount, fdisk and insmod) are also present. In the working directory create a file named initrd.lst and put these file names on it. To check the existence of these files in your system, run the following command:
You should get an error output like this:
The first error is a script to be created in the working directory. The second error is the program tftp found in the directory /usr/bin instead of /bin. The third is the network interface card module (probably not yours) found in the directory /lib/modules/$(uname -r)/kernel/drivers/net. These three files will be discussed in upcoming sections separately soon. If there are other missing files, check for lack of installation or differences in version, distribution or hardware. Adjust the list to match your system. 4.3. Packing initrd
Edit the clone script found in Appendix B, changing the variables as explained in Section 6. Make it executable and copy it to the image directory:
Unmount, compress, and send the initrd image.
5. Booting from Grub floppy disk5.1. Grub menu fileIn the working directory create a file named grub.conf with the following content:
In the last four lines are the Grub commands to boot from network: 5.2. Compiling Grub with network supportTo compile Grub, first download the source tarball from the Grub web site and unpack it. Run configure specifying the menu file you just created and the network interface card model. Run make as usual.
Again, where you see 3c90x put the model of your network interface card. First check if it is supported by Grub. 6. Running the clone scriptThe clone script, shown in Appendix B, is not essential. You can make init=/bin/bash as a kernel parameter and end up with a shell from where you can run the available commands and programs. The script is presented here to show the commands in a formal way and to propose a way to reduce the possibility of damages resulting from mistyping. You have to change the variables tftp_server, nic_module, major_a, family_a and image_a according to your environment and application. Please note that the arrays major_a and family_a are corresponding. Wrong major number for a given family name will mislead the user. You can locate the major and minor numbers of the devices of interest (whole disks and partitions) by listing the /dev directory. The major and minor number are where the size of a regular file is, in the output of the command ls -l, separated by a comma.
The command set -e instructs the shell to abort the script should any command return non-zero code. The message"Kernel panic: Attempted to kill init!" will follow, as in case of normal end. Don't panic! This is normal, given the circumstances. Just turn off the computer. Press Ctrl-Alt-Del to have a smooth reboot before exiting the script to avoid this ugly message. The command insmod will load the network interface module and the command dhcpcd will start DHCP client. Note that the fact that Grub used DHCP during its boot has nothing to do with Linux doing the same. The script makes a big loop and, for each iteration, it asks for one of three operations: Copy from network to device, Copy from device to network or Run fdisk. Then the script asks which block device to use. The array major_a holds the major number for the block devices allowed to be used and the array family_a the respective names for the device families. Next, the script asks the minor number of the block device to be used. 7. Extending the solution7.1. Saving and restoring files instead of file systems
You have to put the mkdir and tar programs in the initrd image so that the script can use them. A. List of files on initrd
B. Clone script
References |
![]() |