[Bug] ramdisk loading fails and the system crashes during Linux kernel startup.

Source: Internet
Author: User

[Bug] ramdisk loading fails and the system crashes during Linux kernel startup.
Bug Description: ramdisk loading fails and the system crashes during Linux kernel startup.
Log information:

 
 
  1. RAMDISK: Couldn't find valid RAM disk image starting at 0.
  2. UDF-fs: No partition found (1)
  3. NILFS: Can't find nilfs on dev ram0.
  4. (1,15):ocfs2_fill_super:1001 ERROR: superblock probe
  5. VFS: Cannot open root device "ram0" or unknown-block(1,0)
  6. Please append a correct "root=" boot option; here are the available partitions:
  7. 0800 8003520 sda driver: sd
  8. 0801 14048 sda1
  9. 0804 1 sda4
  10. 0805 393057 sda5
  11. 0806 102400 sda6
  12. 0807 7488690 sda7
  13. Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
  14. Unable to load '/system/dump '.
  15. Pid: 1, comm: swapper Not tainted 2.6.32.15-hermes-1 #23
  16. Call Trace:

  17. UTC time : 2005-1-1 0:14:52
  18. [ ] panic+0x7a/0x12d
  19. [ ] mount_block_root+0x257/0x275
  20. [ ] mount_root+0x56/0x5a
  21. [ ] prepare_namespace+0x16b/0x198
  22. [ ] kernel_init+0x178/0x188
  23. [ ] child_rip+0xa/0x20
  24. [ ] ? kernel_init+0x0/0x188
  25. [ ] ? child_rip+0x0/0x20
First see Couldn't find valid RAM disk image starting at 0.
Find the code to print this information:
 
 
  1. static int __init
  2. identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
  3. {
  4. const int size = 512;
  5. struct minix_super_block *minixsb;
  6. struct ext2_super_block *ext2sb;
  7. struct romfs_super_block *romfsb;
  8. struct cramfs_super *cramfsb;
  9. struct squashfs_super_block *squashfsb;
  10. int nblocks = -1;
  11. unsigned char *buf;
  12. const char *compress_name;
  13. int i = 0;

  14. buf = kmalloc(size, GFP_KERNEL);
  15. if (!buf)
  16. return -1;

  17. minixsb = (struct minix_super_block *) buf;
  18. ext2sb = (struct ext2_super_block *) buf;
  19. romfsb = (struct romfs_super_block *) buf;
  20. cramfsb = (struct cramfs_super *) buf;
  21. squashfsb = (struct squashfs_super_block *) buf;
  22. memset(buf, 0xe5, size);

  23. /*
  24. * Read block 0 to test for compressed kernel
  25. */
  26. sys_lseek(fd, start_block * BLOCK_SIZE, 0);
  27. sys_read(fd, buf, size);
  28. // Eric Ju Jul 27th 2016
  29. printk("start_block:%d\n",start_block);
  30. for(i=0;i
  31. printk("0x%x ",*(buf+i));
  32. printk("\n");

  33. *decompressor = decompress_method(buf, size, &compress_name);
  34. if (compress_name) {
  35. printk(KERN_NOTICE "RAMDISK: %s image found at block %d\n",
  36. compress_name, start_block);
  37. if (!*decompressor)
  38. printk(KERN_EMERG
  39. "RAMDISK: %s decompressor not configured!\n",
  40. compress_name);
  41. nblocks = 0;
  42. goto done;
  43. }

  44. /* romfs is at block zero too */
  45. if (romfsb->word0 == ROMSB_WORD0 &&
  46. romfsb->word1 == ROMSB_WORD1) {
  47. printk(KERN_NOTICE
  48. "RAMDISK: romfs filesystem found at block %d\n",
  49. start_block);
  50. nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
  51. goto done;
  52. }

  53. if (cramfsb->magic == CRAMFS_MAGIC) {
  54. printk(KERN_NOTICE
  55. "RAMDISK: cramfs filesystem found at block %d\n",
  56. start_block);
  57. nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS;
  58. goto done;
  59. }

  60. /* squashfs is at block zero too */
  61. if (le32_to_cpu(squashfsb->s_magic) == SQUASHFS_MAGIC) {
  62. printk(KERN_NOTICE
  63. "RAMDISK: squashfs filesystem found at block %d\n",
  64. start_block);
  65. nblocks = (le64_to_cpu(squashfsb->bytes_used) + BLOCK_SIZE - 1)
  66. >> BLOCK_SIZE_BITS;
  67. goto done;
  68. }

  69. /*
  70. * Read block 1 to test for minix and ext2 superblock
  71. */
  72. sys_lseek(fd, (start_block+1) * BLOCK_SIZE, 0);
  73. sys_read(fd, buf, size);

  74. /* Try minix */
  75. if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
  76. minixsb->s_magic == MINIX_SUPER_MAGIC2) {
  77. printk(KERN_NOTICE
  78. "RAMDISK: Minix filesystem found at block %d\n",
  79. start_block);
  80. nblocks = minixsb->s_nzones << minixsb->s_log_zone_size;
  81. goto done;
  82. }

  83. /* Try ext2 */
  84. if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
  85. printk(KERN_NOTICE
  86. "RAMDISK: ext2 filesystem found at block %d\n",
  87. start_block);
  88. nblocks = le32_to_cpu(ext2sb->s_blocks_count) <<
  89. le32_to_cpu(ext2sb->s_log_block_size);
  90. goto done;
  91. }

  92. printk(KERN_NOTICE
  93. "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
  94. start_block);

  95. done:
  96. sys_lseek(fd, start_block * BLOCK_SIZE, 0);
  97. kfree(buf);
  98. return nblocks;
  99. }
As you can see, this log is printed because all the branches in this function are not matched successfully. Normally, the function should go to the first branch and jump to the done.
Why didn't I go into the first branch? I guess fd should be the file descriptor pointing to initrd. The read before the first branch should read the content of the first sector of initrd and perform magic comparison. When the match is successful, it indicates that initrd is the correct image file and calls the corresponding decompression function to decompress it. Check whether the initrd file is correct by printing the read buf content. After the experiment, all the printed content is 0xFF, which proves that the initrd file is incorrect.
Why is the initrd file incorrect? The initrd. imgfile on the disk is correct. Continue to trace the call of identify_ramdisk_image to see what fd is? After tracking, we found that the following functions are located in the kernel source code/init/do_mounts_initrd.c.
 
 
  1. int __init initrd_load(void)
  2. {
  3. if (mount_initrd) {
  4. create_dev("/dev/ram", Root_RAM0);
  5. /*
  6. * Load the initrd data into /dev/ram0. Execute it as initrd
  7. * unless /dev/ram0 is supposed to be our actual root device,
  8. * in that case the ram disk is just set up here, and gets
  9. * mounted in the normal path.
  10. */
  11. if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
  12. sys_unlink("/initrd.image");
  13. handle_initrd();
  14. return 1;
  15. }
  16. }
  17. sys_unlink("/initrd.image");
  18. return 0;
  19. }
Initrd. image file? No. How can I change the file name of initrd. img on our disk to initrd. image? And the path is incorrect. I guess the initrd. image file should have some startup code that has created a symbolic link to initrd. img. Continue to find where the initrd. image is created? Find the following code at/init/initramfs. c
 
 
  1. static int __init populate_rootfs(void)
  2. {
  3. int i=0;
  4. char *err = unpack_to_rootfs(__initramfs_start,
  5. __initramfs_end - __initramfs_start);
  6. if (err)
  7. panic(err);/* Failed to decompress INTERNAL initramfs */
  8. if (initrd_start) {
  9. #ifdef CONFIG_BLK_DEV_RAM
  10. int fd;
  11. printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
  12. err = unpack_to_rootfs((char *)initrd_start,
  13. initrd_end - initrd_start);
  14. if (!err) {
  15. free_initrd();
  16. return 0;
  17. } else {
  18. clean_rootfs();
  19. unpack_to_rootfs(__initramfs_start,
  20. __initramfs_end - __initramfs_start);
  21. }
  22. printk(KERN_INFO "rootfs image is not initramfs (%s)"
  23. "; looks like an initrd\n", err);
  24. fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);

  25. if (fd >= 0) {
  26. sys_write(fd, (char *)initrd_start,
  27. initrd_end - initrd_start);
  28. sys_close(fd);
  29. free_initrd();
  30. }
  31. #else
  32. printk(KERN_INFO "Unpacking initramfs...\n");
  33. err = unpack_to_rootfs((char *)initrd_start,
  34. initrd_end - initrd_start);
  35. if (err)
  36. printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
  37. free_initrd();
  38. #endif
  39. }
  40. return 0;
  41. }
The initrd. image file is created here. Another sentence is: sys_write (fd, (char *) initrd_start, initrd_end-initrd_start); it seems that the kernel writes the relevant data from the memory to/init. image. It is not a soft link. Where is initrd_start? Where is the data? After printing initrd_start, it is found that initrd_start is 0xffff880000100000, which is a virtual address that has been converted. Since we know that initrd. image is written to the root file system from the memory, there must be other programs that read our initrd. img into the memory. Where is initrd. img read into the memory? Where is the file path provided? Remember, the lilo. multi. conf file contains the path of the specified initrd. imgfile. It must be that when lilo is started, it reads initrd. img into the memory and passes the address to the kernel. Check the serial port log. The following information is contained in the log just started:
 
 
  1. RAMDISK: 7fa36000 - 7ffff40e
  2. Allocated new RAMDISK: 00100000 - 006c940e
  3. Move RAMDISK from 000000007fa36000 - 000000007ffff40d to 00100000 - 006c940d
As you can see, the starting address of RAMDISK is 0x7fa36000. Is the physical address converted from this virtual address? The third line looks like the kernel moves the RAMDISK content to the 0x00100000 address. After comparing the virtual address 0xffff880000100000, you can determine that the virtual address must be mapped from 0x00100000. Because the kernel uses address ing at low physical addresses, the actual physical address is offset after the virtual high-end address is set. Print the following content before and after RAMDISK is moved to see if it is not an error. It is found that the RAMDISK is 0xFF before it is moved. It can be concluded that LILO has made an error when turning initrd. img. From the perspective of 0xFF, the physical memory should be the initial state after power-on. Suddenly another message is displayed. After the kernel is replaced and the lilo64-C lilo. multi. conf-s 'pwd' is executed, lilo reports a warning message:
 
 
  1. Normally any initial ramdisk (initrd) loaded with a kernel is loaded as
  2. high in memory as possible, but never above 15Mb. This is due to a BIOS
  3. limitation on older systems. On newer systems, this option enables using
  4. memory above 15Mb (up to a kernel imposed limit, around 768Mb) for
  5. passing the initrd to the kernel. The presence of this option merely
  6. indicates that your system does not have the old BIOS limitation.
Let's look at the initial starting address of RAMDISK: 0x7fa36000. Obviously, this address is higher than the address of 15 MB, which indicates that LILO considers the kernel and initrd. the size of img exceeds a fixed limit and initrd is placed in high-end memory. Why does LILO fail to write data into the memory? From the above information, we can see that the BIOS does not support access to the high-end memory when it is just powered on. Therefore, LILO encountered an error when calling the BIOS Write Program, LILO does not care about this error.
Find a technical document on LILO's HomePage, which clearly states that LILO will load initrd. img At the end of the low-end address of the memory (less than 16 Mb ). The limit of 16 Mb is that the BIOS only uses 24-bit address space for data transmission. After reading the LILO code, LILO will be 3 times the kernel image size and initrd. the total size of the img is calculated. When the total size is greater than 14 MB, LILO considers that the low address space below 14 MB cannot be placed into the kernel and initrd image files, so the BIOS supports the address space above 16 MB, therefore, when LILO loads the initrd image, it places initrd in the high address space.
LILO Technical Documentation: commit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.