When you discover a cause to maneuver the Linux house listing from one drive to a different, Jack Wallen has the step
I’ve had a couple of cases wherein relocating the HOME listing on both a Linux desktop or server was essential. This could possibly be due to area or safety points. Both approach, it’d seem to be a reasonably daunting process emigrate the listing containing all consumer recordsdata and directories from one drive to a different. Though it’s a little bit of a prolonged course of, it’s not all that tough.
With that mentioned, let’s see the way it’s executed.
SEE: 40+ open supply and Linux phrases you must know (TechRepublic Premium)
What you’ll want
To make this work, you’ll want a operating occasion of Linux with a minimum of two drives put in. I’ll be demonstrating on Ubuntu Server 20.04, however this could work irrespective of the distribution you’re utilizing.
How you can find the vacation spot drive
The very first thing we have to do is find the drive that can home the HOME directories. You must make sure you understand the precise identify of the drive. To try this, log into the server (or desktop) and challenge the command:
You shouldn’t solely see the drive identify however the mount level for the goal drive (Determine A).
My drive is already formatted. If this can be a new, unformatted drive, you’ll must first create a partition with:
sudo fdisk /dev/sdb
Kind n, for a brand new partition after which sort p to create a main partition. Following that, sort 1 to specify the partition quantity. Hit Enter to simply accept the defaults for the following two questions (first sector/final sector). It is best to now see /dev/sdb1 with the command:
sudo fdisk /dev/sdb
Kind p to print out the knowledge for the partition.
Subsequent, you’ll must partition the drive as ext4 with:
sudo mkfs.ext4 /dev/sdb1
Let’s create a brand new listing to function a mount level for the brand new partition with:
sudo mkdir -p /information/house
Mount the drive:
sudo mount /dev/sdb1 /information/house
How you can copy the recordsdata from /house to the brand new drive
Copy the whole lot from /house to the brand new drive with:
sudo cp -aR /house/* /information/house
Rename /house with:
sudo mv /house /house.bak
Create a brand new house listing with:
sudo mkdir /house
Unmount /dev/sdb1 with:
sudo umount /dev/sdb1
Remount /dev/sdb1, solely this time to the newly-created /house listing with:
sudo mount /dev/sdb1 /house
How you can completely mount the brand new partition
We now want to ensure the brand new partition is mounted, even when the machine is rebooted. For that, we’ll create an entry in /and so on/fstab. Earlier than we do this, we’ve to search out the UUID of the partition with the command:
sudo blkid /dev/sdb1
It is best to see one thing like UUID=”13557fad-d203-4448-991b-c8011907dc1d” within the output (Determine B).
Open fstab for modifying with the command:
sudo nano /and so on/fstab
On the backside of the file (Determine C), add one thing like the next:
UUID=ID /house /ext4 defaults 0 2
The place ID is the UUID of the brand new partition.
Save and shut the file. Remount the partition with:
sudo mount -a
And there you may have it, you’ve efficiently moved the /house listing to its personal drive. You now not want to fret that customers will eat all the area in your Linux OS server drive.
Do ensure to apply this on non-production machines to be sure to’ve received the method down, earlier than making an attempt it on a machine essential to your workflow.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise professionals from Jack Wallen.