Resizing a Linux filesystem without lvm
- Kategorie: Blog
- Veröffentlicht: Samstag, 02. Mai 2020 15:38
- Geschrieben von Martin Wilmes
- Zugriffe: 1727
Recently I had a problem with virtual machine (vmware, ESX) which had a second disk that was too small. So somebody used vmware to resize the disk but, of course the change was not reflected by Linux since the partition size and the file system size must be changed manually. So I came into the game.
The Linux was an RHEL 6 on vmware. It contained a production level Oracle server that was busy (load constantly at 0.5 at least) and accessing the disk in question.
Since this is not my daily job I searched the Internet for hints on traps you could step into when doing this. First of all was to request a full backup of the disk in question so that took some time to complete and I had time for a rehearsal.
Next step was to negotiate a down time of about 2 hours. That was necessary because the manipulation of the file system implied to stop the Oracle server. It might have worked without but I was not ready to take the responsibility on this, not knowing exactl how important this server was.
Ok, now to the action. Here are the steps I used to complete the job:
- Log on to the machine means here to establish a VPN connection and to connect via rdesktop to the vmware ESX. Then I was able to use the console of the virtual machine to log on.
- Stop Oracle (/etc/init.d/rc.oracle stop) and verify that there is no oracle process running any more.
- Just to note how it looks now issue a df -h
- unmount the file system in question (umount /dev/sdb1).
- Resize the partition with fdisk. This involves printing all the partitioning parameters, delete the original partition, recreate it with the same starting position and the full size of the disk. Then write the partition table.
- If the kernel recognized the changed partition size we are fine and can proceed to resizing the file system. Otherwise:
- Remove the Oracle-Link from /etc/rc3.d to prevent Oracle from starting on reboot. Then reboot.
- The kernel should now have recognized the new disk/partition size so we can proceed to
- Resizing the file system: Since it is a ext4 we just need to umount the file system (not necessarily but I prefer to) and then use the command /sbin/resize2fs -p /dev/sdb1 to do the actual resizing. It might be necessary to execute a disk check before so use /sbin/e2fsck -f /dev/sdb1 to do that.
- The most important stuff is done so lets take back any changes to the system that we might have done:
- Remount the file system
- Issue df -h to compare it to the state of before the change.
- Restore the link to the oracle start script in /etc/rc3.de
- (Re)start Oracle
The machine should now be in a safe state and usable as a production ready server again. The problem on the whole thing is that if something goes wrong, specifically on resizing the partition or resizing the file system, you will be lost in nowhere and you will ave to restore a backup of the disk.