最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】Ubuntu下为QEMU建立一个arm平台的可用的根文件系统rootfs

QEMU crifan 8259浏览 0评论

【背景】

折腾:

【记录】尝试用QEMU模拟ARM开发板去加载并运行Uboot,kernel,rootfs

期间,折腾完毕,可以运行kernel:

【记录】Ubuntu下使用QEMU启动Linux内核

后,接着再去参考那人的教程:

Busybox for ARM on QEMU

去弄rootfs。

【折腾过程】

1.先去交叉编译busybox:

【记录】Ubuntu下为QEMU的arm平台交叉编译BusyBox

 

2.再去用cpio创建压缩格式的rootfs:

crifan@ubuntu:busybox-1.16.0$ ls
applets   busybox.links           console-tools  editors    _install   loginutils       Makefile.help  procps   shell              util-linux
arch      busybox_unstripped      coreutils      examples   INSTALL    mailutils        miscutils      README   sysklogd
archival  busybox_unstripped.map  debianutils    findutils  libbb      Makefile         modutils       runit    testsuite
AUTHORS   busybox_unstripped.out  docs           include    libpwdgrp  Makefile.custom  networking     scripts  TODO
busybox   Config.in               e2fsprogs      init       LICENSE    Makefile.flags   printutils     selinux  TODO_config_nommu
crifan@ubuntu:busybox-1.16.0$ cd _install/
crifan@ubuntu:_install$ find .
.
./usr
./usr/bin
./usr/bin/traceroute
./usr/bin/setkeycodes
./usr/bin/ar
./usr/bin/sha512sum
./usr/bin/setsid
./usr/bin/pscan
./usr/bin/arping
./usr/bin/script
./usr/bin/length
./usr/bin/ifplugd
./usr/bin/nohup
./usr/bin/seq
./usr/bin/cryptpw
./usr/bin/nc
./usr/bin/find
./usr/bin/hostid
./usr/bin/mkfifo
./usr/bin/ipcs
./usr/bin/cmp
./usr/bin/bunzip2
./usr/bin/logger
./usr/bin/ether-wake
./usr/bin/unexpand
./usr/bin/passwd
./usr/bin/sha256sum
./usr/bin/cut
./usr/bin/head
./usr/bin/tee
./usr/bin/tr
./usr/bin/runsv
./usr/bin/lzopcat
./usr/bin/tac
./usr/bin/deallocvt
./usr/bin/softlimit
./usr/bin/tail
./usr/bin/[
./usr/bin/eject
./usr/bin/vlock
./usr/bin/wget
./usr/bin/yes
./usr/bin/fdformat
./usr/bin/tty
./usr/bin/envuidgid
./usr/bin/env
./usr/bin/last
./usr/bin/install
./usr/bin/sum
./usr/bin/uniq
./usr/bin/who
./usr/bin/runsvdir
./usr/bin/id
./usr/bin/whoami
./usr/bin/[[
./usr/bin/killall5
./usr/bin/tftpd
./usr/bin/dos2unix
./usr/bin/nslookup
./usr/bin/dirname
./usr/bin/ftpput
./usr/bin/du
./usr/bin/top
./usr/bin/sha1sum
./usr/bin/beep
./usr/bin/fuser
./usr/bin/kbd_mode
./usr/bin/realpath
./usr/bin/chat
./usr/bin/setuidgid
./usr/bin/nmeter
./usr/bin/lpq
./usr/bin/resize
./usr/bin/lzmacat
./usr/bin/envdir
./usr/bin/lpr
./usr/bin/readlink
./usr/bin/hd
./usr/bin/ftpget
./usr/bin/uptime
./usr/bin/timeout
./usr/bin/uuencode
./usr/bin/hexdump
./usr/bin/fold
./usr/bin/printf
./usr/bin/tcpsvd
./usr/bin/crontab
./usr/bin/patch
./usr/bin/readahead
./usr/bin/uudecode
./usr/bin/renice
./usr/bin/time
./usr/bin/cal
./usr/bin/pgrep
./usr/bin/wall
./usr/bin/tftp
./usr/bin/showkey
./usr/bin/udpsvd
./usr/bin/clear
./usr/bin/mkpasswd
./usr/bin/free
./usr/bin/basename
./usr/bin/chrt
./usr/bin/which
./usr/bin/strings
./usr/bin/awk
./usr/bin/unzip
./usr/bin/logname
./usr/bin/comm
./usr/bin/ttysize
./usr/bin/md5sum
./usr/bin/unlzop
./usr/bin/chvt
./usr/bin/mesg
./usr/bin/less
./usr/bin/bzcat
./usr/bin/expr
./usr/bin/xargs
./usr/bin/openvt
./usr/bin/split
./usr/bin/microcom
./usr/bin/bzip2
./usr/bin/rx
./usr/bin/reset
./usr/bin/killall
./usr/bin/chpst
./usr/bin/sort
./usr/bin/sv
./usr/bin/ipcrm
./usr/bin/dc
./usr/bin/cksum
./usr/bin/unlzma
./usr/bin/telnet
./usr/bin/od
./usr/bin/volname
./usr/bin/wc
./usr/bin/unix2dos
./usr/bin/dumpleases
./usr/bin/diff
./usr/bin/test
./usr/bin/expand
./usr/bin/pkill
./usr/bin/rtcwake
./usr/sbin
./usr/sbin/telnetd
./usr/sbin/rdev
./usr/sbin/setfont
./usr/sbin/udhcpd
./usr/sbin/sendmail
./usr/sbin/svlogd
./usr/sbin/inetd
./usr/sbin/ftpd
./usr/sbin/lpd
./usr/sbin/chpasswd
./usr/sbin/crond
./usr/sbin/chroot
./usr/sbin/fbset
./usr/sbin/brctl
./usr/sbin/rdate
./usr/sbin/dnsd
./usr/sbin/fakeidentd
./usr/sbin/setlogcons
./usr/sbin/dhcprelay
./usr/sbin/popmaildir
./usr/sbin/httpd
./usr/sbin/loadfont
./usr/sbin/readprofile
./bin
./bin/hostname
./bin/date
./bin/ping6
./bin/pipe_progress
./bin/stty
./bin/run-parts
./bin/vi
./bin/msh
./bin/egrep
./bin/gunzip
./bin/addgroup
./bin/more
./bin/usleep
./bin/linux64
./bin/mt
./bin/uncompress
./bin/sleep
./bin/iptunnel
./bin/zcat
./bin/ps
./bin/iproute
./bin/linux32
./bin/ash
./bin/df
./bin/cp
./bin/ed
./bin/ping
./bin/ipcalc
./bin/iplink
./bin/fgrep
./bin/cpio
./bin/stat
./bin/scriptreplay
./bin/dd
./bin/ls
./bin/netstat
./bin/tar
./bin/pwd
./bin/fsync
./bin/kill
./bin/iprule
./bin/touch
./bin/umount
./bin/hush
./bin/rmdir
./bin/sed
./bin/sh
./bin/chown
./bin/reformime
./bin/setarch
./bin/mkdir
./bin/cttyhack
./bin/getopt
./bin/false
./bin/deluser
./bin/printenv
./bin/adduser
./bin/gzip
./bin/lzop
./bin/login
./bin/ip
./bin/su
./bin/mv
./bin/rm
./bin/makemime
./bin/chattr
./bin/sync
./bin/dnsdomainname
./bin/watch
./bin/fdflush
./bin/ipaddr
./bin/ln
./bin/busybox
./bin/mknod
./bin/delgroup
./bin/nice
./bin/mountpoint
./bin/pidof
./bin/lsattr
./bin/dumpkmap
./bin/uname
./bin/echo
./bin/chmod
./bin/grep
./bin/cat
./bin/chgrp
./bin/ionice
./bin/mount
./bin/mktemp
./bin/catv
./bin/dmesg
./bin/true
./sbin
./sbin/ifenslave
./sbin/watchdog
./sbin/klogd
./sbin/fsck.minix
./sbin/getty
./sbin/losetup
./sbin/udhcpc
./sbin/reboot
./sbin/runlevel
./sbin/init
./sbin/mkfs.vfat
./sbin/devmem
./sbin/sulogin
./sbin/swapon
./sbin/hwclock
./sbin/depmod
./sbin/vconfig
./sbin/setconsole
./sbin/hdparm
./sbin/insmod
./sbin/lsmod
./sbin/route
./sbin/fdisk
./sbin/ifup
./sbin/adjtimex
./sbin/loadkmap
./sbin/ifdown
./sbin/tunctl
./sbin/switch_root
./sbin/raidautorun
./sbin/slattach
./sbin/mdev
./sbin/mkdosfs
./sbin/mkswap
./sbin/fbsplash
./sbin/freeramdisk
./sbin/nameif
./sbin/ifconfig
./sbin/logread
./sbin/syslogd
./sbin/mkfs.minix
./sbin/findfs
./sbin/man
./sbin/modprobe
./sbin/pivot_root
./sbin/sysctl
./sbin/blkid
./sbin/arp
./sbin/zcip
./sbin/makedevs
./sbin/swapoff
./sbin/fsck
./sbin/rmmod
./sbin/halt
./sbin/poweroff
./sbin/start-stop-daemon
./linuxrc
crifan@ubuntu:_install$ find . | cpio -o --format=newc > ../rootfs.img
3520 blocks
crifan@ubuntu:_install$ cd ..
crifan@ubuntu:busybox-1.16.0$ ls
applets   busybox.links           console-tools  editors    _install   loginutils       Makefile.help  procps      selinux    TODO_config_nommu
arch      busybox_unstripped      coreutils      examples   INSTALL    mailutils        miscutils      README      shell      util-linux
archival  busybox_unstripped.map  debianutils    findutils  libbb      Makefile         modutils       rootfs.img  sysklogd
AUTHORS   busybox_unstripped.out  docs           include    libpwdgrp  Makefile.custom  networking     runit       testsuite
busybox   Config.in               e2fsprogs      init       LICENSE    Makefile.flags   printutils     scripts     TODO
crifan@ubuntu:busybox-1.16.0$ ls rootfs.img -lha
-rw-rw-r-- 1 crifan crifan 1.8M Aug 19 00:17 rootfs.img
crifan@ubuntu:busybox-1.16.0$ gzip -c rootfs.img > rootfs.img.gz
crifan@ubuntu:busybox-1.16.0$ ls rootfs.img* -lha
-rw-rw-r-- 1 crifan crifan 1.8M Aug 19 00:17 rootfs.img
-rw-rw-r-- 1 crifan crifan 965K Aug 19 00:18 rootfs.img.gz
crifan@ubuntu:busybox-1.16.0$ 

 

3.然后去测试一下:

crifan@ubuntu:busybox-1.16.0$ ls
applets        busybox_unstripped      debianutils  include    LICENSE          Makefile.help  README         shell              zImage
arch           busybox_unstripped.map  docs         init       loginutils       miscutils      rootfs.img     sysklogd
archival       busybox_unstripped.out  e2fsprogs    _install   mailutils        modutils       rootfs.img.gz  testsuite
AUTHORS        Config.in               editors      INSTALL    Makefile         networking     runit          TODO
busybox        console-tools           examples     libbb      Makefile.custom  printutils     scripts        TODO_config_nommu
busybox.links  coreutils               findutils    libpwdgrp  Makefile.flags   procps         selinux        util-linux
crifan@ubuntu:busybox-1.16.0$ qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/bin/sh"

然后是可以正常进入rootfs,进入linux命令行了:

can go into rootfs do ls

而且的确是ps和mount都没有东西:

ps and mount no output

 

4.去操作:

# mkdir /proc
# mount -t proc none /proc

效果如图:

mkdir proc then see mount

5.的确,dev下面只有console:

can see only console under dev

所以去

# mkdir /sys
# mount -t sysfs none /sys
# mdev -s

效果是:

do mdev can see many device node

6.对应的,接着去Ubuntu下我们此处的busybox中,去创建对应的启动内容:

crifan@ubuntu:busybox-1.16.0$ cd _install/
crifan@ubuntu:_install$ pwd
/home/crifan/develop/embedded/qemu/rootfs/busybox/busybox-1.16.0/_install
crifan@ubuntu:_install$ ls
bin  linuxrc  sbin  usr
crifan@ubuntu:_install$ mkdir proc sys dev etc etc/init.d
crifan@ubuntu:_install$ ls -lha
total 36K
drwxrwxr-x  9 crifan crifan 4.0K Aug 19 00:33 .
drwxr-xr-x 32 crifan crifan 4.0K Aug 19 00:22 ..
drwxrwxr-x  2 crifan crifan 4.0K Aug 19 00:15 bin
drwxrwxr-x  2 crifan crifan 4.0K Aug 19 00:33 dev
drwxrwxr-x  3 crifan crifan 4.0K Aug 19 00:33 etc
lrwxrwxrwx  1 crifan crifan   11 Aug 19 00:15 linuxrc -> bin/busybox
drwxrwxr-x  2 crifan crifan 4.0K Aug 19 00:33 proc
drwxrwxr-x  2 crifan crifan 4.0K Aug 19 00:15 sbin
drwxrwxr-x  2 crifan crifan 4.0K Aug 19 00:33 sys
drwxrwxr-x  4 crifan crifan 4.0K Aug 19 00:15 usr
crifan@ubuntu:_install$ cd ..
crifan@ubuntu:busybox-1.16.0$ gedit _install/etc/init.d/rcS

对应内容是:

#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s

然后添加可执行的权限:

crifan@ubuntu:busybox-1.16.0$ chmod +x _install/etc/init.d/rcS 
crifan@ubuntu:busybox-1.16.0$ ls _install/etc/init.d/ -lha
total 12K
drwxrwxr-x 2 crifan crifan 4.0K Aug 19 00:34 .
drwxrwxr-x 3 crifan crifan 4.0K Aug 19 00:33 ..
-rwxrwxr-x 1 crifan crifan   74 Aug 19 00:34 rcS
crifan@ubuntu:busybox-1.16.0$ 

重新创建rootfs:

crifan@ubuntu:busybox-1.16.0$ cd _install/
crifan@ubuntu:_install$ find . | cpio -o --format=newc > ../rootfs.img
3522 blocks
crifan@ubuntu:_install$ cd ..
crifan@ubuntu:busybox-1.16.0$ gzip -c rootfs.img > rootfs.img.gz
crifan@ubuntu:busybox-1.16.0$ ls -lha
total 11M
drwxr-xr-x 32 crifan crifan 4.0K Aug 19 00:22 .
drwxrwxr-x  3 crifan crifan 4.0K Aug 19 00:08 ..
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:14 applets
drwxr-xr-x  3 crifan crifan 4.0K Jan 24  2010 arch
drwxr-xr-x  4 crifan crifan 4.0K Aug 19 00:15 archival
-rw-r--r--  1 crifan crifan 5.1K Jan 24  2010 AUTHORS
-rwxrwxr-x  1 crifan crifan 1.7M Aug 19 00:15 busybox
-rw-rw-r--  1 crifan crifan 4.3K Aug 19 00:15 busybox.links
-rwxrwxr-x  1 crifan crifan 2.1M Aug 19 00:15 busybox_unstripped
-rw-rw-r--  1 crifan crifan 1.8K Aug 19 00:15 .busybox_unstripped.cmd
-rw-rw-r--  1 crifan crifan 1.7M Aug 19 00:15 busybox_unstripped.map
-rw-rw-r--  1 crifan crifan 109K Aug 19 00:15 busybox_unstripped.out
-rw-rw-r--  1 crifan crifan  22K Aug 19 00:14 .config
-rw-r--r--  1 crifan crifan  20K Jan 25  2010 Config.in
-rw-rw-r--  1 crifan crifan  22K Aug 19 00:13 .config.old
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 console-tools
drwxr-xr-x  3 crifan crifan  12K Aug 19 00:15 coreutils
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 debianutils
drwxr-xr-x  3 crifan crifan 4.0K Jan 24  2010 docs
drwxr-xr-x  3 crifan crifan 4.0K Aug 19 00:15 e2fsprogs
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 editors
drwxr-xr-x  5 crifan crifan 4.0K Jan 24  2010 examples
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 findutils
-rw-r--r--  1 crifan crifan  231 Jan 24  2010 .gitignore
drwxr-xr-x  3 crifan crifan 4.0K Aug 19 00:14 include
-rw-r--r--  1 crifan crifan  871 Jan 24  2010 .indent.pro
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 init
drwxrwxr-x  9 crifan crifan 4.0K Aug 19 00:33 _install
-rw-r--r--  1 crifan crifan 5.7K Jan 24  2010 INSTALL
-rw-rw-r--  1 crifan crifan  614 Aug 19 00:14 .kconfig.d
-rw-rw-r--  1 crifan crifan    7 Aug 19 00:14 .kernelrelease
drwxr-xr-x  2 crifan crifan  20K Aug 19 00:15 libbb
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 libpwdgrp
-rw-r--r--  1 crifan crifan  18K Jan 24  2010 LICENSE
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 loginutils
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 mailutils
-rw-r--r--  1 crifan crifan  42K Jan 25  2010 Makefile
-rw-r--r--  1 crifan crifan 5.4K Jan 24  2010 Makefile.custom
-rw-r--r--  1 crifan crifan 4.3K Jan 24  2010 Makefile.flags
-rw-r--r--  1 crifan crifan 2.0K Jan 24  2010 Makefile.help
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 miscutils
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 modutils
drwxr-xr-x  4 crifan crifan 4.0K Aug 19 00:15 networking
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 printutils
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 procps
-rw-r--r--  1 crifan crifan 8.6K Jan 24  2010 README
-rw-rw-r--  1 crifan crifan 1.8M Aug 19 00:37 rootfs.img
-rw-rw-r--  1 crifan crifan 965K Aug 19 00:38 rootfs.img.gz
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 runit
drwxr-xr-x  4 crifan crifan 4.0K Jan 25  2010 scripts
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 selinux
drwxr-xr-x  5 crifan crifan 4.0K Aug 19 00:15 shell
drwxr-xr-x  2 crifan crifan 4.0K Aug 19 00:15 sysklogd
drwxr-xr-x 45 crifan crifan 4.0K Jan 24  2010 testsuite
-rw-r--r--  1 crifan crifan  15K Jan 24  2010 TODO
-rw-r--r--  1 crifan crifan  21K Jan 24  2010 TODO_config_nommu
drwxr-xr-x  3 crifan crifan 4.0K Aug 19 00:15 util-linux
-rwxrwxr-x  1 crifan crifan 1.9M Aug 19 00:22 zImage
crifan@ubuntu:busybox-1.16.0$ 

重新测试运行:

qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init"

然后就可以看到熟悉的:

please press enter to active this console

了:

use new sbin init can show please press enter to active this console

以及,可以看到对应的sys文件夹,mount的内容了:

already got sys and dev

至此,参考教程的折腾,算是结束了。

 

【总结】

至此,参考教程,完成了:

使用BusyBox作为最基本的,从ram启动的rootfs,可以正常的进入linux的命令行了。

转载请注明:在路上 » 【记录】Ubuntu下为QEMU建立一个arm平台的可用的根文件系统rootfs

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.173 seconds, using 22.23MB memory