raspi-config Expand root partition to fill SD card 原理
/**********************************************************************************
* raspi-config Expand root partition to fill SD card 原理
* 说明:
* 想知道树莓派是如何完成SD卡扩展的,记录相关文档。
*
* 2017-2-20 深圳 南山平山村 曾剑锋
********************************************************************************/ 一、参考文档:
. 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
. 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"
return
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"
return
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 ]; 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."
return
fi # 再次确认分区表和设备节点提取的数值是否一致
#
# shell script:
# root@aplex:/home/zengjf/hacking# parted /dev/sdb -ms unit s p
# BYT;
# /dev/sdb:1953525168s:scsi:::gpt:ATA ST1000LM035-1RK1:;
# :2048s:943720448s:943718401s:ntfs:Basic data partition:msftdata;
# :943722496s:1953523711s:1009801216s:ntfs:Basic data partition:msftdata;
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n | cut -f -d:)
if [ "$LAST_PART_NUM" != "$PART_NUM" ]; then
whiptail --msgbox "/dev/root is not the last partition. Don't know how to expand"
return
fi # Get the starting offset of the root partition
# 获取文件系统分区起始位置
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f -d:)
[ "$PART_START" ] || return
# 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 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START
p
w
EOF
ASK_TO_REBOOT= # now set up an init.d script,这里的&&是命令运行正常的与,和后面的程序一起组成命令运行链
cat <<\EOF > /etc/init.d/resize2fs_once &&
#!/bin/sh
### BEGIN INIT INFO
# Provides: resize2fs_once
# Required-Start:
# Required-Stop:
# Default-Start: 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" >&
exit
;;
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"
fi
}
raspi-config Expand root partition to fill SD card 原理的更多相关文章
- Resolving 'Root Partition Is Filling Up' Issue on Sophos UTM Firewall
from: https://wandersick.blogspot.com/2016/06/resolving-root-partition-is-filling-up.html This is a ...
- OpenRisc-35-基于orpsoc,eCos的sd card controller的测试实验
引言 之前,曾经在orpsoc的平台上,测试验证过其sd card controller的linux的驱动,但是并不是很完美,经过努力,终于在eCos下完成了其全部功能的验证,包括驱动层验证,文件系统 ...
- [OrangePi] Installation on SD Card
Download any of the available images (xz archive) from Mega or GoogleDrive Download scriptbin_kernel ...
- Python Kivy writes / read the file on the SD card
Path to SD card from jnius import autoclass # SDcard Android # Get path to SD card Android try: Envi ...
- [OrangePi] Backup internal EMMC to SD Card
Boot your Orange PI board from EMMC without SD Card inserted login insert your SD Card Run: sudo ins ...
- I.MX6 uSDHC SD card register
/**************************************************************************** * I.MX6 uSDHC SD card ...
- 【转】VirtualBox direct access to SD Card in Windows--不错
原文网址:http://www.sandyscott.net/2013/08/14/virtualbox-direct-drive-access/ I’ve trying to get my Rasp ...
- SD card技术了解并WINCE下SDHC驱动开发(updated)
Suumary: 简单介绍了一下SD卡的历史和发展,同时结合MX31 ADS上的WINCE 下SDHC驱动更深入的了解该硬件的一些行为特点. 了解SD card SD是Secure Digital C ...
- Using Android Phone to recover SD card formatted with DD command under linux
Using Android Phone to recover SD card formatted with DD command under linux 1. Formatted a sd card ...
随机推荐
- Laravel开发:Laravel框架门面Facade源码分析
前言 这篇文章我们开始讲 laravel 框架中的门面 Facade,什么是门面呢?官方文档: Facades(读音:/fəˈsäd/ )为应用程序的服务容器中可用的类提供了一个「静态」接口.Lara ...
- 安卓常用的xml控件配件的使用包含shape,declare-styleable、selector
今天就讲我所遇到的常用到的一些通过xml文件制作的背景效果,以后用到的话就直接使用啦!哈哈,我一向就是这么懒! 接下来,就开始介绍了 1.shape的使用,可以混合使用 xml控件配置属性 andro ...
- poj2075
Tangled in Cables Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6348 Accepted: 2505 ...
- ORACLE client 11g r2 客户端开发环境配置
一.安装ORACLE客户端,这里不做说明.需要注意的是,客户端解压位置应该在磁盘根目录下. 如果放在带中文字或者空格的文件名的路径下出了问题,可以放到磁盘根目录在安装.应该就会没有问题. 另外,一般安 ...
- 九度OJ 1356:孩子们的游戏(圆圈中最后剩下的数) (约瑟夫环)
时间限制:10 秒 内存限制:32 兆 特殊判题:否 提交:1333 解决:483 题目描述: 每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为JOBDU的资深 ...
- recognition rate generalization识别率 泛化
http://www1.inf.tu-dresden.de/~ds24/lehre/ml_ws_2013/ml_11_hinge.pdf Two extremes: • Big
- CSS 布局实例系列(四)如何实现容器中每一行的子容器数量随着浏览器宽度的变化而变化?
Hello,小朋友们,还记得我是谁吗?对了,我就是~超威~好啦,言归正传,今天的布局实例是: 实现一个浮动布局,红色容器中每一行的蓝色容器数量随着浏览器宽度的变化而变化,就如下图: 肯定有人心里犯嘀咕 ...
- 【译】前端开发者都应知道的 jQuery 小技巧
回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: // Back to top $('a.top').click(f ...
- C# Interactive Shell
C# Pad 有点像VisualStudio中的ImmediateWindow,程序运行中的一些变量都保存着,可以直接从命令行访问,方便执行一些code来进行测试或debug. 上图中右边每一个小时钟 ...
- 让Editplus支持sql语法高亮显示
版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking 本文版权归作者和CSDN共同拥有,欢迎转载.但未经作者允许必须保留此段声明,且在文章页面 ...