www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 嵌入式 > 嵌入式軟件
[導(dǎo)讀]介紹如何調(diào)整linux分區(qū)大小

環(huán)境

服務(wù)器安裝有一個(gè)60G的硬盤(pán),目前已經(jīng)劃分為/、/home、/chroot和/swap,詳細(xì)的分區(qū)信息如何下所示:


Command (m for help): p

Disk /dev/hda: 61.4 GB, 61492838400 bytes
255 heads, 63 sectors/track, 7476 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 915 7349706 83 Linux
/dev/hda2 916 1414 4008217+ 83 Linux
/dev/hda3 1415 7476 48693015 5 Extended
/dev/hda5 1415 1477 506016 82 Linux swap
/dev/hda6 1478 7476 48186936 83 Linux



然后現(xiàn)在希望從/home分區(qū)里面分出大約4GB的空間用于安裝FreeBSD。

過(guò)程

首先,我們需要調(diào)整文件系統(tǒng)的大小(注意是文件系統(tǒng),而不是分區(qū)的大小),然后對(duì)調(diào)整完畢的文件系統(tǒng)進(jìn)行檢查,然后再進(jìn)一步調(diào)整分區(qū)的大小。

文章以我自己用的系統(tǒng)為例子,實(shí)際操作時(shí)根據(jù)情況調(diào)整即可。

用慣了傳統(tǒng)調(diào)整硬盤(pán)工具的人可能會(huì)認(rèn)為文件系統(tǒng)和硬盤(pán)的分區(qū)之間是統(tǒng)一的,實(shí)際上他們之間并不是完整的整體(這也就是為什么BSD可以在一個(gè)硬盤(pán)分區(qū)里面制作多個(gè)文件系統(tǒng)分區(qū))。想像一下帶有移動(dòng)式書(shū)架的書(shū)櫥。你可以通過(guò)移動(dòng)式書(shū)架調(diào)整書(shū)櫥里面書(shū)籍的位置。把書(shū)當(dāng)成文件系統(tǒng),你可以在書(shū)櫥里面放滿(mǎn)書(shū)籍,也可以通過(guò)移動(dòng)式書(shū)架調(diào)整書(shū)櫥的空間。當(dāng)然也可以通過(guò)書(shū)架調(diào)整書(shū)櫥里面書(shū)籍存放的位置。如下圖所示:


|<-- hda1------>|<-- hda2------>|
+---------------+---------------+
|XXXXXXXXXXXXXXX|XXXXXXXXXX| |
|XXXXXXXXXXXXXXX|XXXXXXXXXX| |
+---------------+---------------+



硬盤(pán)分區(qū)/dev/hda1中的文件系統(tǒng)占滿(mǎn)了整個(gè)分區(qū),而/dev/hda2中的文件系統(tǒng)只占用了2/3左右的分區(qū)。

基本的原理就是這樣,現(xiàn)在讓我們開(kāi)始調(diào)整/dev/hda6中文件系統(tǒng)的大?。?


[root@ringmail root]# umount /home
[root@ringmail root]# resize_reiserfs -s 43000M /dev/hda6

<-------------resize_reiserfs, 2002------------->
reiserfsprogs 3.6.4

You are running BETA version of reiserfs shrinker.
This version is only for testing or VERY CAREFUL use.
Backup of you data is recommended.

Do you want to continue? [y/N]:y
Processing the tree: 0%
....20%....40%....60%....80%....100% left 0, 301020 /sec

nodes processed (moved):
int 56 (0),
leaves 8124 (0),
unfm 6313240 (0),
total 6321420 (0).

check for used blocks in truncated region

ReiserFS report:
blocksize 4096
block count 11008000 (12046734)
free blocks 4678034 (5716736)
bitmap block count 336 (368)

Syncing..done



由于/home原來(lái)的大小是47057,而我們希望在/home里面劃分4G的空間出來(lái),取整數(shù)/home的目標(biāo)大小就是43000。所以在resize_reiserfs時(shí)為-s提供大小為43000M。

這樣我們就已經(jīng)完成了文件系統(tǒng)大小調(diào)整的工作,下面讓我們計(jì)算一下目標(biāo)分區(qū)的大小,這個(gè)大小需要根據(jù)你的fdisk里面的Units值來(lái)計(jì)算,因?yàn)橛脖P(pán)分區(qū)都是按照柱面來(lái)劃分的,基本的計(jì)算方法為:43000*1024*1024/8225280=5481.7304699657640834111422346716,然后我們?nèi)∽罱咏闹?482+1478=6960來(lái)作為分區(qū)結(jié)束的柱號(hào),這里面的1478是/home分區(qū)開(kāi)始的柱面號(hào),在前面的fdisk里面可以看到。

調(diào)整完文件系統(tǒng)的大小以后,再使用以下命令以文件系統(tǒng)進(jìn)行全面的檢查:


[root@ringmail root]# reiserfsck --check --fix-fixable /dev/hda6



現(xiàn)在我們已經(jīng)完成文件系統(tǒng)的大小調(diào)整工作,但是硬盤(pán)分區(qū)的大小仍然沒(méi)有調(diào)整,還是跟先前一樣大(可以想像我們從書(shū)櫥里面拿走了幾本書(shū),而書(shū)架的大小并沒(méi)有調(diào)整,依然占用著原來(lái)的空間)。

現(xiàn)在我們要開(kāi)始進(jìn)行整個(gè)操作里面最危險(xiǎn)的操作:如果沒(méi)有必要的話(huà),最好不要進(jìn)行下去:-D,不過(guò)不必過(guò)于擔(dān)心,按照以下操作進(jìn)行即可。

啟動(dòng)fdisk,并按照以下步驟進(jìn)行:


[root@ringmail root]# fdisk /dev/hda

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

Device Boot Start End Blocks Id System
/dev/hda1 * 1 915 7349706 83 Linux
/dev/hda2 916 1414 4008217+ 83 Linux
/dev/hda3 1415 7476 48693015 5 Extended
/dev/hda5 1415 1477 506016 82 Linux swap
/dev/hda6 1478 7476 48186936 83 Linux

Command (m for help): d
Partition number (1-6): 6

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1478-7476, default 1478): 1478
Last cylinder or +size or +sizeM or +sizeK (1478-7476, default 7476): 6960

Command (m for help): p

Disk /dev/hda: 61.4 GB, 61492838400 bytes
255 heads, 63 sectors/track, 7476 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 915 7349706 83 Linux
/dev/hda2 916 1414 4008217+ 83 Linux
/dev/hda3 1415 7476 48693015 5 Extended
/dev/hda5 1415 1477 506016 82 Linux swap
/dev/hda6 1478 6960 44042166 83 Linux

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.



這里需要說(shuō)明的是,由于內(nèi)核仍然使用舊的分區(qū)表,我需要通過(guò)重新啟動(dòng)才可以刷新剛制作的分區(qū)信息,所以在進(jìn)行完重劃分區(qū)操作以后,我對(duì)系統(tǒng)進(jìn)行了重新啟操作。系統(tǒng)重啟后再繼續(xù)后續(xù)的操作過(guò)程。

通過(guò)以上步驟,我們已經(jīng)完成了硬盤(pán)分區(qū)大小調(diào)整的操作,接下來(lái)回到重新調(diào)整文件系統(tǒng)大小的問(wèn)題上來(lái)。由于硬盤(pán)分區(qū)是按照柱面來(lái)計(jì)劃的,我們要在resize_reiserfs步驟上就一步到位調(diào)整文件系統(tǒng)大小與硬盤(pán)分區(qū)大小正好相等是比較困難的事情。所以一般是調(diào)硬盤(pán)分區(qū)比文件系統(tǒng)要大一點(diǎn)點(diǎn),然后再通過(guò)以下命令進(jìn)行同步(當(dāng)然如果你不在意硬盤(pán)分區(qū)里面存在部分空間的話(huà)也可以忽略以下步驟):


[root@ringmail root]# umount /home/
[root@ringmail root]# resize_reiserfs /dev/hda6

<-------------resize_reiserfs, 2002------------->
reiserfsprogs 3.6.4

ReiserFS report:
blocksize 4096
block count 11010541 (11008000)
free blocks 4680574 (4678034)
bitmap block count 337 (336)

Syncing..done



完成以后原有分區(qū)的大小調(diào)整操作已經(jīng)結(jié)束,接下來(lái)需要?jiǎng)?chuàng)建新分區(qū):


[root@ringmail root]# fdisk /dev/hda

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

Device Boot Start End Blocks Id System
/dev/hda1 * 1 915 7349706 83 Linux
/dev/hda2 916 1414 4008217+ 83 Linux
/dev/hda3 1415 7476 48693015 5 Extended
/dev/hda5 1415 1477 506016 82 Linux swap
/dev/hda6 1478 6960 44042166 83 Linux

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (6961-7476, default 6961):
Using default value 6961
Last cylinder or +size or +sizeM or +sizeK (6961-7476, default 7476):
Using default value 7476

Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): a5
Changed system type of partition 7 to a5 (FreeBSD)

Command (m for help): p

Disk /dev/hda: 61.4 GB, 61492838400 bytes
255 heads, 63 sectors/track, 7476 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 915 7349706 83 Linux
/dev/hda2 916 1414 4008217+ 83 Linux
/dev/hda3 1415 7476 48693015 5 Extended
/dev/hda5 1415 1477 506016 82 Linux swap
/dev/hda6 1478 6960 44042166 83 Linux
/dev/hda7 6961 7476 4144738+ a5 FreeBSD

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.



至此,整個(gè)調(diào)整分區(qū)大小及創(chuàng)建新分區(qū)的操作全部完成。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

CPU親和度通過(guò)限制進(jìn)程或線程可以運(yùn)行的CPU核心集合,使得它們只能在指定的CPU核心上執(zhí)行。這可以減少CPU緩存的失效次數(shù),提高緩存命中率,從而提升系統(tǒng)性能。

關(guān)鍵字: Linux 嵌入式

在Linux系統(tǒng)性能優(yōu)化中,內(nèi)存管理與網(wǎng)絡(luò)連接處理是兩大核心領(lǐng)域。vm.swappiness與net.core.somaxconn作為關(guān)鍵內(nèi)核參數(shù),直接影響系統(tǒng)在高負(fù)載場(chǎng)景下的穩(wěn)定性與響應(yīng)速度。本文通過(guò)實(shí)戰(zhàn)案例解析這兩個(gè)...

關(guān)鍵字: Linux 內(nèi)存管理

對(duì)于LLM,我使用b谷歌Gemini的免費(fèi)層,所以唯一的成本是n8n托管。在使用了n8n Cloud的免費(fèi)積分后,我決定將其托管在Railway上(5美元/月)。然而,由于n8n是開(kāi)源的,您可以在自己的服務(wù)器上托管它,而...

關(guān)鍵字: 人工智能 n8n Linux

在Linux系統(tǒng)管理中,權(quán)限控制是安全運(yùn)維的核心。本文通過(guò)解析/etc/sudoers文件配置與組策略的深度應(yīng)用,結(jié)合某金融企業(yè)生產(chǎn)環(huán)境案例(成功攔截98.7%的非法提權(quán)嘗試),揭示精細(xì)化權(quán)限管理的關(guān)鍵技術(shù)點(diǎn),包括命令別...

關(guān)鍵字: Linux 用戶(hù)權(quán)限 sudoers文件

Linux內(nèi)核中的信號(hào)量(Semaphore)是一種用于資源管理的同步原語(yǔ),它允許多個(gè)進(jìn)程或線程對(duì)共享資源進(jìn)行訪問(wèn)控制。信號(hào)量的主要作用是限制對(duì)共享資源的并發(fā)訪問(wèn)數(shù)量,從而防止系統(tǒng)過(guò)載和數(shù)據(jù)不一致的問(wèn)題。

關(guān)鍵字: Linux 嵌入式

在云計(jì)算與容器化技術(shù)蓬勃發(fā)展的今天,Linux網(wǎng)絡(luò)命名空間(Network Namespace)已成為構(gòu)建輕量級(jí)虛擬網(wǎng)絡(luò)的核心組件。某頭部互聯(lián)網(wǎng)企業(yè)通過(guò)命名空間技術(shù)將測(cè)試環(huán)境資源消耗降低75%,故障隔離效率提升90%。本...

關(guān)鍵字: Linux 云計(jì)算

在Linux內(nèi)核4.18+和主流發(fā)行版(RHEL 8/Ubuntu 20.04+)全面轉(zhuǎn)向nftables的背景下,某電商平臺(tái)通過(guò)遷移將防火墻規(guī)則處理效率提升40%,延遲降低65%。本文基于真實(shí)生產(chǎn)環(huán)境案例,詳解從ipt...

關(guān)鍵字: nftables Linux

在Linux設(shè)備驅(qū)動(dòng)開(kāi)發(fā)中,等待隊(duì)列(Wait Queue)是實(shí)現(xiàn)進(jìn)程睡眠與喚醒的核心機(jī)制,它允許進(jìn)程在資源不可用時(shí)主動(dòng)放棄CPU,進(jìn)入可中斷睡眠狀態(tài),待資源就緒后再被喚醒。本文通過(guò)C語(yǔ)言模型解析等待隊(duì)列的實(shí)現(xiàn)原理,結(jié)合...

關(guān)鍵字: 驅(qū)動(dòng)開(kāi)發(fā) C語(yǔ)言 Linux

在Unix/Linux進(jìn)程間通信中,管道(pipe)因其簡(jiǎn)單高效被廣泛使用,但默認(rèn)的半雙工特性和無(wú)同步機(jī)制容易導(dǎo)致數(shù)據(jù)競(jìng)爭(zhēng)。本文通過(guò)父子進(jìn)程雙向通信案例,深入分析互斥鎖與狀態(tài)機(jī)在管道同步中的應(yīng)用,實(shí)現(xiàn)100%可靠的數(shù)據(jù)傳...

關(guān)鍵字: 管道通信 父子進(jìn)程 Linux

RTOS :RTOS的核心優(yōu)勢(shì)在于其實(shí)時(shí)性。它采用搶占式調(diào)度策略,確保高優(yōu)先級(jí)任務(wù)能夠立即獲得CPU資源,從而在最短時(shí)間內(nèi)完成處理。RTOS的實(shí)時(shí)性是通過(guò)嚴(yán)格的時(shí)間管理和任務(wù)調(diào)度算法實(shí)現(xiàn)的,能夠滿(mǎn)足對(duì)時(shí)間敏感性要求極高的...

關(guān)鍵字: Linux RTOS
關(guān)閉