這篇文章將為大家詳細(xì)講解有關(guān)Raspberry Pi OS禁止自動擴(kuò)展tf卡與設(shè)置根分區(qū)大小的示例分析,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)公司主營云巖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),云巖h5成都微信小程序搭建,云巖網(wǎng)站營銷推廣歡迎云巖等地區(qū)企業(yè)咨詢
樹莓派在突然斷電的時(shí)候很容易導(dǎo)致tf卡損壞,我需要另外創(chuàng)建一個(gè)分區(qū)用于保存數(shù)據(jù),系統(tǒng)分區(qū)設(shè)置只讀用于保護(hù)tf卡。
Linux上要消減一個(gè)分區(qū)大小是很難的,然而擴(kuò)展一個(gè)分區(qū)容量比起來簡單很多
Raspbian based on Debian Buster 在系統(tǒng)第一次啟動的時(shí)候會執(zhí)行腳本去擴(kuò)展系統(tǒng)分區(qū)到整個(gè)tf卡的。如果需要另外創(chuàng)建分區(qū),這個(gè)功能是需要禁用的。 Raspbian自動擴(kuò)展tf卡的實(shí)現(xiàn)方式:
/boot/cmdline.txt 末尾init=/usr/lib/raspi-config/init_resize.sh,這個(gè)腳本修改了root分區(qū)的大小,使其擴(kuò)展到真?zhèn)€tf卡
/etc/init.d/resize2fs_once 隨機(jī)啟動腳本會resize2fs 會修改文件系統(tǒng)大小, 并刪除文件自身。
知道這個(gè)就很簡單了,在燒錄好tf卡之后,不要立即插入樹莓派去運(yùn)行,而應(yīng)該在電腦上修改tf卡內(nèi)容。
刪除/boot/cmdline.txt 末尾init=/usr/lib/raspi-config/init_resize.sh 這一串
刪除/etc/init.d/resize2fs_once 腳本中 含resize2fs $ROOT_DEV &&那一行
fdisk 操作tf卡, 重新創(chuàng)建分區(qū)增加size 。我的電腦上是sudo fdisk /dev/sdb
sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): p
Disk /dev/sdb: 14.6 GiB, 15665725440 bytes, 30597120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2fed7fee
Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/sdb2 532480 3620863 3088384 1.5G 83 Linux
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (2048-30597119, default 2048): 532480
Last sector, +sectors or +size{K,M,G,T,P} (532480-30597119, default 30597119): +6G
Created a new partition 2 of type 'Linux' and of size 6 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo e2fsck -f /dev/sdb2
e2fsck 1.44.1 (24-Mar-2018)
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
rootfs: 44456/96576 files (0.2% non-contiguous), 292342/386048 blocks
$ sudo resize2fs /dev/sdb2 6G
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/sdb2 to 1572864 (4k) blocks.
The filesystem on /dev/sdb2 is now 1572864 (4k) blocks long.現(xiàn)在就可以用這個(gè)tf卡啟動樹莓派了,root分區(qū)我只設(shè)置了6G。 進(jìn)入raspbian可以再對剩余空間進(jìn)行分區(qū), cfdisk比較直觀一些。
sudo cfdisk /dev/mmcblk0
之后看到df -h和fdisk -l的大小不一樣用下面命令修復(fù)
sudo resize2fs /dev/mmcblk0p2
關(guān)于Raspberry Pi OS禁止自動擴(kuò)展tf卡與設(shè)置根分區(qū)大小的示例分析就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
當(dāng)前標(biāo)題:RaspberryPiOS禁止自動擴(kuò)展tf卡與設(shè)置根分區(qū)大小的示例分析
標(biāo)題URL:http://www.chinadenli.net/article2/isjgic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站排名、企業(yè)建站、微信小程序、、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)