自定义Raspbian映像无法通过“找不到初始化”启动


11

我正在使用debootstrap构建Raspbian的自定义SD映像,并且生成的映像无法Kernel panic - not syncing: No init found.在我的Raspberry Pi和qemu下启动。我可以在两者上成功启动2012-07-15-wheezy-raspbian映像(尽管在Pi上使用不同的SD卡)。对于qemu,我正在使用XEC Design中的内核。

% qemu-system-arm -M versatilepb -cpu arm1136 -kernel /usr/local/share/qemu/kernel-qemu -m 256 -drive file=raspbian3.img -serial stdio -append "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=tty1,115200 console=tty1 root=/dev/sda2 elevator=noop"
...
EXT3-fs (sda2): error: couldn't mount because of unsupported optional features (240)
EXT2-fs (sda2): error: couldn't mount because of unsupported optional features (240)
EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) readonly on device 8:2.
devtmpfs: mounted
Freeing init memory: 132K
Kernel panic - not syncing: No init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.
[<c001a1cc>] (unwind_backtrace+0x0/0xf0) from [<c037ada0>] (panic+0x58/0x180)
[<c037ada0>] (panic+0x58/0x180) from [<c000857c>] (init_post+0x7c/0xcc)
[<c000857c>] (init_post+0x7c/0xcc) from [<c0475834>] (kernel_init+0xec/0x11c)

添加init=/bin/bash到内核​​命令行无济于事:

Failed to execute /bin/bash.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.

我的映像包含/boot/分区,并且似乎包含正确的内容:

% fdisk -l raspbian3.img

Disk raspbian3.img: 499 MB, 499999744 bytes
255 heads, 63 sectors/track, 60 cylinders, total 976562 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
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
raspbian3.img1   *        1024      132095       65536    c  W95 FAT32 (LBA)
raspbian3.img2          132096      976561      422233   83  Linux

% mount | grep raspbian
/dev/mapper/loop1p2 on /tmp/raspbian type ext4 (rw)
/dev/mapper/loop1p1 on /tmp/raspbian/boot type vfat (rw)

% ls /tmp/raspbian/
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
% ls /tmp/raspbian/boot
arm128_start.elf  arm224_start.elf  bootcode.bin  config.txt          kernel_emergency.img  loader.bin
arm192_start.elf  arm240_start.elf  cmdline.txt   kernel_cutdown.img  kernel.img            start.elf
% ls /tmp/raspbian/sbin/*init*
/tmp/raspbian/sbin/init
% ls /tmp/raspbian/bin/*sh*
/tmp/raspbian/bin/bash  /tmp/raspbian/bin/dash

/sbin/init我图像中的SHA1哈希甚至与2012-07-15-wheezy-raspbian图像的SHA1哈希匹配。

这是我的脚本,图像可以在此处下载。

#!/bin/sh
set -ev

# Author: Michael Gorven <http://michael.gorven.za.net/>

IMAGE="${1?Please specify output image name.}"
IMAGE_SIZE=500
BOOT_SIZE=64
ALIGN_SECTORS=1024
ALIGN_FSBLOCKS="$(($ALIGN_SECTORS*512/4096))"
MIRROR="http://mirrordirector.raspbian.org/raspbian"
PACKAGES="openssh-server sudo ntp fake-hwclock"

bootstrap() {
    if [ ! "$BUILDROOT" ]; then
        echo "BUILDROOT is empty, aborting."
        exit 1
    fi

    qemu-debootstrap --arch=armhf --keyring=~/.gnupg/pubring.gpg wheezy "$BUILDROOT" "$MIRROR"
}

configure() {
    if [ ! "$BUILDROOT" ]; then
        echo "BUILDROOT is empty, aborting."
        exit 1
    fi

    cat > "$BUILDROOT/etc/apt/sources.list" <<-EOF
    deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
    EOF

    cat > "$BUILDROOT/etc/apt/sources.list.d/mene.list" <<-EOF
    deb http://archive.mene.za.net/raspbian wheezy contrib
    EOF

    cat > "$BUILDROOT/etc/apt/sources.list.d/raspi.list" <<-EOF
    deb http://archive.raspberrypi.org/debian/ wheezy main untested
    EOF

    if [ "$http_proxy" ]; then
        cat > "$BUILDROOT/etc/apt/apt.conf.d/30proxy" <<-EOF
        Acquire::http::proxy "$http_proxy";
        EOF
    fi

    wget -O- http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | chroot "$BUILDROOT" apt-key add -
    wget -O- http://archive.mene.za.net/key.asc | chroot "$BUILDROOT" apt-key add -

    chroot "$BUILDROOT" apt-get --yes update
    chroot "$BUILDROOT" apt-get --yes install raspberrypi-bootloader libraspberrypi-bin $PACKAGES
    chroot "$BUILDROOT" apt-get --yes clean

    cp "$BUILDROOT/boot/arm128_start.elf" "$BUILDROOT/boot/start.elf"

    cat > "$BUILDROOT/boot/config.txt" <<-EOF
    disable_overscan=1
    EOF

    cat > "$BUILDROOT/boot/cmdline.txt" <<-EOF
    dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
    EOF

    chroot "$BUILDROOT" adduser --disabled-password --gecos 'rpi,,,,' rpi
    echo 'rpi:rpi' | chroot "$BUILDROOT" chpasswd
    chroot "$BUILDROOT" adduser rpi sudo
    chroot "$BUILDROOT" adduser --disabled-login --shell /bin/false --gecos 'XBMC,,,' xbmc

    cat >> "$BUILDROOT/etc/network/interfaces" <<-EOF
    auto eth0
    iface eth0 inet dhcp
    EOF

    echo "xbmc" > "$BUILDROOT/etc/hostname"

    cat > "$BUILDROOT/etc/fstab" <<-EOF
    /dev/mmcblk0p1  /boot   vfat    defaults    0   0
    /dev/mmcblk0p2  /       ext4    errors=remount-ro,noatime,nodiratime    0   0
    EOF

    cat >> "$BUILDROOT/etc/modules" <<-EOF
    vchiq
    snd_bcm2835
    EOF
}

mkimage() {
    dd if=/dev/zero of="$IMAGE" bs=1MB count=0 seek="$IMAGE_SIZE"
    cat | sfdisk --quiet --unit S --force "$IMAGE" <<-EOF
    $ALIGN_SECTORS,$(($BOOT_SIZE*2048)),c,*
    $(($ALIGN_SECTORS+$BOOT_SIZE*2048)),,L

    EOF

    LOOP="$(basename $(losetup -f))"
    kpartx -a "$IMAGE"
    BOOT="/dev/mapper/${LOOP}p1"
    ROOT="/dev/mapper/${LOOP}p2"

    mkfs.vfat -F 32 -n boot "$BOOT"
    mkfs.ext4 -b 4096 -E stride=$ALIGN_FSBLOCKS,stripe-width=$ALIGN_FSBLOCKS -m 1 -L root "$ROOT"

    MNT="$(mktemp -d --tmpdir raspbian.XXXXXX)"
    mount "$ROOT" "$MNT"
    mkdir "$MNT/boot"
    mount "$BOOT" "$MNT/boot"

    rsync -rtvPHAX "$BUILDROOT" "$MNT"

    umount "$MNT/boot"
    umount "$MNT"

    kpartx -d "$IMAGE"
}

BUILDROOT="$(mktemp -d $PWD/raspbian.XXXXXX)/root/"
bootstrap
configure
mkimage

有趣。我唯一能想到的是,init并未针对与内核相同的体系结构进行编译。
Jivings 2012年

1
@Jivings我的SHA1哈希/sbin/init与Raspbian官方图像中的文件匹配...
mgorven 2012年

所有的证明是您的init与官方的相同。我不是那个意思 内核可能已经用不同的标志进行了编译
Jivings

@Jivings哦,对。据我了解,使用Qemu时内核是外部的,因此是相同的,并且官方图像也有效。
mgorven 2012年

cmdline.txt与基金会的相比如何?
亚历克斯·张伯伦

Answers:


5

问题是从构建目录到映像的rsync没有复制设备和特殊文件,并且没有保留足够的文件属性。具体来说,我需要添加的--archive--devices--specials选项,因此命令现在看起来是这样的:

rsync --archive --devices --specials --hard-links --acls --xattrs --sparse --verbose

现在可以在Qemu下正常启动。


你要写这个吗?作为一个自我回答的问题,这将是很好的;如何建立自定义的Raspbian映像?
亚历克斯·张伯伦

创建一个如何制作自定义图像的博客,而不是在答案中做到这一点,这会更好吗?我确信它不会是几行代码。
Piotr Kula 2012年

@AlexChamberlain我会尽力争取时间。
mgorven 2012年

我已经将工作脚本发布到了我的博客上
mgorven 2012年

0

该错误消息要求使用initramfs来挂载根文件系统。我认为您添加或删除了错误的驱动程序或功能,并且内核无法正常启动。这也解释了为什么官方映像正常启动。

如果这确实是问题所在,则有两种选择:

  1. 查找已删除的驱动程序或功能,然后放回去。另外,请确保不要掩盖模块,而要在主内核映像中内置nito。我推荐这个。
  2. 创建一个initramfs。太麻烦了,不要那样做。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.