04-04-2014, 10:47 PM
(This post was last modified: 04-05-2014, 12:31 AM by gold_finger.)
How To Create and Use a Separate Data Partition
There are advantages to creating a completely separate partition for your data files instead of keeping them on a dedicated /home partition, or on the / (root) partition with the system files. Here are a few:
1. Makes use and sharing of data easier between different operating systems on the computer (Windows or Linux). Instead of having data created while using each OS saved to its own location, they can all read/write data to one central location.
2. Eliminates potential problems with more than one Linux distro using the same /home partition, where the user program configuration files may conflict with each other. (Although it's more rare, this can also happen when upgrading a distro to the latest version of itself.)
3. Makes re-installation of the operating system, upgrading to new distro versions, and switching to different distros easier. Data is safely off on its own partition, so no need to copy it back on after a new install. Just link to the partition again after replacing the root partition with the new installation.
4. Save time for newbies and experienced users whose system gets broken for some reason, requiring a re-installation. No need to attempt accessing broken install to copy off data before replacing the system -- it's already safely off in its own location.
Notes on example used in this tutorial:
1. Mount points can be anywhere you like, but are most typically made under /mnt, /media, or your /home. This example has the mount point under /mnt.
2. You can name your mount point anything you want as long as it doesn't conflict with an already existing filename under that location (mount point). This example uses the name "DATA".
3. Anywhere you see "yourusername" in a command, you are supposed to substitute your actual user name in it's place.
4. The location of the data partition on the drive for this example is /dev/sda5. Make sure you substitute your specific partition in place of sda5 when running these commands.
5. If you want to also have a separate /home partition to preserve your config files for future reinstallations, feel free to do that. That will have no effect on anything below. (Just remember that it will not need to be more than a few GB's in size if it's only holding the config files.)
6. Everything below is done using commands in a terminal. (I've never tried using a GUI, don't know if it's even possible to use a GUI, and wouldn't bother learning the GUI if it were possible because the terminal is quicker.)
Use GParted from a live Linux DVD/USB to create the partitions you want for the operating systems you plan to install. Or use it to make changes, additions, re-sizings, etc. to the partitions already on the disk. Create your data partition and format it according to your needs -- eg. Ext4 if to be used with Linux distros; NTFS if to be shared with a Windows OS. (Here is a good tutorial for GParted if you need it: GParted partitioning software - Full tutorial.)
After installing a Linux operating system, create a mount point for the data partition (eg. /mnt/DATA)
Mount the partition
Take ownership of the mount point
Navigate to the new data mount point
Create typical home folders and any others you want for your data
Find out the UUID# for your data partition
Open your fstab file and make an entry to auto-mount the partition on boot
In leafpad, add either of the two examples below and substitute your UUID# in place of ones below.
Save the changes to fstab and close the text editor.
Now you have a choice to either use "symlinks" between home and the data partition or to "bind" each directory in the data partition to the existing directories in home.
If you use symlinks, delete the existing folders in /home/yourusername that you made duplicates of in the data partition. (I always leave the "Desktop" folder in /home/yourusername and don't create that on the DATA partition.) Then create symlinks for each following this format:
If you bind the directories to home, keep the existing directories in /home/yourusername and follow these instructions (recommend using option #3 -- "Auto Mount at Boot by creating your own Upstart script"):
HowTo: Using Bind to Remount Part of a Partition
That's it. Now your data files will end up on the separate data partition and everything will automatically work that way each time you boot into any OS.
There are advantages to creating a completely separate partition for your data files instead of keeping them on a dedicated /home partition, or on the / (root) partition with the system files. Here are a few:
1. Makes use and sharing of data easier between different operating systems on the computer (Windows or Linux). Instead of having data created while using each OS saved to its own location, they can all read/write data to one central location.
2. Eliminates potential problems with more than one Linux distro using the same /home partition, where the user program configuration files may conflict with each other. (Although it's more rare, this can also happen when upgrading a distro to the latest version of itself.)
3. Makes re-installation of the operating system, upgrading to new distro versions, and switching to different distros easier. Data is safely off on its own partition, so no need to copy it back on after a new install. Just link to the partition again after replacing the root partition with the new installation.
4. Save time for newbies and experienced users whose system gets broken for some reason, requiring a re-installation. No need to attempt accessing broken install to copy off data before replacing the system -- it's already safely off in its own location.
Notes on example used in this tutorial:
1. Mount points can be anywhere you like, but are most typically made under /mnt, /media, or your /home. This example has the mount point under /mnt.
2. You can name your mount point anything you want as long as it doesn't conflict with an already existing filename under that location (mount point). This example uses the name "DATA".
3. Anywhere you see "yourusername" in a command, you are supposed to substitute your actual user name in it's place.
4. The location of the data partition on the drive for this example is /dev/sda5. Make sure you substitute your specific partition in place of sda5 when running these commands.
5. If you want to also have a separate /home partition to preserve your config files for future reinstallations, feel free to do that. That will have no effect on anything below. (Just remember that it will not need to be more than a few GB's in size if it's only holding the config files.)
6. Everything below is done using commands in a terminal. (I've never tried using a GUI, don't know if it's even possible to use a GUI, and wouldn't bother learning the GUI if it were possible because the terminal is quicker.)
Use GParted from a live Linux DVD/USB to create the partitions you want for the operating systems you plan to install. Or use it to make changes, additions, re-sizings, etc. to the partitions already on the disk. Create your data partition and format it according to your needs -- eg. Ext4 if to be used with Linux distros; NTFS if to be shared with a Windows OS. (Here is a good tutorial for GParted if you need it: GParted partitioning software - Full tutorial.)
After installing a Linux operating system, create a mount point for the data partition (eg. /mnt/DATA)
Code:
sudo mkdir /mnt/DATA
Mount the partition
Code:
sudo mount /dev/sda5 /mnt/DATA
Take ownership of the mount point
Code:
sudo chown -R yourusername: /mnt/DATA
Navigate to the new data mount point
Code:
cd /mnt/DATA
Create typical home folders and any others you want for your data
Code:
mkdir Documents Downloads Music Pictures Videos
Find out the UUID# for your data partition
Code:
sudo blkid
Open your fstab file and make an entry to auto-mount the partition on boot
Code:
gksu leafpad /etc/fstab
In leafpad, add either of the two examples below and substitute your UUID# in place of ones below.
- * For an Ext4 formatted partition, add an entry like this to end of file
Code:
# Mount DATA partition under /mnt/DATA
UUID=ceee2524-7df2-4d21-a1f7-9e7e55c722cc /mnt/DATA ext4 defaults 0 2
- * For an NTFS formatted partition (used if sharing with Windows), add an entry like this to end of file
Code:
# Mount DATA partition under /mnt/DATA
UUID=747D4C9C1EFAD1F2 /mnt/DATA ntfs-3g defaults,windows_names,locale=en_US.utf8 0 0
Save the changes to fstab and close the text editor.
Now you have a choice to either use "symlinks" between home and the data partition or to "bind" each directory in the data partition to the existing directories in home.
If you use symlinks, delete the existing folders in /home/yourusername that you made duplicates of in the data partition. (I always leave the "Desktop" folder in /home/yourusername and don't create that on the DATA partition.) Then create symlinks for each following this format:
Code:
ln -s /mnt/DATA/Documents /home/yourusername
If you bind the directories to home, keep the existing directories in /home/yourusername and follow these instructions (recommend using option #3 -- "Auto Mount at Boot by creating your own Upstart script"):
HowTo: Using Bind to Remount Part of a Partition
That's it. Now your data files will end up on the separate data partition and everything will automatically work that way each time you boot into any OS.
Try Linux Beginner Search Engine for answers to Linux questions.