[ATTENTION: These instructions are a personal reminder and you may follow them at your own risk!! I cannot be held responsible if you lose your data or your system becomes inaccessible.]
Sometimes it is not possible to physically access a linux server and go into single user mode to perform the conversion of a root filesystem from ext3 to an ext4 one. The strategy I follow is to disable just about everything on it, block access to incoming users, perform the changes on the filesystem and reboot.
First, alter the filesystem of your root partition (/) in /etc/fstab to ext4. The root filesystem is the partition with mount point /. For example, my fstab line looks like this:
/dev/sda1 / ext3 defaults 0 0
I changed it to read:
/dev/sda1 / ext4 defaults 0 0
Next determine which processes or services are writing on the root partition and stop them so you can perform the conversion. You would want to stop just about any services, except probably from sshd; that includes apache, mysql, samba, to name a few. As it may not be obvious what is writing on disk consider running the following command:
# fuser -v -m / USER PID ACCESS COMMAND /: root kernel mount / root 1 .rce. init root 2 .rc.. kthreadd root 3 .rc.. ksoftirqd/0 root 5 .rc.. kworker/0:0H ... ... ... root 1854 .rc.. scsi_eh_3 root 2041 .rce. udevd root 2042 .rce. udevd root 2423 .rc.. flush-3:0 root 2429 Frce. dhclient root 2587 .rce. syslog-ng root 2588 Fr.e. syslog-ng root 2619 .rce. sshd root 3102 .rce. cron root 3116 .rce. agetty root 3117 .rce. agetty root 3118 .rce. agetty root 3119 .rce. agetty root 3120 .rce. agetty root 3121 .rce. agetty root 15174 .rce. sshd root 15179 .rce. bash root 15194 .rc.. kworker/0:0
Scan the long list of processes fuser will give you for processes with ACCESS containing F and f, which denote open files. Stop the respective processes. In my case it is the dhclient process and the syslog-ng service that have to be stopped. The syslog-ng can be stopped on Gentoo using:
/etc/init.d/syslog-ng stop
while the dhclient can just be killed using its PID, with:
kill -9 2429
Double-check with fuser again that nothing is accessing the filesystem and now remount the root filesystem read-only:
# mount -o remount,ro /
Enable the ext4 features on the existing ext3 filesystem of the root filesystem:
# tune2fs -O extents,uninit_bg,dir_index /dev/sda1 tune2fs 1.42 (29-Nov-2011)
Then run fsck on the filesystem to fix up some on-disk structures that tune2fs has modified:
# e2fsck -fDC0 /dev/sda1 e2fsck 1.42 (29-Nov-2011) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 3A: Optimizing directories Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sa1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sda1: ***** REBOOT LINUX ***** /dev/sda1: 608861/4825088 files (5.5% non-contiguous), 13559414/19277992 blocks
If everything goes according to plan, just reboot the machine and your system will come up using ext4 as the filesystem of your root partition. You can try sync
instead of rebooting your machine, but this may or may not work.
You can follow the same instructions to convert a non-root filesystem too, only this will be much easier, as you can just umount such partitions and perform the conversion steps.