1 (edited by mfleetwo 2021-06-06 10:23:15)

Topic: [SOLVED] Can't shrink ext4 smaller than 30GB but still 8GB free

I have a spinning disk with software on it that I want to propagate using dd to a flash drive - to do a partition copy. The source partition on sdd below is 29.7 GB, the target partition on sdb is 29GB

The source partition has about 8GB free so the interesting content will fit nicely on the target, sdb. I tried to shrink the source partition using gparted but hit a barrier of some kind at 30GB nominal and can't get gparted to take a smaller figure, 28GB say, which would be fine.


Does anyone have experience with this shrinking limit? I'm a little hesitant to try it and see without scoping it out a bit.

Dave

gparted 1.0.0 mint 19



$ sudo fdisk /dev/sdb
[sudo] password for dave:

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 29 GiB, 31142707200 bytes, 60825600 sectors
Disk model: USB Flash Disk
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: 0x8b07ed85

Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 60823551 60821504 29G 83 Linux

Command (m for help): q

dave@dave-2021:~$ sudo fdisk /dev/sdd

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdd: 698.65 GiB, 750156374016 bytes, 1465149168 sectors
Disk model: USB3.0 Device
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: 0x4fa27943

Device Boot Start End Sectors Size Id Type
/dev/sdd1 * 2048 62169087 62167040 29.7G 83 Linux

Command (m for help): q

2

Re: [SOLVED] Can't shrink ext4 smaller than 30GB but still 8GB free

We need to work out why the file system on /dev/sdd1 can't be shrunk any more.

Questions:
1. What type of file system is it?
2. How big did the sdd1 file system use to be?  ~698G by any chance?
   (It might be that the file system has reserved space for millions of inodes and the alternative method will have to be used).

Assuming it's an ext2/3/4 file system run these commands:

sudo dumpe2fs -h /dev/sdd1
sudo resize2fs -P /dev/sdd1

An alternative way to tackle this would be to create a new empty file system on /dev/sdb1 and copy the files instead.

3 (edited by midol 2021-06-05 22:07:48)

Re: [SOLVED] Can't shrink ext4 smaller than 30GB but still 8GB free

mfleetwo wrote:

We need to work out why the file system on /dev/sdd1 can't be shrunk any more.

Questions:
1. What type of file system is it?
2. How big did the sdd1 file system use to be?  ~698G by any chance?
   (It might be that the file system has reserved space for millions of inodes and the alternative method will have to be used).

I think ext4, it was a stock mint 19 install.

Assuming it's an ext2/3/4 file system run these commands:

sudo dumpe2fs -h /dev/sdd1
sudo resize2fs -P /dev/sdd1

An alternative way to tackle this would be to create a new empty file system on /dev/sdb1 and copy the files instead.

ok, like this:

$ sudo dumpe2fs -h /dev/sdd1
[sudo] password for dave:            
dumpe2fs 1.45.5 (07-Jan-2020)
Filesystem volume name:   <none>
Last mounted on:          /media/dave/71220fb1-7a50-483a-9b1a-5d95ee9706bc
Filesystem UUID:          71220fb1-7a50-483a-9b1a-5d95ee9706bc
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux 
Inode count:              1949696
Block count:              7770880
Reserved block count:     388543
Free blocks:              2657740
Free inodes:              1583410
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Tue Oct 30 14:36:04 2018
Last mount time:          Wed Jun  2 14:26:39 2021
Last write time:          Wed Jun  2 14:26:39 2021
Mount count:              11
Maximum mount count:      -1
Last checked:             Tue Feb 23 11:14:38 2021
Check interval:           0 (<none>)
Lifetime writes:          893 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:              256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      3410270b-9bc5-4ed0-baab-0a3aa0427101
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x25ad68b1
Journal features:         journal_incompat_revoke journal_64bit journal_checksum_v3
Journal size:             1024M
Journal length:           262144
Journal sequence:         0x007e4f81
Journal start:            1
Journal checksum type:    crc32c
Journal checksum:         0x3dcc1821

dave@dave-2021:~$ sudo resize2fs -P /dev/sdd1
resize2fs 1.45.5 (07-Jan-2020)
Estimated minimum size of the filesystem: 5207201

but I don't understand what this is telling me

D

4

Re: [SOLVED] Can't shrink ext4 smaller than 30GB but still 8GB free

resize2fs output is saying the smallest the file system can be shrunk to is ~19.9 GiB (5207201 * 4 KiB FS block size).

Use GParted again and try to shrink file system /dev/sdd1 further.
Make sure you use GParted 0.32.0 or later.
(It might be that after the previous shrink from ~698G to ~29G there is less reserved space for millions of inodes allowing the file system to be shrunk further).

5

Re: [SOLVED] Can't shrink ext4 smaller than 30GB but still 8GB free

mfleetwo wrote:

resize2fs output is saying the smallest the file system can be shrunk to is ~19.9 GiB (5207201 * 4 KiB FS block size).

Use GParted again and try to shrink file system /dev/sdd1 further.
Make sure you use GParted 0.32.0 or later.
(It might be that after the previous shrink from ~698G to ~29G there is less reserved space for millions of inodes allowing the file system to be shrunk further).

It worked ok, now 28GB, I don't really see why but thanks anyway.

d