f QEMU Simulator Raspberry Pi ~ 迪貝之家

QEMU Simulator Raspberry Pi

之前寫了一篇使用docker去模擬pi的文章
但測試上會有一些問題
因為我的測試環境是在Virtualbox
docker裏頭的Pi環境又是另一層虛擬化
所以我要從Pi作業系統連通到sql server
一直出錯,連不上去
想用docker是因為懶得為了這個去研究QEMU的網路
但看起來是沒辦法
我也測過將docker的網路啟動為host
還是連不上主機外的sql server
因為QEMU的預設網路是不讓外面的封包進去的
除非你用brige
所以莫法度囉,只好再去研究linux brige
也是搞了好幾天
最後才找到真的有用的一篇文章
Bridging of QEMU emulated Raspberry pi
總之,按照前述的Po文,我編了兩個檔
setup.sh : 用來在virtualbox上的guest設定brige及tap介面
boot.sh : 用來啟動pi
先執行setup.sh
再執行boot.sh
setup.sh 的內容如下 :
brctl addbr br0
ip addr flush dev enp0s3
brctl addif br0 enp0s3
tunctl -u $(whoami)
brctl addif br0 tap0
ip link set dev br0 up
ip link set dev tap0 up
dhclient br0
boot.sh的內容如下 :
qemu-system-arm -nographic -kernel ./kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw console=ttyAMA0" -hda 2020-02-13-raspbian-buster-lite.img -net nic,macaddr=00:16:3e:00:00:01 -net tap,id=mynet0,ifname=tap0,script=no,downscript=no
pi開起來之後去編譯feetds
這是透過tsql 的連線測試
freetds
通了...真的通了
但.....碰到空間問題
root filesystem怎麼會只有1.3G
玩個屁阿
用raspi-config去extend filesystem
它回覆說,這不是SD卡......
回想之前用的docker pi沒這個問題啊!!
想說...既然docker pi的creator可以解決
那表示Internet應該是找得到資料的
果不其然,有囉...確實有這篇文章
QEmu and raspbian, how to increase image size
只是要非常的有耐心
因為這篇Po文有好幾個回覆
解法在其中一個回覆裡
這是我的作法
1. 關掉pi,回到virtualbox guest主機裡
下指令resize raspbian lite image
qemu-img resize 2020-02-13-raspbian-buster-lite.img +20G
再執行boot.sh啟動pi
2.登入pi 砍掉partition2 後,再重建出來
root@raspberrypi:/usr/local/freetds/bin# fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): p
Disk /dev/sda: 21.7 GiB, 23324524544 bytes, 45555712 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x738a4d67
Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA)
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (2048-45555711, default 2048): 524288
Sector 524288 is already allocated.
First sector (532480-45555711, default 532480):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-45555711, default 45555711):
Created a new partition 2 of type 'Linux' and of size 21.5 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
Command (m for help): p
Disk /dev/sda: 21.7 GiB, 23324524544 bytes, 45555712 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x738a4d67
Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/sda2 532480 45555711 45023232 21.5G 83 Linux
Command (m for help): w
The partition table has been altered.
Failed to remove partition 2 from system: Device or resource busy
Failed to add partition 2 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
3.關掉pi重開再登入,下指令resize root file system