Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Expanding online partition ext4
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
alessandro19884
n00b
n00b


Joined: 31 May 2019
Posts: 2

PostPosted: Fri May 31, 2019 12:25 pm    Post subject: Expanding online partition ext4 Reply with quote

Hello to all,
i'm not sure this is the right section for my question, sorry if I was wrong.

I have an email server running on Gentoo in an Hyper-v infrastructure. I have an offline replica for the mail server where i can try what i want. The mail server have different partition, the data is saved in sdb1 and I have to expand sdb1:

Code:
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       4.8G  3.8G  779M  84% /
tmpfs          1001M  300K 1001M   1% /run
udev             10M     0   10M   0% /dev
shm             4.9G     0  4.9G   0% /dev/shm
cgroup_root      10M     0   10M   0% /sys/fs/cgroup
/dev/loop0      604M  336M  225M  60% /usr/portage
/dev/sdb1       197G  185G  3.1G  99% /mnt/data
tmpram          4.9G   26M  4.9G   1% /tmp

I can't turn off the server or unmount the partition, so I need to expand sdb1 (ext4) online. From the hyper-v I assigned other 50GB to sdb so now with cfdisk /dev/sdb I can see the gb at end of the partition like free space. I have this version of kernel:

Code:
uname -r
4.1.15-gentoo-r1

So I assumed that I can expand the ext4 online, but if I try:

Code:
resize2fs /dev/sdb


the server answer:
Code:
resize2fs: Device or resources busy while trying to open /dev/sdb


I'm sure I don't understand something, can someone please help me?

Thank you

[Moderator edit: added [code] tags to preserve output layout. -Hu]
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 2117
Location: Frankfurt, Germany

PostPosted: Fri May 31, 2019 1:26 pm    Post subject: Reply with quote

Hi alessandro19884,

welcome to the Gentoo forums!

Please make sure that you understand the relationship between disks, partitions and filesystems - and how these objects are named in Linux.

alessandro19884 wrote:
From the hyper-v I assigned other 50GB to sdb so now with cfdisk /dev/sdb I can see the gb at end of the partition like free space. I have this version of kernel:

So you increased the size of the disk 'sdb' in hyper-v. Good! But did you also increase the size of the partition 'sdb1' using fdisk?

man resize2fs wrote:
The resize2fs program does not manipulate the size of partitions. If you wish to enlarge a filesystem, you must make sure you can expand the size of the underlying partition first. This can be done using fdisk by deleting the partition and recreating it with a larger size or using lvextend, if you're using the logical volume manager lvm. When recreating the partition, make sure you create it with the same starting disk cylinder as before! Otherwise, the resize operation will certainly not work, and you may lose your entire filesystem. After running fdisk, run resize2fs to resize the ext2 filesystem to use all of the space in the newly enlarged partition.

Your statement
Code:
resize2fs /dev/sdb

won't work, because the filesystem you want to enlarge (/mnt/data) is on /dev/sdb1 (the partition), not on /dev/sdb (the disk). Try
Code:
resize2fs /dev/sdb1

You may want to make a backup of your data before you run resize2fs.

Mike
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 15294

PostPosted: Sat Jun 01, 2019 12:59 am    Post subject: Reply with quote

After you grow the partition, you need the kernel to re-read the partition table. Usually, partition management tools will trigger this for you automatically. In some cases, having a mounted filesystem on the repartitioned drive will prevent re-reading the table. If that happens, you need to unmount the filesystem and force a re-read. I saw that you are unwilling or unable to unmount. However, that may be unavoidable. The good(?) news is that you are severely behind on kernel updates, so you can handle both issues at once, when your next downtime maintenance window arrives.

Once the partition table has been re-read, resize2fs can perform an online growth of the filesystem in the partition.
Back to top
View user's profile Send private message
alessandro19884
n00b
n00b


Joined: 31 May 2019
Posts: 2

PostPosted: Mon Jun 03, 2019 10:44 am    Post subject: Reply with quote

First of all, thank you for the help!


mike155 wrote:
Hi alessandro19884,

welcome to the Gentoo forums!

man resize2fs wrote:
The resize2fs program does not manipulate the size of partitions. If you wish to enlarge a filesystem, you must make sure you can expand the size of the underlying partition first. This can be done using fdisk by deleting the partition and recreating it with a larger size or using lvextend, if you're using the logical volume manager lvm. When recreating the partition, make sure you create it with the same starting disk cylinder as before! Otherwise, the resize operation will certainly not work, and you may lose your entire filesystem. After running fdisk, run resize2fs to resize the ext2 filesystem to use all of the space in the newly enlarged partition.

Your statement
Code:
resize2fs /dev/sdb

won't work, because the filesystem you want to enlarge (/mnt/data) is on /dev/sdb1 (the partition), not on /dev/sdb (the disk). Try
Code:
resize2fs /dev/sdb1

You may want to make a backup of your data before you run resize2fs.

Mike


So if I understand, the only way is to delete the partition with fdisk, and then recreate it larger? After that I can use resize2fs that's right?


Hu wrote:
After you grow the partition, you need the kernel to re-read the partition table


I have a replica where I can try what I want, but how I can grow the partition? With fdisk or cfdisk I don't see nothing, do you mean growing after I unmount the partition?

Hu wrote:
The good(?) news is that you are severely behind on kernel updates, so you can handle both issues at once, when your next downtime maintenance window arrives.


Good news :P
Back to top
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 451
Location: France

PostPosted: Mon Jun 03, 2019 11:24 am    Post subject: Reply with quote

Hello.

Quote:
So if I understand, the only way is to delete the partition with fdisk, and then recreate it larger? After that I can use resize2fs that's right?


Nope. After you have increased disk size (your /dev/sdb), you should resize your disk partition (/dev/sdb1), and only then will you be able to resize the FS that lies in ;)

++
Gi)
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 45383
Location: 56N 3W

PostPosted: Mon Jun 03, 2019 11:42 am    Post subject: Reply with quote

alessandro19884,

Think of the layers you want to change.
At the bottom is the whole disk block device.
This whole disk block device is usually subdivided into partitions. (There a other structures but I'll gloss over them.)
A partition is a block device too.
Partitions hold filesystems, which is the object you want to make bigger.

As its an error to have a filesystem bigger than the partition that contains it, the first step is to enlarge the partition.
Partitions are always a contiguous sequence of blocks. This means that you must have unallocated space following the partition you want to enlarge.

Partition tables are are lists of pointers annd metadat, so losing the partition table pointers does not harm you data, it just makes it more difficult to access.
As no two partitions can occupy the same space, the first step is to delete the existing partition table entry.
Now you can write a new entry, including some or all of the previously unallocated space. To pick up the existing filesystem, the new partition table entry must have the same start point as the old one.

At this point, you have done nothing to your filesystem, but its now smaller than the partition that holds it. That's OK.
Before you can expand the filesystem, the kernel needs to be forced to reread the partition table, so that its aware of the unused space. That does not always work without a reboot.

Lastly, you grow your filesystem.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum