15AH, San Francisco

California, United States.

Send Your Mail At:

tianyingkejishe@sina.cn

Working Hours

Mon-Sat: 9.30am To 7.00pm

【Linux】分区扩容至整个SD卡

一、查看信息

root@somlabs:~# fdisk -l
省略若干


Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk1p0      16384 1628159 1611776  787M 83 Linux

二、操作分区

假如需要扩展分区为mmcblk0p1

root@somlabs:~# fdisk /dev/mmcblk0

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


Command (m for help): p
Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk1p1      16384 1628159 1611776  787M 83 Linux
这里也看到Start扇区也是16384
Command (m for help): d
把这个分区删除
Partition 1 has been deleted.

Command (m for help): p
列出分区信息Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a

Command (m for help): n
新建分区Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
主分区Partition number (1-4, default 1): 1
分区序号,First sector (2048-7745535, default 2048): 16384
这里要使用起始扇区16384这个值Last sector, +sectors or +size{K,M,G,T,P} (16384-7745535, default 7745535):
默认回车取最大,
Created a new partition 1 of type 'Linux' and of size 3.7 GiB.
Partition #1 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.
Re-reading the partition table failed.: Device or 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@somlabs:~# reboot

四、扩容文件系统

resize2fs /dev/mmcblk1p1
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/mmcblk1p1 is m[  122.795430] EXT4-fs (mmcblk1p1): resizing filesystem from 201472 to 966144 blocks
ounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
[  123.861183] EXT4-fs (mmcblk1p1): resized filesystem to 966144
The filesystem on /dev/mmcblk1p1 is now 966144 (4k) blocks long.

五、查看大小

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       3.7G  499M  3.0G  15% /
devtmpfs         88M     0   88M   0% /dev
tmpfs           248M     0  248M   0% /dev/shm
tmpfs           248M  3.4M  245M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           248M     0  248M   0% /sys/fs/cgroup
tmpfs            50M     0   50M   0% /run/user/0
anyShare分享到:
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。
stormwind