OpenWrt Forum Archive

Topic: 3 HOWTOs + pivot_root from ramfs question

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello everyone,

Following 3 posts are step-by step HOWTOs (tested on TL-WR1043ND).

1) loader with kexec -> kernel from nfs with root filesystem embedded into the kernel.

This is useful if your bootloader can't directly boot from net.

2) Simply flash (delete this post).

3) loader with kexec -> kernel from usb stick with root filesystem embedded into the kernel -> switch_root + packages autoinstall from usb stick

That would allow you to change firmware of your device by simply changing contents of usb stick.

(Last edited by usv on 25 May 2012, 06:35)

sudo aptitude install nfs-kernel-server
sudo nano /etc/exports
/home/user/openwrt/kernel-ram/bin/ar71xx/ 192.168.40.177(no_subtree_check)
sudo /etc/init.d/nfs-kernel-server restart

cd ~/openwrt
rm -fr loader-nfs
svn co svn://svn.openwrt.org/openwrt/trunk/ loader-nfs
cd loader-nfs
ln -s ~/openwrt/downloads dl

make menuconfig
#Target System -> Atheros AR7xxx/AR9xxx
#Target Profile -> TP-LINK TL-WR1043N/ND
#Kernel modules -> Filesystems -> kmod-fs-nfs (*)
#Base system -> busybox -> Linux System Utilities -> Support mounting NFS file systems
#Utilities -> kexec-tools (*)

make kernel_menuconfig
#"Kernel type" -> "kexec system call"

mkdir -p files/etc/config
cat > files/etc/config/network

config interface 'loopback'                                                     
        option ifname 'lo'                                                      
        option proto 'static'                                                   
        option ipaddr '127.0.0.1'                                               
        option netmask '255.0.0.0'                                              
                                                                                
config interface 'lan'                                                          
        option ifname 'eth0.1'                                                  
        option type 'bridge'                                                    
        option proto 'static'                                                   
        option ipaddr '192.168.40.177'                                          
        option netmask '255.255.255.0'                                          
                                                                                
config interface 'wan'                                                          
        option ifname 'eth0.2'                                                  
        option proto 'dhcp'                                                     
                                                                                
config switch                                                                   
        option name 'rtl8366rb'                                                 
        option reset '1'                                                        
        option enable_vlan '1'                                                  
                                                                                
config switch_vlan                                                              
        option device 'rtl8366rb'                                               
        option vlan '1'                                                         
        option ports '1 2 3 4 5t'                                               
                                                                                
config switch_vlan                                                              
        option device 'rtl8366rb'                                               
        option vlan '2'                                                         
        option ports '0 5t'

cat > files/etc/rc.local

mkdir /tmp/new
sleep 5
mount -t nfs 192.168.40.190:/home/user/openwrt/kernel-ram/bin/ar71xx/ /tmp/new/ -o nolock
if [ -f /tmp/new/openwrt-ar71xx-generic-vmlinux-initramfs.elf ]; then
  kexec -l /tmp/new/openwrt-ar71xx-generic-vmlinux-initramfs.elf --command-line="board=TL-WR1043ND console=ttyS0,115200"
  killall watchdog
  watchdog -T 300 -t 30 /dev/watchdog
  kexec -e
fi
reboot
exit 0

make; beep

sudo cp bin/ar71xx/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin /srv/tftp/code.bin

setenv ipaddr 192.168.40.177
setenv serverip 192.168.40.190
erase 0xbf020000 +7c0000 # 7c0000: size of the firmware (be aware that you may have a different size thus bricking your router)
tftpboot 0x81000000 code.bin
cp.b 0x81000000 0xbf020000 0x7c0000
bootm 0xbf020000

====================================================================

cd ~/openwrt
rm -fr kernel-ram
svn co svn://svn.openwrt.org/openwrt/trunk/ kernel-ram
cd kernel-ram
ln -s ~/openwrt/downloads dl
make menuconfig
#Target System -> Atheros AR7xxx/AR9xxx
#Target Profile -> TP-LINK TL-WR1043N/ND
#Target Images -> ramdisk
make; beep

(Last edited by usv on 15 May 2012, 04:06)

cd ~/openwrt
rm -fr firmware
svn co svn://svn.openwrt.org/openwrt/trunk/ firmware
cd firmware
./scripts/feeds update packages
./scripts/feeds install nano
./scripts/feeds install pure-ftpd
ln -s ~/openwrt/downloads dl

make menuconfig
#Target System -> Atheros AR7xxx/AR9xxx
#Target Profile -> TP-LINK TL-WR1043N/ND
#Base system  -> block-mount (*)
#Kernel modules -> Filesystems -> kmod-fs-ext4 (*)
#Kernel modules -> USB Support -> kmod-usb-ohci (*)
#Kernel modules -> USB Support -> kmod-usb-storage (*)
#Utilities -> Filesystem -> e2fsprogs (*)
#Utilities -> Editors -> nano (M)
#Network -> File Transfer -> pure-ftpd (M)

mkdir -p files/etc/config
cat > files/etc/config/fstab

config global automount                                                         
        option from_fstab 1                                                     
        option anon_mount 1                                                     
                                                                                
config global autoswap                                                          
        option from_fstab 1                                                     
        option anon_swap 0                                                      
                                                                                
config mount                                                                    
        option target   /                                                       
        option device   /dev/sda1                                               
        option fstype   ext4                                                    
        option options  rw,sync,noatime                                         
        option enabled  1                                                       
        option enabled_fsck 1                                                   
                                                                                
config swap                                                                     
        option device   /dev/sda2                                               
        option enabled  0

cat > files/etc/opkg.conf

src/gz attitude_adjustment file:///packages

cat > files/etc/rc.local

if [ ! -f /usr/lib/opkg/lists/attitude_adjustment ]; then
  opkg update && {
    opkg install nano
    opkg install pure-ftpd
    /etc/init.d/pure-ftpd enable
    /etc/init.d/pure-ftpd start
    true
  } || reboot
fi
exit 0

make; beep

sudo cp bin/ar71xx/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin /srv/tftp/code.bin

setenv ipaddr 192.168.40.177
setenv serverip 192.168.40.190
erase 0xbf020000 +7c0000 # 7c0000: size of the firmware (be aware that you may have a different size thus bricking your router)
tftpboot 0x81000000 code.bin
cp.b 0x81000000 0xbf020000 0x7c0000
bootm 0xbf020000

====================================================================

sudo rm -fr /media/usb0/*
sudo tar -C /media/usb0/ -zxf bin/ar71xx/openwrt-ar71xx-generic-rootfs.tar.gz
sudo cp -a bin/ar71xx/packages/ /media/usb0/
sudo umount /media/usb0/

(Last edited by usv on 15 May 2012, 04:07)

cd ~/openwrt
rm -fr loader-usb
svn co svn://svn.openwrt.org/openwrt/trunk/ loader-usb
cd loader-usb
ln -s ~/openwrt/downloads dl

make menuconfig
#Target System -> Atheros AR7xxx/AR9xxx
#Target Profile -> TP-LINK TL-WR1043N/ND
#Kernel modules -> Filesystems -> kmod-fs-ext4 (*)
#Kernel modules -> USB Support -> kmod-usb-ohci (*)
#Kernel modules -> USB Support -> kmod-usb-storage (*)
#Utilities -> Filesystem -> e2fsprogs (*)
#Utilities -> kexec-tools (*)

make kernel_menuconfig
#"Kernel type" -> "kexec system call".

mkdir -p files/etc
cat > files/etc/rc.local

mkdir /tmp/new
until [ -e /dev/sda1 ]; do                                                      
  sleep 1                                                                       
done                                                                            
mount /dev/sda1 /tmp/new
if [ -f /tmp/new/linux.elf ]; then
     kexec -l /tmp/new/linux.elf --command-line="board=TL-WR1043ND console=ttyS0,115200" # DIR-825-B1
     #Set the watchdog, so that the booting should complete before the watchdog restarts the system
     killall watchdog
     watchdog -T 300 -t 30 /dev/watchdog
     kexec -e
fi
exit 0

make; beep

sudo cp bin/ar71xx/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin /srv/tftp/code.bin

setenv ipaddr 192.168.40.177
setenv serverip 192.168.40.190
erase 0xbf020000 +7c0000 # 7c0000: size of the firmware (be aware that you may have a different size thus bricking your router)
tftpboot 0x81000000 code.bin
cp.b 0x81000000 0xbf020000 0x7c0000
bootm 0xbf020000

====================================================================

cd ~/openwrt
rm -fr kernel-usb
svn co svn://svn.openwrt.org/openwrt/trunk/ kernel-usb
cd kernel-usb
./scripts/feeds update packages
./scripts/feeds install nano
./scripts/feeds install pure-ftpd
ln -s ~/openwrt/downloads dl

make menuconfig
#Target System -> Atheros AR7xxx/AR9xxx
#Target Profile -> TP-LINK TL-WR1043N/ND
#Target Images -> ramdisk
#Kernel modules -> Filesystems -> kmod-fs-ext4 (*)
#Kernel modules -> USB Support -> kmod-usb-ohci (*)
#Kernel modules -> USB Support -> kmod-usb-storage (*)
#Utilities -> Filesystem -> e2fsprogs (*)
#Utilities -> Editors -> nano (M)
#Network -> File Transfer -> pure-ftpd (M)

mkdir -p files/etc
cat > files/etc/opkg.conf

src/gz attitude_adjustment file:///packages

cat > files/etc/rc.local

if [ ! -f /usr/lib/opkg/lists/attitude_adjustment ]; then
  opkg update
  opkg install nano
  opkg install pure-ftpd
  /etc/init.d/pure-ftpd enable
  /etc/init.d/pure-ftpd start
fi
exit 0

mkdir -p files/lib/preinit
cat > files/lib/preinit/rootfs

rootfs=/dev/sda1

make; beep

sudo rm -fr /media/usb0/*
sudo tar -C /media/usb0/ -zxf bin/ar71xx/openwrt-ar71xx-generic-rootfs.tar.gz
sudo cp -a bin/ar71xx/packages/ /media/usb0/
sudo cp bin/ar71xx/openwrt-ar71xx-generic-vmlinux-initramfs.elf /media/usb0/linux.elf
sudo umount /media/usb0/

(Last edited by usv on 25 May 2012, 17:50)

The discussion might have continued from here.