Maybe there is a misunderstanding.
4) writing a bash script is not particularly difficult, though what you wrote seem a lot like kernel parameters, but more generally a bash script needs to be either called from the console or autoexecuted at boot time; each Linux distro may have different ways to autoexecute something at boot time and you need to find the mechanism used by the specific distro you use. But maybe they will run "too early" in the boot process or "too late" (cannot say).
Can you check /proc/cmdline? (no idea if the approach is the same in recent Linux kernels and/or specifically in ArchLinux)
See here:
http://www.linuxques...87/#post2917469
https://bbs.archlinu...c.php?id=106197
For me at least, writing bash script is very very difficult, I don't know why bash script is very sensitive with whitespaces
The same url (linux questions) also popped out too when searching for custom boot parameters in google, thanks anyway
the command
cat /proc/cmdline
indeed returns the current boot parameter
Particularly if - as you just did with me - after describing yourself as a Linux n00b, you start lecturing on initramfs hooks (mind you it is OK as long as you do it with me , as I am definitely a Linux n00b).
LOL at lecturing, I am sorry then, probably my tone is aggressive and annoying, actually, it's just 'FYI', but I'm sorry if that makes me aggressive and annoying
Finnaly!!! these days are gone. After heavy intense of googling, looking at stackoverflow, forcing myself reading antix live iso init script.
Thanks to star brilliant for making me able to boot into vhd, though his code is very hard coded and doesn't work for me, so I had to type the script in emergency shell every time I boot into arch linux.
and whoever made the lvm2 hook script (My script which boot into raw image suffered the same fate with lvm, the root device won't appear unless a specific script is run)
and wonko the sane for his helps
Tested on arch linux with RAW image with partition table, I don't know if it's work with RAW image without partition table
Do it at your own risk. For whatever reason there are some obscure error everytime I turn off arch linux.
Installation instruction (on arch linux):
1. If you haven't installed ntfs-3g and parted, install the package (recommended: upgrade the system and refresh the package list first)
recommended:
pacman -Syu
pacman -S ntfs-3g parted
2. This step is optional, jump to the next step if you already sure
Try to mount RAW image first (with partition table) and see if it's successful
losetup /dev/loop0 /mnt/sdb1/archlinux.vhd
if /dev/loop0 is already used, try /dev/loop1, or /dev/loop2, or so on
partprobe /dev/loop0
check whether the partition appear (usually /dev/loop0p1)
fdisk -l /dev/loop0
try to mount the partition and see the content
mkdir /mnt/loop0p1
mount /dev/loop0p1 /mnt/loop0p1
ls /mnt/loop0p1
if it's fails, it's probably the default option of the loop module by not allowing any partition and only one loop device allowed
save this file as /etc/modprobe.d/loop.conf
# Increase loop partition limit and maximum loop device allowed
options loop max_part=64 max_loop=8
restart and try again
3. Choose either a or b
a.
Download the file in
https://drive.google...Qk9kaGZKTnZNb28
put the file initcpio.zip/initcpio/hooks/loopboot on /lib/initcpio/hooks/loopboot
put the file initcpio.zip/initcpio/install/loopboot on /lib/initcpio/install/loopboot
OR
b.
Save this file as /lib/initcpio/hooks/loopboot
loopboot
#!/bin/bash
run_hook ()
{
local param cmdline=$(cat /proc/cmdline) loop_dev loop_part_num loop_file_path loop_dev_path
#local cmdline="root=/dev/loop123p321 loop_file_path=/archlinux.vhd loop_dev_path=/dev/sda1"
echo $cmdline
for param in $cmdline; do
value=${param#*=}
case $param in
root=*) if [[ "${value/loop}" == "$value" ]];
then echo "Root device is not a loop device. loopboot hook will be terminated."; return
else local loop_dev=${value%p*}
local loop_part_num=${value##*p}
fi ;;
loop_file_path=*) local loop_file_path=$value ;;
loop_dev_path=*) local loop_dev_path=$value ;;
esac
done
#echo $loop_dev and $loop_part_num
if [ "$loop_file_path" == "" ] || [ "$loop_dev_path" == "" ];
then echo "Either loop_file_path or loop_dev_path parameter does not specified. loopboot hook will be terminated."; return
fi
blkid
echo "$loop_dev_path"
local loop_dev_type=$(blkid -s TYPE -o value $loop_dev_path)
echo "$loop_dev_type"
mkdir /host
if [[ "$loop_dev_type" == "ntfs" ]];
then ntfs-3g $loop_dev_path /host; echo "mounted using ntfs-3g";
else mount -t $loop_dev_type $loop_dev_path /host; echo "mount -t $loop_dev_type $loop_dev_path /host"; echo "mounted using mount";
fi
losetup $loop_dev /host$loop_file_path
partprobe $loop_dev
#echo $loop_file_path and $loop_dev_path
}
# vim: set ft=sh ts=4 sw=4 et:
Save this file as /lib/initcpio/install/loopboot
loopboot
#!/usr/bin/bash
build() {
local mod
for mod in loop fuse; do
add_module "$mod"
done
add_binary /usr/bin/ntfs-3g
add_binary /usr/bin/losetup
add_binary /usr/bin/partprobe
add_runscript
}
help() {
cat <<HELPEOF
This hook enables loopback booting using RAW image in initramfs.
Installation: edit /etc/mkinitcpio.conf, add this hook after block hook
>HOOKS="...block loopboot filesystems..."
Usage: append this on boot parameter: loop_file_path= (file directory where the loop located) loop_dev_path= (device directory where the loop located). Change the root as loop
Example: root=/dev/loop2p1 loop_file_path=/archlinux.img loop_dev_path=/dev/sdb1
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:
3. Edit /etc/mkinitcpio.conf (using vi, emacs, nano, etc)
Scroll down until you see HOOKS="...
edit the line, add 'loopboot' into the line
HOOKS="...block loopboot filesystems..."
4. Rebuild the initramfs
mkinitcpio -p linux --verbose >> initcpio-result
5. Verify the partprobe and ntfs-3g is already installed into initramfs (using vi, emacs, nano, etc)
(I like using vi, so I use vi as an example here)
vi initcpio-result
Tip:
On vi, type
?ntfs-3g
and press enter to search for ntfs-3g
type
?partprobe
and press enter to search for partprobe
type
:q
and press enter to quit
6. Edit the grub4dos menu.
I recommend using the latest grub4dos version possible, because grub4dos 0.4.4 cannot read ext4 formatted partition on RAW image
title Arch Linux loopback booting
find --set-root /ada.vhd
map --heads=0 --sectors-per-track=0 /ada.vhd (hd3)
map --hook
root (3,0)/boot
kernel /vmlinuz-linux root=/dev/loop0p1 rw loop_file_path=/ada.vhd loop_dev_path=/dev/sda1
initrd /initramfs-linux.img
Explanation
/ada.vhd is path where the RAW image stored, on yours it might be different like /VHD/archlinux.img
root (3,0) means the linux is on the first partition, if yours is on the second partition, then it becomes root (3,1), and so on
/dev/loop0p1 means the linux is on the first partition, if yours is on the second partition, then it becomes /dev/loop0p2, and so on
/dev/sda1 device where the RAW image is stored, if it's on different disk it might be in /dev/sdb1, /dev/sdc1, and so on
if it's on different partition then it might be in /dev/sda2, /dev/sda3, and so on