Reducing size of partition

I have the following setup on a drive (an SSD):

Disk /dev/sde: 477 GiB, 512110190592 bytes, 1000215216 sectors                                         
Units: sectors of 1 * 512 = 512 bytes                                                                  
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0002209b

Device     Boot      Start            End       Sectors  Size   Id  Type
/dev/sde1             2048      4208639      4206592    2G  82  Linux swap / Solaris
/dev/sde2  *    4208640   843075583   838866944  400G 83  Linux

Current usage of sde2:

linux-5:~ # df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sde2       394G   81G  313G  21% /

File system on sde2:

linux-5:~ # df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
/dev/sde2      ext4     412719200  84113868 327750084  21% /

Please note that this partition contains my entire SuSE 13.2 system, i.e., the entire file system (from /bin to/var).

I wish to reduce the size of sde2 so that I can install Leap 42.1 on the drive. Given current usage, which includes three VirtualBox machines (constituting 79 GB out of the 81 GB total), I wish to reduce the 13.2 partition size from the current 400 GB to 160 GB, and then create a new partition of about 200 GB for the Leap 42.1 installation, leaving the remaining ~100 GB open.

Perusing numerous references (SuSE enterprise manuals), forums, webpages, etc., I have encountered various concepts such as “shrinking” file systems and “resizing” partitions. One of these (not from SuSE) implies that to accomplish my task, I need to both shrink the file system (e.g., using resize2fs) and then resize the partition (e.g., using fdisk). In short, I am unable to determine the proper terminology and wish to move cautiously here.

What I have determined thus far is that I must first unmount the ext4 file system. I believe I can then use the YaST partitioner to resize the partition. If I’m wrong, then I get to reinstall the entire system. Of course, I will back up the virtual machines.

Again, I am uncertain about the steps I need to take and invite your comments and suggestions. Thank you.

You got it from a live boot disk so that the partition is not mounted resize using the tool of your choice. Many like gparted which I believe is actually what yast uses. If done from command line tools you would need to first shrink the file system before shrinking the partition.

Not when resizing it is possible to lose data so you need a very good backup. Of course it is always best to simply do these sort of things when you install. I always keep a second boot partition for testing or moving to a new OS/version

I note you do not mentions a home partition which is default on openSUSE and does make these sort of things much easier since personal data and settings are always on /home. If you do not have a separate home partition I encourage you to take this opportunity to make one

Just download and run gparted live (it’s the livecd version of gparted).

It’ll re-size both the file system and partition together automatically without asking.

And, it’s nice to use GUI tools.

When shrinking, be sure to do the following first to get best results

  • empty the trash
  • clear the /tmp directory if it doesn’t clear automatically on shutdown
  • zero your empty space
  • Defrag big files by moving them to another partition and back again.
  • If you have a lot of personal files and access to external storage, move the files to external storage so you’re not moving those files during shrinkage.

Gparted Live
The download page. Note that the default selection is the i586 32-bit image. DO NOT use this. Download the 64-bit image instead! The 32-bit image is limited in a number of different ways.
http://gparted.org/download.php

More info if you want, but Gparted Live is so simple and easy to use, I’d say most experienced people don’t need to “read the docs”
http://gparted.org/livecd.php

Remember, you want to locate your re-sized partitions all to the left and create free space <after> your existing partitions. If you change the order of partitions, your existing Grub may not work. Also, do not create a partition in the new free space, the install for your new OS will be looking for free space, not existing partitions (formatted or not).

TSU

Thank you both for the responses.

tsu2 - how should I zero empty space? I found the following but I’m not certain how to configure and use it:

dd if=/dev/zero of=/filename_on_partition

DONT’T DO THAT. That will destroy the contents of what is after mentioned the of=.

Just forget the zeroing

Please note that I have not previously resized a partition and thus am not familiar with the procedures or the tools (other than YaST partitioner, which I understand may not be suitable for this project).

After the last post, I tried to but was unable to find answers to the following:

  1. Why does one “zero empty space” in the partition in the context of reducing the size of a partition?

  2. What is the effect of “zeroing empty space?”

  3. Are those zeros left in place or should they be erased before resizing the partition?

Thank you.

hcvv -

Thanks - your response came in as I was writing my last set of questions. I will skip that step.

I did not previously mention that this PC is triple boot, and has SuSE 13.1 (on sda6). In light of tsu2’s comment, I installed gparted (not live) on the 13.1 system and let it scan the system. That brought up sde2 - the partition I wish to reduce in size (as well as all of the other drives). Very nice interface and excellent manual!

It seems rather straightforward with gparted on the 13.1 system to:

  1. unmount sde2 (if necessary – 13.1/run/media/root appears to pick it up);

  2. select “resize/move” and enter the desired new size of the partition – the “data” (the yellow portion) is already to the left and preceding empty space is reading zero.

This seems to be all I need to do (everything of value is already backed up).

What am I missing? Thank you.

Using another Linux on the same system is of course as good as using a live CD. And easier to do.

To avoid the magicaly mount of that partition by your 13.1, add an entry in /etc/fstab for it (can be done with YaST on the 13.1 system), adding the noauto option. Then the desktop feature that thinks that everything it sees is “media” will do nothing.

Please do not forget to check if the /etc/fstab on your 13.2 is still OK. The /dev/disk/by-…/some-id could have been changed. Particulary if the by-uuid is used.
Same for your grub2 configuration.

Thank you. I have been booting back and forth between the 13.1 and 13.2 systems over the last day to explore and get ready for the change to sde2, so the fstab and grub config files (on both systems) appear to be in order. As I discovered on another machine, and as discussed at length in this forum last week (in my "Restoring Leap 42.1 to Bootloader post), that could change when I go to install Leap 42.1 on sde, but I have a suspicion why that occurred - quite possibly a change to the UUID for one of the drives - as you mention.

Is my proposed strategy at the end of post #7 correct?

  1. unmount sde2; and

  2. select “resize/move” and enter the desired new size of the partition.

I would appreciate your feedback before I “push the button.”

Thanks.

  1. When it is mounted, you should umounyt of course. But you must also be sure it is not mounted by some spontanious desktop action. Thus my advice to create an entry in the 13.1 /etc/fstab. Maybe that is not realy needed as long as youdo not use the file system from your desktop. but take care.

  2. I guess that is correct. Many people say that gdisk is trustworthy doing these things. I never did these things this way, but I must add that, with some 25+ years of Unix/Linux system administration experience, I have probably some more insight in doing these things from the CLI.

In any case, as others said already, check if your backups are allright and do not hesitate to make an extra backup before you “push the button”.

Thank you and thanks again to tsu2 - it worked and I’m back on the air in 13.2, ready to install Leap 42.1! And grub.cfg came out unscathed.

I looked at gdisk but ran into a conflict attempting to install it through software.opensuse.org 1-click, so I just fired up gparted. (I suspect that you would have done this through the command line – e.g., resize2fs [see above] and fdisk – perhaps next time.)

If this might assist others, here are the before and after screen shots from gparted.

Pending operation (see lower portion of panel):

http://susepaste.org/images/15618158.png

After completion (but running gparted in 13.2, hence the mounted indication as root):

http://susepaste.org/images/72119504.png

Thanks again. I sincerely appreciate the assistance and the education - I could not have done this without your help.

I forgot to mention - the most critical aspect. VirtualBox, about 98% of the file system from a size-on-disk standpoint, and the most labor-intensive portion of the 13.2 installation, also survived and functions properly. Thankfully, the Windows activation was not affected by the change in the size of the partition.

Thanks again.