溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Raspberry Pi OS禁止自動(dòng)擴(kuò)展tf卡與設(shè)置根分區(qū)大小的示例分析

發(fā)布時(shí)間:2021-11-19 18:31:53 來(lái)源:億速云 閱讀:233 作者:柒染 欄目:互聯(lián)網(wǎng)科技

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

樹(shù)莓派在突然斷電的時(shí)候很容易導(dǎo)致tf卡損壞,我需要另外創(chuàng)建一個(gè)分區(qū)用于保存數(shù)據(jù),系統(tǒng)分區(qū)設(shè)置只讀用于保護(hù)tf卡。

Linux上要消減一個(gè)分區(qū)大小是很難的,然而擴(kuò)展一個(gè)分區(qū)容量比起來(lái)簡(jiǎn)單很多

Raspbian based on Debian Buster 在系統(tǒng)第一次啟動(dòng)的時(shí)候會(huì)執(zhí)行腳本去擴(kuò)展系統(tǒng)分區(qū)到整個(gè)tf卡的。如果需要另外創(chuàng)建分區(qū),這個(gè)功能是需要禁用的。 Raspbian自動(dòng)擴(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ī)啟動(dòng)腳本會(huì)resize2fs 會(huì)修改文件系統(tǒng)大小, 并刪除文件自身。

知道這個(gè)就很簡(jiǎn)單了,在燒錄好tf卡之后,不要立即插入樹(shù)莓派去運(yùn)行,而應(yīng)該在電腦上修改tf卡內(nèi)容。

  1. 刪除/boot/cmdline.txt 末尾init=/usr/lib/raspi-config/init_resize.sh 這一串

  2. 刪除/etc/init.d/resize2fs_once 腳本中 含resize2fs $ROOT_DEV &&那一行

  3. 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卡啟動(dòng)樹(shù)莓派了,root分區(qū)我只設(shè)置了6G。 進(jìn)入raspbian可以再對(duì)剩余空間進(jìn)行分區(qū), cfdisk比較直觀一些。

sudo cfdisk /dev/mmcblk0

之后看到df -h和fdisk -l的大小不一樣用下面命令修復(fù)

sudo resize2fs /dev/mmcblk0p2

關(guān)于Raspberry Pi OS禁止自動(dòng)擴(kuò)展tf卡與設(shè)置根分區(qū)大小的示例分析就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI