2

I have one hard disk on my server

[root@CentOS dev]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       4.9G  722M  3.9G  16% /
tmpfs           246M     0  246M   0% /dev/shm
/dev/sda1       194M   28M  157M  15% /boot
/dev/sda2       9.9G  164M  9.2G   2% /home

I want to shrink the home partition to two partitions

I found resize2fs command

umount /home/
e2fsck -f /dev/sda2
resize2fs /dev/sda2 3G
mount /home/

after executing

/dev/sda3       4.9G  722M  3.9G  16% /
tmpfs           246M     0  246M   0% /dev/shm
/dev/sda1       194M   28M  157M  15% /boot
/dev/sda2       5.0G  160M  4.6G   4% /home

the size of /home reduced 3G but I can't found the name of new partition

Any one who can give me an idea to solve this, i'll be grateful.

3

the size of /home reduced 3G but I can't found the name of new partition

Why should there be a new partition? Let's step through what you did:

umount /home/
e2fsck -f /dev/sda2

The partition is unmounted and checked.

resize2fs /dev/sda2 3G

The partition is resized. I don't do this very often but it seems bizarre to me that sda2 is now 5.0 GB, and not 3.0 GB, if that is what you asked for.

So you now have some free space on the drive that can be used to create new partitions. However, you did not actually do anything to create them, so of course they are not there.

To create a new partition without a GUI, use fdisk or parted (notice, no g). IMO the former is simpler, although if you have a GPT disk, make sure your version of fdisk supports GPT (it will indicate if it doesn't). Note that as per man resize2fs:

The resize2fs program does not manipulate the size of partitions. [...] If you wish to shrink an ext2 partition, first use resize2fs to shrink the size of filesystem. Then you may use fdisk(8) to shrink the size of the partition. When shrinking the size of the partition, make sure you do not make it smaller than the new size of the ext2 filesystem!

I highlighted the first sentence to emphasize the fact that you have shrunk the filesystem, not the partition. This is a bit confusing since df refers to device nodes (i.e., disk partitions) as filesystems. It actually refers to the filesystem on the partition, which is not the same thing.

So, now you have shrunk the filesystem, you can shrink the partition, then you can add a new one (and create a new filesystem in it).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.