博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
raspi-config Expand root partition to fill SD card 原理
阅读量:5917 次
发布时间:2019-06-19

本文共 3607 字,大约阅读时间需要 12 分钟。

/********************************************************************************** *          raspi-config Expand root partition to fill SD card 原理 * 说明: *     想知道树莓派是如何完成SD卡扩展的,记录相关文档。 *                               *                                              2017-2-20 深圳 南山平山村 曾剑锋 ********************************************************************************/一、参考文档:    1. Raspbian: how to resize the root partition to fill SD card        https://coderwall.com/p/mhj8jw/raspbian-how-to-resize-the-root-partition-to-fill-sd-card    2. raspi-config        https://github.com/asb/raspi-config/blob/master/raspi-config二、raspi-config主要源代码有关SD卡扩展函数分析:    do_expand_rootfs() {      # -h : FILE exists and is a symbolic link (same as -L)      if ! [ -h /dev/root ]; then        whiptail --msgbox "/dev/root does not exist or is not a symlink. Don't know how to expand" 20 60 2        return 0      fi          # readlink用来找出符号链接所指向的位置。       ROOT_PART=$(readlink /dev/root)      # 从变量$string的开头, 删除最短匹配$substring的子串      PART_NUM=${ROOT_PART#mmcblk0p}      if [ "$PART_NUM" = "$ROOT_PART" ]; then        whiptail --msgbox "/dev/root is not an SD card. Don't know how to expand" 20 60 2        return 0      fi          # NOTE: the NOOBS partition layout confuses parted. For now, let's only       # agree to work with a sufficiently simple partition layout      if [ "$PART_NUM" -ne 2 ]; then        whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2        return 0      fi      # 再次确认分区表和设备节点提取的数值是否一致      #       # shell script:      #   root@aplex:/home/zengjf/hacking# parted /dev/sdb -ms unit s p       #   BYT;      #   /dev/sdb:1953525168s:scsi:512:4096:gpt:ATA ST1000LM035-1RK1:;      #   1:2048s:943720448s:943718401s:ntfs:Basic data partition:msftdata;      #   2:943722496s:1953523711s:1009801216s:ntfs:Basic data partition:msftdata;      LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)      if [ "$LAST_PART_NUM" != "$PART_NUM" ]; then        whiptail --msgbox "/dev/root is not the last partition. Don't know how to expand" 20 60 2        return 0      fi          # Get the starting offset of the root partition      # 获取文件系统分区起始位置      PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d:)      [ "$PART_START" ] || return 1      # Return value will likely be error for fdisk as it fails to reload the      # partition table because the root fs is mounted      fdisk /dev/mmcblk0 <
/etc/init.d/resize2fs_once && #!/bin/sh ### BEGIN INIT INFO # Provides: resize2fs_once # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 S # Default-Stop: # Short-Description: Resize the root filesystem to fill partition # Description: ### END INIT INFO . /lib/lsb/init-functions case "$1" in start) log_daemon_msg "Starting resize2fs_once" && resize2fs /dev/root && # 真正调整大小的地方 rm /etc/init.d/resize2fs_once && # 删除文件,表明该文件只能被运行一次 update-rc.d resize2fs_once remove && log_end_msg $? ;; *) echo "Usage: $0 start" >&2 exit 3 ;; esac EOF chmod +x /etc/init.d/resize2fs_once && # 给出下次运行的权限 update-rc.d resize2fs_once defaults && # 默认运行 if [ "$INTERACTIVE" = True ]; then whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2 fi }

 

转载地址:http://cifvx.baihongyu.com/

你可能感兴趣的文章
程序员全国不同地区,微信(面试 招聘)群。
查看>>
【干货】界面控件DevExtreme视频教程大汇总!
查看>>
用户管理脚本之删除用户——Delete_user.sh
查看>>
前端重构实践(二) —— 模块化开发
查看>>
ssh 与 locale
查看>>
使用makecontext实现用户线程【转】
查看>>
将Flash 嵌入WPF 程序
查看>>
《自己动手做交互系统》——2.3 制作过程
查看>>
闭包 !if(){}.call()
查看>>
关闭CentOS6启动进度条,显示详细自检信息
查看>>
垂直居中的几种实现方法
查看>>
CentOS-6.5安装配置Tomcat-7
查看>>
CSS定位
查看>>
ASP.NET Web API中参数的传递方式
查看>>
我的友情链接
查看>>
python MySQLdb安装和使用
查看>>
Eclipse SVN 冲突的 介绍 及 四种解决方式
查看>>
总结thinkphp快捷查询getBy、getField、getFieldBy用法及场景
查看>>
无线路由器使用交换机模式上网不稳定
查看>>
poj 1789 Truck History
查看>>