- 論壇徽章:
- 0
|
查看系統(tǒng)現(xiàn)在結(jié)構(gòu)
[root@seker /]# fdisk -l
Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1057 8385930 83 Linux
/dev/sda3 1058 1122 522112+ 82 Linux swap / Solaris
/dev/sda4 1123 2088 7759395 5 Extended
[root@seker /]#
[root@seker /]# df -Th
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda2 ext3 7.8G 3.0G 4.5G 40% /
/dev/sda1 ext3 99M 15M 80M 16% /boot
tmpfs tmpfs 125M 0 125M 0% /dev/shm
[root@seker /]#
根據(jù)上面輸出,先計算出一個值來,我們以后要用到:
sda1 = 100M 從柱面1到柱面13. 也就是說12個柱面是100M空間
1.
在邏輯分區(qū)建立一個新的分區(qū) 大小為300M
[root@seker /]# fdisk /dev/sda
The number of cylinders for this disk is set to 2088.
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): n
First cylinder (1123-2088, default 1123):
Using default value 1123
Last cylinder or +size or +sizeM or +sizeK (1123-2088, default 2088): +300M
Command (m for help): p
Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1057 8385930 83 Linux
/dev/sda3 1058 1122 522112+ 82 Linux swap / Solaris
/dev/sda4 1123 2088 7759395 5 Extended
/dev/sda5 1123 1159 297171 83 Linux
Command (m for help): w
這里,再計算一下 給sda5 300M 使用柱面恰好是占用了 1159 - 1123 = 36 個.和我們前面計算的100M=12個柱面相吻合
[root@seker /]# partprobe /dev/sda
[root@seker /]# mke2fs -j /dev/sda5
讓你新建的分區(qū)馬上生效,之后再格式化成ext3.
[root@seker /]# mount /dev/sda5 /mnt
[root@seker /]# cp /etc/rc.d/init.d/* /mnt/
[root@seker /]# ls /mnt/ | wc -l
74
[root@seker /]# sync;sync
[root@seker /]#
將新分區(qū)掛載 并寫入寫文件進去.現(xiàn)在時74個文件在新分區(qū)上.
2.
一切準(zhǔn)備就緒,我們先縮小它.
[root@seker /]# umount /mnt
[root@seker /]#
要想縮小或者是放大,都必須要離線.
[root@seker /]# tune2fs -O ^has_journal /dev/sda5
tune2fs 1.39 (29-May-2006)
刪除分區(qū)上的日志,也就是把系統(tǒng)先轉(zhuǎn)化成ext2格式.(也可以不做這里的轉(zhuǎn)換,直接用ext3的就支持.引用man: resize2fs - ext2/ext3 file system resizer.)
[root@seker /]# e2fsck -f /dev/sda5
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda5: 84/74296 files (2.4% non-contiguous), 11687/297168 blocks
[root@seker /]#
接著對文件系統(tǒng)做強制檢查.
[root@seker /]# resize2fs /dev/sda5 150M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/sda5 to 153600 (1k) blocks.
The filesystem on /dev/sda5 is now 153600 blocks long.
[root@seker /]# 開始收縮,收縮至150M
[root@seker /]# tune2fs -j /dev/sda5
tune2fs 1.39 (29-May-2006)
Creating journal inode: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@seker /]# 再將ext2轉(zhuǎn)成ext3.
[root@seker /]# mount /dev/sda5 /mnt
[root@seker /]# df -Th /dev/sda5
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda5 ext3 146M 5.8M 134M 5% /mnt
[root@seker /]# ls /mnt/ | wc -l
74
[root@seker /]# 驗證大小,以及上面的文件是否還在. 一切安好.
再做寫入測試
[root@seker mnt]# dd if=/dev/zero of=./big_file bs=5M count=28
dd: 寫入 “./big_file”: 設(shè)備上沒有空間
28+0 records in
27+0 records out
145690624 bytes (146 MB) copied, 2.58229 seconds, 56.4 MB/s
[root@seker mnt]#
[root@seker mnt]# df -Th /dev/sda5
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda5 ext3 146M 146M 0 100% /mnt
[root@seker mnt]# 寫到146M后提示空間已滿.
縮小成功.
3.放大
放大比縮小困難一點.因為縮小不需要去更改柱面位置.
[root@seker ~]# umount /mnt
[root@seker ~]# 還是必須離線
[root@seker ~]# tune2fs -O ^has_journal /dev/sda5
tune2fs 1.39 (29-May-2006)
[root@seker ~]# 還是轉(zhuǎn)化成ext2
[root@seker ~]# e2fsck -f /dev/sda5
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda5: 85/38152 files (2.4% non-contiguous), 149445/153600 blocks
[root@seker ~]# 還是強制檢查
[root@seker ~]# resize2fs /dev/sda5 500M
resize2fs 1.39 (29-May-2006)
The containing partition (or device) is only 297171 (1k) blocks.
You requested a new size of 512000 blocks.
[root@seker ~]# 嘗試加大已經(jīng)不好用了.提示只能是297171個blocks.因為分區(qū)時柱面結(jié)束為止被鎖定.
我們突破一下:
[root@seker ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2088.
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): p
Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1057 8385930 83 Linux
/dev/sda3 1058 1122 522112+ 82 Linux swap / Solaris
/dev/sda4 1123 2088 7759395 5 Extended
/dev/sda5 1123 1159 297171 83 Linux
Command (m for help): d
Partition number (1-5): 5
# 將sda5刪掉 不用擔(dān)心,數(shù)據(jù)不會丟.之后馬上新建.
Command (m for help): n
First cylinder (1123-2088, default 1123):
Using default value 1123
Last cylinder or +size or +sizeM or +sizeK (1123-2088, default 2088):
# 結(jié)束的柱面位置是關(guān)鍵.我們在上面算過了100M用到12個柱面,現(xiàn)在我想擴大到500M
# 那么就是從開始位置(1123)處再加上12*5的數(shù)值 結(jié)果就是1183
# 那就在lasr cylinder:這里輸出:1183
Command (m for help): p
/dev/sda5 1123 1183 489951 83 Linux
# 查看確認一下,存盤退出.
Command (m for help): w
The partition table has been altered!
再次嘗試放大
[root@seker ~]# resize2fs /dev/sda5 500M
resize2fs 1.39 (29-May-2006)
The containing partition (or device) is only 489951 (1k) blocks.
You requested a new size of 512000 blocks.
因為我們計算的是個粗略的值,畢竟存在誤差.故500M無法滿足,但這步能提示出能放大的最大數(shù):
is only 489951 (1k) blocks.
[root@seker ~]# resize2fs /dev/sda5 489951K
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/sda5 to 489951 (1k) blocks.
The filesystem on /dev/sda5 is now 489951 blocks long.
[root@seker ~]# 這次成功了.
[root@seker ~]# mount /dev/sda5 /mnt
[root@seker ~]# df -Th /dev/sda5
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda5 ext2 464M 142M 303M 32% /mnt
[root@seker ~]# 加載上來看看,已經(jīng)是464M了,和我們的計算基本吻合.看看已用用量142M是我們之前的數(shù)據(jù),還存在的. 只是類型上時ext2.
拿下來,再轉(zhuǎn)換成ext3吧
[root@seker ~]# umount /mnt/
[root@seker ~]# tune2fs -j /dev/sda5
tune2fs 1.39 (29-May-2006)
Creating journal inode: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@seker ~]# mount /dev/sda5 /mnt
[root@seker ~]# df -Th /dev/sda5
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda5 ext3 464M 151M 295M 34% /mnt
[root@seker ~]# ls /mnt/ |wc -l
75
[root@seker ~]# 原來的文件還在.
完美了.
做寫入測試:
[root@seker ~]# dd if=/dev/zero of=/mnt/seker_file_1 bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.124672 seconds, 168 MB/s
[root@seker ~]# dd if=/dev/zero of=/mnt/seker_file_2 bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.278653 seconds, 75.3 MB/s
[root@seker ~]# dd if=/dev/zero of=/mnt/seker_file_3 bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.373639 seconds, 56.1 MB/s
[root@seker ~]# df -Th /dev/sda5
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda5 ext3 464M 211M 235M 48% /mnt
[root@seker ~]#
寫了三個20M的文件進去.查看一下一切安好.
好久不來發(fā)帖了..歡迎一起研究.有什么問題 請多多指教..
[[i] 本帖最后由 Seker 于 2009-7-1 13:39 編輯 [/i]] |
|