amouiche / qnap_mtd_resize_for_bullseye

Script for resizing MTD partitions on a QNAP device in order to be able to upgrade from buster to bullseye
GNU General Public License v2.0
54 stars 11 forks source link

Debian Buster installer on modified mtd partitions #20

Closed lpaolini closed 2 years ago

lpaolini commented 2 years ago

Hi Arnaud,

I've successfully updated a TS-219p and a TS-221 using your script, so thanks again! Now, how can I build a Debian buster installer image for the new partition table?

I tried different methods, but with no success.

Method 1: 1) downloaded kernel-6281 (on TS-219p) and padded it to 3MB with truncate -s 3145728 kernel-6281 2) downloaded initrd and padded it to 12MB with truncate -s 12582912 initrd 3) created an image with cat /dev/mtd0 /dev/mtd4 /dev/mtd5 kernel-6281 initrd > debian_buster_installer

Method 2: 1) downloaded kernel-6281 (on TS-219p) and padded it to 2MB with truncate -s 2097152 kernel-6281 2) downloaded initrd and padded it to 12MB with truncate -s 12582912 initrd 3) copied the padded kernel to "Kernel_legacy" partition with cp kernel-6281 /dev/mtd3 4) copied the padded initrd to "RootFS1" partition with cp initrd /dev/mtd2 5) created an image with cat /dev/mtd0 /dev/mtd4 /dev/mtd5 /dev/mtd1 /dev/mtd2 > debian_buster_installer

Obviously I'm doing something wrong, as they both fail the CRC check (Bad magic number) while trying to boot.

Any ideas? Thanks, Luca

amouiche commented 2 years ago

Hello Luca, what would be the purpose of debian_buster_installer (how do expect to use this file in practice) ? Arnaud

lpaolini commented 2 years ago

To reinstall Debian from scratch, in case I need it. Doesn't it make sense?

amouiche commented 2 years ago

but how do you use the debian_buster_installer file ? On which state are you starting your install (from a QNAP firmware or on a QNAP with debian already installed) ?

For example, cp kernel-6281 /dev/mtd3 will not work on a debian (not even sure it will work on QNAP firmware). /dev/mtd3 is a MTD device. you don't write on it like a HDD. you have to use special tools that erase the device before writing on it (ie. flashcp, flash_erase)

what you need to install the debian installer from a already installed debian firmware is:

flashcp -v kernel-6281 /dev/mtd1
flashcp -v initrd /dev/mtd2
reboot

You don't need to care about padding.

Be very careful to not write or erase /dev/mtd0. Your QNAP will not boot

lpaolini commented 2 years ago

Ok, I got it, at last. Many thanks @amouiche for explaining.

If you expect to use the QNAP recovery features (ie. press reset button during poweron), and present this 'image' file with a TFTP server, you must know that the bootloader doesn't flash the whole file, but only fixed parts:

  • 2MB of the expected kernel partition
  • 9MB of rootfs

This obviously makes it impossible to create an image based on modified mtd partitions which can be restored using QNAP recovery mode.