[SOLVED]Creating a new home partition

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
wedjlok

[SOLVED]Creating a new home partition

Post by wedjlok »

I have read (and in the past with other distros actually done it) moving the /home partition outside of the / partition space. And have seen several other posts in this forum as well...

But my question is, to me anyway, a little unique. When I installed Mint, I let it do its own thing and put it all on its own partition within root (except for the swap, of course). So Now I want to move /home to a separate partition of its own, but the partitioning schemes seems weird to me.

lsblk -f shows this:

Code: Select all

NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
sr0                                                           
sda                                                           
├─sda2                                                        
├─sda5      swap         d7154ea7-1bd0-4d24-8a83-e06f1482e6ae [SWAP]
└─sda1      ext4         7836adf8-6f6d-4704-9921-81d111b8b7ef /
and sudo parted --list shows this:

Code: Select all

Model: ATA TOSHIBA MQ01ABD0 (scsi)
Disk /dev/sda: 640GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size    Type      File system     Flags
 1      1049kB  634GB  634GB   primary   ext4            boot
 2      634GB   640GB  6324MB  extended
 5      634GB   640GB  6324MB  logical   linux-swap(v1)
So essentially, I have a root partition (/sda1) that houses everything system, and then the swap space is actually /sda5 nested WITHIN /sda2
This is what gparted looks like:
Image

So what's my best course for doing a partition move/change, and moving /home to the new partition when swap is at /sda2 already?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
dcrowder
Level 4
Level 4
Posts: 202
Joined: Tue May 24, 2011 6:48 pm
Location: Dallas Texas USA

Re: Creating a new home partition

Post by dcrowder »

So sda2 is an extended partition. BIOS boot computers can only have 4 primary partitions. To get more than 4, create extended and then make as many partitions within it as needed. Cannot see your image (404 error).

I have not moved home partition as you request, but I would think you create new partition, add it to /etc/fstab, copy/move your files to new home, and reboot (or remount fstab). Obviously back up your data first in case something goes wrong.
Mint 21 Vanessa | Cinnamon | x64
WharfRat

Re: Creating a new home partition

Post by WharfRat »

Your linux partition /dev/sda1 is 634GB so in order to create a partition for home you would have to resize that partition to free-up space for a home partition.

Determine how much space is being used and resize it leaving some additional space. So if you're using 40GB now resize it to 50GB or so.

Then create a new partition in the freed-up space and format it ext4. Then you will be able to use that partition for /home.
wedjlok

Re: Creating a new home partition

Post by wedjlok »

That's a bit of what I was most concerned about, since the swap is already labeled as /sda2 with /sd5 nested inside. I would prefer to have my swap at the end, but how would i accomplish that with partitioning for /home if there's not a space between / and /home?
But what you said is ideally what I am wanting to do, shrink the / partition, create a new partition for /home and keep a separate swap partition.
WharfRat

Re: Creating a new home partition

Post by WharfRat »

Your swap is already toward the end of the disk.

When you "shrink" /dev/sda1 the extended partition will remain where it is.

Then create a primary partition from the freed-up space. It will most likely get assigned /dev/sda3.

Shrink it with gparted from right-to left, i.e., the end of the partition toward the start of the partition, using the live media.

One you have that done and you're booted back to your Mint installation, I can provide the necessary terminal lines to set the /home partition up.
wedjlok

Re: Creating a new home partition

Post by wedjlok »

WharfRat wrote:Your swap is already toward the end of the disk.

When you "shrink" /dev/sda1 the extended partition will remain where it is.

Then create a primary partition from the freed-up space. It will most likely get assigned /dev/sda3.

Shrink it with gparted from right-to left, i.e., the end of the partition toward the start of the partition, using the live media.

One you have that done and you're booted back to your Mint installation, I can provide the necessary terminal lines to set the /home partition up.
Thanks! I'm planning on doing some backing up before I start, so hopefully tomorrow I'll get to do it. If you want, you can go ahead and give me the commands and I'll just make note of them since it'll be done on this computer anyway. I would appreciate that a lot.
WharfRat

Re: Creating a new home partition

Post by WharfRat »

wedjlok wrote:Thanks! I'm planning on doing some backing up before I start.
Good move :wink:

Enter these one lin at a time. Change PART to the home partition assignment. If you formatted the partition to other than ext4 then reflect that in FMT.

You can skip sudo rm -r /old_home (next to last line) until after you reboot and check the new home's content.

Code: Select all

PART=sda3

FMT=ext4

sudo cp -a /etc/fstab /etc/fstab.old

sudo mkdir /mnt/newhome

sudo mount -t $FMT /dev/$PART /mnt/newhome

sudo chown $USER:$USER /mnt/newhome

cd /home

find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/

sudo umount /mnt/newhome

sudo mv /home /old_home

sudo mkdir /home

sudo mount /dev/$PART /home

sudo rm -r /old_home

echo -e "# /dev/$PART \n$(blkid|grep $PART|grep -wo "UUID=\"[^\"]*\""|tr -d '"')  /home   $FMT   errors=remount-ro,noatime  0 2" |sudo tee -a /etc/fstab

Good luck :wink:
wedjlok

Re: Creating a new home partition

Post by wedjlok »

Awesome! Thank you for your help. I'll let you know how everything went.
MintBean

Re: Creating a new home partition

Post by MintBean »

Why do people opt for these strange partition layouts? Seems pointless if you don't want >4 partitions. Is there any other advantage.
wedjlok

Re: Creating a new home partition

Post by wedjlok »

I'm simply doing it so that i can keep my /home intact and not effected by changing around the distro too much, and in case I change altogether. After all, I'm running Mint with Cinnamon slated and LXDE and Openbox in it's place, so it's an odd setup to begin with.
dcrowder
Level 4
Level 4
Posts: 202
Joined: Tue May 24, 2011 6:48 pm
Location: Dallas Texas USA

Re: Creating a new home partition

Post by dcrowder »

MintBean wrote:Why do people opt for these strange partition layouts? Seems pointless if you don't want >4 partitions. Is there any other advantage.
According to his original post...
wedjlok wrote:...When I installed Mint, I let it do its own thing and put it all on its own partition within root (except for the swap, of course)...
He did the default Mint install setup. Mine is the same setup since I took the default.
Mint 21 Vanessa | Cinnamon | x64
MintBean

Re: Creating a new home partition

Post by MintBean »

Oh, I assumed he had clicked some weird option and forgot about it. When did this become the default? I'm sure I didn't do anything special with my Mint 18.0 install and I didn't get an extended partition... unless I was on autopilot!?
WharfRat

Re: Creating a new home partition

Post by WharfRat »

MintBean wrote:Oh, I assumed he had clicked some weird option and forgot about it. When did this become the default? I'm sure I didn't do anything special with my Mint 18.0 install and I didn't get an extended partition... unless I was on autopilot!?
It could be because you have a gpt partition table.

I recall the same situation with earlier versions of Mint too where the default install created an extended partition for swap or encrypted lvm setup on /dev/sda5.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Creating a new home partition

Post by catweazel »

WharfRat wrote:
MintBean wrote:I recall the same situation with earlier versions of Mint too where the default install created an extended partition for swap or encrypted lvm setup on /dev/sda5.
It's normal:

Code: Select all

Device         Boot     Start       End   Sectors  Size Id Type
/dev/nvme0n1p1 *         2048 421435391 421433344  201G 83 Linux
/dev/nvme0n1p2      421437438 488396799  66959362   32G  5 Extended
/dev/nvme0n1p5      421437440 426956799   5519360  2.6G 82 Linux swap / Solaris
The same scheme is applied to NVMe devices.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
MintBean

Re: Creating a new home partition

Post by MintBean »

WharfRat wrote:
MintBean wrote:It could be because you have a gpt partition table.
Oh, so I do. Always assumed I had MBR for some reason. Thanks.
GPT seems superior to me... no need for extra concepts like extended partitions.
hcentaur13

Re: Creating a new home partition

Post by hcentaur13 »

Having /home in its own partition makes sense.
That means you don't need to backup and restore /home when a new ubstall of a new OS like Mint 19, 2o and so on as strongly required when /home is a simple directory under /.
You can leave /home untouched then - except of some configuration files the user(s) have to see as new installed. /reset / means formatting the whole directory tree of the whole system - except of dedicated partitions to get them clean.

Extending linux to use more room than currently available is easy:
- shutdown and reboot as root only
- insert a new drive
- create there the partitions you needs now
- move the directory and its whole content onto the newly created partition - the root directory of the partition is the place the data in the directory is placed to.
- insert a new line into /etc/fstab that points to the now emty directory as mountpoint and the new partition as source the mountpoint has to point do
and
- mount -a
and anything is done - you can allow any user to login now. The new partition replaces the old direcvtory now.

The trick is simple and works only when there is nothing and nobody accesses the path that gets moved. For /home this is done for when no user and no user application is active. For other directories there should be no access!

In question boot a live system to move the data around and changing the /etc/fstab.

To only extend the number of partitions as you would like to do now you would go over a live system yet.
- shink /dev/sda1 - / - to a resonable size
- extend /dev/sda2 by the now available free space
the next szeps see above. You may give /swap a bit more place to get more reserve of cirtual RAM.
There is no change of a path needed. There is no change of environment needed.
mr_raider
Level 7
Level 7
Posts: 1897
Joined: Sun Jun 20, 2010 9:50 am
Location: Montreal, QC

Re: Creating a new home partition

Post by mr_raider »

MintBean wrote:Oh, I assumed he had clicked some weird option and forgot about it. When did this become the default? I'm sure I didn't do anything special with my Mint 18.0 install and I didn't get an extended partition... unless I was on autopilot!?
To be accurate, that is teh default Ubuntu option for an empty disk, formatted to MBR. Actually, the installer preselects the LVM option when you run it which is even worse for noobs.
Image
MintBean

Re: Creating a new home partition

Post by MintBean »

Thanks Mr Raider. Yes I think LVM as a default is a poor option. Should be left for advanced users who choose it.
wedjlok

Re: Creating a new home partition

Post by wedjlok »

WharfRat wrote: Good move :wink:

Enter these one lin at a time. Change PART to the home partition assignment. If you formatted the partition to other than ext4 then reflect that in FMT.

You can skip sudo rm -r /old_home (next to last line) until after you reboot and check the new home's content.

Code: Select all

PART=sda3
Good luck :wink:
Not to sound too dumb, but "PART"? I cannot find any command for that. And one last thing, what about dealing with UUID issues for the /home...?
WharfRat

Re: Creating a new home partition

Post by WharfRat »

wedjlok wrote:Not to sound too dumb, but "PART"? I cannot find any command for that. And one last thing, what about dealing with UUID issues for the /home...?
PART is not a command, it's a bash variable assignment. Nothing is going to happen when you paste the PART line in the terminal, but it will assign what's on the right of the =

Code: Select all

[bill@XPS] ~ $ PART=sda7
[bill@XPS] ~ $ echo $PART
sda7
[bill@XPS] ~ $ 
This line echo -e "# /dev/$PART \n$(blkid|grep $PART|grep -wo "UUID=\"[^\"]*\""|tr -d '"') /home $FMT errors=remount-ro,noatime 0 2" will write the necessary information to fstab.

The tail end of the line "sudo tee -a /etc/fstab" will append the results of the line above.

Just enter the assignment for PART and FMT then test the line like so - I'm using sda7 for demonstration purposes.

Code: Select all

[bill@XPS] ~ $ PART=sda7
[bill@XPS] ~ $ FMT=ext4
[bill@XPS] ~ $ echo -e "# /dev/$PART \n$(blkid|grep $PART|grep -wo "UUID=\"[^\"]*\""|tr -d '"')  /home   $FMT   errors=remount-ro,noatime  0 2"
# /dev/sda7 
UUID=846d79b5-b9de-4dc1-977e-68b2d68c3a6d  /home   ext4   errors=remount-ro,noatime  0 2
[bill@XPS] ~ $ 
If you go line-by-line you'll be fine. Just make sure you use the correct partition assignment for your home.
Locked

Return to “Beginner Questions”