今回は、Androidのみを使ってArch Linuxのイメージを展開する方法
めんどくさい場合は、adb shell
しても良いですが、Arch Linuxは、Androidのみでも展開、起動可能です。.img
にしても直接書き込んでも良いですが、イメージファイルにしておいたほうが便利です。
Android
1
2
3
4
5
6
7
8
9
10
11
12
| $ su -
$ mkdir arch
$ dd if=/dev/zero of=alarm.img bs=1024 count=1145728 # Create 1.2GB empty file
$ mkfs.ext2 -F alarm.img
$ mount -t ext2 -o loop alarm.img arch/
$ wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
$ cd arch
$ tar -xvzf ../ArchLinuxARM-armv7-latest.tar.gz .
$ cd ..
$ umount arch
$ mkdir -p /sdcard/arch
$ mv alarm.img /sdcard/arch
|
これで、alarm.img
ができますので、それを使います。
mount -t ext2
が失敗する場合は、Arch Linuxなどで実行して、alarm.img
を作ってもよいです。
ArchLinux
1
2
3
4
5
6
7
8
9
10
11
12
13
| $ su -
$ mkdir arch
$ dd if=/dev/zero of=alarm.img bs=1024 count=1145728 # Create 1.2GB empty file
$ mkfs.ext2 -F alarm.img
$ mount -t ext2 -o loop alarm.img arch/
$ wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
$ cd arch
$ tar -xvzf ../ArchLinuxARM-armv7-latest.tar.gz .
$ cd ..
$ umount arch
$ adb push alarm.img /sdcard/arch
$ adb shell
|
あとは、マウントスクリプトを書いて、それを実行します。
/sdcard/arch/alarm.boot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| if [ -f /data/data/com.zpwebsites.linuxonandroid/files/busybox ]; then
export box=/data/data/com.zpwebsites.linuxonandroid/files/busybox
elif [ -f /data/data/com.zpwebsites.linuxonandroid.opensource/files/busybox ]; then
export box=/data/data/com.zpwebsites.linuxonandroid.opensource/files/busybox
else
export box=/system/xbin/busybox
fi
export mnt=/data/local/mnt
export loop=/dev/block/loop255
export img=/sdcard/arch/alarm.img
if [[ ! -d $mnt ]]; then mkdir $mnt; fi
perm=$(id|cut -b 5)
if [ "$perm" != "0" ]; then
echo "This script requires root! Type: su"; exit;
fi
echo "Starting up ArchLinux"
if [ ! -b $loop ]; then
$box mknod $loop b 7 255
fi
$box losetup $loop $img
$box mount -t ext4 $loop $mnt
$box mount -o bind /dev $mnt/dev
$box mount -t devpts devpts $mnt/dev/pts
$box mount -t proc proc $mnt/proc
$box mount -t sysfs sysfs $mnt/sys
#$box mount -o bind /sdcard $mnt/sdcard
#if [ -d /sdcard/external_sd ]; then
# $bbox mount -o bind /sdcard/external_sd $mnt/external_sd
#fi
#if [ -d /Removable/MicroSD ]; then
# $bbox mount -o bind /Removable/MicroSD $mnt/external_sd
#fi
#if [ -d /storage ]; then
# $bbox mount -o bind /storage $mnt/external_sd
#fi
cd $mnt
$box sysctl -w net.ipv4.ip_forward=1
if [ ! -f $mnt/etc/resolv.conf ];then
echo "nameserver 8.8.8.8" > $mnt/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $mnt/etc/resolv.conf
fi
if [ ! -f $mnt/etc/hosts ];then
echo "127.0.0.1 localhost" > $mnt/etc/hosts
echo "Arch is configured that can be accessed from the IP:"
fi
ifconfig wlan0
echo ""
PATH_=$PATH
export PATH=$bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin:/bin:/usr/local/sbin
export TERM=xterm
export USER=root
export HOME=/root
export SHELL=/bin/bash
$box chroot . /bin/bash
# $box chroot $mnt /root/init.sh
unset LD_PRELOAD
export PATH=$PATH_
cd ..
if [ -d $mnt/sdcard ];then
$box umount $mnt/sdcard
fi
if [ -d $mnt/external_sd ];then
$box umount $mnt/external_sd
fi
if [ -d $mnt/dev/pts ];then
$bbox umount $mnt/dev/pts
fi
$box umount $mnt/dev
$box umount $mnt/proc
$box umount $mnt/sys
$box umount $mnt
$box losetup -d $loop &> /dev/null
echo "Shutting down ArchLinux"
|
Android
1
2
| $ su -
$ sh /sdcard/arch/alarm.boot
|
参考:
http://adam-dej.github.io/nexus9-hacking/2014/12/28/n9-arch-userspace.html
しかし、このままではネットワークなどにつながりませんので、以下を参考に、init.sh
を起動時に実行するようにしておきます。上のスクリプト中に書いておけばよいでしょう。イメージをマウント後にAndroidで作っても良いし、ArchLinuxを起動後に作っても良いです。
Android : /data/local/mnt/root/init.sh
Arch : /root/init.sh
/data/local/mnt/root/init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| if [ ! -d /home/archlinux ];then
echo "Starting first boot setup......."
chmod a+rw /dev/null
chmod a+rw /dev/ptmx
chmod 1777 /tmp
chmod 1777 /dev/shm
chmod +s /usr/bin/sudo
groupadd -g 3001 android_bt
groupadd -g 3002 android_bt-net
groupadd -g 3003 android_inet
groupadd -g 3004 android_net-raw
mkdir /var/run/dbus
chown dbus.dbus /var/run/dbus
chmod 755 /var/run/dbus
usermod -a -G android_bt,android_bt-net,android_inet,android_net-raw dbus
echo "shm /dev/shm tmpfs nodev,nosuid,noexec 0 0" >> /etc/fstab
cd /root
chown -R archlinux.users /home/archlinux
echo
echo "Now give your user account (named archlinux) a password"
echo
echo "Please enter the new password below"
echo
passwd archlinux
usermod -a -G admin archlinux
usermod -a -G android_bt,android_bt-net,android_inet,android_net-raw archlinux
# Fix for sdcard read/write permissions by Barry flanagan
chown archlinux /external_sd/
groupadd -g 1015 sdcard-rw
usermod -a -G sdcard-rw archlinux
fi
|