Minecraft Blogs / Other

Linux — Using file reference links to make dual-booting easier

  • 48 views, 2 today
  • 3
  • 0
Hebgbs's Avatar Hebgbs
Level 48 : Master Archer
45

So you're dual-booting Linux

Congratulations! You are of an elite few which are growing by the week who have become tired of being limited by a corporate interest's walled garden and either want to do more with their PC, or scamper away into a wonderland devoid of insipid advertisements, excessive data collection, unwarranted monitoring of your activities and / or at the very least, sate your curiosity of whether an open-source solution is for you.

…Great. You have another filesystem to manage now, your other partitions aren't mounted. and… why can't you access any of your files?

…Why can't you access any of your files? Because… you can. And it's not that difficult either.

One partition for all

If you've been using Windows for some time (or macOS but we're not talking about that presently), your files are typically in the user directory which was created when you've made your account. For simplicity sake, For this exercise the user — you — have named this account Foo.

Foo has been a diligent end-user, neatly organizing their files into the directories Windows made available to them in %userprofile%naaah let's be real homie, your junk is all over the place. Stray files you never came back to in your desktop, every file type under the sun in Downloads/ even though you could had organised it better, videos in Pictures/, music in Documents/, programmes installed… wherever as you just did not care, your entire Windows partition is in shambles because of your neglect. Don't feel bad! You, like many other people are the same way, and it's okay to be human. Beside, you can take this as an opportunity to shape up your filesystem management.

We can do something really cool with the data on your disk, Foo — and you can expand this skillset to cover basically any digital need under the sun, where a suite of files can reside in one place, but be in multiple locations, at the same time. And knowing better, you can make practically-infinite replications of existing directories for a game to do mods on, which would be handy to understand yourself so you are not held hostage by software solutions which do this for you.

Setting up for success

Let's just talk about the five directories you should be interacting with the most;
  • Documents/
  • Downloads/
  • Music/
  • Pictures/
  • Videos/
If you had been diligent, then these five directories should be what matters most to you, at all times since that's where all of your stuff is at. So let's just say for sake of argument, your computer's WIndows instance is in… well, Windows/. C:\ — with label "Windows" — is where your files are at. (OEMs may call this partition different things; OS, System and so-on, but let's keep things simple.)

Understanding this much, in your Linux system once you modified /etc/fstab to include this:LABEL=Windows /mnt/Windows ntfs-3g nosuid,nodev,nofail,x-gvfs-show,gid=1000,uid=1000,umask=000 0 0

And, do this (or, a solution like gnome-disks does it for you):sudo mkdir /mnt/Windows

Then when you reboot your system, the partition with label "Windows" will mount in /mnt/Windows. So let's assume when Linux was installed, you (wisely) named your open-source instance user "Foo". We have two systems, with accounts named "Foo" on each. So these are where your files would be:
  • /mnt/Windows/Users/Foo
  • /home/Foo
Let's use them. I'll also demonstrate some terminal magic to speed things along and make this a single command:printf 'Documents\nDownloads\nMusic\nPictures\nVideos' | xargs -I {} sh -c "rm -rf $HOME/{} && ln -s /mnt/Windows/Users/$USER/{}/ $HOME"

…What the hell is that?? Let's break that down:
  •  printf '...'  — All of the directories, they're separated by \n to print newlines, too.
  •  | Pipe. It's used in this context to forward output from the previous command.
  •  xargs … — From its manual: "build and execute command lines from standard input". We're doing that.
  •  -I {}  — String replacement. Using the output from printf, piped as input to xargs. Rather than the while-else loop basic programming teaches you, we're removing programming from our command since we don't have time for that; each line is executed with whatever {} becomes.
  •  sh -c "..."  — We're executing two commands here, and this is happening five times. While  xargs  is great for doing one thing multiple times, for multiple things which need to happen it's not so great, so a shell command is executed five times, to do operations for each directory as defined in in the  printf  statement. Of those two commands:
    •  rm -rf $HOME/{}  — This will remove recursively, and with disregard for other factors (acting with force) anything after its declaration, which in this case is the five directories in $HOME.
      $HOME is a system variable for /home/$USER, where $USER in this case is "Foo".
    •  ln -s …  — Use link to do symbolic, or in plain-speak; make symbolic links. In this case, from the five directories as defined in printf @ /mnt/Windows/Users/$USER (Foo) to $HOME.
      Not necessary to understand now, but it'd be nice for you to know; cross-partition links can only be symbolic: as in; defined by absolute path rather than defined by existing inode / file ID.

Possible traps

File and directory references work quite a bit differently than their referenced counterparts — whereas before if you were to write one file as one file, if you have a bunch of reference links to the same file everywhere then writing one file will change many references… unless the file is written as a new reference. Which means, you may also have to de-reference (delete) an existing link before writing to it.

If you are writing into the original reference for a linked directory, then that file is written once, but used many times elsewhere. If you want to write a unique file in a referenced directory, then the directory must be de-referenced first, then created anew with all files and directories elsewhere linked into it, and finally whatever is to be changed, must be de-referenced if produced as part of the referencing process (i.e. using globstars in shell commands) before writing into it.

Not being mindful of this can lead into more than one instance of accidentally saving changes for a file and having those changes negatively affect referenced instances of the same directory in other projects; a bit of Butterfly Effect action going on for such events. So, be careful of how references are handled and it shouldn't ever be an issue, but of course as you are human, you are bound to err.

Another thing about creating file references elsewhere — if you use shell commands to copy directories, you need to be mindful of ensuring if links for directories and files are to be preserved for the duplicate that you do not have them de-referenced. But also, the fact you can copy things and de-reference the links can save a lot of effort if needing to de-reference a directory for making changes to one or more files which you do not wish to have propagate for other references. This is great to know for testing certain changes to a project, where you do not initially wish for those changes to become part of every project instance until you are sure for the test instance, outcomes are as-expected and to your approval.

One more thing about links; files (and files only) can be hard-linked — as in, referenced not by absolute or relative path, but by their journal entry. File references are harder to figure out because they act exactly like files, and when the original file is deleted, all subsequent references still exist. Some malware exploit this feature of hard-links to be almost irremovable, and even for files you know are not malicious, if you're intending to remove a particular file which you have hard links for then all links must also be removed to completely liberate that journal entry for a different file to take its place.

It's a lot to mind and think about, but so long your file manager tells you what's a reference and where these references are, you'll be able to manage your filesystem with relative ease using a graphical interface. Both KDE Project's Dolphin and later iterations of Xfce's Thunar enable seeing these things, so you can worry less of what you're about to do and hopefully finish your work faster.

What's the point?

With this information, you now understand how to make transitioning from one platform to another even easier — rather than juggling two suites of directories for your files, you can (with varying degrees of effort) make it so no matter what Linux instance you are on, you can pick up and carry on in short order to continue your work and leisure on open-source system instances.
Tags

1 Update Logs

Tags : by Hebgbs 05/18/2024 4:56:44 pmMay 18th

Forgot to add tags, so tags have been included to make finding this much easier for the masses. Apologies for inconvenience.

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome