Fedora + qemu + ARM

Posted on Thu 01 February 2018 in autre

L'émulateur qemu a un très bon support ARM. Afin de tester la construction correcte de mes RPMs personnels, je me suis dit que je pourrais l'essayer sur ma propre machine.

Il existe une dizaines de documentations diverses et variées pour démarrer qemu avec l'architecture ARM mais aucune n'a fonctionné chez moi du coup j'ai décidé de faire un bon RTFM des familles et d'essayer (presque) tout seul.

Installation

Pensez à installer qemu ainsi que quelques outils dont nous aurons besoin plus tard.

sudo dnf install qemu-system-arm libguestfs-tools-c

Récupérer le noyau et l'initrd

L'architecture ARM est particulièrement différente d'un PC x86 traditionnel, pour démarrer qemu en ARM il va falloir passer un noyau et un ramdisk.

Récupérons une image Fedora ARM minimale, il s'agit d'une installation toute prête destinée à être copiée telle quelle sur un périphérique (micro SD par exemple) et ensuite de le configurer.

https://arm.fedoraproject.org

L'heure à laquelle j'écris il s'agit de Fedora 27, récupérons l'image.

wget https://download.fedoraproject.org/pub/fedora/linux/releases/27/Spins/armhfp/images/Fedora-Minimal-armhfp-27-1.6-sda.raw.xz
xz -d Fedora-Minimal-armhfp-27-1.6-sda.raw.xz

Ensuite nous pouvons sortir le kernel et l'inirtd.

virt-builder --get-kernel Fedora-Minimal-armhfp-27-1.6-sda.raw.xz

Cela vous sortira deux fichiers :

  • initramfs-4.13.9-300.fc27.armv7hl.img (initrd)
  • vmlinuz-4.13.9-300.fc27.armv7hl (noyau)

Redimensionner l'image

L'image étant minimale, il est nécessaire de l'agrandir, ici il ne s'agira uniquement de la taille maximale du fichier il sera nécessaire d'agrandir la partition une fois Fedora configuré

qemu-img resize Fedora-Minimal-armhfp-27-1.6-sda.raw +20G

Modifiez 20G par la taille désirée comme bon vous semble.

Démarrage

Il est maintenant temps de démarrer notre machine, pour ce faire, nous allons rediriger la sortie de la console Linux sur stdio. C'est comme si votre écran était directement dans le terminal !

Nous spécifions les paramètres suivants :

  • -kernel : le noyau Linux,
  • -initrd : l'image initramfs,
  • -smp 4 : le nombre de cœur CPU à utiliser (adaptez),
  • -m 2G : on alloue 2Go de mémoire vive (adaptez),
  • -M virt : on utilise la machine qemu arm virtuelle,
  • -no-reboot : on ne reboot pas automatiquement (optionnel),
  • -nographic : pas de fenêtre graphique,
  • -hda Fedora-Minimal-armhfp-27-1.6-sda.raw : l'image de disque,
  • -append "console=ttyAMA0 rw root=LABEL=_/ rootwait quiet" : les paramètres du noyau.

Démarrons notre machine :

qemu-system-arm                                             \
    -kernel ./vmlinuz-4.13.9-300.fc27.armv7hl               \
    -initrd ./initramfs-4.13.9-300.fc27.armv7hl.img         \
    -smp 4                                                  \
    -m 2G                                                   \
    -M virt                                                 \
    -no-reboot                                              \
    -nographic                                              \
    -hda Fedora-Minimal-armhfp-27-1.6-sda.raw               \
    -append "console=ttyAMA0 rw root=LABEL=_/ rootwait quiet"

WARNING: Image format was not specified for 'Fedora-Minimal-armhfp-27-1.6-sda.raw' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
[    0.037614] /cpus/cpu@0 missing clock-frequency property
[    0.037710] /cpus/cpu@1 missing clock-frequency property
[    0.037729] /cpus/cpu@2 missing clock-frequency property
[    0.037747] /cpus/cpu@3 missing clock-frequency property
[    0.285601] dmi: Firmware registration failed.
[   12.077406] dmi-sysfs: dmi entry is absent.
[   13.441269] sr_init: platform driver register failed for SR
[   13.701551] rodata_test: test data was not read only
[  OK  ] Started Show Plymouth Boot Screen.
[  OK  ] Started Forward Password Requests to Plymouth Directory Watch.
[  OK  ] Reached target Local Encrypted Volumes.
[  OK  ] Reached target System Initialization.
[  OK  ] Listening on Open-iSCSI iscsiuio Socket.
[  OK  ] Reached target Sockets.
[  OK  ] Reached target Paths.
[  OK  ] Reached target Basic System.
[  OK  ] Started dracut initqueue hook.
[  OK  ] Found device /dev/disk/by-label/_\x2f.
[  OK  ] Reached target Initrd Root Device.
         Starting dracut pre-mount hook...
[  OK  ] Reached target Remote File Systems (Pre).
[  OK  ] Reached target Remote File Systems.
[  OK  ] Started dracut pre-mount hook.
         Starting File System Check on /dev/disk/by-label/_\x2f...
[  OK  ] Started File System Check on /dev/disk/by-label/_\x2f.
         Mounting /sysroot...
[  OK  ] Mounted /sysroot.
[  OK  ] Reached target Initrd Root File System.
         Starting Reload Configuration from the Real Root...
[  OK  ] Started Reload Configuration from the Real Root.
[  OK  ] Reached target Initrd File Systems.
[  OK  ] Reached target Initrd Default Target.
         Starting dracut pre-pivot and cleanup hook...
[  OK  ] Started dracut pre-pivot and cleanup hook.
         Starting Cleaning Up and Shutting Down Daemons...
[  OK  ] Stopped dracut pre-pivot and cleanup hook.
[  OK  ] Stopped dracut pre-mount hook.
         Starting Setup Virtual Console...
[  OK  ] Stopped target Remote File Systems.
[  OK  ] Stopped target Initrd Default Target.
[  OK  ] Stopped target Initrd Root Device.
         Starting Plymouth switch root service...
[  OK  ] Stopped target Remote File Systems (Pre).
[  OK  ] Stopped dracut initqueue hook.
[  OK  ] Stopped target Basic System.
[  OK  ] Stopped target Paths.
[  OK  ] Stopped target Slices.
[  OK  ] Stopped target Sockets.
[  OK  ] Closed Open-iSCSI iscsiuio Socket.
         Stopping Open-iSCSI...
[  OK  ] Stopped target Timers.
[  OK  ] Stopped target System Initialization.
[  OK  ] Stopped Apply Kernel Variables.
[  OK  ] Stopped udev Coldplug all Devices.
[  OK  ] Stopped dracut pre-trigger hook.
[  OK  ] Stopped Create Volatile Files and Directories.
[  OK  ] Stopped target Local File Systems.
[  OK  ] Stopped target Local Encrypted Volumes.
[  OK  ] Stopped target Swap.
         Stopping udev Kernel Device Manager...
[  OK  ] Stopped udev Kernel Device Manager.
[  OK  ] Started Setup Virtual Console.
[  OK  ] Started Plymouth switch root service.
[  OK  ] Stopped Open-iSCSI.
[  OK  ] Started Cleaning Up and Shutting Down Daemons.
[  OK  ] Stopped dracut pre-udev hook.
[  OK  ] Stopped dracut cmdline hook.
[  OK  ] Stopped Create Static Device Nodes in /dev.
[  OK  ] Stopped Create list of required stavice nodes for the current kernel.
[  OK  ] Closed udev Kernel Socket.
[  OK  ] Closed udev Control Socket.
         Starting Cleanup udevd DB...
[  OK  ] Started Cleanup udevd DB.
[  OK  ] Reached target Switch Root.
         Starting Switch Root...
[  OK  ] Started System Security Services Daemon.
[  OK  ] Reached target User and Group Name Lookups.
         Starting Login Service...
[  OK  ] Started Login Service.
[  OK  ] Started firewalld - dynamic firewall daemon.
[  OK  ] Reached target Network (Pre).
         Starting Network Manager...
[  OK  ] Started Network Manager.
[  OK  ] Reached target Network.
         Starting OpenSSH server daemon...
[  OK  ] Started Logout off all iSCSI sessions on shutdown.
[  OK  ] Reached target Remote File Systems (Pre).
[  OK  ] Reached target Remote File Systems.
         Starting Permit User Sessions...
         Starting Network Manager Script Dispatcher Service...
[  OK  ] Started Permit User Sessions.
         Starting Hold until boot process finishes up...
[  OK  ] Started Command Scheduler.
         Starting Terminate Plymouth Boot Screen...
[  OK  ] Started OpenSSH server daemon.
[  OK  ] Started Network Manager Script Dispatcher Service.

Fedora 27 (Twenty Seven)
Kernel 4.13.9-300.fc27.armv7hl on an armv7l (ttyAMA0)

Tada !

Attention toutefois, l'émulation ARM est très couteuse en temps CPU.

Redimensionnement partition

Lorsque vous aurez fait la première configuration, votre / sera toujours dans sa taille initiale. Augmentons la :

growpart /dev/vda 4
resize2fs /dev/vda4
reboot

Pensez toutefois à vérifier qu'il s'agit bien de /dev/vda.

Liens

  • https://fedoraproject.org/wiki/Architectures/ARM/F27/Installation
  • https://wiki.qemu.org/Documentation/Platforms/ARM