使用Qemu运行Ubuntu文件系统(1)
参考
平台
概述
正文
kernel_dir=./Linux-4.14.
kernel_image=${kernel_dir}/arch/arm/boot/zImage
dtb_image=${kernel_dir}/arch/arm/boot/dts/vexpress-v2p-ca9.dtb sudo qemu-system-arm \
-M vexpress-a9 \
-m 1024M \
-smp \
-kernel ${kernel_image} \
-nographic \
-append "root=/dev/mmcblk0 rw rootfstype=ext4 console=ttyAMA0,115200" \
-net nic,vlan= -net tap,vlan=,ifname=tap2 \
-sd ./ubuntu_rootfs/ubuntu.img \
-dtb ${dtb_image}
一、安装Qemu
sudo apt-get install qemu-user-static
二、下载和解压 ubuntu-core
先从官方上获取ubuntu core的tar包:http://cdimage.ubuntu.com/ubuntu-base/releases/16.04/release/
选择下载ubuntu-base-16.04-core-armhf.tar.gz,下载完之后,创建临时文件夹并解压根文件系统:
mkdir tmp
sudo tar -xf ubuntu-base-16.04-core-armhf.tar.gz -C tmp/
三、修改根文件系统
1、准备网络
sudo cp -b /etc/resolv.conf tmp/etc/resolv.conf
2、准备qemu
cp /usr/bin/qemu-arm-static tmp/usr/bin/
3、增加软件源
sudo vim tmp/etc/apt/source.list 将下面的两行的注释取消掉:
deb http://ports.ubuntu.com/ubuntu-ports/ xenial universe
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial universe
4、进入根文件系统进行操作
可以使用下面的脚本ch-mount.sh将根目录切换到tmp下:
#!/bin/bash function mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${}proc
sudo mount -t sysfs /sys ${}sys
sudo mount -o bind /dev ${}dev sudo chroot ${}
} function umnt() {
echo "UNMOUNTING"
sudo umount ${}proc
sudo umount ${}sys
sudo umount ${}dev } if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $ $
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $ $
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${}
echo 2nd parameter : ${}
fi
切换根目录:
sudo ch-mount.sh -m tmp/
更新
apt update
apt upgrade
安装软件包
apt install udev #否则ttyAMA0无法找到
apt install vim #vim编辑器
apt install net-tools #ifconfig,netstat,route,arp等
apt install iputils-ping #ping
apt install sudo #sudo命令
#apt install ssh #ssh的client和server
apt install ethtool #ethtool命令,显示、修改以太网设置
#apt install wireless-tools #iwconfig等,显示、修改无线设置
apt install ifupdown #ifup,ifdown等工具
#apt install network-manager #Network Manager服务和框架,高级网络管理
apt install rsyslog #系统log服务
apt install bash-completion #bash命令行补全
apt install htop #htop工具,交互式进程查看器
apt install nfs-common #可以远程挂载mount -t nfs
apt install telnetd #可以用telnet登录
对于bash命令自动补全功能,需要安装bash-completion,此外还需要修改/etc/bash.bashrc,将下面的命令的注释去掉:
# enable bash completion in interactive shells
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
然后重新登录即可。
创建用户
useradd -s '/bin/bash' -m -G adm,sudo pengdl #增加pengdl用户,同时加到sudo用户组,这样就可以使用sudo命令了
passwd pengdl #给pengdl用户设置密码
passwd root #修改root密码
pengdl ALL=(ALL:ALL) ALL
设置ip
编辑/etc/network/interfaces,添加如下内容:
auto lo
iface lo inet loopback auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1
设置hostname
设置主机名称:
echo "ubuntu-arm">/etc/hostname 设置本机入口ip:
echo "127.0.0.1 localhost">>/etc/hosts
echo "127.0.1.1 ubuntu-arm">>/etc/hosts
在软件安装完毕后,退出根目录:ctrl+D 或者 exit
执行umount:
./ch-mount.sh -u tmp/
四、制作根文件系统
查看根文件系统的大小
du -sh tmp/
351M tmp/
生成镜像,并格式为ext4
dd if=/dev/zero of=ubuntu.img bs=1M count=
mkfs.ext4 ubuntu.img
mkdir mnt
sudo mount ubuntu.img mnt
sudo cp -rfp tmp/* mnt
sudo umount mnt #检查并修复ubuntu.img
e2fsck -p -f ubuntu.img
五、测试
开机:
[ 8.915670] Freeing unused kernel memory: 1024K
[ 12.875789] systemd[]: Failed to insert module 'autofs4': No such file or directory
[ 13.486345] systemd[]: systemd running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN)
[ 13.497463] systemd[]: Detected architecture arm. Welcome to Ubuntu 16.04 LTS! [ 13.536063] systemd[]: Set hostname to <ubuntu-arm>.
[ 15.590117] systemd-gpt-aut () used greatest stack depth: bytes left
[ 16.987350] systemd[]: Reached target Swap.
...
[ OK ] Found device /dev/ttyAMA0.
[ OK ] Reached target Sound Card.
[ OK ] Started ifup for eth0.
[ OK ] Found device /sys/subsystem/net/devices/eth0.
[ OK ] Started LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Started Raise network interfaces.
[ OK ] Reached target Network.
Starting /etc/rc.local Compatibility...
[ OK ] Started /etc/rc.local Compatibility.
[ OK ] Started Serial Getty on ttyAMA0.
[ OK ] Started Getty on tty5.
[ OK ] Started Getty on tty3.
[ OK ] Started Getty on tty6.
[ OK ] Started Getty on tty2.
[ OK ] Started Getty on tty1.
[ OK ] Started Getty on tty4.
[ OK ] Reached target Login Prompts.
[ OK ] Reached target Multi-User System.
[ OK ] Reached target Graphical Interface.
Starting Update UTMP about System Runlevel Changes...
[ OK ] Started Update UTMP about System Runlevel Changes. Ubuntu 16.04 LTS ubuntu-arm ttyAMA0 ubuntu-arm login: pengdl
Password:
Last login: Sun Aug :: UTC on ttyAMA0
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.14.+ armv7l) * Documentation: https://help.ubuntu.com/
pengdl@ubuntu-arm:~$ ifconfig
eth0 Link encap:Ethernet HWaddr :::::
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (2.1 KB) TX bytes: (296.0 B)
Interrupt: lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (0.0 B) pengdl@ubuntu-arm:~$ ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) () bytes of data.
bytes from 61.135.169.121: icmp_seq= ttl= time=4.12 ms
bytes from 61.135.169.121: icmp_seq= ttl= time=3.71 ms
bytes from 61.135.169.121: icmp_seq= ttl= time=3.83 ms
^C
--- www.a.shifen.com ping statistics ---
packets transmitted, received, % packet loss, time 2017ms
rtt min/avg/max/mdev = 3.717/3.891/4.125/0.186 ms pengdl@ubuntu-arm:~$ sudo apt install htop
Reading package lists... Done
Reading state information... Done
Suggested packages:
lsof strace
The following NEW packages will be installed:
htop
upgraded, newly installed, to remove and not upgraded.
Need to get 67.7 kB of archives.
After this operation, kB of additional disk space will be used.
Get: http://ports.ubuntu.com/ubuntu-ports xenial/universe armhf htop armhf 2.0.1-1 [67.7 kB]
Fetched 67.7 kB in 2s (27.0 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package htop.
(Reading database ... files and directories currently installed.)
Unpacking htop (2.0.-) ..._2.0.1-1_armhf.deb ...
Processing triggers for mime-support (.59ubuntu1) ...
关机:
pengdl@ubuntu-arm:~$ sudo shutdown -h now
[ OK ] Stopped target Timers.
[ OK ] Stopped Daily apt activities.
[ OK ] Stopped target System Time Synchronized.
[ OK ] Stopped target Graphical Interface.
[ OK ] Stopped Daily Cleanup of Temporary Directories.
[ OK ] Stopped target Multi-User System.
[ OK ] Stopped target Login Prompts.
Stopping Getty on tty6...
Stopping Getty on tty1...
Stopping Getty on tty5...
Stopping Getty on tty4...
[ OK ] Stopped getty on tty2-tty6 if dbus and logind are not available.
Stopping Getty on tty2...
Stopping Getty on tty3...
Stopping LSB: Set the CPU Frequency Scaling governor to "ondemand"...
[ OK ] Reached target Unmount All Filesystems.
[ OK ] Stopped target Sound Card.
Stopping Serial Getty on ttyAMA0...
[ OK ] Removed slice system-getty.slice.
[ OK ] Stopped /etc/rc.local Compatibility.
[ OK ] Stopped target Network.
Stopping Raise network interfaces...
Stopping Permit User Sessions...
[ OK ] Removed slice system-serial\x2dgetty.slice.
[ OK ] Stopped LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Stopped Permit User Sessions.
[ OK ] Stopped target Basic System.
[ OK ] Stopped target Paths.
[ OK ] Stopped Forward Password Requests to Wall Directory Watch.
[ OK ] Stopped Dispatch Password Requests to Console Directory Watch.
[ OK ] Stopped target Slices.
[ OK ] Stopped target System Initialization.
[ OK ] Stopped target Encrypted Volumes.
[ OK ] Stopped target Swap.
Stopping Update UTMP about System Boot/Shutdown...
Stopping Load/Save Random Seed...
Stopping Network Time Synchronization...
[ OK ] Stopped target Sockets.
[ OK ] Stopped target Remote File Systems.
[ OK ] Stopped target Remote File Systems (Pre).
[ OK ] Stopped Load/Save Random Seed.
[ OK ] Stopped Network Time Synchronization.
[ OK ] Stopped Update UTMP about System Boot/Shutdown.
[ OK ] Stopped Create Volatile Files and Directories.
[ OK ] Stopped Raise network interfaces.
[ OK ] Stopped Apply Kernel Variables.
[ OK ] Stopped target Local File Systems.
[ OK ] Stopped target Local File Systems (Pre).
[ OK ] Stopped Create Static Device Nodes in /dev.
[ OK ] Stopped Remount Root and Kernel File Systems.
[ OK ] Stopped Load Kernel Modules.
[ OK ] Reached target Shutdown.
[ 385.729940] reboot: Power down
sudo brctl delif br0 tap2
sudo tunctl -d tap2
TUNSETIFF: Device or resource busy
brctl show
bridge name bridge id STP enabled interfaces
br0 .f48e387d73d8 no enp3s0
virbr0 8000.000000000000 yes
重启:
pengdl@ubuntu-arm:~$ sudo reboot
[sudo] password for pengdl:
[ OK ] Stopped target Sound Card.
[ OK ] Reached target Unmount All Filesystems.
[ OK ] Stopped target Timers.
[ OK ] Stopped Daily apt activities.
[ OK ] Stopped target System Time Synchronized.
[ OK ] Stopped Daily Cleanup of Temporary Directories.
[ OK ] Stopped target Graphical Interface.
[ OK ] Stopped target Multi-User System.
Stopping LSB: Set the CPU Frequency Scaling governor to "ondemand"...
[ OK ] Stopped target Login Prompts.
Stopping Getty on tty5...
Stopping Getty on tty3...
Stopping Getty on tty2...
Stopping Getty on tty6...
[ OK ] Stopped getty on tty2-tty6 if dbus and logind are not available.
Stopping Getty on tty4...
Stopping Serial Getty on ttyAMA0...
Stopping Getty on tty1...
[ OK ] Stopped Getty on tty4.
[ OK ] Stopped Serial Getty on ttyAMA0.
[ OK ] Stopped Getty on tty2.
[ OK ] Removed slice system-serial\x2dgetty.slice.
Stopping Permit User Sessions...
[ OK ] Removed slice system-getty.slice.
[ OK ] Stopped /etc/rc.local Compatibility.
[ OK ] Stopped target Network.
Stopping Raise network interfaces...
[ OK ] Stopped LSB: Set the CPU Frequency Scaling governor to "ondemand".
[ OK ] Stopped Permit User Sessions.
[ OK ] Stopped target Basic System.
[ OK ] Stopped target Paths.
[ OK ] Stopped Forward Password Requests to Wall Directory Watch.
[ OK ] Stopped Dispatch Password Requests to Console Directory Watch.
[ OK ] Stopped target Sockets.
[ OK ] Stopped target Slices.
[ OK ] Stopped target System Initialization.
Stopping Network Time Synchronization...
[ OK ] Stopped target Encrypted Volumes.
Stopping Load/Save Random Seed...
Stopping Update UTMP about System Boot/Shutdown...
[ OK ] Stopped target Swap.
[ OK ] Stopped target Remote File Systems.
[ OK ] Stopped target Remote File Systems (Pre).
[ OK ] Stopped Network Time Synchronization.
[ OK ] Stopped Load/Save Random Seed.
[ OK ] Stopped Update UTMP about System Boot/Shutdown.
[ OK ] Stopped Create Volatile Files and Directories.
[ OK ] Stopped Raise network interfaces.
[ OK ] Stopped Apply Kernel Variables.
[ OK ] Stopped Load Kernel Modules.
[ OK ] Stopped target Local File Systems.
[ OK ] Stopped target Local File Systems (Pre).
[ OK ] Stopped Remount Root and Kernel File Systems.
[ OK ] Stopped Create Static Device Nodes in /dev.
[ OK ] Reached target Shutdown.
[ 85.454918] reboot: Restarting system
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.14.+ (pengdonglin@pengdonglin-dell) (gcc version 4.8. (prerelease) (Sourcery CodeBench Lite 2014.05-)) # SMP PREEMPT Thu Apr :: CST
[ 0.000000] CPU: ARMv7 Processor [410fc090] revision (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[ 0.000000] OF: fdt: Machine model: V2P-CA9
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] cma: Reserved MiB at 0x9f000000
使用Qemu运行Ubuntu文件系统(1)的更多相关文章
- 使用Qemu运行Ubuntu文件系统 —— 搭建SVE学习环境(2)
开发环境 PC:ubuntu18.04 Qemu:4.1 Kernel:Linux-5.2 概述 由于要学习ARM的SVE技术,但是目前还没有支持SVE指令的板子,所以只能用Qemu来模拟,但是发现Q ...
- xv6 + Qemu 在Ubuntu下编译运行教程【转】
转自:https://blog.csdn.net/yinglang19941010/article/details/49310111 如果想要离线看教程,可以下载该 文档 一.使用工具说明 1. ...
- Android 手机上安装并运行 Ubuntu 12.04
ubuntu.sh脚本的原地址变动了,导致下载不了,现在更新了网盘地址.小技巧:遇到一些下载失效的时候可以试一试p2p下载工具(如 easyMule.迅雷等)试一试,说不定有人分享过~* —————— ...
- 【Ubuntu 16】深入Ubuntu文件系统
Ubuntu文件系统的设计目的就是把文件有序地组织在一起,提供一个从逻辑上组织文件的文件系统.除了文件的组织外,文件安全也是文件系统的设计要点,所以文件的访问权限是文件系统不可缺少的组成部分 Ubun ...
- 用Qemu运行/调试arm linux【转】
转自:https://blog.csdn.net/absurd/article/details/78984244 用Qemu运行/调试arm linux,这事情干过好几次了,久了就忘记了,每次都要重新 ...
- 使用ramdisk启动ubuntu文件系统
环境 Qemu 4.1 vexpress-ca9 概述 为了减小linux内核的大小,可以把一些外设驱动编译成内核模块,但是在启动ubuntu的时候,需要读取flash,但是此时flash的驱动模块存 ...
- VirtualBox虚拟机运行Ubuntu如何不卡
VirtualBox虚拟机运行Ubuntu如何不卡 转自http://www.xuzefeng.com/post/85.html 上一篇文章<VirtualBox虚拟机安装Ubuntu详细教程& ...
- Windows10 上运行Ubuntu Bash
Windows10 上运行Ubuntu Bash 2016年4月6日,Windows 10 Insider Preview 发布的版本 14316,添加了Ubuntu Bash,在Windows上提供 ...
- I.MX6 使用Ubuntu文件系统
/********************************************************************************* * I.MX6 使用Ubuntu文 ...
随机推荐
- Storm——Android SQLite数据库管理类库
Storm是一个Android SQLite数据库管理类库,可以通过注解创建表和迁移数据库.它不是ORM框架. 特性: 1.通过@Annotations创建表: 2.通过@Annotations迁 ...
- Javascript转义字符串中的特殊字符处理
Web应用系统中,客户端发送请求到服务器,请求中的字符串参数,在被序列化成json过程中有些特殊字符会被空格代, 导致传递到服务器端再解析的时候,原本的输入参数就会被改变. 目前遇到的特殊字符有加号( ...
- js网页下载csv格式的表格
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 高性能之html
下面是alloyteam的总结,还是那句老话站在巨人的肩膀上看的远. 避免使用Iframe Iframe也叫内联frame,可以把一个HTML文档嵌入到另一个文档中.使用iframe的好处是被嵌入的文 ...
- PHP页面间传值的几种方法
方法一:require_once //Page a: <?php $a = "hello"; ?> //Page b: <?php require_once &q ...
- Codeforces 555C Case of Chocolate 其他
原文链接https://www.cnblogs.com/zhouzhendong/p/9272797.html 题目传送门 - CF555C 题意 给定一个 $n\times n(n\leq 10^9 ...
- oracle数据入库出现空格问题
java做数据入库,不知为什么报如下图错误: debug发现数据是两位,如(FB),但是入库后发现FB后面多了两个空格,检查表发现类型声明是char(4),上网百度,说是char类型会自动补足.参考h ...
- day 58 bootstrap part2
bootstrap组件的官网, https://v3.bootcss.com/components/#page-header 在bootstrap里面出了HTML和css样式之外还有很多的辅助工具,我 ...
- HDU 1022 火车进站【栈】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列2方式出栈.进站不一定 ...
- Mybatis之延迟加载机制
1. 延迟加载的含义: 用到的时候才会去进行相关操作 2. 延迟加载的例子: 2.1 spring的BeanFactory,在getBean()的时候才创建Bean 2.2 物理分页查询,只有点击 ...