Convert mobile to a linux booting device - Lun device (Part 2).

How to boot linux on desktop/laptop using mobile device.

Following outlines usage of mobiles as lun devices.

This is a continuation of previous document (Part 1).

Read applicable warnings here.

The author is not liable to any extent for loss of any data and/or damage of micro-sd card.

Most micro-sd card comes pre-formatted with vfat/exfat single partition. Steps below assumes that sd-card being used has vfat or exfat with single partition.
Please do not use any micro-sd card with existing data on it. Buy a new or prepare an old/existing one by formatting it into a single partition.

Booting Linux ISO's

How can I boot an iso OS on bare metal without having to write to a DVD first ?

1. Use a boot-loaders which has feature to boot a iso eg. GRUB. This requires lengthy preparation of a bootable usb drive, and very much works except with some isos. Using this method is beyond scope of this document.
2. Use a mobile device. This also requires lots of initial pre-understanding on how mobile devices work. See (Part 1).

Benefits:
If you are an OS developer who push lots of iso's and want them tested on bare metal with same ease as on VM(Virtual Machine) or an Emulator, then this is quite suitable method, only hurdle is getting it started.

Step 1
  • Download alpinelinux iso.

Download the following iso file onto your hard-disk.

cd /home/user/
wget https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-extended-3.18.4-x86_64.iso

Mount micro-sd(use one with minimum capacity of 4Gb) and create a root directory boot-isos. Transfer iso to micro-sd card.

mount /dev/sdXY /mnt/sdXY # (replace device name and path correctly)
mkdir /mnt/sdXY/boot-isos
cd /mnt/sdXY/boot-isos

cp /home/user/alpine-extended-3.18.4-x86_64.iso ./
Step 2
  • Create new files on device with given content.

1. File: /cache/bin/recovery.misc.sh
Note: if you are following previous (Part 1), then this file has not changed.

#!/sbin/sh
DATE=$(date)
mount -o remount,rw /
mount -o remount,ro /dev/stl9   # system
echo $DATE >> /tmp/recovery.misc.log

echo 10 > /sys/class/backlight/aat1401-backlight/brightness
echo 0 > /sys/class/backlight/aat1401-backlight/brightness

. /cache/bin/luns.sh &

mount -o remount,ro /dev/stl10  # cache
mount -o remount,ro /dev/stl11  # data

2. File: /cache/bin/luns.sh
Note: if you are following previous (Part 1), then rename this file to luns-cardreader.sh and create a new file luns.sh.

#!/sbin/sh
DATE=$(date)
echo "$DATE LUNS" >> /tmp/recovery.misc.log
F=/sys/devices/lm-2/gadget/lun0/file
ON=/sys/devices/virtual/usb_composite/usb_mass_storage/enable

F0=/dev/block/mmcblk0p1
F0MNT=/storage/extSdCard
mkdir -p $F0MNT
opts='ro,relatime,fmask=0022,dmask=0022,iocharset=iso8859-1,shortname=mixed,errors=remount-ro'
busybox mount -t vfat -o $opts $F0 $F0MNT

F1=$F0MNT/boot-isos/alpine-extended-3.18.4-x86_64.iso
echo 0 > $ON && echo "$F1" > $F && echo 1 > $ON

For some reason if you are unable to edit these files, using busybox vi <file name> on device itself, then copy and save these scripts to your /home/user as recovery.misc.sh, luns.sh using your favourite editor. then use adb to push it to /cache/bin/ (see adb docs on howto).

Step 3
  • Shut-down (off) the device.
  • Insert prep'ed micro-sd card from above.
  • Attach device via usb to a desktop/laptop.
  • Wait for 5-10 secs, and now the card is bootable.
  • Now reboot attached desktop/laptop to alpinelinux.

Booting Linux images

This is an interesting method, as one can make a bootable image to ones specification, including multi-partitioned image suitable for storing running data or config files.

Process described below is for making an alpinelinux bootable image. The image was created using running knoppix (v8.6.0) linux with required applications installed on it.

The resultant boot-able image is of a sys type installation.

Step 1
cd /home/user/

Create bootable image as described here: sys.

Step 2

Mount micro-sd(use one with minimum capacity of 4Gb) and create a root directory alpine. Transfer a.img to micro-sd card.

mount /dev/sdXY /mnt/sdXY # (replace device name and path correctly)
mkdir /mnt/sdXY/alpine
cd /mnt/sdXY/alpine

cp /home/user/a.img ./alpine-3.18.4-x86_64-sys-a.img
Step 3
  • Create new files on device with given content.

1. File: /cache/bin/recovery.misc.sh
Note: if you are following previous (Part 1), then this file has not changed.

2. File: /cache/bin/luns.sh
Note: if you are following previous (Part 1), then rename this file to luns-cardreader.sh and create a new file luns.sh.

#!/sbin/sh
DATE=$(date)
echo "$DATE LUNS" >> /tmp/recovery.misc.log
F=/sys/devices/lm-2/gadget/lun0/file
ON=/sys/devices/virtual/usb_composite/usb_mass_storage/enable

F0=/dev/block/mmcblk0p1
F0MNT=/storage/extSdCard
mkdir -p $F0MNT
opts='ro,relatime,fmask=0022,dmask=0022,iocharset=iso8859-1,shortname=mixed,errors=remount-ro'
busybox mount -t vfat -o $opts $F0 $F0MNT

F1=$F0MNT/alpine/alpine-3.18.4-x86_64-sys-a.img
echo 0 > $ON && echo "$F1" > $F && echo 1 > $ON
Step 4
  • Shut-down (off) the device.
  • Insert prep'ed micro-sd card from above.
  • Attach device via usb to a desktop/laptop.
  • Wait for 5-10 secs, and now the card is bootable.
  • Now reboot attached desktop/laptop to alpinelinux.

Booting Linux installed on micro-sdcard

With above 2 methods going why would one want to prep sdcard to be the only bootable disk, when one can add dozens of bootable images/isos on it and have same effect ?

Answer could be many, but if its still needed then one method is outlined below.

Step 1
  • I have left out howto's for this section. Almost all Linux distros have documentation on howto create a bootable usb-disk with linux installed on it. Visit those pages and create one. See resources below. Once done insert into the device and happy-boot to linux.
    I have updated and added new section here: (Part 1 - offmode booting).

Author

V.Krishn


Resources


Edit - History - Print - Recent Changes - Search
Page last modified on November 23, 2023, at 02:07 AM