The attached script, also available
here, shrinks the last partition of a drive to free some space on it.
This can allow to install Slackware or Slint on the same drive as another already installed Linux distribution.
Indeed this can be done by gparted, but being just a shell script it can be run directly from the Slackware or Slint installer. Incidentally being a command line application it is accessible to blind users through a Braille device or a console screen reader like speakup.
It only handles partitions formatted with an ext* file system that are the last one of the drive. I should work if the drive has a GPT or a DOS partition table. It tries hard to be fool proof.
Theory of operation:
- List the partitions meeting the specs.
- Let the user choose which one to shrink if several.
- Check that the partition be not mounted, especially not as /
- Let the user type the new (smaller) size of the partition in a range, as a number of gigabytes.
- Check the file system.
- Shrink the file system.
- Shrink the partition.
I tested on Slint using the same versions of the software
e2fsprogs and
util-linux as in Slackware-current, built for Slint.
Please test and report any issue.
To get back the initial sizes of the file system and the partition you could run something like below. I assume that the drive is named /dev/sdb and that the partition has the number 4 and is named /dev/sdb4, adapt accordingly:
Code:
umount /dev/sdb4
e2fsck -f /dev/sdb4
echo ",+" | sfdisk --no-tell-kernel --no-reread -N 4 /dev/sdb
partprobe
resize2fs /dev/sdb4
The options "--no-tell-kernel --no-reread" are only useful if you run the script from a partition on the same drive as the target.
EDIT. I added the partprobe command to make the kernel aware of the new layout, else resize2fs would say "nothing to do".
PS Indeed Slackware as Slint can be installed alongside Windows on the same drive (preferably in EFI mode to avoid interference between boot loaders in my opinion). I do not plan to provide a script to shrink a Windows volume, as it is doable and probably safer from Windows itself, cf.:
https://docs.microsoft.com/en-us/win...a-basic-volume
PPS According to "man btrfs-resize" and "man resize_reiserfs" it should be possible to support btrfs and reiserfs file systems too (not xfs and f2fs if I understand well). I have zero experience with these, proposed patches are welcome. EDIT: the 'chfs' command is supposed to allow shrinking jfs2 file systems, but doesn't seem to be available for Linux. At least it's not provided by jfsutils.