商会资讯

 找回密码
 立即注册

QQ登录

只需一步,快速开始

用新浪微博连接

一步搞定

搜索
热搜: 活动 交友 discuz
查看: 8710|回复: 0
打印 上一主题 下一主题

Ext2文件系统转换为Ext3的方法

[复制链接]

109

主题

1

好友

3774

积分

管理员

Rank: 9Rank: 9Rank: 9

  • ta_mind
    mb_qb7
    2013-3-19 01:56
  • classn_01: 366 classn_02

    [LV.9]以坛为家II

    跳转到指定楼层
    楼主
    发表于 2016-11-22 17:02:51 |只看该作者 |倒序浏览
    Ext2文件系统在操作系统崩溃或者非法关机的情况下重启之后,要开始漫长的自检过程。自检的时间大致和硬盘的大小有关。因此,现在大部分LINUX系统在安装的时候都使用了Ext3。但如果使用了Ext2文件系统,又不想重装系统的话,可以采用下面提供的方法将Ext2转换为Ext3。

    本人已经验证了文中提到的ext2转换到ext3的方法。具体见正文的标注。
    Converting Ext2 Filesystems toExt3
    Copyright (C) 2003by Steve Litt
    [ Linux Library | Troubleshooters.Com | Email Steve Litt | Copyright Notice ]Contents:Executive SummaryUntil recently, the Ext2 filesystem has been the Linux default. Ext2is a technological miracle. Low fragmentation, redundant enough to bereliably regenerated on error yet diskspace efficient, fast, andadaptable. But when the computer is rebooted or powered off withoutcorrectly shutting down, Ext2 filesystems are placed in an error state.When the computer comes back up, the user is confronted with some mildlyconfusing, and very intimidating, messages and choices. Should he letthe filesystem correct itself? Warning, this can lose data!
    Journalized filesystems are made to eliminate such error messages.The Ext3 filesystem is an Ext2 filesystem with a journal file and somefilesystem driver additions making the filesystem journalized.

    My research and those of others, as well as limited experimentationby myself, indicate that the tune2fs -j command, which is the primarycommand for converting from Ext2 to Ext3, is safe to run even onwriteable mounted partitions. However, when possible, I run the commandon unmounted or read-only mounted partitions. It might besuperstitious, but I feel that is playing it safe. Nevertheless, whenconfronted with situations making unmounting difficult, I run thecommand on writeable mounted partitions.

    Converting the root directory from Ext2 to Ext3 is a little moredifficult. Converting back from Ext3 to Ext2 is a hairy and dangerousprocedure. Instructions for both are given in this document, but thinklong and hard before converting the root directory.

    DisclaimerObviously, you use this document at your own risk. I am notresponsible for any damage or injury caused by your use of thisdocument, or caused by errors and/or omissions in this document. Ifthat's not acceptable to you, you may not use this document. By usingthis document you are accepting this disclaimer.
    Converting from Ext2 to Ext3The conversion procedure is simple enough. Imagine /dev/hda10mounted as /test – the procedure would be as follows:
    • Log in as root
    • Make sure /etc/fstabhas         /dev/hda10 mounted to /test as ext2, read write
    • umount /dev/hda10
      • If you can't unmount it, thenremount it read only (mount -o remount,ro /dev/hda10)
    • tune2fs -j /dev/hda10
    • Edit /etc/fstab,and for         /dev/hda10, changeext2 to ext3
    • mount /dev/hda10
    • /sbin/shutdown -h now
    • mount | grep /dev/hda10
      • If it's not shown as ext3,                 reboot, if still not, troubleshoot
      • Otherwise, you're done.
        
    A few explanations are in order. The tunefs command creates thejournal file, which is kept in a special inode on the device (bydefault). You then must change the /etc/fstabentry to reflect it's a journalling filesystem, and then mount it.

    Converting the /usr directoryThis applies only to those systems in which the /usr tree has its own partition.Converting the /usrdirectory presents a challenge because commands like tune2fs are locatedin the /usr tree, so it must be mounted. Mount it read only with thefollowing command:
    mount -o remount,ro /usr
    Then run tune2fs -j, edit /etc/fstab, and then unmountand remount /usr.
    Converting the / directoryFirst, think long and hard before deciding to convert the rootdirectory. Ext3's primary purpose is shorter recovery from disasterrather than data loss prevention. Converting the root directory fromExt2 to Ext3 isn't difficult, but converting it back from Ext3 to Ext2is a treacherous process fraught with problems. But, if you really mustperform the Ext2 to Ext3 conversion on the root directory, here's how,assuming /dev/hda2 ismounted as the root directory and /dev/hda1is mounted as /boot:
    • Log in as root
    • Edit /etc/fstab andchange ext2 to  ext3 on the line referencing theroot directory. /*这里仅指出需要修改的是根目录,也就是fstab文件中/boot一行对应的ext2是不需要修改的*/
    • tune2fs -j /dev/hda2
    • cd /boot
    • mv initrd-2.4.18-26.8.0.img initrd-2.4.18-26.8.0.img.ext2
    • mkinitrdinitrd-2.4.18-26.8.0.img 2.4.18-26.8.0
    • reboot
         

    In the preceding, you MUST perform all the steps, including the mkinitrd, before rebooting.Failing to perform all the steps before rebooting produces a "buriedshovel" where if only you could boot the machine, you could run the mkinitrd command, and if onlyyou could run the mkinitrdcommand, you could boot the machine.

    笔者验证了本小节提到的将根目录(/)从ext2转换为ext3。完全按照本小节讲解的方法在RH 9上实现,重启后可以正常进入系统。如果需要永久性的关闭当系统非法关机后启动时的硬盘检测的话,可以再进入系统后,执行命令:
      tune2fs -c 0 device
      其中device即为你想避免自检的分区,我这里/dev/hda1挂载在/下,/dev/hda2挂载在/boot。两个都需要关闭检测的话,可以:
      tune2fs -c 0 /dev/hda1
      tune2fs -c 0 /dev/hda2
      如果要设置隔多长时间检测一次的话,可以使用:
      tune2fs -i interval device
      这里不再举例,具体的使用方法见tune2fs。
    Converting from Ext3 back to Ext2There may come a time when you want to convert back to Ext2. Fordirectories other than the root directory or /usr, it's pretty easy. Thefollowing once again uses the example of /dev/hda10 mounted to directory /test:

        
    • umount /dev/hda10
         
        
    • tune2fs -O ^has_journal/dev/hda10
        
    • e2fsck /dev/hda10
        
    • Edit /etc/fstab tochange /dev/hda10 to mounttype ext2
        
    • mount /dev/hda10
    The tune2fs commandremoves the journal inode, and the e2fsckcommand completes that removal.
    Back-Converting the root directory
    The root directory is a challenge for a number of reasons. First, itmust be mounted for the system to run, but it must be unmounted to runthe e2fsck command. Also,different distros behave different ways. The mkinitrd command varies widelybetween distros. The preceding works on a Red Hat 8.0 machine, butother machines might require other solutions. We'll assume that /dev/hda1 is /boot, while /dev/hda2 is the root directory (/).

        
    • Log in as root
        
    • Edit /etc/fstab tochange the /dev/hda2 linefrom ext3 to ext2
        
    • reboot
        
    • Log in as root
        
    • mv initrd-2.4.18-26.8.0.img initrd-2.4.18-26.8.0.img.ext3
        
    • mkinitrdinitrd-2.4.18-26.8.0.img 2.4.18-26.8.0
        
    • Place your Knoppix CD in the CD drive
        
    • reboot
        
    • Notice you are now booted to Knoppix
        
    • Ctrl+Alt+F2 to access a root prompt
        
    • umount /dev/hda1
        
    • umount /dev/hda2
        
    • tune2fs -O ^has_journal/dev/hda2
        
    • e2fsck /dev/hda2
        
    • mount -t ext3 /dev/hda2/mnt/hda2
        

           
      • This should fail. If it does, it proves that the partition nolonger has a journaling inode.
          
        
    • reboot
        
    • Remove the Knoppix CD and press Enter as prompted
        
    • Notice you are now booted to the original operating system(hopefully)
        
    • Log in as root
        
    • Execute a mountcommand to verify an Ext2 root partition.
    Back Converting the /usrdirectoryAssume that /usr ismounted by /dev/hda4


        
    • Place your Knoppix CD in the CD drive
        
    • reboot
        
    • Notice you are now booted to Knoppix
        
    • Ctrl+Alt+F2 to access a root prompt
        
    • umount /dev/hda4
        
    • tune2fs -O ^has_journal/dev/hda4
        
    • e2fsck /dev/hda4
        
    • mount -t ext3 /dev/hda4/mnt/hda4
        

           
      • This should fail. If it does, it proves that the partition nolonger has a journaling inode.
          
        
    • reboot
        
    • Remove the Knoppix CD and press Enter as prompted
        
    • Notice you are now booted to the original operating system(hopefully)
        
    • Log in as root
        
    • Execute a mountcommand to verify an Ext2 /usrpartition.
    SummaryConverting from Ext2 to Ext3 is usually easy, although converting theroot partition is usually undesirable. From what I hear, and from mylimited testing, the tune2fs -jcommand is so safe that it can be performed on a partition mountedread-write. However, it's usually easy to unmount the partition ormount it read-only, and when that's easy, I've done it that way.

    Changing the filesystem type of the root directory requires rebuildingthe initrd image. Those procedures are explained in this document.
    分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    分享分享0 收藏收藏0 转发到微博
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    回顶部