# compiled busybox not working in initramfs

## idiv0

I'm trying to create an initramfs and followed the custom initramfs wiki page (amd64). http://wiki.gentoo.org/wiki/Custom_Initramfs

The problem is that my compiled busybox doesn't work in the initramfs (only package use flags are ipv6 and static).

Using gentoo.igz from a minimal install image works, if I change the busybox binary with mine, it doesn't.

I have removed everything from gentoo.igz, the only files that remain are busybox/symlinks and init/symlinks.

Tried copying my busybox as bb and keeping the original busybox, running bb will output:

```
[<uptime>] traps: bb[<pid>] trap invalid opcode ip:4556e8 sp:7fffd7694e20 error:0 in bb[400000+1d7000]

Illegal instruction
```

Could this be due to my kernel configuration missing something? There's nothing on the wiki mentioning any extra steps required.

One thing I did notice is that my version (for which I used the default configuration) contains more applets:

```
[, [[, acpid, addgroup, adduser, adjtimex, ar, arp, arping, ash, awk, base64, basename, bb, bbconfig, bbsh, blkid, blockdev, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod,

chown, chpasswd, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, conspy, cp, cpio, crond, cryptpw, cttyhack, cut, date, dd, deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff,

dirname, dmesg, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr, false, fbset, fdflush, fdformat, fdisk, fgconsole, fgrep,

find, findfs, flash_eraseall, flash_lock, flash_unlock, flashcp, flock, free, freeramdisk, fsck, fsync, ftpd, fuser, getopt, getty, ginit, grep, groups, gunzip, gzip, halt, hd, hdparm, head, hexdump,

hostname, httpd, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, init, insmod, install, ionice, iostat, ip, ipaddr, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall,

killall5, last, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, login, losetup, lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, man, md5sum, mdev, mesg,

microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.reiser, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv, nameif, nanddump, nandwrite,

nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf,

ps, pscan, pstree, pwd, pwdx, raidautorun, rdate, readahead, readlink, realpath, reboot, renice, reset, resize, rev, rm, rmdir, rmmod, route, rtcwake, runlevel, rx, script, scriptreplay, sed, sendmail,

seq, setarch, setconsole, setfont, setkeycodes, setlogcons, setserial, setsid, setuidgid, sh, sha1sum, sha256sum, sha3sum, sha512sum, showkey, sleep, softlimit, sort, split, start-stop-daemon, stat,

strings, stty, su, sum, swapoff, swapon, switch_root, sync, sysctl, tac, tail, tar, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize,

tunctl, tune2fs, ubiattach, ubidetach, ubimkvol, ubirmvol, ubirsvol, ubiupdatevol, udhcpc, udhcpc6, udhcpd, umount, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime,

users, usleep, vconfig, vi, vlock, volname, wall, watch, watchdog, wc, wget, which, who, whoami, whois, xargs, xz, xzcat, yes, zcat, zcip
```

While the one provided on the live CD minimal image:

```
[, [[, acpid, ash, awk, base64, basename, beep, blkid, blockdev, bootchartd, brctl, bzip2, cat, chat, chgrp, chmod, chown, chpasswd, chroot, chvt, clear, cp, cut, date, dd, depmod, devmem, df,

dhcprelay, dirname, dmesg, dnsdomainname, du, dumpkmap, dumpleases, echo, env, false, fbsplash, fgconsole, fgrep, find, findfs, flock, free, freeramdisk, fsync, ftpd, grep, groups, gunzip, gzip, halt,

hd, head, hexdump, hostid, hostname, id, ifconfig, ifenslave, ifplugd, init, insmod, ionice, iostat, kbd_mode, kill, killall, linuxrc, ln, loadfont, loadkmap, losetup, lpd, lpq, lpr, ls, lsmod, lsof,

lspci, lsusb, lzop, lzopcat, makedevs, makemime, man, mdev, mdstart, mesg, microcom, mkdir, mkdosfs, mke2fs, mkfs.ext2, mkfs.vfat, mknod, mktemp, modinfo, modprobe, more, mount, mpstat, mv, nbd-client,

ntpd, pgrep, ping, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, ps, pstree, pwd, pwdx, rdate, rdev, readlink, reboot, reformime, reset, rev, rm, rmdir, rmmod, route, rtcwake, script,

scriptreplay, sed, sendmail, setfont, setserial, sh, sha256sum, sha512sum, showkey, sleep, smemcap, sort, stty, swapoff, swapon, switch_root, sync, sysctl, tac, tail, tar, test, timeout, touch, true,

tty, tunctl, ubiattach, ubidetach, ubimkvol, ubirmvol, ubirsvol, ubiupdatevol, udhcpc, udhcpd, umount, uname, uniq, unlzop, unxz, uptime, volname, wget, which, whoami, whois, xargs, xz, xzcat, yes,

zcat
```

Extra details:

Testing in quemu-system-x86_64 with the kernel and initrd parameters, using my system kernel.

----------

## NeddySeagoon

idiv0,

Welcome to Gentoo

Your error

```
traps: bb[<pid>] trap invalid opcode ip:4556e8 sp:7fffd7694e20 error:0 in bb[400000+1d7000]

Illegal instruction
```

tells that your -march= is set incorrectly in your CFLAGS= in make.conf.

Its allowing gcc to use instructions that your CPU does not know how to execute.

Every package you have built may be affected.

Please post your 

```
emerge --info
```

and the content of /proc/cpuinfo, just for one CPU.

----------

## idiv0

Thank you NeddySeagoon!

I hadn't thought of that. I added all the instructions I had into make.conf (pretty much everything).

Thought of KVM, added myself to the correct group, logged in again, added -enable-kvm to the qemu params and everything is working now.

Interesting to see how easily you can reduce portability.

----------

## NeddySeagoon

idiv0,

 *Quote:*   

> Extra details:
> 
> Testing in quemu-system-x86_64 with the kernel and initrd parameters, using my system kernel.

 

Maybe I missed this the first time round but I had problems installing in a libvirtd KVM.

I got a lot of illegal instruction errors too.

That shouldn't happen as the VMs should see the underlying CPU.  There is something odd with libvirtd CPU detection as 

```
gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
```

told me my 64 bit VM install was running on a pentium-m, which is a 32 bit CPU.

For me, the fix was 

```
virsh edit <VM-Name>
```

and change   

```
<os>

    <type arch='x86_64' machine='pc-0.14'>hvm</type>

</os>
```

the machine= element.  Thats the fixed one.

----------

