読者です 読者をやめる 読者になる 読者になる

/home/tnishinaga/TechMEMO

日々行ったこと、面白かったことを書き留めます。

黒柴(KURO-SHEEVA)にdebian jessieを入れる

SheevaPlug ARM Linux Debian

tnishinaga.hatenablog.com

この記事の続きです.

前回はLinuxカーネルをビルドして動かしてみるところまでやりました. 今回はdebianのイメージを作って動かしてみたいと思います.

debootstrapでdebian環境を作る

debootstrapはdebianの基本システムを簡単に作れる公式ツールです. Arch Linuxではyaourtで導入できます.

$ yaourt debootstrap

また,debootstrapを完了するためにはbinfmtとqemu user modeのstaticバイナリが必要です.以下のコマンドで導入及び有効化してください. binfmtやqemu user modeについての解説は,ググるか,C89で僕のスタンドが同人誌の中でほんの少し解説するようなので,興味のある方は「3日目東ム36-a 迷惑研」にいらしてください.

$ yaourt -S binfmt-support binfmt-qemu-static
$ sudo update-binfmts --enable qemu-arm
$ yaourt -S qemu-user-static

debootstrapを用いてarmel用のdebian jessie環境を作るには,以下のコマンドを実行します. なお,後の作業で必要なため,debootstrapは前回linuxカーネルのソースをおいたところで実行してください.

$ cd 
$ mkdir -p debian-jessie-armel/usr/bin
$ cp /usr/bin/qemu-arm-static debian-jessie-armel/usr/bin/
$ sudo debootstrap --arch armel jessie debian-jessie-armel http://ftp.jp.debian.org/debian

次にchrootでこのdebian環境に入り,初期設定としてrootのパスワードだけ設定します.

$ LC_ALL=C LANGUAGE=C LANG=C sudo chroot debian-jessie-armel /bin/bash
# export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# passwd
# exit
$ cd ~/

Linux Kernelからモジュールとかヘッダを入れる

前回ビルドしたlinuxカーネルのうち,モジュールとヘッダファイルをこのdebian環境に入れます.

$ cd linux
$ make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- modules
$ sudo make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- INSTALL_MOD_PATH=~/debian-jessie-armel modules_install
$ sudo make ARCH=arm CROSS_COMPILE=arm-unknown-linux-gnueabi- INSTALL_HDR_PATH=~/debian-jessie-armel/usr headers_install
$ cd ~/

SDカードにDebian環境をインストールする

前回作成したLinuxカーネルと今回作ったDebian環境をSDカードに入れていきます. なお,私の持っている黒柴のU-BootはSDカードの第2パーティションをrootfsとして起動するようになっていたので,第1パーティションカーネル,第2パーティションにrootfsを置くような構成にします.

fdisk等を用いて,第1パーティションを64MBのfat,残りをext4パーティションとしてパーティション分けを行ってください. そして次のコマンドでフォーマットを行います.

$ sudo mkfs.vfat /dev/sdX1 (Xは各自環境に合わせる)
$ sudo mkfs.ext4 /dev/sdX2

フォーマットが終わったら,第1パーティションを/mnt/fat,第2パーティションを/mnt/ext4にマウントします.

$ sudo mkdir -p /mnt/fat
$ sudo mkdir -p /mnt/ext4
$ mount -t vfat /dev/sdX1 /mnt/fat
$ mount -t ext4 /dev/sdX2 /mnt/ext4

後はカーネルdebian環境をSDカードに入れ,アンマウントします.

$ sudo cp uImage+dtb /mnt/fat/
$ sudo rsync -avh debian-jessie-armel/ /mnt/ext4/
$ sudo umount /mnt/fat
$ sudo umount /mnt/ext4 

以上でインストールは完了です.

起動してみる

最後に,黒柴にSDカードを刺した後,前回と同様の方法で起動してみます.

Marvell>> mmcinit
Marvell>> fatload mmc 0:1 0x02000000 uimage+dtb
Marvell>> bootm

正しく動作すれば,debianのログインプロンプトが出てくるはずです. 以下に動作時のログを乗せておきます.

Marvell>> mmcinit
SDHC found. Card desciption is:
Manufacturer:       0x74, OEM "JE"
Product name:       "USD  ", revision 1.0
Serial number:      1280314594
Manufacturing date: 1/2012
CRC:                0x00, b0 = 0
Marvell>> fatload mmc 0:1 0x02000000 uimage+dtb
reading uimage+dtb

4298473 bytes read
Marvell>> bootm
## Booting image at 02000000 ...
   Image Name:   Linux-sheeva-esata
   Created:      2015-12-25   5:13:54 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    4298409 Bytes =  4.1 MB
   Load Address: 02000000
   Entry Point:  02000040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.3.0 (tnishinaga@arch-tx201) (gcc version 5.2.0 (crosstool-NG crosstool-ng-1.22.0) ) #6 PREEMPT Fri Dec 25 14:07:55 JST 2015
CPU: Feroceon 88FR131 [56251311] revision 1 (ARMv5TE), cr=0005397f
CPU: VIVT data cache, VIVT instruction cache
Machine model: Globalscale Technologies eSATA SheevaPlug
Memory policy: Data cache writeback
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttyS0,115200 root=/dev/mmcblk0p2 rw
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 510664K/524288K available (6261K kernel code, 214K rwdata, 1680K rodata, 176K init, 666K bss, 13624K reserved, 0K cma-reserved, 0K highmem)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xe0800000 - 0xff000000   ( 488 MB)
    lowmem  : 0xc0000000 - 0xe0000000   ( 512 MB)
    pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
    modules : 0xbf000000 - 0xbfe00000   (  14 MB)
      .text : 0xc0008000 - 0xc07c9984   (7943 kB)
      .init : 0xc07ca000 - 0xc07f6000   ( 176 kB)
      .data : 0xc07f6000 - 0xc082b9c0   ( 215 kB)
       .bss : 0xc082b9c0 - 0xc08d24a0   ( 667 kB)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Preemptible hierarchical RCU implementation.
    Build-time adjustment of leaf fanout to 32.
NR_IRQS:16 nr_irqs:16 16
clocksource: orion_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9556302233 ns
sched_clock: 32 bits at 200MHz, resolution 5ns, wraps every 10737418237ns
Console: colour dummy device 80x30
Calibrating delay loop... 1191.11 BogoMIPS (lpj=5955584)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x81e0 - 0x8238
mvebu-soc-id: MVEBU SoC ID=0x6281, Rev=0x2
devtmpfs: initialized
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
xor: measuring software checksum speed
   arm4regs  :  1084.400 MB/sec
   8regs     :   804.000 MB/sec
   32regs    :   970.800 MB/sec
xor: using function: arm4regs (1084.400 MB/sec)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
cpuidle: using governor menu
Feroceon L2: Enabling L2
Feroceon L2: Cache support initialised.
[Firmware Info]: /ocp@f1000000/ethernet-controller@72000/ethernet0-port@0: local-mac-address is not set
raid6: int32x1  gen()   115 MB/s
raid6: int32x1  xor()    76 MB/s
raid6: int32x2  gen()   167 MB/s
raid6: int32x2  xor()   103 MB/s
raid6: int32x4  gen()   185 MB/s
raid6: int32x4  xor()   119 MB/s
raid6: int32x8  gen()   187 MB/s
raid6: int32x8  xor()   116 MB/s
raid6: using algorithm int32x8 gen() 187 MB/s
raid6: .... xor() 116 MB/s, rmw enabled
raid6: using intx1 recovery algorithm
vgaarb: loaded
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource orion_clocksource
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
futex hash table entries: 256 (order: -1, 3072 bytes)
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
kirkwood-pinctrl f1010000.pin-controller: registered pinctrl driver
irq: Cannot allocate irq_descs @ IRQ34, assuming pre-allocated
irq: Cannot allocate irq_descs @ IRQ66, assuming pre-allocated
mv_xor f1060800.xor: Marvell shared XOR driver
mv_xor f1060800.xor: Marvell XOR (Registers Mode): ( xor cpy intr )
mv_xor f1060900.xor: Marvell shared XOR driver
mv_xor f1060900.xor: Marvell XOR (Registers Mode): ( xor cpy intr )
Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
console [ttyS0] disabled
f1012000.serial: ttyS0 at MMIO 0xf1012000 (irq = 26, base_baud = 12500000) is a 16550A
console [ttyS0] enabled
loop: module loaded
sata_mv f1080000.sata: slots 32 ports 2
scsi host0: sata_mv
scsi host1: sata_mv
ata1: SATA max UDMA/133 irq 32
ata2: SATA max UDMA/133 irq 32
nand: device found, Manufacturer ID: 0xec, Chip ID: 0xdc
nand: Samsung NAND 512MiB 3,3V 8-bit
nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
Scanning device for bad blocks
Bad eraseblock 2909 at 0x000016ba0000
Bad eraseblock 3657 at 0x00001c920000
3 ofpart partitions found on MTD device orion_nand
Creating 3 MTD partitions on "orion_nand":
0x000000000000-0x000000100000 : "u-boot"
0x000000100000-0x000000500000 : "uImage"
0x000000500000-0x000020000000 : "root"
libphy: orion_mdio_bus: probed
mv643xx_eth: MV-643xx 10/100/1000 ethernet driver version 1.4
mv643xx_eth_port mv643xx_eth_port.0 eth0: port 0 with MAC address f0:ad:4e:00:5c:d9
libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-pci: EHCI PCI platform driver
ehci-orion: EHCI orion driver
orion-ehci f1050000.ehci: EHCI Host Controller
orion-ehci f1050000.ehci: new USB bus registered, assigned bus number 1
ata1: SATA link down (SStatus 0 SControl F300)
orion-ehci f1050000.ehci: irq 29, io mem 0xf1050000
orion-ehci f1050000.ehci: USB 2.0 started, EHCI 1.00
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver ums-datafab
usbcore: registered new interface driver ums-freecom
usbcore: registered new interface driver ums-jumpshot
usbcore: registered new interface driver ums-sddr09
usbcore: registered new interface driver ums-sddr55
mousedev: PS/2 mouse device common for all mice
rtc-mv f1010300.rtc: rtc core: registered f1010300.rtc as rtc0
i2c /dev entries driver
orion_wdt: Initial timeout 21 sec
mvsdio f1090000.mvsdio: Got CD GPIO
mvsdio f1090000.mvsdio: Got WP GPIO
MV-CESA:Could not register sha1 driver
MV-CESA:Could not register hmac-sha1 driver
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
oprofile: no performance counters
oprofile: using timer interrupt.
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Btrfs loaded
mmc0: new high speed SDHC card at address b368
rtc-mv f1010300.rtc: setting system clock to 2013-01-01 11:42:16 UTC (1357040536)
mmcblk0: mmc0:b368 USD   3.75 GiB 
 mmcblk0: p1 p2
ALSA device list:
  No soundcards found.
ata2: SATA link down (SStatus 0 SControl F300)
EXT2-fs (mmcblk0p2): error: couldn't mount because of unsupported optional features (240)
EXT4-fs (mmcblk0p2): couldn't mount as ext3 due to feature incompatibilities
EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device 179:2.
devtmpfs: mounted
Freeing unused kernel memory: 176K (c07ca000 - c07f6000)
random: systemd urandom read with 7 bits of entropy available
systemd[1]: systemd 215 running in system mode. (+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR)
systemd[1]: Detected architecture 'arm'.

Welcome to Debian GNU/Linux 8 (jessie)!

systemd[1]: Failed to insert module 'autofs4'
systemd[1]: Failed to insert module 'ipv6'
systemd[1]: Set hostname to <arch-tx201>.
systemd[1]: Cannot add dependency job for unit dbus.socket, ignoring: Unit dbus.socket failed to load: No such file or directory.
systemd[1]: Cannot add dependency job for unit display-manager.service, ignoring: Unit display-manager.service failed to load: No such file or directory.
systemd[1]: Expecting device dev-ttyS0.device...
         Expecting device dev-ttyS0.device...
systemd[1]: Starting Forward Password Requests to Wall Directory Watch.
systemd[1]: Started Forward Password Requests to Wall Directory Watch.
systemd[1]: Starting Remote File Systems (Pre).
[  OK  ] Reached target Remote File Systems (Pre).
systemd[1]: Reached target Remote File Systems (Pre).
systemd[1]: Starting Encrypted Volumes.
[  OK  ] Reached target Encrypted Volumes.
systemd[1]: Reached target Encrypted Volumes.
systemd[1]: Starting Dispatch Password Requests to Console Directory Watch.
systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
systemd[1]: Starting Paths.
[  OK  ] Reached target Paths.
systemd[1]: Reached target Paths.
systemd[1]: Set up automount Arbitrary Executable File Formats File System Automount Point.
systemd[1]: Starting Swap.
[  OK  ] Reached target Swap.
systemd[1]: Reached target Swap.
systemd[1]: Starting Root Slice.
[  OK  ] Created slice Root Slice.
systemd[1]: Created slice Root Slice.
systemd[1]: Starting User and Session Slice.
[  OK  ] Created slice User and Session Slice.
systemd[1]: Created slice User and Session Slice.
systemd[1]: Starting Delayed Shutdown Socket.
[  OK  ] Listening on Delayed Shutdown Socket.
systemd[1]: Listening on Delayed Shutdown Socket.
systemd[1]: Starting /dev/initctl Compatibility Named Pipe.
[  OK  ] Listening on /dev/initctl Compatibility Named Pipe.
systemd[1]: Listening on /dev/initctl Compatibility Named Pipe.
systemd[1]: Starting Journal Socket (/dev/log).
[  OK  ] Listening on Journal Socket (/dev/log).
systemd[1]: Listening on Journal Socket (/dev/log).
systemd[1]: Starting udev Control Socket.
[  OK  ] Listening on udev Control Socket.
systemd[1]: Listening on udev Control Socket.
systemd[1]: Starting udev Kernel Socket.
[  OK  ] Listening on udev Kernel Socket.
systemd[1]: Listening on udev Kernel Socket.
systemd[1]: Starting Journal Socket.
[  OK  ] Listening on Journal Socket.
systemd[1]: Listening on Journal Socket.
systemd[1]: Starting System Slice.
[  OK  ] Created slice System Slice.
systemd[1]: Created slice System Slice.
systemd[1]: Starting system-getty.slice.
[  OK  ] Created slice system-getty.slice.
systemd[1]: Created slice system-getty.slice.
systemd[1]: Starting system-serial\x2dgetty.slice.
[  OK  ] Created slice system-serial\x2dgetty.slice.
systemd[1]: Created slice system-serial\x2dgetty.slice.
systemd[1]: Starting Increase datagram queue length...
         Starting Increase datagram queue length...
systemd[1]: Starting Load Kernel Modules...
         Starting Load Kernel Modules...
systemd[1]: Starting udev Coldplug all Devices...
         Starting udev Coldplug all Devices...
systemd[1]: Mounting Debug File System...
         Mounting Debug File System...
systemd[1]: Starting Create list of required static device nodes for the current kernel...
         Starting Create list of required static device nodes...rrent kernel...
systemd[1]: Mounted POSIX Message Queue File System.
systemd[1]: Started Set Up Additional Binary Formats.
systemd[1]: Mounted Huge Pages File System.
systemd[1]: Starting Slices.
[  OK  ] Reached target Slices.
systemd[1]: Reached target Slices.
systemd[1]: Starting Remount Root and Kernel File Systems...
         Starting Remount Root and Kernel File Systems...
[  OK  ] Mounted Debug File System.
systemd[1]: Mounted Debug File System.
[  OK  ] Started Increase datagram queue length.
systemd[1]: Started Increase datagram queue length.
[  OK  ] Started Load Kernel Modules.
systemd[1]: Started Load Kernel Modules.
[  OK  ] Started Create list of required static device nodes ...current kernel.
systemd[1]: Started Create list of required static device nodes for the current kernel.
[  OK  ] Started Remount Root and Kernel File Systems.
systemd[1]: Started Remount Root and Kernel File Systems.
[  OK  ] Started udev Coldplug all Devices.
systemd[1]: Started udev Coldplug all Devices.
systemd[1]: Starting Various fixups to make systemd work better on Debian...
         Starting Various fixups to make systemd work better on Debian...
systemd[1]: Starting Load/Save Random Seed...
         Starting Load/Save Random Seed...
systemd[1]: Starting Create Static Device Nodes in /dev...
         Starting Create Static Device Nodes in /dev...
systemd[1]: Mounted Configuration File System.
systemd[1]: Mounted FUSE Control File System.
systemd[1]: Starting Apply Kernel Variables...
         Starting Apply Kernel Variables...
systemd[1]: Starting Syslog Socket.
[  OK  ] Listening on Syslog Socket.
systemd[1]: Listening on Syslog Socket.
systemd[1]: Starting Sockets.
[  OK  ] Reached target Sockets.
systemd[1]: Reached target Sockets.
systemd[1]: Starting Journal Service...
         Starting Journal Service...
[  OK  ] Started Journal Service.
systemd[1]: Started Journal Service.
[  OK  ] Started Various fixups to make systemd work better on Debian.
[  OK  ] Started Load/Save Random Seed.
[  OK  ] Started Create Static Device Nodes in /dev.
[  OK  ] Started Apply Kernel Variables.
         Starting udev Kernel Device Manager...
[  OK  ] Reached target Local File Systems (Pre).
[  OK  ] Reached target Local File Systems.
systemd-udevd[1159]: starting version 215
         Starting Create Volatile Files and Directories...
[  OK  ] Reached target Remote File Systems.
         Starting Trigger Flushing of Journal to Persistent Storage...
         Starting LSB: Raise network interfaces....
[  OK  ] Started udev Kernel Device Manager.
[  OK  ] Started Create Volatile Files and Directories.
         Starting Update UTMP about System Boot/Shutdown...
         Starting Copy rules generated while the root was ro...
[  OK  ] Started Copy rules generated while the root was ro.
systemd-journald[1157]: Received request to flush runtime journal from PID 1
[  OK  ] Started Trigger Flushing of Journal to Persistent Storage.
[  OK  ] Started Update UTMP about System Boot/Shutdown.
[  OK  ] Found device /dev/ttyS0.
[  OK  ] Started LSB: Raise network interfaces..
[  OK  ] Reached target Network.
[  OK  ] Reached target System Initialization.
[  OK  ] Reached target Timers.
[  OK  ] Reached target Basic System.
         Starting Regular background program processing daemon...
[  OK  ] Started Regular background program processing daemon.
         Starting /etc/rc.local Compatibility...
         Starting getty on tty2-tty6 if dbus and logind are not available...
         Starting System Logging Service...
         Starting Permit User Sessions...
[  OK  ] Started /etc/rc.local Compatibility.
[  OK  ] Started Permit User Sessions.
[  OK  ] Started System Logging Service.
         Starting Getty on tty2...
[  OK  ] Started Getty on tty2.
         Starting Getty on tty1...
[  OK  ] Started Getty on tty1.
         Starting Serial Getty on ttyS0...
[  OK  ] Started Serial Getty on ttyS0.
[  OK  ] Started getty on tty2-tty6 if dbus and logind are not available.
         Starting Getty on tty6...
[  OK  ] Started Getty on tty6.
         Starting Getty on tty5...
[  OK  ] Started Getty on tty5.
         Starting Getty on tty4...
[  OK  ] Started Getty on tty4.
         Starting Getty on tty3...
[  OK  ] Started Getty on tty3.
[  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.

Debian GNU/Linux 8 arch-tx201 ttyS0

arch-tx201 login:

実は,Linuxカーネルを1からビルドして,rootfsも用意して正しく動いたのが初めてなので,すごく嬉しいです. やたー!