=========================== Linux Server Administration - reboot/shutdown, backups =========================== -IAN! idallen@idallen.ca Shutdown and Reboot ------------------- Unlike a Knoppix CDROM running purely in memory with no disk partitions mounted, a Unix/Linux machine that has parts of a hard disk mounted should never be powered off or reset without a "clean" shut down. The O/S kernel keeps disk information in memory - if you power off the machine, that memory is never written to disk and corruption of the disk partition may result. This rule applies whenever you have real hard disk partitions mounted, even if you have hard disk partitions mounted in Knoppix. Unmount all your disk partitions before you power off the machine. Doing a clean "shutdown" of the machine does this for you. To shut down cleanly any Unix/Linux system from a terminal, become the root super-user and type: # shutdown -h now The "-h" means "halt the system". You can also use "-r" for "reboot". Backups and cloning ------------------- If your hard disk has enough space, you can keep duplicate backups of your Mini system in other partitions on your disk. This will save you time if you damage your Mini system and have to start over. Keeping a "pure" copy of your upgraded Mini system for restore purposes may save you from re-install and long re-update process later. There are many ways to keep these backups. Here are two, A & B: A. Archival (non-bootable) backup partitions: This method makes a copy of your current Mini system (in partition 5) to another partition (e.g. partition 6, 7, 8, etc.) but does not make changes to the other partition to make it bootable. If something damages partition 5, you can erase partition 5 and take the archived version and copy it back to partition 5 to restore a known state. You can create and save as many copies as you have disk space. Only the one partition (usually #5) is bootable; the others are simply archival backup copies. Creating a non-bootable archive backup copy of your current partition (#5): a) use fdisk or cfdisk to create a new logical partition number N that is large enough to hold everything in your current partition b) use mke2fs to create a Linux file system in the new partition number N: # mke2fs -j /dev/hdXN # change X and N (if this fails with "no such device or address", reboot and try again) c) mount the new empty partition number N: # mkdir -p /mnt/hdXN # change X and N # mount /dev/hdXN /mnt/hdXN # change X and N d) copy the root of the current partition to the new partition: # cp -ax / /mnt/hdXN # change X and N e) unmount it: # umount /mnt/hdXN # change X and N Note that the archival backup partition is not properly bootable, since we haven't changed any of its files to know that it is now living on partition N, not partition 5. Attempts to boot the archival backup will cause it cross-link back to its old home on partition 5, which is a Bad Thing. Do not boot archival backup partitions - use them for storage only. Restoring from the archival backup to the current partition (#5): It is not always safe to try to a full restore of an entire backup partition into the partition you are currently running. You can safely copy back a few files; but, the safest way to do a full partition restore is to boot a rescue disk (e.g. Knoppix), mount the backup partition, erase the current partition (#5), mount the empty current partition, and then do the copy from the backup to the current: a) boot Knoppix or some other rescue system - do not boot the partition you will be copying into! b) mount the backup partition number N: # mkdir -p /mnt/hdXN # change X and N # mount /dev/hdXN /mnt/hdXN # change X and N c) erase the current partition (usually number 5 in this course): # mke2fs -j /dev/hdX5 # change X d) mount the empty current partition (usually number 5 in this course): # mkdir -p /mnt/hdX5 # change X # mount /dev/hdX5 /mnt/hdX5 # change X e) copy the backup partition to the empty current partition: # cp -ax /mnt/hdXN /mnt/hdX5 # change X and N f) unmount both partitions and reboot: # umount /mnt/hdXN # change X and N # umount /mnt/hdX5 # change X # shutdown -r now When you reboot the current partition, it will be using the restored data from the backup partition. You can have many backup partitions - save your work often! Do *NOT* try to boot or use the archival backup partitions directly (see above for why). B. Alternating or serial bootable backup partitions: Using this backup system, you keep multiple bootable partitions, always copying everything and booting a new partition before making any major change to the system. If anything goes wrong with the changes, you can boot back into the previous partition, re-copy it to a new partition, re-boot into the new partition, and try the changes again. If you find something doesn't work in the current system, you can reboot to a previous system and see if it worked "before". Summary of this "serial bootable" backup system: - copy your Mini system into a new partition - adjust the configuration of the copy in the new partition so that it can be booted (edit /etc/fstab) - make a GRUB boot entry for the new partition (edit menu.lst) - boot into the copied Mini system - carry on and make changes in the new system - repeat as necessary You can keep as many bootable partitions as you have space for. Creating a bootable copy of your current partition: a) use fdisk or cfdisk to create a new logical partition number N that is large enough to hold everything in your current partition b) use mke2fs to create a Linux file system in the new partition number N: # mke2fs -j /dev/hdXN # change X and N (if this fails with "no such device or address", reboot and try again) c) mount the new empty partition number N: # mkdir -p /mnt/hdXN # change X and N # mount /dev/hdXN /mnt/hdXN # change X and N d) copy the root of the current partition to the new partition: # cp -ax / /mnt/hdXN # change X and N e) fix the ROOT mount point /etc/fstab in the new partition: - edit the fstab file in your new partition N: # vi /mnt/hdXN/etc/fstab - change only the root partition (usually the first line) to be the new /dev/hdXN number of the new partition, e.g. you might change /dev/hda5 to /dev/hda6 (use the actual X and N from above) - do *NOT* change any other lines; they are still correct - write out the fstab file f) create a GRUB menu entry to boot the new partition N: Add three lines to your GRUB menu.lst file (located in partition 1). Change 'N' to be your new Linux partition number, 'Z' to be its GRUB number (one less than 'N'), and change 'Y' to be the GRUB number of your disk (probably 0 if you have only one disk): title extra-Nth kernel (hdY,Z)/boot/vmlinuz root=/dev/hdXN vga=791 initrd (hdY,Z)/boot/initrd.img g) unmount your new partition and reboot: # umount /mnt/hdXN # change X and N # shutdown -r now You can keep "cloning forward" your Mini system into new partitions as you make changes and want to take checkpoints. If anything breaks, you simply move back to a previous copy and re-clone. When you run out of disk space for new clones, you can start erasing and overwriting earlier clone copies. You can keep a "ring" of backup Mini systems: Device Boot Start End Blocks Id System /dev/hda1 * 1 98 49360+ 83 Linux /dev/hda2 99 583 244440 82 Linux swap /dev/hda3 584 1940 683928 83 Linux /dev/hda4 1941 100640 40944960 5 Extended /dev/hda5 1941 3971 1023592+ 83 Linux /dev/hda6 3972 6002 1023592+ 83 Linux /dev/hda7 6003 8033 1023592+ 83 Linux /dev/hda8 8034 10064 1023592+ 83 Linux