sudo mkdir -p /mnt/runimg pi@raspberry4:~ $ sudo mount --bind /media/netdir/raspbrreyPi/mnt_runimg /mnt/runimg pi@raspberry4:~ $ ls -l /mnt/runimg/ total 24593408 -rwxrwxrwx+ 1 99 99 4555014144 Jan 7 22:32 2019-04-08-raspbian-stretch_chroot.img -rwxrwxrwx+ 1 systemd-timesync 98 3481272320 Mar 23 22:09 2019-04-08-raspbian-stretch-make-new.img -rwxrwxrwx+ 1 root root 3481272320 Dec 30 09:55 2019-04-08-raspbian-stretch-make-old.img -rwx------+ 1 99 99 3829399552 Jan 26 21:38 2019-09-26-raspbian-buster_jin.img -rw-r--r--+ 1 root root 5934940160 Apr 13 22:14 2020-02-13-raspbian-buster_jin-make.img drwxrwxrwx+ 1 root root 160 Dec 19 22:41 bak -rw-rw-rw-+ 1 99 99 1728053248 Mar 25 22:50 readynas_compile_tool2.img -rw-rw-rw-+ 1 99 99 2173698048 Jan 8 23:25 readynas_compile_tool.img pi@raspberry4:~ $ sudo mkdir -p ~/rpi_mnt pi@raspberry4:~ $ sudo losetup -f -P --show /mnt/runimg/2020-02-13-raspbian-buster_jin-make.img /dev/loop1 pi@raspberry4:~ $ sudo mount /dev/loop0p2 -o rw ~/rpi_mnt pi@raspberry4:~ $ cd ~/rpi_mnt pi@raspberry4:~/rpi_mnt $ sudo mount /dev/loop0p1 -o rw ~/rpi_mnt/boot/ pi@raspberry4:~/rpi_mnt $ sudo mount --bind /dev ~/rpi_mnt/dev/ pi@raspberry4:~/rpi_mnt $ sudo mount --bind /sys ~/rpi_mnt/sys/ pi@raspberry4:~/rpi_mnt $ sudo mount --bind /proc ~/rpi_mnt/proc/ pi@raspberry4:~/rpi_mnt $ sudo mount --bind /dev/pts ~/rpi_mnt/dev/pts pi@raspberry4:~/rpi_mnt $ sudo mkdir -p /media/netdir/source/raspberrypi/4-08_new_raspi pi@raspberry4:~/rpi_mnt $ sudo mkdir -p ~/rpi_mnt/mnt/compile pi@raspberry4:~/rpi_mnt $ sudo mount --bind /media/netdir/source/raspberrypi/4-08_new_raspi ~/rpi_mnt/mnt/compile pi@raspberry4:~/rpi_mnt $ cd ~/rpi_mnt pi@raspberry4:~/rpi_mnt $ sudo chroot . bin/bash root@raspberry4:/# root@raspberry4:/# ls -l total 75 drwxr-xr-x 2 root root 4096 Feb 14 01:00 bin drwxr-xr-x 3 root root 3072 Jan 1 1970 boot drwxr-xr-x 18 root root 4060 Apr 13 22:18 dev drwxr-xr-x 108 root root 4096 Apr 1 21:50 etc drwxr-xr-x 3 root root 4096 Feb 14 00:55 home drwxr-xr-x 16 root root 4096 Feb 14 00:58 lib drwx------ 2 root root 16384 Feb 14 01:15 lost+found drwxr-xr-x 2 root root 4096 Feb 14 00:51 media drwxr-xr-x 3 root root 4096 Mar 21 13:47 mnt drwxr-xr-x 4 root root 4096 Feb 14 01:01 opt dr-xr-xr-x 151 root root 0 Jan 1 1970 proc drwx------ 3 root root 4096 Mar 21 13:54 root drwxr-xr-x 4 root root 4096 Feb 14 00:51 run drwxr-xr-x 2 root root 4096 Feb 14 01:00 sbin drwxr-xr-x 2 root root 4096 Feb 14 00:51 srv dr-xr-xr-x 12 root root 0 Apr 13 21:56 sys drwxrwxrwt 3 root root 4096 Apr 1 22:52 tmp drwxr-xr-x 11 root root 4096 Feb 14 01:01 usr drwxr-xr-x 11 root root 4096 Feb 14 00:51 var root@raspberry4:/# echo 00:00:00 00:00:00 root@raspberry4:/# date Mon 13 Apr 2020 10:18:29 PM JST root@raspberry4:/# cd /bdf -hT Filesystem Type Size Used Avail Use% Mounted on /dev/loop0p2 ext4 5.2G 2.9G 2.1G 59% / /dev/loop0p1 vfat 253M 53M 200M 21% /boot udev devtmpfs 1.8G 0 1.8G 0% /dev nas-27-59-FD:/data/tmp/source/raspberrypi/4-08_new_raspi nfs 5.5T 3.4T 2.2T 62% /mnt/compile root@raspberry4:/# cd /boot root@raspberry4:/boot# ls -l total 52964 -rwxr-xr-x 1 root root 23983 Feb 3 21:50 bcm2708-rpi-b.dtb -rwxr-xr-x 1 root root 24246 Feb 3 21:50 bcm2708-rpi-b-plus.dtb -rwxr-xr-x 1 root root 23764 Feb 3 21:50 bcm2708-rpi-cm.dtb -rwxr-xr-x 1 root root 23688 Feb 3 21:50 bcm2708-rpi-zero.dtb -rwxr-xr-x 1 root root 24424 Feb 3 21:50 bcm2708-rpi-zero-w.dtb -rwxr-xr-x 1 root root 25310 Feb 3 21:50 bcm2709-rpi-2-b.dtb -rwxr-xr-x 1 root root 25439 Feb 3 21:50 bcm2710-rpi-2-b.dtb -rwxr-xr-x 1 root root 26480 Feb 3 21:50 bcm2710-rpi-3-b.dtb -rwxr-xr-x 1 root root 27099 Feb 3 21:50 bcm2710-rpi-3-b-plus.dtb -rwxr-xr-x 1 root root 25294 Feb 3 21:50 bcm2710-rpi-cm3.dtb -rwxr-xr-x 1 root root 40988 Feb 3 21:50 bcm2711-rpi-4-b.dtb -rwxr-xr-x 1 root root 52304 Jan 17 19:01 bootcode.bin -rwxr-xr-x 1 root root 208 Feb 14 01:16 cmdline.txt -rwxr-xr-x 1 root root 1784 Feb 14 00:57 config.txt -rwxr-xr-x 1 root root 18693 Jun 25 2019 COPYING.linux -rwxr-xr-x 1 root root 3112 Feb 12 22:33 fixup4cd.dat -rwxr-xr-x 1 root root 6200 Feb 12 22:33 fixup4.dat -rwxr-xr-x 1 root root 9192 Feb 12 22:30 fixup4db.dat -rwxr-xr-x 1 root root 9192 Feb 12 22:33 fixup4x.dat -rwxr-xr-x 1 root root 2656 Feb 6 00:25 fixup_cd.dat -rwxr-xr-x 1 root root 6745 Feb 6 00:25 fixup.dat -rwxr-xr-x 1 root root 9817 Feb 6 00:25 fixup_db.dat -rwxr-xr-x 1 root root 9819 Feb 6 00:25 fixup_x.dat -rwxr-xr-x 1 root root 145 Feb 14 01:16 issue.txt -rwxr-xr-x 1 root root 5424376 Feb 3 21:50 kernel7.img -rwxr-xr-x 1 root root 5757200 Feb 3 21:50 kernel7l.img -rwxr-xr-x 1 root root 13521408 Feb 3 21:50 kernel8.img -rwxr-xr-x 1 root root 5142912 Feb 3 21:50 kernel.img -rwxr-xr-x 1 root root 1594 Jan 17 19:01 LICENCE.broadcom drwxr-xr-x 2 root root 15872 Feb 14 00:55 overlays -rwxr-xr-x 1 root root 784316 Feb 12 22:33 start4cd.elf -rwxr-xr-x 1 root root 4593508 Feb 12 22:33 start4db.elf -rwxr-xr-x 1 root root 2784800 Feb 12 22:33 start4.elf -rwxr-xr-x 1 root root 3546468 Feb 12 22:33 start4x.elf -rwxr-xr-x 1 root root 690884 Feb 12 22:33 start_cd.elf -rwxr-xr-x 1 root root 4859912 Feb 12 22:33 start_db.elf -rwxr-xr-x 1 root root 2883204 Feb 12 22:33 start.elf -rwxr-xr-x 1 root root 3797384 Feb 12 22:33 start_x.elf root@raspberry4:/boot# cat cmdline.txt console=serial0,115200 console=tty1 root=PARTUUID=ea7d04d6-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh splash plymouth.ignore-serial-consoles root@raspberry4:/boot# root@raspberry4:/boot# root@raspberry4:/boot# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/loop0p2 ext4 5.2G 2.9G 2.1G 59% / /dev/loop0p1 vfat 253M 53M 200M 21% /boot udev devtmpfs 1.8G 0 1.8G 0% /dev nas-27-59-FD:/data/tmp/source/raspberrypi/4-08_new_raspi nfs 5.5T 3.4T 2.2T 62% /mnt/compile root@raspberry4:/boot# cd /usr/lib/raspi-config/ root@raspberry4:/usr/lib/raspi-config# ls -l total 12 -rwxr-xr-x 1 root root 187 Jan 10 00:22 cmstart.sh -rwxr-xr-x 1 root root 4964 Jan 10 00:22 init_resize.sh root@raspberry4:/usr/lib/raspi-config# cat init_resize.sh #!/bin/sh reboot_pi () { umount /boot mount / -o remount,ro sync if [ "$NOOBS" = "1" ]; then if [ "$NEW_KERNEL" = "1" ]; then reboot -f "$BOOT_PART_NUM" else echo "$BOOT_PART_NUM" > "/sys/module/${BCM_MODULE}/parameters/reboot_part" fi fi echo b > /proc/sysrq-trigger sleep 5 exit 0 } check_commands () { if ! command -v whiptail > /dev/null; then echo "whiptail not found" sleep 5 return 1 fi for COMMAND in grep cut sed parted fdisk findmnt partprobe; do if ! command -v $COMMAND > /dev/null; then FAIL_REASON="$COMMAND not found" return 1 fi done return 0 } check_noobs () { if [ "$BOOT_PART_NUM" = "1" ]; then NOOBS=0 else NOOBS=1 fi } get_variables () { ROOT_PART_DEV=$(findmnt / -o source -n) ROOT_PART_NAME=$(echo "$ROOT_PART_DEV" | cut -d "/" -f 3) ROOT_DEV_NAME=$(echo /sys/block/*/"${ROOT_PART_NAME}" | cut -d "/" -f 4) ROOT_DEV="/dev/${ROOT_DEV_NAME}" ROOT_PART_NUM=$(cat "/sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition") BOOT_PART_DEV=$(findmnt /boot -o source -n) BOOT_PART_NAME=$(echo "$BOOT_PART_DEV" | cut -d "/" -f 3) BOOT_DEV_NAME=$(echo /sys/block/*/"${BOOT_PART_NAME}" | cut -d "/" -f 4) BOOT_PART_NUM=$(cat "/sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition") OLD_DISKID=$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p') check_noobs ROOT_DEV_SIZE=$(cat "/sys/block/${ROOT_DEV_NAME}/size") TARGET_END=$((ROOT_DEV_SIZE - 1)) PARTITION_TABLE=$(parted -m "$ROOT_DEV" unit s print | tr -d 's') LAST_PART_NUM=$(echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1) ROOT_PART_LINE=$(echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:") ROOT_PART_START=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 2) ROOT_PART_END=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 3) if [ "$NOOBS" = "1" ]; then EXT_PART_LINE=$(echo "$PARTITION_TABLE" | grep ":::;" | head -n 1) EXT_PART_NUM=$(echo "$EXT_PART_LINE" | cut -d ":" -f 1) EXT_PART_START=$(echo "$EXT_PART_LINE" | cut -d ":" -f 2) EXT_PART_END=$(echo "$EXT_PART_LINE" | cut -d ":" -f 3) fi } fix_partuuid() { DISKID="$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')" sed -i "s/${OLD_DISKID}/${DISKID}/g" /etc/fstab sed -i "s/${OLD_DISKID}/${DISKID}/" /boot/cmdline.txt } check_variables () { if [ "$NOOBS" = "1" ]; then if [ "$EXT_PART_NUM" -gt 4 ] || \ [ "$EXT_PART_START" -gt "$ROOT_PART_START" ] || \ [ "$EXT_PART_END" -lt "$ROOT_PART_END" ]; then FAIL_REASON="Unsupported extended partition" return 1 fi fi if [ "$BOOT_DEV_NAME" != "$ROOT_DEV_NAME" ]; then FAIL_REASON="Boot and root partitions are on different devices" return 1 fi if [ "$ROOT_PART_NUM" -ne "$LAST_PART_NUM" ]; then FAIL_REASON="Root partition should be last partition" return 1 fi if [ "$ROOT_PART_END" -gt "$TARGET_END" ]; then FAIL_REASON="Root partition runs past the end of device" return 1 fi if [ ! -b "$ROOT_DEV" ] || [ ! -b "$ROOT_PART_DEV" ] || [ ! -b "$BOOT_PART_DEV" ] ; then FAIL_REASON="Could not determine partitions" return 1 fi } check_kernel () { local MAJOR=$(uname -r | cut -f1 -d.) local MINOR=$(uname -r | cut -f2 -d.) if [ "$MAJOR" -eq "4" ] && [ "$MINOR" -lt "9" ]; then return 0 fi if [ "$MAJOR" -lt "4" ]; then return 0 fi NEW_KERNEL=1 } main () { get_variables if ! check_variables; then return 1 fi check_kernel if [ "$NOOBS" = "1" ] && [ "$NEW_KERNEL" != "1" ]; then BCM_MODULE=$(grep -e "^Hardware" /proc/cpuinfo | cut -d ":" -f 2 | tr -d " " | tr '[:upper:]' '[:lower:]') if ! modprobe "$BCM_MODULE"; then FAIL_REASON="Couldn't load BCM module $BCM_MODULE" return 1 fi fi if [ "$ROOT_PART_END" -eq "$TARGET_END" ]; then reboot_pi fi if [ "$NOOBS" = "1" ]; then if ! parted -m "$ROOT_DEV" u s resizepart "$EXT_PART_NUM" yes "$TARGET_END"; then FAIL_REASON="Extended partition resize failed" return 1 fi fi if ! parted -m "$ROOT_DEV" u s resizepart "$ROOT_PART_NUM" "$TARGET_END"; then FAIL_REASON="Root partition resize failed" return 1 fi partprobe "$ROOT_DEV" fix_partuuid return 0 } mount -t proc proc /proc mount -t sysfs sys /sys mount -t tmpfs tmp /run mkdir -p /run/systemd mount /boot mount / -o remount,rw sed -i 's| init=/usr/lib/raspi-config/init_resize\.sh||' /boot/cmdline.txt sed -i 's| sdhci\.debug_quirks2=4||' /boot/cmdline.txt if ! grep -q splash /boot/cmdline.txt; then sed -i "s/ quiet//g" /boot/cmdline.txt fi sync echo 1 > /proc/sys/kernel/sysrq if ! check_commands; then reboot_pi fi if main; then whiptail --infobox "Resized root filesystem. Rebooting in 5 seconds..." 20 60 sleep 5 else sleep 5 whiptail --msgbox "Could not expand filesystem, please try raspi-config or rc_gui.\n${FAIL_REASON}" 20 60 fi reboot_pi root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# root@raspberry4:/usr/lib/raspi-config# compile finish bash: compile: command not found root@raspberry4:/usr/lib/raspi-config# exit exit pi@raspberry4:~/rpi_mnt $ cd pi@raspberry4:~ $ sudo umount ~/rpi_mnt/mnt/compile pi@raspberry4:~ $ sudo umount ~/rpi_mnt/dev/pts pi@raspberry4:~ $ sudo umount ~/rpi_mnt/proc pi@raspberry4:~ $ sudo umount ~/rpi_mnt/sys pi@raspberry4:~ $ sudo umount ~/rpi_mnt/dev pi@raspberry4:~ $ sudo umount ~/rpi_mnt umount: /home/pi/rpi_mnt: target is busy. pi@raspberry4:~ $ sudo losetup -d /dev/loop0 pi@raspberry4:~ $