Packer CentOS AMI: loop device not found - linux

So I'm trying to make modifications to an ISO in a Packer instance, but I keep getting the following error message:
==> amazon-ebs.centos-efi: + sudo mount -t iso9660 -o loop 'temporary.iso' /tmp/tmp.M5xCLte5mi
==> amazon-ebs.centos-efi: mount: temporary.iso: failed to setup loop device: No such file or directory
And I cannot seem to understand why this is happening. Things I have tried:
I have tried mounting in a different directory.
Running modprobe loop
Running losetup
Creating a loop device: sudo mknod -m640 /dev/loop8 b 7 8
Neither of them worked. So I've come here for some guidance.
I'll provide relevant bits of my Packer template below:
source "amazon-ebs" "centos-efi" {
ami_name = "centos-efi-{{timestamp}}"
ssh_username = "centos"
instance_type = "t2.medium"
region = "${var.aws_region}"
source_ami = "ami-04f798ca92cc13f74"
skip_create_ami = true
tag {
key = "Name"
value = "CentOS EFI Build"
}
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 32
volume_type = "gp2"
delete_on_termination = true
}
}
Provisioner Code:
ISO_ORIG=$(mktemp -d)
ISO_CHANGE=$(mktemp -d)
ls -al /tmp
sleep 15
sudo mount -t iso9660 -o loop temporary.iso $ISO_ORIG
cd $ISO_ORIG
Any recommendations?

Related

Unable to mount volume created by terraform

I am using the following terraform template
resource "aws_instance" "ec2" {
ami = "${var.ami_id}"
instance_type = "${var.flavor}"
key_name = "${var.key_name}"
availability_zone = "${var.availability_zone}"
security_groups= ["${var.security_group}"]
tags = {Name = "${var.instance_name}"}
}
resource "aws_volume_attachment" "ebs_volume" {
device_name = "/dev/sdg"
volume_id = "vol-006d716dad719545c"
instance_id = "${aws_instance.ec2.id}"
}
to launch an instance in aws and attach volume to that instance.
When i execute this i see that the instance is created and volume is attached to the instance as well.
ubuntu#ip-172-31-10-43:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91M 1 loop /snap/core/6350
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/930
loop2 7:2 0 88.4M 1 loop /snap/core/6964
loop3 7:3 0 18M 1 loop /snap/amazon-ssm-agent/1335
xvda 202:0 0 50G 0 disk
└─xvda1 202:1 0 50G 0 part /
xvdg 202:96 0 20G 0 disk
But when i try to mount the volume im getting this weird error
ubuntu#ip-172-31-10-43:~$ sudo mkdir -p /goutham
ubuntu#ip-172-31-10-43:~$ sudo mount /dev/xvdg /goutha,
mount: /goutha,: mount point does not exist.
ubuntu#ip-172-31-10-43:~$ sudo mount /dev/xvdg /goutham
mount: /goutham: wrong fs type, bad option, bad superblock on /dev/xvdg, missing codepage or helper program, or other error.
Can anyone please help me out as to what mistake i am doing in this exercise.
Thanks in advance.
You can make a file system on an attached disk using user data and terraform script.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
https://www.terraform.io/docs/providers/aws/r/instance.html#user_data
Create a sh file, templates/mkfs.sh
#!/bin/bash
while ! ls /dev/xvdg > /dev/null
do
sleep 5
done
if [ `file -s /dev/xvdg | cut -d ' ' -f 2` = 'data' ]
then
mkfs.xfs /dev/xvdg
fi
terraform script,
data "template_file" "mkfs" {
template = "${file("${path.module}/templates/mkfs.sh")}"
}
resource "aws_instance" "ec2" {
...
user_data = "${data.template_file.mkfs}"
...
}
It will be run when an ec2 instance is created and wait until disk is mounted. after that it will create file system.
I figured it i think i missed creating the file system in the volume as the volume im trying to attach is an empty volume
so this helped me out
$ sudo mkfs -t xfs /dev/xvdg
and
sudo mkdir -p /goutham
sudo mount /dev/xvdg /goutham
Thanks

Unable to execute script using user_data

I'm trying to execute a script once while ec2 boots up so have following in instance.tf.
resource "aws_instance" "test" {
ami = "i-33434"
user_data = "${data.template_file.user-data.rendered}"
}
data "template_file" "user-data" {
template = "${file("templates/init.tpl")}"}
And have init.tpl file created under templates folder with below content:
#!/bin/bash
sudo mkdir /ecs
mkfs -t ext4 /dev/xvdt10
mkfs -t ext4 /dev/xvdt11
mkdir /ecs/folder1
mkdir /ecs/folder2
mount /dev/xvdt10 /ecs/folder1
mount /dev/xvdt11 /ecs/folder2
echo /dev/xvdt10 /ecs/folder1 ext4 defaults,nofail 0 2 >> /etc/fstab
echo /dev/xvdt11 /ecs/folder2 ext4 defaults,nofail 0 2 >> /etc/fstab

How to mount a USB drive on Android Things?

I'm attempting to read files off of a USB drive for an Android Things app on a Raspberry Pi. I'm able to scan the list of mounted devices like so:
public static List<File> ScanForFiles(Context context){
ArrayList<File> files = new ArrayList<>();
try{
BufferedReader reader = new BufferedReader(new FileReader("/proc/self/mountinfo"));
String line;
while ((line = reader.readLine()) != null) {
String[] columns = line.split(" ");
Log.i(TAG, "Mounted: " + columns[4]);
//files.addAll(getListFiles(new File(columns[4])));
}
} catch (Exception ex){
ex.printStackTrace();
}
printFileInformation("/proc/partitions");
return files;
}
private static void printFileInformation(String fileName){
Log.i("TitanTV", "Reading contents of " + fileName);
try{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = reader.readLine()) != null){
Log.i("TitanTV", line);
}
} catch (Exception ex){
ex.printStackTrace();
}
}
Which displays the following output:
I: Mounted: /
I: Mounted: /dev
I: Mounted: /dev
I: Mounted: /dev/pts
I: Mounted: /dev/memcg
I: Mounted: /dev/cpuctl
I: Mounted: /proc
I: Mounted: /sys
I: Mounted: /sys/fs/selinux
I: Mounted: /sys/fs/pstore
I: Mounted: /acct
I: Mounted: /mnt
I: Mounted: /mnt/runtime/default/emulated
I: Mounted: /mnt/runtime/read/emulated
I: Mounted: /mnt/runtime/write/emulated
I: Mounted: /config
I: Mounted: /data
I: Mounted: /oem
I: Mounted: /gapps
I: Mounted: /storage
I: Mounted: /storage/emulated
I: Mounted: /storage/self
I: Reading contents of /proc/partitions
I: major minor #blocks name
I: 1 0 8192 ram0
I: 1 1 8192 ram1
I: 1 2 8192 ram2
I: 1 3 8192 ram3
I: 1 4 8192 ram4
I: 1 5 8192 ram5
I: 1 6 8192 ram6
I: 1 7 8192 ram7
I: 1 8 8192 ram8
I: 1 9 8192 ram9
I: 1 10 8192 ram10
I: 1 11 8192 ram11
I: 1 12 8192 ram12
I: 1 13 8192 ram13
I: 1 14 8192 ram14
I: 1 15 8192 ram15
I: 179 0 7761920 mmcblk0
I: 179 1 65536 mmcblk0p1
I: 179 2 1024 mmcblk0p2
I: 179 3 1024 mmcblk0p3
I: 179 4 32768 mmcblk0p4
I: 179 5 32768 mmcblk0p5
I: 179 6 524288 mmcblk0p6
I: 179 7 524288 mmcblk0p7
I: 179 8 64 mmcblk0p8
I: 179 9 64 mmcblk0p9
I: 179 10 1024 mmcblk0p10
I: 179 11 32768 mmcblk0p11
I: 179 12 32768 mmcblk0p12
I: 179 13 262144 mmcblk0p13
I: 179 14 262144 mmcblk0p14
I: 179 15 2683736 mmcblk0p15
I: 8 0 7847935 sda
I: 8 1 7845888 sda1
However, my thumb drive isn't apart of the list. So I'm guessing I need to mount it in some way. How can I mount the thumb drive and access the files on it?
ADB ONLY SOLUTION
Seem like as of now USB drives aren't mounted automatically. In order to make your code work I had to mount it manually.
As you can see (from /proc/partitions) in the /proc partition the USB drive is detected as sda.
ADB mounting
Make a directory to mount to
mkdir /mnt/usb
Mount the device
mount -t vfat -o rw /dev/block/sda1 /mnt/usb
Now you should be able to list (and manage) the files on the USB drive both via ADB and from within the app (/mnt/usb will also be logged).
I think the only solution is to create a service in init.rc to be able to execute the script with root permisions on Boot.
Apparently Android things doesnt have a solution right know.
Something like:
on property:dev.bootcomplete=1
start bootcomplete_handler
service bootcomplete_handler /system/bin/sh /system/bin/bc_handler.sh
class late_start
user root
group root
disabled
oneshot
But dont know if this will work
I have made an script that every 10 seconds if detects a usb storage units mounts it automatically, the only problem is to launch it on Boot, maybe this could help you, I have my post here:
Execute Script on Boot Android Things
And the script:
while true; do
if [ "$( ls -l /dev/block/sd* | wc -l)" -ge 1 ];
then echo "partition available"
if [ "$( mount | grep "usbAlv" -c)" -ge 1 ]; #if partition not mounted
then echo " Unit Mounted"
else
echo "not mounted"
//if folder where we mount the partition doesnt exist
if [ !"$( ls -l /sdcard/usbAlv | wc -l)" -ge 1 ];
then mkdir /sdcard/usbAlv
fi
su root << EOSU
mount -t vfat -o rw /dev/block/sd* /sdcard/usbAlv
EOSU
fi
else
echo "not partition available"
fi
sleep 10;
done
Hope it helps, i guess now is the only posible way to do it programatically
Working and discarded options
1. Use ADB (working)
As answerer by Onik in this post
2. Use USB API (working)
As Android API for USB allows bulkTransfer, you can code SCSI compatible commands.
You can also try existing libraries such as libaums, posted by Phaestion in response to this similar question
3. Inject shell commands at init.rc at boot.img (NOT working)
Shell commands can be injected to the init.rc file inside the boot.img (not the init.rc file that you can find in the /root directory). However, given the A-B boot nature of the AndroidThings compilation, I have been unable to make it work.
4. Add advanced app permissions (NOT working)
The following permissions seem promising to execute root commands from the app. However, permission denied error continues to block the root command execution.
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MANAGE_USB" tools:ignore="ProtectedPermissions" />
I even tried to compile an AndroidThings distribution with an app with such permissions but the Android Things console does NOT allow to include the app to the compilation
5. White list the app (NOT working)
There is a white list for priviledged apps. However, this white list is placed in a priviledged directory and cannot be overwritten even from the shell command with root user
6. Install the app at a priviledged location (NOT working)
Apps installed in priviledged directories can execute root commands. However, AndroidThings does NOT allow to install apps at such locations (even from the shell with root user)

Yocto fails to boot after adding package

I'm about to build a Linux-Yocto filesystem for Xilinx Zynq platform.
Everything runs fine until I added one more package to the rootfs.
It doesn't matter what kind of package I'm adding it always fails with:
INIT: version 2.88 booting
/etc/init.d/rcS: line 17: mount: command not found
/etc/init.d/rc: line 66: stty: command not found
/etc/rcS.d/S02banner.sh: line 11: /bin/mknod: No such file or directory
/etc/rcS.d/S02sysfs.sh: line 14: mount: command not found
/etc/rcS.d/S02sysfs.sh: line 17: grep: command not found
/etc/rcS.d/S06checkroot.sh: line 142: mount: command not found
/etc/rcS.d/S06checkroot.sh: line 145: ln: command not found
Starting Bootlog daemon: bootlogd: cannot find console device 249:0 under /dev
bootlogd.
/etc/rcS.d/S37populate-volatile.sh: line 12: dirname: command not found
/etc/rcS.d/S37populate-volatile.sh: line 13: sed: command not found
/etc/rcS.d/S37populate-volatile.sh: line 193: /proc/cmdline: No such file or directory
/etc/rcS.d/S38devpts.sh: line 13: grep: command not found
/etc/rcS.d/S38dmesg.sh: line 17: dmesg: command not found
/etc/rcS.d/S39hostname.sh: line 10: /bin/hostname: No such file or directory
/etc/rcS.d/S39hostname.sh: line 19: hostname: command not found
/etc/rcS.d/S55bootmisc.sh: line 64: date: command not found
/etc/rcS.d/S55bootmisc.sh: l
INIT: Entering runlevel: 5
/etc/init.d/rc: line 66: stty: command not found
Starting ntpd: /etc/rc5.d/S20ntpd: line 42: start-stop-daemon: command not found
done
Stopping Bootlog daemon: /etc/rc5.d/S99stop-bootlogd: line 62: start-stop-daemon: command not found
bootlogd.
And:
INIT: cannot execute "/sbin/getty"cannot execute "/sbin/getty"
INIT: Id "1" respawning too fast: disabled for 5 minutes
INIT: cannot execute "/sbin/getty"
INIT: Id "PS0" respawning too fast: disabled for 5 minutes
My local.conf:
MACHINE ?= "zedboard-zynq7"
DISTRO ?= "poky"
EXTRA_IMAGE_FEATURES = "debug-tweaks"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K"
PACKAGECONFIG_pn-qemu-native = "sdl"
PACKAGECONFIG_pn-nativesdk-qemu = "sdl"
ASSUME_PROVIDED += "libsdl-native"
CONF_VERSION = "1"
#AT-ubifs config
MKUBIFS_ARGS = "-m 2048 -e 126976 -c 1884"
#added by hob
PACKAGE_CLASSES = "package_rpm "
#added by hob
DL_DIR = "/home/jonas/Zynq_AT_Debug/Yocto/poky/build/downloads"
#added by hob
SSTATE_DIR = "/home/jonas/Zynq_AT_Debug/Yocto/poky/build/sstate-cache"
#added by hob
SSTATE_MIRRORS = ""
#added by hob
PARALLEL_MAKE = "-j 8"
#added by hob
BB_NUMBER_THREADS = "8"
#added by hob
INCOMPATIBLE_LICENSE = ""
#added by hob
SDKMACHINE = "x86_64"
#added by hob
http_proxy = ""
#added by hob
https_proxy = ""
#added by hob
ftp_proxy = ""
#added by hob
all_proxy = ""
#added by hob
CVS_PROXY_HOST = ""
#added by hob
CVS_PROXY_PORT = ""
#added by hob
IMAGE_EXTRA_SPACE = "0"
#added by hob
TOOLCHAIN_BUILD = "False"
#added by hob
IMAGE_FSTYPES = "ubifs cpio"
#added by hob
LINGUAS_INSTALL = ""
My Image recipe:
require /home/jonas/Zynq_AT_Debug/Yocto/poky/meta/recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL = "sysvinit-pidof \
update-alternatives-opkg shadow-securetty init-ifupdown \
initscripts-functions base-files update-rc.d \
run-postinsts openssh udev-cache zlib libcrypto \
util-linux-libblkid openssh-scp openssh-keygen \
mtd-utils-ubifs initscripts openssh-ssh \
udev-utils modutils-initscripts eglibc \
shadow netbase openssh-sshd udev base-passwd \
sysvinit mtd-utils openssl-conf libkmod lzo \
util-linux-libuuid libwrap sysvinit-inittab \
iperf nbench-byte ntp ntpdate nano"
DESCRIPTION = "***** Yocto-filesystem"
If I take out nano everything is fine.
I hope someone can help me.
To add more package into the rootfs,
in conf/local.conf add this line:
IMAGE_INSTALL_append = " nano"
The space in front is really important.
In addition, please show where you get your bsp and your conf/bblayers.conf
Edit:
Let's start from the beginning. Copy this, replace my local.conf to yours local.conf. With this minimal set up, you could at least bitbake core-image-minimal
Then, to add your packages into the image, just add them to IMAGE_INSTALL_append = " "
MACHINE ?= "zedboard-zynq7"
DISTRO ?= "poky"
EXTRA_IMAGE_FEATURES = "debug-tweaks ssh-server-openssh package-manager"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K"
PACKAGECONFIG_pn-qemu-native = "sdl"
PACKAGECONFIG_pn-nativesdk-qemu = "sdl"
ASSUME_PROVIDED += "libsdl-native"
CONF_VERSION = "1"
#AT-ubifs config
MKUBIFS_ARGS = "-m 2048 -e 126976 -c 1884"
PACKAGE_CLASSES = "package_rpm "
DL_DIR = "/home/jonas/Zynq_AT_Debug/Yocto/poky/build/downloads"
SSTATE_DIR = "/home/jonas/Zynq_AT_Debug/Yocto/poky/build/sstate-cache"
SSTATE_MIRRORS = ""
PARALLEL_MAKE = "-j ${#oe.utils.cpu_count()}"
BB_NUMBER_THREADS = "${#oe.utils.cpu_count()}"
SDKMACHINE = "x86_64"
IMAGE_FSTYPES = "ubifs cpio"
IMAGE_INSTALL_append = " nano smartpm openssh-sftp-server "

cgroups works well until reloading config (hangs on mount)

I am walking around this problem a long time - cgroups just don't want to work when reloading config file again(hangs on mount), have to reboot each time to changes take effect.
This are my steps:
(1.)Fresh start of OS.
(2.)cgsnapshot -s
# Configuration file generated by cgsnapshot
mount {
cpuset = /sys/fs/cgroup/cpuset;
cpu = /sys/fs/cgroup/cpu;
cpuacct = /sys/fs/cgroup/cpuacct;
memory = /sys/fs/cgroup/memory;
devices = /sys/fs/cgroup/devices;
freezer = /sys/fs/cgroup/freezer;
net_cls = /sys/fs/cgroup/net_cls;
blkio = /sys/fs/cgroup/blkio;
perf_event = /sys/fs/cgroup/perf_event;
}
(3.)cgclear(4.)cgsnapshot -s
# Configuration file generated by cgsnapshot
(5.)cgconfigparser -l /etc/cgconfig.conf (6.)cgsnapshot -s
mount {
cpu = /cgroup/cpu_mem_blkio;
cpuacct = /cgroup/cpu_mem_blkio;
memory = /cgroup/cpu_mem_blkio;
blkio = /cgroup/cpu_mem_blkio;
}
group hello1 {
...
group hello2 {
...
(7.)bash script /etc/rc.d/rc.cgred start
Now everything is working, but when i do this (the same config):
(8.)cgclear
(9.)cgconfigparser -l /etc/cgconfig.conf
It hangs forever, when i use strace it stops at:
mount("cgroup", "/cgroup/cpu_mem_blkio", "cgroup", 0,
"cpu,cpuacct,blkio,memory") = ? ERESTARTNOINTR (To be restarted)
Could someone point me whats wrong?
How i can i add new group, without rebooting?
Is this normal behavior of cgroups?
I even tried adding this patch from here:
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
<at> <at> -1909,7 +1909,7 <at> <at> static void cgroup_kill_sb(struct super_block *sb)
*
* And don't kill the default root.
*/
- if (css_has_online_children(&root->cgrp.self) ||
+ if (!list_empty(&root->cgrp.self.children) ||
root == &cgrp_dfl_root)
cgroup_put(&root->cgrp);
else
still testing, but looks the same.
Looks like the right way of doing it, is setting everything from the command line.
mount -t cgroup -o cpu,memory,blkio,cpuacct cpu_mem_blkio /cgroup/cpu_mem_blkio
mkdir /cgroup/cpu_mem_blkio/hello1
mkdir /cgroup/cpu_mem_blkio/hello2
echo 200 > /cgroup/cpu_mem_blkio/hello1/cpu.shares
echo 200M > /cgroup/cpu_mem_blkio/hello1/memory.limit_in_bytes
echo 400M > /cgroup/cpu_mem_blkio/hello1/memory.memsw.limit_in_bytes
echo 100 > /cgroup/cpu_mem_blkio/hello1/blkio.weight
...

Resources