April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

CentOS 5: Converting Ext3 to Ext4

OS: CentOS 5.6 64bit
Kernel version: 2.6.18-238.19.1.el5
Backup partition: /backup (mount from /dev/sdb)

1. First of all, its recommended to backup everything first. We will us ‘dd‘ command to backup the whole partition to another hard disk. That hard disk is attached via SATA cable. We will format the backup hard disk with ext3 filesystem and and mount as /backup partition:

$ fdisk /dev/sdb
…..

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-3916, default 3916):
Using default value 3916

Command (m for help): w
The partition table has been altered!

……

The sequence I press in the keyboard is: n > p > 1 > enter > enter > w

2. Then, format the partition table /dev/sdb1 with ext3 filesystem:

$ mkfs.ext3 /dev/sdb1
3. Mount the backup partition to  /backup:

$ mkdir /backup
$ mount /dev/sdb1 /backup
4. Lets check our partition summary:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       47G  3.3G   41G   8% /
/dev/sda1              99M   20M   75M  21% /boot
tmpfs                 501M     0  501M   0% /dev/shm
/dev/sdb1              76G  173M   75G   1% /backup
5. Lets backup “/” partition and put the image into backup directory:

$ dd if=/dev/VolGroup00/LogVol00 of=/backup/VolGroup00-LogVol00.bak
100466688+0 records in
100466688+0 records out
51438944256 bytes (51 GB) copied, 807.368 seconds, 63.7 MB/s
6. Now we need to install one package called e4fsprogs. The e4fsprogs packages contain a number of utilities for creating, checking, modifying, and correcting inconsistencies in fourth extended (ext4 and ext4dev) file systems:

$ yum -y install e4fsprogs
7. We start to do the ext4 filesystem conversion:

$ tune4fs -O extents,uninit_bg,dir_index /dev/VolGroup00/LogVol00
tune4fs 1.41.12 (17-May-2010)

Please run e4fsck on the filesystem.
8. As what has been advised, we need to run filesystem check after tune. I rather do this in single-mode (init 1) to reduce risks. DON’T PROCEED TO REBOOT ONCE THIS STEP COMPLETE!

$ init 1
$ e4fsck -fDC0 /dev/VolGroup00/LogVol00
………
Group descriptor checksum is invalid. FIXED.
Adding dirhash hint to filesystem.

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/VolGroup00/LogVol00: ***** FILE SYSTEM WAS MODIFIED *****
/dev/VolGroup00/LogVol00: ***** REBOOT LINUX *****
/dev/VolGroup00/LogVol00: 112086/12558336 files (0.7% non-contiguous), 1252590/12558336 blocks
9. Change the /etc/fstab to make sure the system will mount the new ext4 filesystem afterwards:

$ vi /etc/fstab

Change following line:

/dev/VolGroup00/LogVol00 /                       ext4    defaults        1 1
10. Rebuild the initrd to make sure our system will mount /sysroot as ext4 and reboot the server once complete:

$ mkinitrd -v -f initrd-2.6.18-238.19.1.el5.img 2.6.18-238.19.1.el5
$ init 6
11. If we directly reboot after fsck on step 8, then we will have kernel panic, unless the kernel is 2.6.28 and later. Once up, lets check whether is it run on ext4 or not:

$ mount | grep ext4
/dev/mapper/VolGroup00-LogVol00 on / type ext4 (rw)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>