這篇文章將為大家詳細講解有關(guān)Raspberry Pi OS禁止自動擴展tf卡與設(shè)置根分區(qū)大小的示例分析,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
創(chuàng)新互聯(lián)公司主營云巖網(wǎng)站建設(shè)的網(wǎng)絡公司,主營網(wǎng)站建設(shè)方案,成都APP應用開發(fā),云巖h5成都微信小程序搭建,云巖網(wǎng)站營銷推廣歡迎云巖等地區(qū)企業(yè)咨詢
樹莓派在突然斷電的時候很容易導致tf卡損壞,我需要另外創(chuàng)建一個分區(qū)用于保存數(shù)據(jù),系統(tǒng)分區(qū)設(shè)置只讀用于保護tf卡。
Linux上要消減一個分區(qū)大小是很難的,然而擴展一個分區(qū)容量比起來簡單很多
Raspbian based on Debian Buster 在系統(tǒng)第一次啟動的時候會執(zhí)行腳本去擴展系統(tǒng)分區(qū)到整個tf卡的。如果需要另外創(chuàng)建分區(qū),這個功能是需要禁用的。 Raspbian自動擴展tf卡的實現(xiàn)方式:
/boot/cmdline.txt 末尾init=/usr/lib/raspi-config/init_resize.sh,這個腳本修改了root分區(qū)的大小,使其擴展到真?zhèn)€tf卡
/etc/init.d/resize2fs_once 隨機啟動腳本會resize2fs 會修改文件系統(tǒng)大小, 并刪除文件自身。
知道這個就很簡單了,在燒錄好tf卡之后,不要立即插入樹莓派去運行,而應該在電腦上修改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)在就可以用這個tf卡啟動樹莓派了,root分區(qū)我只設(shè)置了6G。 進入raspbian可以再對剩余空間進行分區(qū), cfdisk比較直觀一些。
sudo cfdisk /dev/mmcblk0
之后看到df -h和fdisk -l的大小不一樣用下面命令修復
sudo resize2fs /dev/mmcblk0p2
關(guān)于Raspberry Pi OS禁止自動擴展tf卡與設(shè)置根分區(qū)大小的示例分析就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。