Linux Partitions & Second Hard Drive with Back-up Script
Updated: 2012-01-04, Ubuntu 10.04.03 LTS, with thumbnails for small screens.
Summary: This page shows methods that can be used to partition a hard drive and add a second hard disk to a computer running Ubuntu linux. You MUST MAKE BACKUPS of any important files whenever you change the partitioning on a hard drive. You can easily wipe your drive with no chance of recovery.
Note: If you are creating a new computer and have two hard drives, I have found it to be easier to get the operating system installed with only one hard drive and then add the second hard drive after powering down your new system.
-
Install The Software:
Since the latest Ubuntu distribution comes with a very nice disk utility, the only software you need to install is gnome-schedule, to easily schedule cron jobs. There is another disk info and partitioning program, called gparted if you want to compare them.
me@myhost$ sudo apt-get install gnome-schedule gparted -
Partitions Info:
WARNING: REMEMBER that deleting /removing a partition will ERASE ALL DATA on the partition! There is no "undo".
To find out the details about your storage divices, go to System --> Amdinistration --> Disk Utility. Normally, it is best to decide on your partioning scheme BEFORE you install an operating system. Here are thumbnails of both the Disk Utility and the gparted programs. Click for a closer look.
If you want to change partitions, you must first unmount them. Here is some important gparted documentation. I believe gparted is used from the Ubuntu live CD, for example, if you want to create a separate "/home" partition. You can switch which hard drive you are looking at by selecting from the drop-down menu on the right. Before creating new partitions, remove the old one(s) first, as a separate step.
-
Mount Second Hard Drive by editing /etc/fstab:
WARNING: You can seriously mess up access to your system if you ruin the fstab (Filesystem Table) file. Make sure you make a backup FIRST and know how to revert to it.
On a home system it is easy enough to edit the /etc/fstab file using gedit:
me@myhost$ sudo gedit /etc/fstabI suggest you follow the suggestions in the file and make your changes robust by getting a UUID number. In a separate terminal, the command for drive /dev/sda1 (see above) would be:
me@myhost$ sudo blkid -o value -s UUID /dev/sda1Enter the data using the spacing of the lines above it. In my example, the "/", "/home", and "swap" partitions are all on the same disk, but have different UUID numbers generated at installation. For my 2 backup disks, I manually enterd the names "/bu300" and "/bu250" after I had created these directories (folders) at the top level.
# /etc/fstab: static file system information.
#
#[PARTIAL FILE: Columns are as follows: file system name, mount point, type of filesystem, options, dump, and pass. I have no idea what dump and pass are...]
#
UUID=27ad31b0-2a9d-4ed2-89a4-5cc028088664 / ext4 errors=remount-ro 0 1
UUID=edbed3cc-dd0a-404c-898e-551eb41a1bb3 /home ext4 defaults 0 2
UUID=99e91184-e43b-4889-8bfb-ae86017ed5ec none swap sw 0 0
UUID=ab5830c2-6591-48f9-854e-ee702ccdda5b /bu300 ext4 defaults 0 0
UUID=43ff7d13-ece5-4459-9a0c-8421d86d51a0 /bu250 ext4 defaults 0 0
There is a graphical program (GUI) that may help you do this called Storage Device Manager (search in Synaptic). I have successfully used it with a second hard drive, but now use the direct method described above.
-
Create & Run A Backup Script Using rsync:
Give yourself permissions if necessary on your /backup drive:
me@myhost$ sudo chown -R USER_NAME /backup
me@myhost$ sudo chgrp -R USER_NAME /backupThe program rsync efficiently synchronizes two folders by only modifying the parts of the final directory that have changed since the last synchronization. The -av options DO NOT delete files, however, they only update changed files and add new ones. You need to eventually "clean up" the /backup folder of stuff you REALLY want to delete.
Below is an sample backup script that matches the default files in a Ubuntu Linux installation. In this example the only mount point created was /backup for a single backup hard drive. You need to substitute your user name for USER_NAME. I create and extra folder called "Voice" for lectures, foreign language CDs, etc. You need to delete the comment sign "#" to use.
rsync -av /home/USER_NAME/Documents/ /backup/Documents
rsync -av /home/USER_NAME/Downloads/ /backup/Downloads
rsync -av /home/USER_NAME/Music/ /backup/Music
rsync -av /home/USER_NAME/Pictures/ /backup/Pictures
rsync -av /home/USER_NAME/Public/ /backup/Public
rsync -av /home/USER_NAME/Videos/ /backup/Videos
#rsync -av /home/USER_NAME/Voice/ /backup/Voice
You can create a cron job easily using the GUI tool gnome-schedule Applications --> System Tools --> Schedule. If you named your backup script above "backup.sh" in your home directory, then the "Command" box in Schedule would be "/home/USER_NAME/backup.sh". Schedule it for once a day when you know your computer will be on and CHECK IT OFTEN to be sure your files are getting backed up.




