clonezilla copy log-file(s) to usb-device - linux

i want to create/restore an image of a system completely unattended with an clonezilla-live usb-stick. So far the unattended backup/restore works fine. I just plug in the stick, boot up the pc and after the work is done the pc shut down.
Now i need an confirmation that the backup/restore was successfull.
For this purpose i want to execute an shell script which copy the log-file into an specific file to a other partition on the usb-stick after the work is done.
I tried to execute the script as postrun-method in the syslinux.cfg but this always led to an error.
Furthermore i tried it with drbl-ocs but i'm not sure if i did it right.
here is the shell script i want to execute:
#!/bin/sh
#############
/opt/drbl/sbin/ocs-sr -q2 -j2 -z1p -i 4096 -p true savedisk img sda
#############
dir=/home/partimag/logs/
time=$(date +"%H-%M-%S") # current time
i=$(ls -l $dir | wc -l) # index
# create log-directory if it didn't exist
if [ ! -e $dir ]
then
sudo mkdir $dir
fi
# create new log-directory (
sudo mkdir $dir/$i"_"#$time
# copy all log-files to the created directory
sudo cp /var/log/* $dir/$i"_"#$time
# shut-down the machine
sudo shutdown -h now
the first instruction (after the shebang) was my attempt to use the drbl-ocs but i have not really an idea what this is. I believe it's another interpreter which can handle shell scripts too.. Am i right ?
an here is the syslinux.cfg i use:
append initrd=/live/initrd.img boot=live username=user config quiet noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun="mount /dev/sdb2 /mnt/" ocs_prerun1="mount --bind /mnt/ /home/partimag/" ocs_live_run="/lib/live/mount/medium/syslinux/clonezilla.sh" ocs_live_extra_param="" ocs_live_batch="yes" vga=788 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
please help !
Thanks :)

ok got it :)
the only thing to do was to add the interpreter in front of the ocs_live_run method.
Now the syslinux.cfg looks like this:
append initrd=/live/initrd.img boot=live username=user config quiet noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun="mount /dev/sdb2 /mnt/" ocs_prerun1="mount --bind /mnt/ /home/partimag/" ocs_live_run="bash /lib/live/mount/medium/syslinux/clonezilla.sh" ocs_live_extra_param="" ocs_live_batch="yes" vga=788 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1
please rate if this was usefull for you :)

Related

Clonezilla script fails: Unable to find target hard drive

I have saved a disk to an image.
I can restore this image to a new drive when I use the manual approach where Clonezilla asks all these questions.
I answer them using the Beginner Mode.
I don't change anything or do anything fancy.
Now I am trying to automatically deploy this image using a script:
#
set prefix=/boot/grub/
set default="0"
set timeout="5"
set hidden_timeout_quiet=false
if loadfont $prefix/unicode.pf2; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
fi
if background_image $prefix/logo-jpik.png; then
set color_normal=black/black
set color_highlight=red/black
else
set color_normal=cyan/blue
set color_highlight=white/blue
fi
menuentry "Apply Software Image from Pendrive"{
search --set -f /live/vmlinuz
linux /live/vmlinuz boot=live union=overlay username=user hostname=JPSC config components quiet noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=pt vga=791 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 ocs_live_batch="no" ocs_prerun="ln -s /lib/live/mount/medium/Image/ /home/partimag/" ocs_live_run="ocs-sr -e1 auto -e2 -batch -r -j2 -scr -p poweroff restoredisk Image/ mmcblk0" ocs_live_extra_param=""
echo "Loading Clonezilla..."
initrd /live/initrd.img
}
Using this script, I get the follow error:
"Unable to find target hard drive"
Does anybody know why and can tell me what I need to change?
Thank you!
Here is what my image files look like:
I got it:
I needed to edit \boot\grub\grub.cfg from this version...
linux /live/vmlinuz boot=live union=overlay username=user hostname=JPSC config components quiet noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=pt vga=791 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 ocs_live_batch="no" ocs_prerun="ln -s /lib/live/mount/medium/Image/ /home/partimag/" ocs_live_run="ocs-sr -e1 auto -e2 -batch -r -j2 -scr -p poweroff restoredisk Image/ mmcblk0" ocs_live_extra_param=""
... to this:
linux /live/vmlinuz boot=live union=overlay username=user hostname=JPSC config components quiet noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=pt vga=791 ip= nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 ocs_live_batch="no" ocs_prerun="ln -s /lib/live/mount/medium/Image/ /home/partimag/" ocs_live_run="ocs-sr -e1 auto -e2 -batch -r -j2 -scr -p poweroff restoredisk Image/ nvme0n1" ocs_live_extra_param=""

How to change permission of vmware's shared folder

I'm using ubuntu 16.04 on vmware player. The shared folder is enabled and is visible on /mnt/fghs. But, the owner(root) can't be changed by chown. How to change it? Please, advice me.
Additionally, some person said the owner could be changed after modifying /etc/fstab. But, I couldn't find any information in /etc/fstab like .host :/ /mnt/hgfs vmhgfs defaults 0 0. When I add the line into /etc/fstab file, wmware can't be start up.
probably a little bit late, but anyway.
Firstly, unmount your shared folder:
sudo umount /mnt/hgfs
then run:
vmhgfs-fuse .host:/ /mnt/hgfs -o uid=1000 -o gid=1000 -o umask=0033
where you should consider change uid and gid to yours. Remember that:
id -u
id -g
will return your current user and group ID.
Take a look to vmhgfs-fuse --help for more options ;)
Resolved. Use allow_other option to grant access.
vmhgfs-fuse -o allow_other .host:/ /mnt/hgfs
see unix.stackexchange.com: vmhgfs-fuse-permission-denied-issue
You can try those steps
sudo su
touch /bin/remount_hgfs
chmod a+x /bin/remount_hgfs
echo '#!/bin/sh -e' >> /bin/remount_hgfs
echo 'umount /mnt/hgfs' >> /bin/remount_hgfs
echo 'mount /mnt/hgfs' >> /bin/remount_hgfs
echo '.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0' >> /etc/fstab
line=`wc -l /etc/rc.local | cut -f1 -d' '`; sed -i "${line}ish /bin/remount_hgfs" /etc/rc.local
reboot

How to use chroot in a Makefile?

I am building my own Debian-based Linux with own kernel and software. One of the last steps of the make-process has to be done in a chrooted environment:
Install the custom kernel using dpkg
Create symbolic links to the kernel and initrd.img
Execute ldconfig
Set my custom theme for the splash screen using plymouth
Update the initrd.img
While the installation of the kernel succeeds and the symbolic links are acutally created, all other commands do not seem to work. If I boot into the system the splash screen is set to the default and the initrd.img cannot find the HDD nor the kernel. So the updating of the initrd.img inside the dpkg-installation process seems to fail somehow. The plymouth script to set the theme does not work either.
To fix this, I manually chroot into the system and do the following:
Set my custom theme for the splash screen using plymouth
Execute ldconfig
Update the initrd.img
This works perfectly fine. Next time I boot the system, my splash screen is shown and everything starts properly.
Here is my approach to get this done in my Makefile:
cp $(INTEGRATION_KERNEL_IMAGE) $(ROOTFS)/tmp/kernel.deb
cd $(ROOTFS); /usr/bin/sudo /bin/mount -t proc proc proc/; /usr/bin/sudo /bin/mount -t sysfs sys sys/; /usr/bin/sudo /bin/mount -o bind /dev dev/
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/usr/bin/dpkg --force-not-root -i /tmp/kernel.deb"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/ln -nsf vmlinuz-3.2.54-rt75custom /boot/vmlinuz"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/ln -nsf initrd.img-3.2.54-rt75custom /boot/initrd.img"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/sbin/ldconfig"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/bash /usr/sbin/plymouth-set-default-theme my_theme"
/usr/sbin/chroot --userspec=0:0 $(ROOTFS) /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin HOME=/root bash -c "/bin/bash /usr/sbin/update-initramfs -u"
/usr/bin/sudo /bin/umount $(ROOTFS)/proc; /usr/bin/sudo /bin/umount $(ROOTFS)/sys; /usr/bin/sudo /bin/umount $(ROOTFS)/dev
The output of make does not provide any errors on this topic. Well, it possibly cannot do this because make does not know what is going on inside the chrooted environment. But how can I find out what is going wrong?
A possible workaround would be to put everything I mentioned above in a shell script and execute this in the chrooted environment. But I would prefer to do everything in the Makefile and I do not know if the workaround really works. I have not verified this yet.
Have you tried saving command output in the chroot environment and extracting it later? For example:
/usr/sbin/chroot [...] bash -c "/usr/bin/dpkg [...] >> /root/chroot.log"
or
/usr/sbin/chroot [...] bash -c "/usr/bin/dpkg [...] | tee -a /root/chroot.log"
followed by
cp $(ROOTFS)/root/chroot.log .
In the long run I would suggest to avoid code duplication and Makefile clutter, either by passing everything in a single chroot command or by copying over a script.
You should be able to get rid of most or all of the bash -c and /bin/bash invocations. That should simplify things even more.

Beaglebone inittab issue

I am developing an application in beaglebone.
I want to add start up scripts to my Beaglebone but I can not find /etc/inittab.
I am using the image : Angstrom-Cloud9-IDE-GNOME-eglibc-ipk-v2012.05-beaglebone-2012.06.18.img.xz
I think in the previous versions of image there is /etc/initab but for the new distributions I could not find the inittab :/
I want to apply this : Automatic login on Angstrom Linux
but I can not because there is no /etc/inittab.
Where is the inittab in new distributions.
When I write uname -r it gives:
3.2.23
Regards
inittab has been replaced by systemd
This is how I did it for the serial console. You can probably adapt it easily for tty1 by replacing "serial-getty#..." by "getty#...", but I haven't tested it.
cp /lib/systemd/system/serial-getty#.service /etc/systemd/system/autologin#.service
rm /etc/systemd/system/getty.target.wants/serial-getty#ttyO0.service
ln -s /etc/systemd/system/autologin#.service /etc/systemd/system/getty.target.wants/serial-getty#ttyO0.service
Create the following script file in any location (/home/root/autologin.sh in my case)
#!/bin/sh
exec /bin/login -f root
Make it executable
chmod a+x autologin.sh
Edit /etc/systemd/system/autologin#.service and update the ExecStart command by adding the -n (Do not prompt the user for a login name) and -l (Invoke the specified login_program instead of /bin/login) options.
ExecStart=-/sbin/agetty -n -l /home/root/autologin.sh -s %I 115200

Mount /var on ramdisk at boot - Bash Script Issue

I have an embedded device where i need to put my /var and /tmp in ram in order to diminish the number of writes on the drive (Compact flash). I know how to do it with /tmp as i don't have to recover anything whenever i reboot or shutdown.
But the /var directory has important stuff. I have been researching and i found this, but it doesn't seem to be working.
Here is the script:
# insert this on file 'rc.sys.init'
# after the mount of the root file system
# to create the /var on ramdisk
echo "Create ramdisk........."
#dd if=/dev/zero of=/dev/ram0 bs=1k count=16384
mkfs.ext2 -j -m 0 -q -L ramdisk /dev/ram0
if [ ! -d /mnt/ramdisk ]; then
mkdir -p /mnt/ramdisk
fi
mount /dev/ram0 /mnt/ramdisk
if [ -L /var ]; then
tar -xf /vartmp.tar -C /mnt/ramdisk
else
tar -C / -cf /vartmp.tar var
cp -a /var /mnt/ramdisk
rm -rf /var
ln -s /mnt/ramdisk/var /var
fi
# insert this into file 'halt'
# to stop the ram disk properly on shutdown.
#
if [ -e /vartmp.tar ]; then
rm -f /vartmp.tar
fi;
tar -C /mnt/ramdisk -cf /vartmp.tar var
Is there any problem with this script? If not, in which inicialization and termination script should i include them?
For all that have the same problem i do i have solved my problem (kind of)
The two scripts i posted are correct and accomplish the job. What you have to be careful is where you put them.
In Slackware the first run script is rc.S. At first i copy pasted my first script into the middle of that one. It definitely should be there, just not where i put it. You have to see where does the script rc.S call for a particular directory or file from /var. The creation of the ramdisk should be before those lines.
the shutdown script should be added in the bottom of the rc.6 script (shutdown script)
Also i should point out that although this improves the life expectancy of the drive, it is a little volatile and sometimes randomly reboots, so be careful.
Nice script...but it seems to me that it is volatile for several reasons. First did you tell the system max ramdisk size...first as a kernel argument.....linux /vmlinuz ramdisk_size=204800......then in rc mke2fs -t ext2 /dev/ram1 204800.....and maybe use ram1 not ram0.......also use a script for manual saving of ramdisk contents to /var.....cp -a /mnt/ramdisk/var/. /var........backup real /var to another directoryusin tar compression, but introducing tar compression to reduce data size probably introduces lag, latency and instability. Just seems to me to be so.

Resources