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 ...
随机推荐
- obj-c学习笔记
本文转载至 http://blog.csdn.net/c395565746c/article/details/7573793 当对象经过在dealloc方法处理时,该对象就已经处于已销毁状态,其它 ...
- BestCoder Round #63 (div.2)
感觉有些无聊的比赛. A 暴力枚举下就行 B 简单的dp,但是wa了一发后就去先把C做了,然后发现如果输入的100个数,是如1,2,3,4,...,100,然后k=50,个数为c(100,50).果断 ...
- jquery 访问后台方法 并且获取后方法返回的数据
说明: 1.开发环境 asp.net MVC4 c#语言. 后台方法位于控制器中ProController.cs中 后台方法如下: public string GetNumber() { string ...
- POJ 2856 Y2K Accounting Bug【简单暴力】
链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...
- js滚动到指定位置显示或隐藏元素
$(function(){ $(window).scroll(function(){ var scroll_top=$(window).scrollTop(); console.log(scroll_ ...
- ElasticSearch(二十一)正排和倒排索引
1.区别 搜索的时候,要依靠倒排索引:排序的时候,需要依靠正排索引,看到每个document的每个field,然后进行排序,所谓的正排索引,其实就是doc values 在建立索引的时候,一方面会建立 ...
- ABAP动态生成经典应用之Dynamic SQL Excute 程序
[转自http://blog.csdn.net/mysingle/article/details/678598]开发说明:在SAP的系统维护过程中,有时我们需要修改一些Table中的数据,可是很多Ta ...
- fields_for
1 一对多 Using Strong Parameters With Fields For & Nested Forms in Rails 4 http://www.rubyexperimen ...
- 动态创建selectjs 操作select和option
1.动态创建select function createSelect(){ var mySelect = document.createElement("select"); myS ...
- 每天一个Linux命令(13)less命令
less命令的作用与more十分相似,都可以用来浏览文字档案的内容,不同的是less命令允许用户向前或向后浏览文件,而more命令只能向前浏览. 用less命令显示文件时,用PageUp键向上翻页,用 ...