歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 在線調整ext3磁盤容量

在線調整ext3磁盤容量

日期:2017/3/1 14:43:38   编辑:關於Linux
在線調整ext3磁盤容量 調整前先用 tar cf /disk/home.tar /home 進行打包備份。 1、查看磁盤分區情況 fdisk -l Disk /dev/sda: 291.9 GB, 291999055872 bytes 255 heads, 63 sectors/track, 35500 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes 磁盤大小,塊大小,柱面情況 [root@localhost ~]# df -B 4k Filesystem 4K-blocks Used Available Use% Mounted on /dev/sda2 990087 500195 438786 54% / /dev/sda5 3575306 41828 3348932 2% /home /dev/sda1 11659 2638 8419 24% /boot tmpfs 67424 0 67424 0% /dev/shm df –B 4k 以4k為以單位查看,方便計算後面分區修改後的大小 [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 3.8G 2.0G 1.7G 54% / /dev/sda5 14G 164M 13G 2% /home /dev/sda1 46M 11M 33M 24% /boot tmpfs 264M 0 264M 0% /dev/shm 磁盤分區及目錄的掛載情況 2、記錄磁盤柱面情況以及需要劃分的分區大小 計算終止柱面號 e.g: 原先/usr/local的大小為5000 MB, 起始柱面號為2550, 終止柱面號為3157. 那麼我現在要將它的大小改為1000MB, 應該這樣計算終止柱面號( [3.2] = 4 ): 終止柱面號 = 2550 + [(1000 * 1024 * 1024 ) / 8225280] = 2678 使用fdisk刪除原來的分區(以前分區的數據不會丟失!). 然後新建一個分區, 新分區於舊分區唯一的區別就在於分區大小不一樣, 這表現在他們終止柱面號不同. 增加分區大小: 終止柱面號設置為空閒空間的最後一個柱面號. 減小分區大小: 終止柱面號由計算得出. 3、調整步驟 umount /dev/sda5 #卸載分區 fsck -n /dev/sda5 # -n參數只輸出磁盤信息,不修復 tune2fs -O ^has_journal /dev/sda5 #將ext3轉換為ext2,因為只有ext2支持調整分區大小 e2fsck -f /dev/sda5 #檢查ext2文件系統是否正常 接著調整分區大小,但是要保證調整後的分區大小要大於當前分區已經使用的空間大小。 比如當前分區已使用180M,至少要保證這個分區預留1G的空間。 resize2fs /dev/sda5 5000M #調整分區為5G fdisk /dev/sda #注意此處是sda,非sda5。 重新建立分區信息(注意分區標識符一定要選對,此處是sda5,所以刪除的時候選擇5) [root@localhost ~]# fdisk /dev/sda 注意這裡是/dev/sda而非/dev/sda5 The number of cylinders for this disk is set to 2610. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): 刪除分區(/dev/sda5) Command (m for help): d Partition number (1-5): 5 創建新分區 Command (m for help): n First cylinder (773-2610, default 773): 773 這裡會被詢問填寫新分區的大小,開始柱面默認即可,現在關鍵介紹結束柱面的計算。 由前面數據可知,文件系統的大小為1280000*4K,為了確保我們的分區足夠大以包含文件系統,這裡可以增加文件系統大小的3%——5%來作為分區大小。 因此分區大小為Size=1280000*4K*1.05=5376000K Last cylinder or +size or +sizeM or +sizeK (773-2610, default 2610): +5376000K 接著使用參數a Command (m for help): a Partition number (1-5): 5 選項a的解釋為 toggle a bootable flag 對於這個選項不是很理解,但一個明顯的作用就是為新的分區分配區號,這裡選擇5(/dev/sda5)。 接著將修改寫入分區表並退出fdisk Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks 重啟系統。 reboot fsck -n /dev/sda5 #檢查調整後的分區信息 tune2fs -j /dev/sda5 #將ext2轉換成ext3 reboot #再次重啟系統 啟動後看看/home的大小 df -B 4k df -h fdisk -l 如果沒有被掛載,編輯 /etc/fstab 文件後,執行 mount -a 進行掛載。 對於分割出來的空閒分區可以用 fdisk /dev/sda 創建新的分區。注意磁盤柱面號的啟始與截止位置。
Copyright © Linux教程網 All Rights Reserved