Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

How to expand the OS disk on the SD card on Maix-II ? #32

Open
chayitw opened this issue Jan 26, 2022 · 2 comments
Open

How to expand the OS disk on the SD card on Maix-II ? #32

chayitw opened this issue Jan 26, 2022 · 2 comments

Comments

@chayitw
Copy link

chayitw commented Jan 26, 2022

Hi All,
我使用目前的鏡像版本 "maixpy3-0.3.5_MaixII-Dock_20211216.img",
由於其根目錄僅有254.5M的大小, 所以參考底下這篇說明想試著擴增到2G:
https://www.cnblogs.com/USTHzhanglu/p/15207336.html

   但也僅能擴增到381.8M, 雖然可以開機, 但並沒有成功完成擴增, 底下是操作過程紀錄,
   可以給一些建議嗎? 感謝。

新年快樂
-chayi

BusyBox v1.27.2 () built-in shell (ash)

------run profile file-----


/ |/ /__ ()_ __ / / ()__ __ ____ __
/ /|
/ / _ `/ /\ \ / / /__/ / _ / // /\ \ /
// //_,///_\ //////_,//_\

root@sipeed:/# [framebuffer](240,240, 24bpp)

root@sipeed:/# fdisk -l

Disk /dev/mmcblk0: 29.1 GiB, 31266439168 bytes, 61067264 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: gpt
Disk identifier: AB6F3888-569A-4926-9668-80941DCB40BC

Device Start End Sectors Size Type
/dev/mmcblk0p1 49152 49663 512 256K Microsoft basic data
/dev/mmcblk0p2 49664 54159 4496 2.2M Microsoft basic data
/dev/mmcblk0p3 54160 578447 524288 256M Microsoft basic data
/dev/mmcblk0p4 578448 609167 30720 15M Microsoft basic data
/dev/mmcblk0p5 609168 61067230 60458063 28.8G Microsoft basic data

root@sipeed:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 254.5M 147.8M 101.6M 59% /
tmpfs 29.4M 16.0K 29.4M 0% /tmp
none 29.3M 0 29.3M 0% /dev
/dev/mmcblk0p5 28.8G 48.0K 28.8G 0% /mnt/UDISK
/dev/mmcblk0p5 28.8G 48.0K 28.8G 0% /root
root@sipeed:/# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): d
Partition number (1-5, default 5): 3

Partition 3 has been deleted.

Command (m for help): d
Partition number (1,2,4,5, default 5): 4

Partition 4 has been deleted.

Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

Command (m for help): n
Partition number (3-5, default 3): 3
First sector (54160-61067230, default 55296): 54160
Last sector, +sectors or +size{K,M,G,T,P} (54160-61067230, default 61067230): +2G

Created a new partition 3 of type 'Linux filesystem' and of size 2 GiB.

Command (m for help): n
Partition number (4,5, default 4): 4
First sector (4247552-61067230, default 4247552):
Last sector, +sectors or +size{K,M,G,T,P} (4247552-61067230, default 61067230): +1G

Created a new partition 4 of type 'Linux filesystem' and of size 1 GiB.

Command (m for help): n
Selected partition 5
First sector (6344704-61067230, default 6344704):
Last sector, +sectors or +size{K,M,G,T,P} (6344704-61067230, default 61067230):

Created a new partition 5 of type 'Linux filesystem' and of size 26.1 GiB.

Command (m for help): x

Expert command (m for help): n
Partition number (1-5, default 5): 3

New name: rootfs

Partition name changed from '' to 'rootfs'.

Expert command (m for help): n
Partition number (1-5, default 5): 4

New name: swap

Partition name changed from '' to 'swap'.

Expert command (m for help): n
Partition number (1-5, default 5): 5

New name: UDISK

Partition name changed from '' to 'UDISK'.

Expert command (m for help): r

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

root@sipeed:/# reboot
root@sipeed:/# Stopping ntpd: done
Stop dropbear: OK
Stopping telnetd: start-stop-daemon: warning: killing process 840: No such process
FAIL
Stopping network...
Saving random seed... done.
disable android usb
sh: write error: No such device
Stopping app...
killall: python3: no process killed
Stopping logging: OK
save /etc/asound.conf ...
Unload mpp modules
module is not loaded
module is not loaded
module is not loaded
umount: none busy - remounted read-only
The system is going down NOW!
Sent SIGTERM to all processes
Sen[30]HELLO! BOOT0 is starting!
[32]BOOT0 commit : e3b2a9e
[35]board init start
[37]set pll start
[40]set pll end
[41][pmu]: bus read error
[44][pmu]: bus read error
[46]board init ok
[48]chip id check OK
[50]DRAM BOOT DRIVE INFO: V0.41
[53]DRAM CLK = 528 MHz
[55]DRAM Type = 2 (2:DDR2,3:DDR3)
[59]DRAMC read ODT off.
[61]DRAM ODT off.
[63]DRAM SIZE =64 M
[70]DRAM simple test OK.
[72]rtc standby flag is 0x0, super standby flag is 0x0
[77]dram size =64
MESSAGE: [0x0] TEE-CORE: OP-TEE version: sun8iw19p1_v0.6.0-14-gf6954e7 #1 2019年 11月 21日 星期四 01:34:42 UTC arm
ERROR: [0x0] TEE-CORE:platform_standby_fdt_parse:126: no pmu node
ERROR: [0x0] TEE-CORE:sunxi_twi_parse_from_dt:84: no pmu node
------run rc.preboot file-----
setup console
fbv - The Framebuffer Viewer
/home/res/logo.png
140 x 140
swapon: /dev/mmcblk0p4: Invalid argument
Setting up swapspace version 1, size = 1073737728 bytes
------run rc.modules file-----
------run rc.final file-----
Load mpp modules
insmod: can't insert '/lib/modules/4.9.118/videobuf2-core.ko': No such file or directory
insmod: can't insert '/lib/modules/4.9.118/videobuf2-memops.ko': No such file or directory
insmod: can't insert '/lib/modules/4.9.118/videobuf2-v4l2.ko': No such file or directory
load /etc/asound.conf ...
alsactl: set_control:1461: Cannot write control '2:0:0:codec trigger playback time value:0' : Operation not permitted
alsactl: set_control:1461: Cannot write control '2:0:0:codec trigger capture time value:0' : Operation not permitted
Starting app...
enable android usb
Initializing random number generator... done.
Starting network...
Starting telnetd: OK
Start dropbear: OK
Starting ntpd: done

BusyBox v1.27.2 () built-in shell (ash)

------run profile file-----


/ |/ /__ ()_ __ / / ()__ __ ____ __
/ /|
/ / _ `/ /\ \ / / /__/ / _ / // /\ \ /
// //_,///_\ //////_,//_\

root@sipeed:/# [framebuffer](240,240, 24bpp)

root@sipeed:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 254.5M 147.8M 101.6M 59% /
tmpfs 29.4M 16.0K 29.4M 0% /tmp
none 29.3M 0 29.3M 0% /dev
/dev/mmcblk0p5 26.1G 48.0K 26.1G 0% /mnt/UDISK
/dev/mmcblk0p5 26.1G 48.0K 26.1G 0% /root
root@sipeed:/# fdisk -l

Disk /dev/mmcblk0: 29.1 GiB, 31266439168 bytes, 61067264 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: gpt
Disk identifier: AB6F3888-569A-4926-9668-80941DCB40BC

Device Start End Sectors Size Type
/dev/mmcblk0p1 49152 49663 512 256K Microsoft basic data
/dev/mmcblk0p2 49664 54159 4496 2.2M Microsoft basic data
/dev/mmcblk0p3 54160 4247551 4193392 2G Linux filesystem
/dev/mmcblk0p4 4247552 6344703 2097152 1G Linux filesystem
/dev/mmcblk0p5 6344704 61067230 54722527 26.1G Linux filesystem

root@sipeed:/# resize2fs /dev/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
resize2fs: Invalid argument While checking for on-line resizing support
root@sipeed:/# fdisk -l

Disk /dev/mmcblk0: 29.1 GiB, 31266439168 bytes, 61067264 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: gpt
Disk identifier: AB6F3888-569A-4926-9668-80941DCB40BC

Device Start End Sectors Size Type
/dev/mmcblk0p1 49152 49663 512 256K Microsoft basic data
/dev/mmcblk0p2 49664 54159 4496 2.2M Microsoft basic data
/dev/mmcblk0p3 54160 4247551 4193392 2G Linux filesystem
/dev/mmcblk0p4 4247552 6344703 2097152 1G Linux filesystem
/dev/mmcblk0p5 6344704 61067230 54722527 26.1G Linux filesystem

root@sipeed:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 381.8M 147.8M 228.8M 39% /
tmpfs 29.4M 16.0K 29.4M 0% /tmp
none 29.3M 0 29.3M 0% /dev
/dev/mmcblk0p5 26.1G 48.0K 26.1G 0% /mnt/UDISK
/dev/mmcblk0p5 26.1G 48.0K 26.1G 0% /root
root@sipeed:/#

@junhuanchen
Copy link
Contributor

@chayitw
Copy link
Author

chayitw commented Feb 9, 2022

look this https://github.com/USTHzhanglu/Tina-Image-Scripts

hi @junhuanchen ,
謝謝, 這個問題我自己解掉了, 剛看了一下您提供的連結, 發現很棒, 它考慮的更多、更詳盡,
如果有人單純是要做rootfs磁區擴增(分區擴容), 底下是我的方式以及一些紀錄,
也提供給社區成員參考看看。
謝謝,
chayi

@chayitw

To expand the OS disk on the SD card on Maix-II

主要參考網址: https://www.cnblogs.com/USTHzhanglu/p/15207336.html

  1. 燒錄鏡像v831-m2dock-maixpy3-0.4.0-20220114.img到SD卡。

    (原本的磁區大小為)
    Device Start End Sectors Size Type
    /dev/mmcblk0p1 49152 49663 512 256K Microsoft basic data
    /dev/mmcblk0p2 49664 57855 8192 4M Microsoft basic data
    /dev/mmcblk0p3 57856 844287 786432 384M Microsoft basic data
    /dev/mmcblk0p4 844288 62333918 61489631 29.3G Microsoft basic data

  2. 取出SD卡到一般的UNIX系統,來擴充磁區大小:
    $sudo fdisk /dev/sdb

    (比如擴增成如下, p3在模組上由384M擴增為20G)
    Device Start End Sectors Size Type
    /dev/mmcblk0p1 49152 49663 512 256K Microsoft basic data
    /dev/mmcblk0p2 49664 57855 8192 4M Microsoft basic data
    /dev/mmcblk0p3 57856 42000383 41942528 20G Linux filesystem
    /dev/mmcblk0p4 42000384 62333918 20333535 9.7G Linux filesystem

    (預計在模組上會看到如下根目錄/變為19.9G)
    root@sipeed:/# df -h
    Filesystem Size Used Available Use% Mounted on
    /dev/root 19.9G 283.1M 19.6G 1% /
    tmpfs 29.4M 16.0K 29.4M 0% /tmp
    none 29.3M 0 29.3M 0% /dev
    /dev/mmcblk0p4 9.7G 24.0K 9.7G 0% /mnt/UDISK
    /dev/mmcblk0p4 9.7G 24.0K 9.7G 0% /root

    相關細節請見文末。

  3. 進行 e2fsck & resize2fs以讓FileSystem大小相符
    $sudo umount /media/chayi/(rootfs)
    $sudo e2fsck -f /dev/sdb3
    $sudo resize2fs /dev/sdb3

  4. 回到模組,開機成功且擴充完成。

附錄

A.有關第2項相關細節操作供參考:

$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.

命令 (m 以獲得說明): p
Disk /dev/sdb: 29.7 GiB, 31914983424 bytes, 62333952 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: gpt
Disk identifier: AB6F3888-569A-4926-9668-80941DCB40BC

所用裝置 Start 結束 磁區 Size 類型
/dev/sdb1 49152 49663 512 256K Microsoft basic data
/dev/sdb2 49664 57855 8192 4M Microsoft basic data
/dev/sdb3 57856 844287 786432 384M Microsoft basic data
/dev/sdb4 844288 62333918 61489631 29.3G Microsoft basic data

命令 (m 以獲得說明): d
分割區編號 (1-4, default 4): 3

Partition 3 has been deleted.

命令 (m 以獲得說明): d
分割區編號 (1,2,4, default 4): 4

Partition 4 has been deleted.

命令 (m 以獲得說明): n
分割區編號 (3,4, default 3): 3
First sector (57856-62333918, default 59392): 57856
Last sector, +sectors or +size{K,M,G,T,P} (57856-62333918, default 62333918): +20G

Created a new partition 3 of type 'Linux filesystem' and of size 20 GiB.
Partition #3 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

命令 (m 以獲得說明): p
Disk /dev/sdb: 29.7 GiB, 31914983424 bytes, 62333952 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: gpt
Disk identifier: AB6F3888-569A-4926-9668-80941DCB40BC

所用裝置 Start 結束 磁區 Size 類型
/dev/sdb1 49152 49663 512 256K Microsoft basic data
/dev/sdb2 49664 57855 8192 4M Microsoft basic data
/dev/sdb3 57856 42000383 41942528 20G Linux filesystem

Filesystem/RAID signature on partition 3 will be wiped.

命令 (m 以獲得說明): n
Selected partition 4
First sector (42000384-62333918, default 42000384):
Last sector, +sectors or +size{K,M,G,T,P} (42000384-62333918, default 62333918):

Created a new partition 4 of type 'Linux filesystem' and of size 9.7 GiB.

命令 (m 以獲得說明): x

專家命令 (m 以獲得說明): n
分割區編號 (1-4, default 4): 3

New name: rootfs

Partition name changed from '' to 'rootfs'.

專家命令 (m 以獲得說明): n
分割區編號 (1-4, default 4): 4

New name: UDISK

Partition name changed from '' to 'UDISK'.

專家命令 (m 以獲得說明): r

命令 (m 以獲得說明): w
The partition table has been altered.
Failed to remove partition 4 from system: 裝置或系統資源忙碌中
Failed to update system information about partition 3: 裝置或系統資源忙碌中
Failed to add partition 4 to system: 裝置或系統資源忙碌中

The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
(如有上述訊息, 重插拔SD卡即可看到partions被更新。或先umount後再來進行fdisk也可以)

B.有關第3項相關細節供參考:

$sudo umount /media/chayi/(rootfs)
$sudo e2fsck -f /dev/sdb3
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
/dev/sdb3: 4137/6000 files (0.0% non-contiguous), 72667/98304 blocks

$sudo resize2fs /dev/sdb3
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/sdb3 to 5242816 (4k) blocks.
The filesystem on /dev/sdb3 is now 5242816 (4k) blocks long.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants