From 4352da90e9c07dbbc6ce69b25719e0606abadec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 29 Jan 2018 14:20:58 +0100 Subject: [PATCH] chg: Auto compute offset/size when mounting the image --- doc/setup_with_proot.md | 73 ++++++++++---------------------- shell_utils/basic_mount_image.sh | 17 +++++--- 2 files changed, 35 insertions(+), 55 deletions(-) diff --git a/doc/setup_with_proot.md b/doc/setup_with_proot.md index 0b833ff..bace259 100644 --- a/doc/setup_with_proot.md +++ b/doc/setup_with_proot.md @@ -56,66 +56,39 @@ file yields an unlimited number of "0x00" bytes. ``` > dd if=/dev/zero bs=1024k count=2048 >> XXXX-XX-XX-raspbian-jessie-lite.img ``` -* Expand the root (second) partition using fdisk. The first partition listed is the boot -partition, which shouldn't be changed. In the new partition, the "First sector" should be -the value that was the "start" sector of the old root partition (137216 in the example -below, but this varies depending on the version of the Raspbian image). The "Last sector" -should be the default, and it should be significantly larger than it was before (6909951 vs. -2715647 in the example). +* Expand the root (second) partition using sfdisk: ``` - > fdisk XXXX-XX-XX-raspbian-jessie-lite.img + > echo ", +" | sfdisk -N 2 XXXX-XX-XX-raspbian-jessie-lite.img + Checking that no-one is using this disk right now ... OK - Command (m for help): *p* - Disk XXXX-XX-XX-raspbian-jessie-lite.img: 3.3 GiB, 3537895424 bytes, 6909952 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: 0x244b8248 + Disk 2017-11-29-raspbian-stretch-lite.img: 3.7 GiB, 4005560320 bytes, 7823360 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: 0x37665771 - Device Boot Start End Sectors Size Id Type - XXXX-XX-XX-raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT32 (LBA) - XXXX-XX-XX-raspbian-jessie-lite.img2 137216 2715647 2578432 1.2G 83 Linux + Old situation: - Command (m for help): *d* - Partition number (1,2, default 2): *2* + Device Boot Start End Sectors Size Id Type + 2017-11-29-raspbian-stretch-lite.img1 8192 93236 85045 41.5M c W95 FAT32 (LBA) + 2017-11-29-raspbian-stretch-lite.img2 94208 3629055 3534848 1.7G 83 Linux - Partition 2 has been deleted. + 2017-11-29-raspbian-stretch-lite.img2: + New situation: + Disklabel type: dos + Disk identifier: 0x37665771 - Command (m for help): *n* - Partition type - p primary (1 primary, 0 extended, 3 free) - e extended (container for logical partitions) - Select (default p): + Device Boot Start End Sectors Size Id Type + 2017-11-29-raspbian-stretch-lite.img1 8192 93236 85045 41.5M c W95 FAT32 (LBA) + 2017-11-29-raspbian-stretch-lite.img2 94208 7823359 7729152 3.7G 83 Linux - Using default response p. - Partition number (2-4, default 2): - First sector (2048-6852607, default 2048): *137216* - Last sector, +sectors or +size{K,M,G,T,P} (131216-6909951, default 6909951): - - Created a new partition 2 of type 'Linux' and of size 3.2 GiB. - - Command (m for help): *w* - The partition table has been altered. - Syncing disks. + The partition table has been altered. + Syncing disks. ``` -* Mount the image in loop mode: first, edit shell_utils/basic_mount_image.sh to use the -proper values for $BOOT_START and $ROOT_START, which you can obtain using fdisk and "p" -as in the previous step. You must also change $IMAGE to the correct path. Then run: -``` - sudo ./shell_utils/basic_mount_image.md -``` -* Verify the path to the mounted partitions in /dev, and resize the root (larger) filesystem -to fill the new larger partition using resize2fs: -``` - > df | grep /mnt/arm - /dev/loop0 3927752 1955672 1794172 53% /mnt/rpi-root - /dev/loop1 57288 18960 38328 34% /mnt/rpi-boot - - > sudo resize2fs /dev/loop0 -``` +* Edit shell_utils/basic_mount_image.sh to use the correct image path ($IMAGE) Installing the dependencies =========================== diff --git a/shell_utils/basic_mount_image.sh b/shell_utils/basic_mount_image.sh index 0e37efe..188dd55 100755 --- a/shell_utils/basic_mount_image.sh +++ b/shell_utils/basic_mount_image.sh @@ -17,23 +17,30 @@ set -x # Double check the path and offsets as noted above! # Path to the image -IMAGE='New_Circlean.img' +IMAGE='2018-01-29_CIRCLean.img' # Start sector of boot (first) partition -BOOT_START=8192 +BOOT_START=`sfdisk -J ${IMAGE} | grep img1 | sed -n 's/.*"start": \([[:digit:]]*\).*/\1/p'` +# Amount of sectors of boot (first) partition +BOOT_SIZE=`sfdisk -J ${IMAGE} | grep img1 | sed -n 's/.*"size": \([[:digit:]]*\).*/\1/p'` # Start sector of root (second) partition -ROOT_START=92160 +ROOT_START=`sfdisk -J ${IMAGE} | grep img2 | sed -n 's/.*"start": \([[:digit:]]*\).*/\1/p'` +# Amount of sectors of root (second) partition +ROOT_SIZE=`sfdisk -J ${IMAGE} | grep img2 | sed -n 's/.*"size": \([[:digit:]]*\).*/\1/p'` + # Locations you'd like the partitions mounted BOOT_PATH='/mnt/rpi-boot' ROOTFS_PATH='/mnt/rpi-root' # Calculate offsets for each partition offset_boot=$((${BOOT_START} * 512)) +sizelimit_boot=$((${BOOT_SIZE} * 512)) offset_rootfs=$((${ROOT_START} * 512)) +sizelimit_rootfs=$((${ROOT_SIZE} * 512)) # TODO: add logic for creating directories if they aren't already there mkdir -p ${BOOT_PATH} mkdir -p ${ROOTFS_PATH} # Mount each partition in loop mode -mount -o loop,offset=${offset_boot} ${IMAGE} ${BOOT_PATH} -mount -o loop,offset=${offset_rootfs} ${IMAGE} ${ROOTFS_PATH} +mount -o loop,offset=${offset_boot},sizelimit=${sizelimit_boot} ${IMAGE} ${BOOT_PATH} +mount -o loop,offset=${offset_rootfs},sizelimit=${sizelimit_rootfs} ${IMAGE} ${ROOTFS_PATH} echo "Image mounted" 1>&2