I'm trying to make a .img from a tarball using the following script I found:
#!/bin/bash
# Packages required
# dosfstools parted
# Can be run on any Linux system
# loop.max_part=15 must be in kernel cmdline (cmdline.txt for rpi)
# then reboot
echo "creating image to fit on 2Gb card"
dd if=/dev/zero of=arch-rpi.img bs=1M count=1850
echo "Partitioning"
fdisk arch-rpi.img <<EOF
o
n
p
1
+100M
t
c
n
p
2
w
EOF
sleep 5
losetup -f arch-rpi.img
sleep 5
echo "Formatting vfat"
mkfs.vfat /dev/loop0p1
sleep 5
mkdir boot
echo "Mounting boot"
mount /dev/loop0p1 boot
echo "Installing"
echo "Formatting ext4"
mkfs.ext4 /dev/loop0p2
sleep 5
mkdir root
echo "Mounting root"
mount /dev/loop0p2 root
wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
echo "Installing"
bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root
sync
mv root/boot/* boot
sync
umount boot root
losetup -d /dev/loop0p1
losetup -d /dev/loop0p1
losetup -d /dev/loop0
echo "All complete, image arch-rpi.img created, compressing...."
zip -9 arch-rpi.img.zip arch-rpi.img
I'm doing this on my Raspberry Pi - Raspbian Wheezy. And when it gets to the line mkfs.vfat /dev/loop0p1
It says there's no such file / directory. I've read enough on Linux to know I'm trying to mount the .img as a loop device and then use mkfs to prepare the image for the tarball, but I don't quite know why loop0p# files are not there, they are listed by fdisk -l
. What do I need to to in order to get this script I found working?
partprobe
afterfdisk
to update the kernel. – psusi Mar 03 '15 at 04:47partx -u
orlosetup -P
- those are userspace scans that instruct the kernel to update the partition table. You dont need boot-parameters and a reboot to find a partition - you just need to scan for it. – mikeserv Mar 03 '15 at 12:19partx
works as an alternative topartprobe
, but iirc,losetup -P
also only works if you booted with the max_parts argument. – psusi Mar 03 '15 at 15:09losetup -Pf file
will scan a loopfile for partitions.man losetup
says--partscan
Force the kernel to scan the partition table on a newly created loop device. You can try the example snippet in my answer below - there are arguments configured for that module in either my initramfs/etc
or my root dir of the same name. Also,modinfo
shows it is loaded with no parameters. – mikeserv Mar 03 '15 at 15:36