龙芯2K1000内核及文件系统烧写流程(恢复Boot内核引导配置及分区)


恢复龙芯2K1000板子上的/boot/文件内容及配置

  • 由于之前操作失误,将板子上/dev/sda1硬盘分区上的内容格式化了,但是龙芯板子启动pmon引导的默认参数使用的是硬盘第一分区中的/boot/bott.cfg中的配置内容。具体内容参考如下:
titel "YXKJ_TEST"
	kernel (wd0,0)/boot/vmlinuz_yxkj_1104_02
	initrd (wd0,0)/boot/rootfs.cpio.gz
	args console=ttyS0,115200 console=tty0 
  • pmon引导会首先读取其中的内容,将该配置目录下的内核和文件系统引导去内存中进行启动。
  • 由于之前操作失误,所以现在首先需要进行板子的恢复工作。流程如下 :
  •   首先,使用网络方式读取内核和文件系统镜像启动。
    
  •   正常进入文件系统中,在硬盘第一分区中创建/boot目录并按照之前的配置格式准备好boot.cfg文件。
    
  •   重新启动,进入之前写好的文件系统中,将硬盘第一分区挂载到当前可执行目录下,将准备好的文件系统烧写到硬盘第一分区中,确保下次启动能够引导启动第一分区中的文件系统。
    

网络挂载内核及文件系统镜像启动

  • 启动龙芯板子,进入pmon执行命令
PMON> ifaddr syn0 192.168.10.139

PMON> load tftp://192.168.10.94/vmlinuz_usenfs

PMON> initrd tftp://192.168.10.94/rootfs.cpio.gz

PMON> g console=tty console=ttyS0,115200

在这里插入图片描述* 启动正常:
在这里插入图片描述

tftp方式下载内核及文件系统镜像配置/boot配置启动目录

  • 使用tftp方式从tftp服务器下载内核及文件系统镜像到板子上:
# tftp 192.168.10.94 -g -r vmlinuz_usenfs
vmlinuz_usenfs       100% |********************************| 11.8M  0:00:00 ETA
# ls
cantest.sh      dumpdesc        ls2k-igb.sh
dpdk.sh         ls2k-gmac.sh    vmlinuz_usenfs
# tftp 192.168.10.94 -g -r rootfs.cpio.gz
rootfs.cpio.gz       100% |********************************| 57.4M  0:00:00 ETA

在这里插入图片描述

  • 挂载硬盘第一分区,并创建/boot配置目录
mount /dev/sda1 /mnt/dev1
//此时挂载失败,原因是/dev/sda1分区并没有进行文件类型格式化。
mkfs.ext2 /dev/sda1 //进行文件类型格式化

在这里插入图片描述* 查看挂载情况并创建目录及配置文件

df -h
cd /mnt/dev1
rm -rf lost+found
mkdir boot
cd boot
cp /root/vmlinuz_usenfs .
cp /root/rootfs.cpio.gz .
vi boot.cfg

在这里插入图片描述* 创建boot.cfg配置文件(该配置启动时文件系统还是启动在内存中,并没有运行在硬盘存储中,所以在文件系统中的修改都不会保存。)

timeout 5                        
default 0                                       
showmenu 1                                
                                              
titel "YXKJ_TEST"                             
        kernel (wd0,0)/boot/vmlinuz_usenfs    
        initrd (wd0,0)/boot/rootfs.cpio.gz    
        args console=ttyS0,115200 console=tty0

解压文件系统镜像并保存在硬盘第一分区中。

  • 解压文件系统镜像
cd /mnt/dev1/boot/
cp rootfs.cpio.gz ../
cd ..
gunzip rootfs.cpio.gz
cpio -idmv < rootfs.cpio
rm rootfs.cpio

//修改网络配置
cd etc/network/
vi interface

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
pre-up ifconfig eth0:0 192.168.10.139
up ifconfig eth0:0 192.168.10.139

在这里插入图片描述* 再次修改启动配置内容,添加硬盘存储的文件系统启动:

timeout 5
default 0
showmenu 1

titel "YXKJ_TEST"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        args console=ttyS0,115200 console=tty0 init=/linuxrc rw root=/dev/sda1 rootfstype=ext2

titel "YXKJ_TEST_img"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        initrd (wd0,0)/boot/rootfs.cpio.gz
        args console=ttyS0,115200 console=tty0

titel "YXKJ_TEST_dev2"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        args console=ttyS0,115200 console=tty0 init=/linuxrc rw root=/dev/sda2 rootfstype=ext2
  • 板子重启查看:结果报错:
    在这里插入图片描述
  • 更新pmon设备树:
load -r -f 0xbfc00000 tftp://192.168.10.94/gzrom-dtb.bin

结果还是不行,需要重新格式化磁盘再创建

在这里插入图片描述

清空磁盘空间再次创建分区及初始化boot.cfg
  • 清空磁盘再次创建分区并格式化
fdisk /dev/sda
# fdisk /dev/sda 

Welcome to fdisk (util-linux 2.32.1).
Changes will rem[ 1156.828000]  sda:
ain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
No partition is defined yet!
Could not delete partition 1

//创建新的分区/dev/sda1
# fdisk /dev/sda 

Welcome to fdisk (util-linux 2.32.1).
Changes will remain[ 1298.301000]  sda:
 in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-31277231, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-31277231, default 31277231): 

Created a new partition 1 of type 'Linux' and of size 14.9 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partiti[ 1304.819000]  sda: sda1
on table.
Syncing disks.

//挂载分区
# mount /dev/sda1 /mnt/
[ 1339.785000] EXT4-fs (sda1): mounting ext2 file system using the ext4 subsystem
[ 1339.806000] EXT4-fs (sda1): mounted filesystem without journal. Opts: (null)
# ls
cantest.sh    dpdk.sh       dumpdesc      ls2k-gmac.sh  ls2k-igb.sh
# cd /mnt/
# df -h
Filesystem                Size      Used Available Use% Mounted on
n                       662.7M         0    662.7M   0% /dev
tmpfs                   691.7M         0    691.7M   0% /dev/shm
tmpfs                   691.7M      1.6M    690.1M   0% /run
tmpfs                   691.7M         0    691.7M   0% /sys/fs/cgroup
tmpfs                   691.7M         0    691.7M   0% /tmp
/dev/sda1                14.7G     20.0K     13.9G   0% /mnt

//创建新的boot目录及boot.cfg
cd /mnt/
mkdir boot
cd boot/
vi boot.cfg

timeout 5                                                                        
default 0                                                                        
showmenu 1                                                                       
                                                                                 
titel "YXKJ_TEST"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        args console=ttyS0,115200 console=tty0 init=/linuxrc rw root=/dev/sda1 ro
                                                                                 
titel "YXKJ_TEST_img"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        initrd (wd0,0)/boot/rootfs.cpio.gz
        args console=ttyS0,115200 console=tty0
                                                                                 
titel "YXKJ_TEST_dev2"
        kernel (wd0,0)/boot/vmlinuz_usenfs
        args console=ttyS0,115200 console=tty0 init=/linuxrc rw root=/dev/sda2 ro
   
//tftp下载文件到boot目录下
# ifconfig 
docker0   Link encap:Ethernet  HWaddr 02:42:61:99:AC:05  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 96:BD:CB:5C:0E:F4  
          inet addr:192.168.10.182  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1024 errors:0 dropped:0 overruns:0 frame:0
          TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:63286 (61.8 KiB)  TX bytes:5811 (5.6 KiB)
          Interrupt:20 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:12160 (11.8 KiB)  TX bytes:12160 (11.8 KiB)

# tftp 192.168.10.94 -g -r vmlinuz_usenfs
vmlinuz_usenfs       100% |********************************| 11.8M  0:00:00 ETA
# tftp 192.168.10.94 -g -r rootfs.cpio.gz
rootfs.cpio.gz       100% |********************************| 57.4M  0:00:00 ETA

//卸载磁盘
cd /
umount /mnt
reboot

使用loongnix重新烧写板子(为了重新分区)

  • 之前操作还是不能使/dev/sda1成为引导启动分区,并且还是找不到boot.cfg启动配置文件,所以决定使用U盘烧写loongnix系统进行磁盘分区并设置引导启动分区。
root@ubuntu:# dd if=loongnix-20190331.iso of=/dev/sdb

烧写loongnix系统镜像完成。

  • 重新分配boot分区并设置boot.cfg引导配置目录。
  • 进入系统中已root身份登录,修改boot.cfg。
  • 4
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值