How to add bootsector to CD using linux? - nasm

How do I write a bootsector to a cd using linux? I made the boot sector in nasm and I have compiled the binary. I have tried to use dd from linux and I tried partcopy but nothing is working, not even masteriso.

You want to use dd. Try this:
dd status=noxfer conv=notrunc bs=512 count=1 if=mybootloader.bin of=/dev/cddevice
Replace cddevice with your /dev entry for the CD, or with the name of a disk image file.

Related

Windows MBR Overritten by linux command dd if=/dev/zero of=/dev/sdb bs=512 count1

I know it's a stupid thing what I have done : In a Linux Virtual machine I did dd if=/dev/zero of=/dev/sdb bs=512 count1 to my external hard disk containing windows
Now I Cannot detect the external Hard drive in my windows machine.
I thing the MBR Partition is gone
What to do now ? any way to resotre my data on the external Hard disk ?
You should be able to fix this from Linux, using the boot-repair tool:
More information is on the link given, and is too long to include all here.

How to Configure a Shell Script to continue after Reboot

I am currently trying to install SAP servers on Linux and I've run into a bit of a situation. Script must follow below steps
Set swap size
Reboot server
Perform SAP installation.
So I have created the single script which will set the swap space & do the installation but not sure how I can add the reboot feature in it. I read some blogs which refers to use /etc/rc.local but it seems in this case I will have to create two scripts:
Script 1: It will set the value for swap space & then add the calling of second script in rc.local
Script 2: It will have syntax to perform SAP installation.
is there any way that I use single script to for complete setup??
You can use a swapfile, a reboot is not required:
# Create swapfile of 2G
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap /swapfile
swapon /swapfile
# Run SAP installation
# If you don't need the additional swap after the installation ...
swapoff /swapfile # Might take a while
rm /swapfile

How to use dd Linux command to download a file from the internet?

Ok, I know this might sound crazy but.
Let's say I am logged in and work on the virtual machine on the server through SSH. I have a link and I want to download a file (1 GB) with dd command.
So how to do that?
For me it has to be something like this
dd if="www.speed.hetzner.de/1GB.bin" of=~/dir bs=20
Please tell me, I was looking everywhere and can't find the answer.
If you actually want to use dd for the output processing (writing an ISO file to a block device for example), you can pipe curl into dd:
curl 'http://address.for/your.iso' | dd conv=noerror,sync bs=4M of=/dev/sdX
dd Does not support doing this over the network, you should download your file using curl or wget:
wget -O ~/dir/1GB.bin http://www.speed.hetzner.de/1GB.bin

kdump fails when /etc/kdump.conf points /dev/sdx and path /

I try to get vmcore editting /etc/kdump.conf on RHEL6.5 or CentOS.
/etc/fstab is set
/dev/sda7 /dump
ext4 /dev/sda7
path /
When I issue commands below, it does not emit vmcore at all.
echo 1 > /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger
Strange thing is, when I edit /etc/fstab,
UUID=XXXX-XXXX-XXXX-XXXX-XXXX /dump
System emits vmcore.
Why? and how can I get vmcore with the lines,
ext4 /dev/sda7
path /
Thank you very much.
When executing
# service kdump restart
kdump regenerates initrd.img.
I unpacked initrd.img and found that command "findfs" is related to this matter.
man findfs tells that only UUID or LABEL needs to be offerd as an argument.
So, the answer is, you can't use device-name in /etc/kdump.conf.
Thanks.

Simulate a faulty block device with read errors?

I'm looking for an easier way to test my application against faulty block devices that generate i/o read errors when certain blocks are read. Trying to use a physical hard drive with known bad blocks is a pain and I would like to find a software solution if one exists.
I did find the Linux Disk Failure Simulation Driver which allows creating an interface that can be configured to generate errors when certain ranges of blocks are read, but it is for the 2.4 Linux Kernel and hasn't been updated for 2.6.
What would be perfect would be an losetup and loop driver that also allowed you to configure it to return read errors when attempting to read from a given set of blocks.
It's not a loopback device you're looking for, but rather device-mapper.
Use dmsetup to create a device backed by the "error" target. It will show up in /dev/mapper/<name>.
Page 7 of the Device mapper presentation (PDF) has exactly what you're looking for:
dmsetup create bad_disk << EOF
0 8 linear /dev/sdb1 0
8 1 error
9 204791 linear /dev/sdb1 9
EOF
Or leave out the sdb1 parts to and put the "error" target as the device for blocks 0 - 8 (instead of sdb1) to make a pure error disk.
See also The Device Mapper appendix from "RHEL 5
Logical Volume Manager Administration".
There's also a flakey target - a combo of linear and error that sometimes succeeds. Also a delay to introduce intentional delays for testing.
It seems like Linux's built-in fault injection capabilities would be a good idea to use.
Blog: http://blog.wpkg.org/2007/11/08/using-fault-injection/
Reference: https://www.kernel.org/doc/Documentation/fault-injection/fault-injection.txt
The easiest way to play with block devices is using nbd.
Download the userland sources from git://github.com/yoe/nbd.git and modify nbd-server.c to fail at reading or writing on whichever areas you want it to fail on, or to fail in a controllably random pattern, or basically anything you want.
I would like to elaborate on Peter Cordes answer.
In bash, setup an image on a loopback device with ext4, then write a file to it named binary.bin.
imageName=faulty.img
mountDir=$(pwd)/mount
sudo umount $mountDir ## make sure nothing is mounted here
dd if=/dev/zero of=$imageName bs=1M count=10
mkfs.ext4 $imageName
loopdev=$(sudo losetup -P -f --show $imageName); echo $loopdev
mkdir $mountDir
sudo mount $loopdev $mountDir
sudo chown -R $USER:$USER mount
echo "2ed99f0039724cd194858869e9debac4" | xxd -r -p > $mountDir/binary.bin
sudo umount $mountDir
in python3 (since bash struggles to deal with binary data) search for the magic binary data in binary.bin
import binascii
with open("faulty.img", "rb") as fd:
s = fd.read()
search = binascii.unhexlify("2ed99f0039724cd194858869e9debac4")
beg=0
find = s.find(search, beg); beg = find+1; print(find)
start_sector = find//512; print(start_sector)
then back in bash mount the faulty block device
start_sector=## copy value from variable start_sector in python
next_sector=$(($start_sector+1))
size=$(($(wc -c $imageName|cut -d ' ' -f1)/512))
len=$(($size-$next_sector))
echo -e "0\t$start_sector\tlinear\t$loopdev\t0" > fault_config
echo -e "$start_sector\t1\terror" >> fault_config
echo -e "$next_sector\t$len\tlinear\t$loopdev\t$next_sector" >> fault_config
cat fault_config | sudo dmsetup create bad_drive
sudo mount /dev/mapper/bad_drive $mountDir
finally we can test the faulty block device by reading a file
cat $mountDir/binary.bin
which produces the error:
cat: /path/to/your/mount/binary.bin: Input/output error
clean up when you're done with testing
sudo umount $mountDir
sudo dmsetup remove bad_drive
sudo losetup -d $loopdev
rm fault_config $imageName

Resources