Rolling Out Linux - page 4
Another method I sometimes use is to bypass the installation process entirely by copying a disk image from a correctly configured machine to the new one. Change a few settings and you have a clone of the original. This method works best if you have identical hardware, although different ethernet cards etc. could work ok, with a careful kernel module set up.
I have only tested these methods with Debian and Slackware, but in principle they should work just fine with other Linux distributions
Take off the Lid
The crudest way to do this is to get out your screwdriver and take the lids off both machines. Then plug take the disk out of one into a spare disk controller cable on the the other.
Incidentally, several people I have talked to in the UK and Europe routinely export configured hard disks with images of Linux on them to US server farms. Once they reach their destination they are plugged into a machine as an ordinary disk. Usually the furthest I take it a server disk is into the next office--but you get the idea!
Anyway, back to the task in hand of cloning a server.
To achieve this, the properly configured disk is plugged in the new machine as a secondary. You may need to alter jumpers on an IDE disk to make it act as a slave, or change the id on a SCSI disk. If you are unsure what the jumper settings are for your disk, then the manufacturers' web sites are usually very helpful. You would then typically want to boot from a rescue or install floppy, get a shell and then type
dd if=/dev/hdb of=/dev/hda bs=1024k
The parameters for the dd command are the input if= which is the old disk, the output of= which is the new disk and the blocksize, which depends on the disk's cache, but typical figures would be 64k on a small modern IDE to 2048k on a ultrawide SCSI with much larger cache
/dev/hda is the default name for the first IDE disk and
/dev/hdb the default for the second IDE disk. For machines that already have more than one disk fitted or that are using SCSI you will have to adjust this command
If you do not have identical hardware on both machines then a command like
dd if=/dev/hdb1 of=/dev/hda1 bs=1024k
is better. In this case
/dev/hdb1 is the first partition on the old disk and /dev/hda1 is the partition on the target disk. You will have use fsck and lilo to get things straight in this case--see below.
Copying disk images over the net
There is another way to copy whole images of disks from a machine already set up.
Instead of installing afresh from a distribution CD or via ftp you can copy the disk image over a local network connection.
The advantage of this approach is that there is no need to take the machines to pieces or alter any jumpers. It is also faster than a NFS network install. This method takes around 20 minutes to copy 800 Meg of disk space even with 10BaseT ethernet and cheap realtek ethernet cards if you follow the directions below.
The disadvantage is that this isn't a method that distribution makers seem to have considered, so an important tool which is needed is missing. This tool is an easy way to copy data over a local network. But of course I have found a simple way round this, and have put the tools on a special floppy disk. The floppy disk image is here.
Just download it and use rawrite or dd as explained in any Installation guide to copy it onto a blank, formatted floppy
Now are you ready with your cables and floppy disks? Let's go.
Use an ordinary Linux boot/install floppy to start up and then configure networking.Next go and grab a configured machine and alter its network settings to be very insecure. Basically you want root to allow unauthenticated remote shells, which is a very bad idea on a live network.
To do this alter /etc/hosts.allow to allow access from the new machine to be configured, uncomment the line
#shell stream tcp nowait root /usr/sbin/tcpd /usr/sbin/ in.rshd
In /etc/inetd.conf by removing the leading # sign. Then use the command
killall -HUP inetd
to ensure that the changes to the configuration file are read.
For more details on
/etc/hosts.allow see our network security article.
Add the hostname of the target machine to
/etc/hosts and then add its name to the root .rhost file. (Be sure to undo these changes on the source machine before it goes back on a live network.)
To get maximum network bandwidth I use a UTP crossover cable to directly connect the two machines together without the use of a hub.
These cables are widely available and great for direct machine to machine connections! They should work fine with 100BaseT but if you are using gigabyte ethernet my understanding is that the crossover cable will not work.
Once you have the two machine up and running, one off a bootdisk, and the other as standard multiuser on the bootdisk equipped machine, follow through the install until networking is configured. This might take approximately 5 minutes if you are not used to it. I find that the easiest thing to do is to partition the disk as you would like to see it in the end and "install" to a spare hard disk partition. If you want the "real" copy of Linux to go on
/dev/hda1 then it is a good idea to tell installation at this point to use
/dev/hda5 or another spare partition. After you have got to the stage where networking is enabled and se,tup, get a shell up, swap in our standalone rsh floppy, and say
mount /dev/fd0 /mnt
/mnt/rsh 10.0.0.1 "dd if=/dev/hda1 bs=1500" > /dev/hda1
Where 10.0.0.1 is the IP address of the other machine, the input file if= is the the disk partition you wish to copy from the remote, and the bs= blocksize is 1500 bytes to optimise the ethernet connection. The final /dev/hda1 is the redirect to the hard disk on the local machine. See the notes in the section above for more details on the dd command.
This step takes a few minutes. For example using 10BaseT and copying a 900Meg partition between a pair of new K6s took 17 minutes 41 seconds in testing.
After copying disk images with either of these techniques, there is some cleaning up to do on the target machine. To do this, it is best to "forget about" the install you just did, by rebooting This eats into your time, but i found a problem with the lilo phase below when I didn't reboot.
After rebooting, get a shell and run fsck on the root partition..
fsck -y /dev/hda1
Next mount the new hard disk's root partition.
mount /dev/hda1 /target
/target/etc/init.d/network to give the machine it's new ip and hostname. Then do
lilo -v -r /target
to install lilo correctly pointing at the new kernel.
Finally, type in
just to be paranoid that your alterations to the hostname and network are flushed to the harddisk.
Then you can reboot and the new machine should work the same as the old one.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: CoreOS, Oracle Enterprise Linux 7 and Ubuntu 14.10
- 5Linux Top 3: Knoppix 7.3, Slacko Puppy 5.7 and PC-BSD 10.0.1