-
Notifications
You must be signed in to change notification settings - Fork 5
/
slpm-genimg
executable file
·63 lines (53 loc) · 1.1 KB
/
slpm-genimg
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
#!/bin/sh
# --pancake 2010
if [ ! "$UID" = 0 ]; then
echo "You need root."
exit 1
fi
fs=10
img=image.ext2
mkfs=mke2fs
msg="\x1b[47m \x1b[0m"
# basic devices
cd _prefix
mkdir -p dev/pts proc sys tmp
cd dev
rm -f console tty null zero
mknod -m 660 console c 5 1
mknod -m 660 mem c 1 1
mknod -m 660 tty c 5 0
mknod -m 660 null c 1 3
mknod -m 660 zero c 1 5
cd ..
cd ..
sz=$(printf %d $(du -hs _prefix|awk '{print $1}') 2>/dev/null)
sz=$(($sz+$fs))M
printf "$msg image size: $sz\n"
cancel() {
printf "\n$msg ^C operation cancelled\n"
umount .mnt
rm -rf .mnt
rm -f $img
exit 1
}
trap cancel INT
printf "$msg create raw disk: $img\n"
rm -f $img
# normal
#dd if=/dev/zero of=image.ext2 count=1 bs=$sz
# sparse
#dd if=/dev/zero of=$img bs=1k count=0 seek=$sz
truncate -s $sz $img
printf "$msg format: $mkfs\n"
yes | $mkfs $img
printf "$msg source root: _prefix\n"
mkdir -p .mnt
mount -o loop $img .mnt
cp -rfa _prefix/* .mnt
umount .mnt
sync
rm -rf .mnt
printf "$msg done\n"
echo
printf "$msg qemu -kernel /tmp/bzImage -hda $img -append 'root=/dev/sda init=/bin/dash'\n"
echo