-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqemu-rootfs.sh
More file actions
executable file
·37 lines (31 loc) · 865 Bytes
/
qemu-rootfs.sh
File metadata and controls
executable file
·37 lines (31 loc) · 865 Bytes
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
#!/usr/bin/env bash
# -*- coding: UTF-8 -*-
## Create an image (img) file to use it with QEMU
image_create() {
local fullpath=$1
local size=$2
local dir=/tmp/img-rootfs
[[ ! -d $(dirname ${fullpath}) ]] && echo [!] destination directory '$(dirname ${fullpath}) does not exist' && exit 1
[[ -f ${fullpath} ]] && echo [!] file '${fullpath} already exist' && exit 1
cmd="qemu-img create ${fullpath} ${size}"
echo $cmd
$cmd
[[ $? != "0" ]] && return 1
cmd="mkfs.ext4 ${fullpath}"
echo $cmd
$cmd
[[ $? != "0" ]] && return 1
cmd="mkdir $dir"
echo $cmd
$cmd
cmd="mount -o loop ${fullpath} $dir"
echo $cmd
sudo $cmd
cmd="debootstrap --arch amd64 focal $dir"
echo $cmd
sudo $cmd
echo "clean up"
sudo umount $dir
rm -r $dir
}
image_create $HOME/Downloads/jessie.img 1g