分享

扩容ext4文件系统

 rookie 2012-04-13

原来一个分区分得太小了(只有5G),等拷贝完数据才知道太小了。于是尝试了扩容的办法。以前对ext3干过这样的事情,看了ext3上的wiki介绍,得知做法和原来的ext2/ext3一样(看来兼容性还是不错)。下面是我的扩容过程

首先下载你要扩容的分区,这样当然是最保险的,如果你就是不想卸载,只要你别对其做写操作,也没有问题。

接下来就是用fdisk删除该分区,然后用你期望的大小重建该分区。这里要注意的是,分区的开始扇区一定要和删除前保持一致,否则文件系统就会遭到破坏。下面是我的实际操作过程

  1. # fdisk /dev/sda  
  2.   
  3. Command (m for help): p  
  4.   
  5. Disk /dev/sda: 64.4 GB, 64424509440 bytes  
  6. 255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors  
  7. Units = sectors of 1 * 512 = 512 bytes  
  8. Sector size (logical/physical): 512 bytes / 512 bytes  
  9. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  10. Disk identifier: 0x00067b51  
  11.   
  12.    Device Boot      Start         End      Blocks   Id  System  
  13. /dev/sda1   *          63    29302559    14651248+  83  Linux  
  14. /dev/sda2        29302784    39061503     4879360   83  Linux  
  15.   
  16. Command (m for help): d  
  17. Partition number (1-4): 2  
  18.   
  19. Command (m for help): n  
  20. Command action  
  21.    e   extended  
  22.    p   primary partition (1-4)  
  23. p  
  24. Partition number (1-4, default 2):  
  25. Using default value 2  
  26. First sector (29302560-125829119, default 29302560): 29302784  
  27. Last sector, +sectors or +size{K,M,G} (29302784-125829119, default 125829119): +20G  
  28.   
  29. Command (m for help): p  
  30.   
  31. Disk /dev/sda: 64.4 GB, 64424509440 bytes  
  32. 255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors  
  33. Units = sectors of 1 * 512 = 512 bytes  
  34. Sector size (logical/physical): 512 bytes / 512 bytes  
  35. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  36. Disk identifier: 0x00067b51  
  37.   
  38.    Device Boot      Start         End      Blocks   Id  System  
  39. /dev/sda1   *          63    29302559    14651248+  83  Linux  
  40. /dev/sda2        29302784    71245823    20971520   83  Linux  
  41.   
  42. Command (m for help): w  
  43. The partition table has been altered!  
  44.   
  45. Calling ioctl() to re-read partition table.  
  46.   
  47. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.  
  48. The kernel still uses the old table. The new table will be used at  
  49. the next reboot or after you run partprobe(8) or kpartx(8)  
  50. Syncing disks.  


而后执行下面的指令

  1. # partprobe /dev/sda  
  2. # e2fsck -f /dev/sda2  
  3. e2fsck 1.41.12 (17-May-2010)  
  4. Pass 1: Checking inodes, blocks, and sizes  
  5. Pass 2: Checking directory structure  
  6. Pass 3: Checking directory connectivity  
  7. Pass 4: Checking reference counts  
  8. Pass 5: Checking group summary information  
  9. data: 38934/305216 files (0.1% non-contiguous), 1140469/1219840 blocks  
  10. [root@wgzhao-nb wgzhao]# resize2fs /dev/sda2 20G  
  11. resize2fs 1.41.12 (17-May-2010)  
  12. Resizing the filesystem on /dev/sda2 to 5242880 (4k) blocks.  
  13. The filesystem on /dev/sda2 is now 5242880 blocks long.  

我们再挂载上来,得到的就是我期望的大小了(20G)
  1. # df -h  
  2. Filesystem            Size  Used Avail Use% Mounted on  
  3. /dev/sda1              14G  6.5G  7.2G  48% /  
  4. tmpfs                 1.4G  296K  1.4G   1% /dev/shm  
  5. /dev/sda2              20G  4.3G   16G  22% /data  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多