歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux增加分區大小

Linux增加分區大小

日期:2017/3/1 17:22:03   编辑:關於Linux
這裡以Red hat AS4 為例。當磁盤分區發現不夠用時,能想道的第一個做法就是增加分區大小。但是一般Linux如果沒有采用邏輯卷管理,則動態增加分區大小很困難,一個能想道的辦法就是,備份分區文件系統數據,刪除分區,然後再重新創建分區,恢復備份的文件系統,這個做法比較玄,可能刪除分區後導致系統無法啟動。

第二個做法就是,創建一個新的邏輯分區(當然必須有未使用的磁盤空間能分配),將文件系統從老分區拷貝到新分區,然後修改fstab,使用新分區/文件系統替換老的分區/文件系統

第三種做法是,創建一個新的邏輯分區,將新的邏輯分區格式化ext3(或其他類型)的文件系統,mount到磁盤空間不夠的文件系統,就跟原來的分區/文件系統一樣的使用。

這裡采用的是第三種方式:

sdb為第二個SCSI硬盤。
[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb

The number of cylinders for this disk is set to 8942.
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/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
可以看出sdb1,2,3為主分區,sdb4為擴展分區。後面的sdb5,6,7則為邏輯分區。柱面編號(Start,End)是連續的,sdb7只用道了1173,而從擴展分區看最大到8942,也就是說,還有7769個柱面是空閒的,一個柱面大小為8225280,約為8M大小。還剩7769*8225280bytes,約62G未使用。

新增加一個邏輯分區(注:若涉及到主分區和擴展分區,實際情況可能比這個復雜,這裡4個主分區(包括擴展分區)都分過了,所以只能分邏輯分區)
Command (m for help): n
First cylinder (1174-8942, default 1174):
Using default value 1174

增加大小為10G
Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M
增加後看一下,多了一個邏輯分區/dev/sdb8

Command (m for help): p

Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
/dev/sdb8 1174 2419 10008463+ 83 Linux


可以看到,增加了一個sdb8的分區,柱面號從1174到2419.
寫入分區表,執行分區操作
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: 設備或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

分區完後,是看不到文件系統的
[root@hdp0 hadoop]# df -m
Filesystem 1M-塊 已用 可用 已用% 掛載點
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var

重啟機器

reboot

格式化文件系統

[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8

mount文件系統,/home/develop 為/home下一目錄
[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop

查看文件系統,可以看到新建立的分區/文件系統已經掛載上,能夠使用了。

[root@hdp0 hadoop]# df -m
Filesystem 1M-塊 已用 可用 已用% 掛載點
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
/dev/sdb8 9621 54 9079 1% /home/develop

摘自 hongweigg的專欄
Copyright © Linux教程網 All Rights Reserved