1 (edited by mfleetwo 2022-07-05 09:22:53)

Topic: How do I shrink Linux OS partition while it is in use

Hi,

I have built a new desktop, installed Linux Mint V20.3 Cinnamon 64bit Edge edition. The built and Linux installation, no problems. This Desktop has a large SSD, 1TB. This time, for this built I haven’t partitioned the drive (Do not ask me why, it was a mistake) and now I do have a huge drive for Linux and would like to organise it in at least 2 or 3 partitions. One partition for Linux and an extra or 2 for data saving.

So, I started searching for a software to help me on this and came across GParted which for what I read it seems to me that is capable in assisting me on this, for what I read apparently I could run the Desktop from either a Live CD or a USB to have access to my Desktop SSD and work on the partitions.

I had used in the past for Windows PCs, AOMEI Partition Assistant but I do not think it has a version for Linux.

I have installed GParted in my Linux Desktop, I can see my drive but of course, all partitions are mounted, so the answer is working from the USB or CD drives.

In my opinion, there are two possible solutions:

Option 1: As stated above, run the Desktop with a Live CD or USB and rearrange the drive. The trouble here is that I will need to create, size and move partitions but for what I see the partitions listed are:

/dev/sda1     fat 32     /boot/efi (Mount Point)     with the Flag as boot (For what I read I should not touch it)

Then is listed the extended partition which has a Logical Partition within it using the same space as follows:

/dev/sda2     extended         931.01 GiB
    /dev/sda5     ext4             931.01 GiB         26.50GiB Used

Here is my main problem, how do I resize and move the partition sda5 (File System ext4) and make it, let say 100 GB (I think this should be sufficient to run Linux, am I right?). I think Mint is installed in this partition, is this correct? Or else where is Mint Installed?

Based on GParted this partition is the Blue one in the attached JPG. I would like to place this partition towards the left, besides the green one (boot), so on the right I will just have the light blue one, a large space that I could either leave it entirely or split it in two or three partitions for data saving.

The questions for this option are:

- How do I run the Desktop from a USB or Live CD? Where do I download GParted for either of these options?

- Once I have either USB or CD ready, I change to boot option and make the desktop to boot from either of them. Once the Desktop runs in this way I could rearrange my SSD as explained above. Now, the USB or CD option will give me a graphical interface to see the drive or will it be just like working with the “Terminal”. If this is the case, I will need to know what commands should I write and achieve my aim.


Option 2: This option, in my opinion is just to remove the SSD, connect it to another desktop, create the partitions and then install Linux in it.
- In what File System should I create and format the partitions? Or the formatting side of it will be taken care by Mint installation? This will be possible for one partition I think, what about the other/s?

- In this option, I could run GParted for Windows, may you send me a link from where I could download it? I have a Desktop running Win 7 Ultimate 64bit.

Between Option 1 and 2, I prefer Option 1 because it has a learning opportunity that I would like to take if anyone in this forum is prepared to guide me, is this possible?

Please, see the attached JPG for a graphical GParted illustration of my drive.
Well, How do I attach and images to my post? I do not find anything to let me do this.

I thank anyone that is able to assist me on this.

Kind regards,

Carlos
=

2

Re: How do I shrink Linux OS partition while it is in use

GParted Live distribution is what you want

1. Download GParted Live distribution - https://gparted.org/download.php
2. Write to USB drive - https://gparted.org/liveusb.php
3. Boot GParted Live - https://gparted.org/livecd.php

Alternatively there are multiple other Linux live distributions which include the GParted application.  Several of them are mentioned on the GParted Wikipedia page.  https://en.wikipedia.org/wiki/GParted#Background

3

Re: How do I shrink Linux OS partition while it is in use

For guidance on how to attach images to a post see this thread.  [solved] put screenshot into post?

4 (edited by mfleetwo 2022-07-08 15:22:02)

Re: How do I shrink Linux OS partition while it is in use

Well, I think I managed to upload the image and it should clearly shows the the blue partition inside the light blue partition. I hope this works fine and someone comment on this, how do I go about it? Thanks

SSD 1 TB Partitions Screenshot

Edit: Convert link to picture to embedded picture ~mfleetwo

5

Re: How do I shrink Linux OS partition while it is in use

I decided to copy from my 1st post the section I am concern, mainly the Blue-Light Blue partition, I said on Option 1:

As stated above, run the Desktop with a Live CD or USB and rearrange the drive. The trouble here is that I will need to create, size and move partitions but for what I see the partitions listed are:

/dev/sda1     fat 32     /boot/efi (Mount Point)     with the Flag as boot (For what I read I should not touch it)

Then is listed the extended partition which has a Logical Partition within it using the same space as follows:

/dev/sda2     extended         931.01 GiB
    /dev/sda5     ext4             931.01 GiB         26.50GiB Used

Here is my main problem, how do I resize and move the partition sda5 (File System ext4) and make it, let say 100 GB (I think this should be sufficient to run Linux, am I right?). I think Mint is installed in this partition, is this correct? Or else where is Mint Installed?

Based on GParted this partition is the Blue one in the attached JPG. I would like to place this partition towards the left, besides the green one (boot), so on the right I will just have the light blue one, a large space that I could either leave it entirely or split it in two or three partitions for data saving.

How do I deal with this partition inside a partition?

6

Re: How do I shrink Linux OS partition while it is in use

A partition inside a partition is often found on an MSDOS partitioned disk drive.  The outer partition is called an Extended Partition.  The inner partitions are called Logical Partitions.  You can have multiple Logical Partitions inside an Extended Partition.

The steps you need are:
1. Use a live distribution as discussed above because it is not possible to shrink a partition containing an ext4 file system while the OS is running from it.
2. Shrink sda5 (ext4) partition to your wanted size of 100 G.
3. Create one or more Logical Partitions in the free space.

7

Re: How do I shrink Linux OS partition while it is in use

mfleetwo wrote:

A partition inside a partition is often found on an MSDOS partitioned disk drive.  The outer partition is called an Extended Partition.  The inner partitions are called Logical Partitions.  You can have multiple Logical Partitions inside an Extended Partition.

The steps you need are:
1. Use a live distribution as discussed above because it is not possible to shrink a partition containing an ext4 file system while the OS is running from it.
2. Shrink sda5 (ext4) partition to your wanted size of 100 G.
3. Create one or more Logical Partitions in the free space.

Over the weekend I worked on this SSD and tried to rearrange the partitions.
From the picture above what I thought was that if I reduce sda5 to about 100GB I should be able to run Linux and end up with a partition for data saving and both separated. The initial idea was good but didn’t know the possibilities and the end result was not as expected.

After sda5 was resized I ended up with the extended partition sda2 light blue containing two partitions in dark blue sda5 and sda6 and the worse thing is that if I want to used sda6 I need to format it so I could have access to it. Based on what I read the extended partition sda2 created as extended contains the logical partitions sda5 and sda6 and it seems to me that is the way they will stay.

Now, if I want to use sda6 I have to format it, at present I do not have access to it (I just can’t save anything in there the partition is not recognised by Linux); but there is a 1.94GiB used that I do not have a clue what that is and neither know the effect on the system once I format sda6 because this 1.94GiB will disappear. Will still Linux run?

When I format this partition and I select Partition - > Format, what File System should I select? This large partition will be used only for data saving (pictures, videos, files in various formats, but no software will be installed in here), your advice will be greatly appreciated, thanks.

Well here should be what it looks like my SSD drive after this.

https://i.postimg.cc/X7h4PntV/New-Partitions.jpg

Edit: Convert link to picture to embedded picture ~mfleetwo

8

Re: How do I shrink Linux OS partition while it is in use

Reboot your machine back to it's own OS.

As root do the following steps:
1. Create mount point directory.  mkdir /data
2. Edit file /etc/fstab adding entry:

/dev/sda6   /data   ext4   defaults   1 2

3. Mount the file system.  mount /data
4. Allow all users to write to the file system.  chmod a=rwx /data

9

Re: How do I shrink Linux OS partition while it is in use

Let me confirm I understand all the steps:

I start the PC and open File that will show me a line with the following:
PCname:~$

Am I in the root directory or do I need to go further back? I am familiar with DOS and File is similar but not the same and wouldn’t like to write commands in the wrong place.

If opening File is in the root directory, I type

1. Create mount point directory.  mkdir /data
Shouldn’t I specify where the directory data should be made?


Then, on Step 2. Shall I write the /etc/fstab hit enter and write the following line and hit enter or make all one line and hit enter? O just write the line

/dev/sda6   /data   ext4   defaults   1 2

The above line is quite clear to me I think, I specify the partition (/dev/sda6), the directory (/data), the file system (ext4) and then “defaults and 1 2” I need to know what they do mean, at this stage I assume it is like saying default settings and the numbers should mean options.

Steps 3 and 4 are clear, after the data directory creation I mount it with 3 and make this directory open for everyone in 4.

Thanks for your time

10

Re: How do I shrink Linux OS partition while it is in use

The forward slash at the start of /data makes the name an absolute name not a relative name to your current directory.  The directory data will be created in the root (/) directory.
Hint: Search absolute vs relative file names.



First display the current contents of the /etc/fstab file with:

cat /etc/fstab

Then use this command to append the line to the end of the file. (double greater than is append, single greater than is replace)

echo /dev/sda6 /data ext4 defaults 1 2 >> /etc/fstab

Read the manual page describing the the format of the fstab file by

man fstab

or read it online fstab(5) - Linux manual page.