Linux Lite Forums

Software - Support => Tutorials => Topic started by: gold_finger on April 04, 2014, 06:47:52 PM

Title: HowTo: Create and Use a Separate Data Partition
Post by: gold_finger on April 04, 2014, 06:47:52 PM
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/sda5Make 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 (http://www.dedoimedo.com/computers/gparted.html).)

After installing a Linux operating system, create a mount point for the data partition (eg. /mnt/DATA)
Code: [Select]
sudo mkdir /mnt/DATA
Mount the partition
Code: [Select]
sudo mount /dev/sda5 /mnt/DATA
Take ownership of the mount point
Code: [Select]
sudo chown -R yourusername: /mnt/DATA
Navigate to the new data mount point
Code: [Select]
cd /mnt/DATA
Create typical home folders and any others you want for your data
Code: [Select]
mkdir Documents Downloads Music Pictures Videos
Find out the UUID# for your data partition
Code: [Select]
sudo blkid
Open your fstab file and make an entry to auto-mount the partition on boot
Code: [Select]
gksu leafpad /etc/fstab
In leafpad, add either of the two examples below and substitute your UUID# in place of ones below.

Code: [Select]
# Mount DATA partition under /mnt/DATA
UUID=ceee2524-7df2-4d21-a1f7-9e7e55c722cc /mnt/DATA  ext4  defaults  0   2
Code: [Select]
# 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: [Select]
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 (http://forums.linuxmint.com/viewtopic.php?f=42&t=74321)

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.
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: Wirezfree on April 04, 2014, 08:47:21 PM
Hi gold_finger,

Very nice work...
This is very nice step by step procedure...
The link was also useful for the "Bind" option upstart.

David
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: gold_finger on April 04, 2014, 10:51:15 PM
Thanks Wirezfree.

Recognize that NTFS partition entry?

Stole it from your prior post because I don't have any Windows partitions myself.  :o

Have guided people through this several times now and decided to just make a tutorial so I don't keep writing the same thing over and over again.  Posted a copy here and one on the Mint forums.  Hopefully it's clear enough for people to follow.
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: Jerry on April 05, 2014, 01:23:15 AM
Fantastic tutorial!
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: Wirezfree on April 05, 2014, 06:00:33 PM
Thanks Wirezfree.

Recognize that NTFS partition entry?

Stole it from your prior post because I don't have any Windows partitions myself.  :o

Have guided people through this several times now and decided to just make a tutorial so I don't keep writing the same thing over and over again.
Posted a copy here and one on the Mint forums.  Hopefully it's clear enough for people to follow.

Hi gold_finger,

Yes, I thought... Now where have I seen this before.... mmmm

I have more or less got everything nailed down on my base install, the link to the different symlink/bind options was useful.

I have some errors in the dmesg.log, and because I'm cautious by nature, and before diving headlong in...
I want to see/check if any of these errors will/maybe come back and bite me at some point.


David
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: gold_finger on April 07, 2014, 02:58:57 PM
Fantastic tutorial!

Thanks Valtam.  Hope it comes in handy for people.
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: m654321 on August 06, 2014, 09:58:37 AM
Hi gold_finger,

This is to confirm that I tried your advice of 4th April in this thread on how to create & use a separate data partition for my dual boot set up (LL 1.0.8 with zorin 9) , and it worked! I used the symlink method for uniting both distros at a common data partition.  As a linux newbie that felt a real achievement, especially as I had to modify one of your lines of code!

In LL 1.0.8, the Terminal rejected the term 'Documents' in the following line:
ln -s /mnt/DATA/Documents /home/yourusername    (I didn't understand why you choose 'Documents' here especially as you had created several home folders in a previous line, i.e.
mkdir Documents Downloads Music Pictures Videos

So I changed it to..
ln -s /mnt/DATA /home/yourusername     (this worked)

I notice that when I boot up in either distro of the dual-boot, I have to go to the DATA link in /home and open it with administrator's password in order to access it, that is access is not automatic.  Otherwise it works really well.

Many thanks for this, gold_finger!

Kind regards
Mike

Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: gold_finger on August 07, 2014, 12:28:35 AM
m654321,

Glad to here this was useful for you.

The process can definitely be a bit confusing.  The most confusing part is what to do with the existing folders in your /home/username directory.

First, folders are created on the DATA partition to hold all of your files.  Easiest thing is to just use same names you normally have in the /home/username directory -- Documents, Downloads, Music, etc.  So the line that you referred to (mkdir Documents Downloads Music Pictures Videos) is doing that.  It's making the folders on the DATA partition.  (I'm sure you have done this step.)

The corresponding folders that already exist on /home/username will either need to be deleted, or not depending on which linking choice you pick.

When symlinking the existing folders in your home directory need to be deleted first.  If you don't delete them, then what will happen is you will be attempting to create a symlink directory that has the same name as an already existing one.  The system won't allow that.  So in the example, you need to delete the existing Documents folder in /home/username; then create the symlink from the DATA partition to /home/username with ln -s /mnt/DATA/Documents /home/username.  You'll then have a symlinked folder called "Documents" show back up in /home/username.

When using the bind method, what you're doing there can be thought of as re-mounting specific folders in the DATA partition to the /home/username location.  When mounting something, there needs to be a mount point.  Just like when you created the mount point of /mnt/DATA for the DATA partition, you need to have a mount point for the specific folders that you are binding (re-mounting) to /home/username.  So, in this situation you need to keep the existing folders.  They will now serve as mount points and the command would be:  mount --bind /mnt/DATA/Documents /home/username/Documents

To Summarize difference between the two methods:

Symlinking
Delete existing Documents folder from /home/username directory.  (Do the same for any other folders that you want located on the DATA partition.)
*  Then run command below to create a symlinked folder in /home/username that points back to /mnt/DATA/Documents.
Code: [Select]
ln -s /mnt/DATA/Documents /home/username*  When you open your /home/username directory you will now see the Documents folder again, but it's really just a link pointing back to the folder of that name on the DATA partition.
If you delete the Documents symlink, there will be no more listing for Documents in your home directory.  The files will still exist, but to see them you need to go to /mnt/DATA/Documents.

Binding
Keep the existing Documents folder in /home/username.  It will serve as a mount point to bind to from the DATA partition.
*  Run command below to bind the Documents folder on DATA partition to the folder located in /home/username.
Code: [Select]
mount --bind /mnt/DATA/Documents /home/username/Documents*  When you open your /home/username directory you will see the Documents folder.  That folder is not a link.  What you are seeing is the Documents folder on the DATA partition.
If you unbind the Documents folder you bound, you will still see a listing for Documents in your home directory.  If you then go into that /home/username/Documents folder, you will not see any of the files there.  The directory is there (because it was used as a mount point), but your files reside on /mnt/DATA/Documents.

Don't worry if you're still a bit confused.  It took me a while to wrap my head around it too.


Basically, it sounds like you had not deleted the existing folders in your home directory before trying to create the symlinks.  Also, sounds like you need to change ownership of either /mnt/DATA or /home/username/DATA, or both so you don't need to access as Administrator.

I'm guessing that you have a Documents, Downloads, Music, etc. folder in /home/username and in /home/username/DATA.  It you are saving things by navigating to /home/username/DATA, then picking the Documents (or other) folder in there to save to -- those DO end up on the DATA partition.  If you are saving to /home/username/Documents -- those DO NOT end up on the DATA partition.

It won't be hard to fix ownership and/or location mix-ups if you want to do that.
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: m654321 on March 10, 2018, 09:16:57 AM
Is it okay to symlink 'Desktop' to a separate physical data partition?


I ask this because goldfinger symlinked the usual directories, i.e. Documents, Downloads, etc,, but avoided 'Desktop'.


I wondered if there was a reason for this?


Mike
Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: tuto on September 05, 2018, 01:42:20 PM
Hi. I am new LinuxLite user and in this community.
 
I am using a dual-boot Windows 7 / LinuxLite 3.8. I did three partitions, with a DATA shared partition between both:

Code: [Select]
e-yole@yole-PC:~$ blkid -o list
device                        fs_type     label        mount point                       UUID
-----------------------------------------------------------------------------------------------------------------------------
/dev/sda1                     ntfs                     (not mounted)                     8C9853D09853B782
/dev/sda2                     ntfs        DATA         /mnt/DATA                         45EB77F618AAC695
/dev/sda5                     ext4        LinuxLite    /                                 22fb55a4-bd8b-4495-a5a1-9869f07e5b46
/dev/sda6                     swap                     [SWAP]                            13597903-198d-4b78-b90e-8bd11ad08045

I use bind method for DATA partition, but I known not as hide the /dev/sda1 partition (Disk C:\ in Windows OS) from Thunar file manager:

Code: [Select]
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda5 with label "LinuxLite" during installation.
UUID=22fb55a4-bd8b-4495-a5a1-9869f07e5b46 /               ext4    errors=remount-ro 0       1
# --------------------------------------------------------------------------------------------
# swap was on /dev/sda6 during installation.
UUID=13597903-198d-4b78-b90e-8bd11ad08045 none            swap    sw              0       0
# --------------------------------------------------------------------------------------------
# DATA directory in /mnt was created and your owner and group allows was
# changed to $USER:$USER. This shared data partition was on /dev/sda2 with
# label "DATA" during installation.
UUID=45EB77F618AAC695 /mnt/DATA ntfs-3g defaults,windows_names,locale=es_ES.utf-8  0      0
# --------------------------------------------------------------------------------------------
# Bind personal folders between /mnt/DATA partition and $HOME folders in
# after mount /dev/sda2 in /mnt/DATA directory only.
/mnt/DATA/Documentos /home/e-yole/Documentos auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Descargas /home/e-yole/Descargas auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Imágenes /home/e-yole/Imágenes auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Música /home/e-yole/Música auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Vídeos /home/e-yole/Vídeos auto bind,x-systemd.requires=/mnt/DATA 0      0
# --------------------------------------------------------------------------------------------
# For avoid inconsistencies in ntfs files systems on internal disks
# on computer with recent Windows or Linux OS's dual-booted, the
# hibernation and fast restart features was disabled, run Windows
# command 'powercfg /h off' as Administrator (see ntfs-3g man page).
# --------------------------------------------------------------------------------------------
# Windows OS (C:\ volume) /dev/sda1 partition is not show on desktop.
UUID=5C3ACAFB3ACAD0E6 /opt/sda1 ntfs noauto,ro,nouser 0     0

I have read that to use
Quote
hide
flag in Gparted would serve, but to boot from WindowsOS, that flag would be erased.

Any other idea is welcome...!

( I am sorry by bad English language use; I am learning it, yet.)

Title: Re: HowTo: Create and Use a Separate Data Partition
Post by: tuto on September 06, 2018, 09:57:11 PM
Update:
I found as hide the WindowsOS partition in LinuxLite session.

Using Menu>Settings>Disks application, I edit the mount options, uncheck box about mount at begin and show in user's interface. I also check box about to use additional credentials.

The final fstab file look:

Code: [Select]
e-yole@yole-PC:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda5 with label "LinuxLite" during installation.
UUID=22fb55a4-bd8b-4495-a5a1-9869f07e5b46 /               ext4    errors=remount-ro 0       1
# --------------------------------------------------------------------------------------------
# swap was on /dev/sda6 during installation.
UUID=13597903-198d-4b78-b90e-8bd11ad08045 none            swap    sw              0       0
# --------------------------------------------------------------------------------------------
# DATA directory in /mnt was created and your owner and group allows was
# changed to $USER:$USER. This shared data partition was on /dev/sda2 with
# label "DATA" during installation.
UUID=45EB77F618AAC695 /mnt/DATA ntfs-3g defaults,windows_names,locale=es_ES.utf-8  0      0
# --------------------------------------------------------------------------------------------
# Bind personal folders between /mnt/DATA partition and $HOME folders in
# after mount /dev/sda2 in /mnt/DATA directory only.
/mnt/DATA/Documentos /home/e-yole/Documentos auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Descargas /home/e-yole/Descargas auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Imágenes /home/e-yole/Imágenes auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Música /home/e-yole/Música auto bind,x-systemd.requires=/mnt/DATA 0      0
/mnt/DATA/Vídeos /home/e-yole/Vídeos auto bind,x-systemd.requires=/mnt/DATA 0      0
# --------------------------------------------------------------------------------------------
# For avoid inconsistencies in ntfs files systems on internal disks
# on computer with recent Windows or Linux OS's dual-booted, the
# hibernation and fast restart features was disabled, run Windows
# command 'powercfg /h off' as Administrator (see ntfs-3g man page).
# --------------------------------------------------------------------------------------------
# Windows OS (C:\ volume) /dev/sda1 partition is not show on desktop. For that this take effect, the
# mount actions of sda1 device was modify from Diks utility application (graphic mode), uncheck the
# options mount at begin, no show in user interface, and check the additional credentials for mount
# option. This added the option flags nosuid,nodev,nofail,noauto,x-udisks-auth.
# UUID=5C3ACAFB3ACAD0E6 /opt/sda1 ntfs noauto,ro,nouser 0     0
/dev/sda1 /mnt/sda1 auto nosuid,nodev,nofail,noauto,x-udisks-auth 0 0

I hope that is help to others users with doubt similar.