Is it possible to fully copy an SD card (including the MBR)? - copy

I have an SD card that I use in my Raspberry pi configuration, and I recently purchased a bigger card.
I'd like to avoid to re-install the os (OpenElec) and to transfert all the files already present (almost 60Gb), but to do something like dd from the sdcard to my local disk, then do an other dd from my local disk to the new sdcard and that's it.
Is it possible?
Plot twist, I'm on MacOS (but I believe that for that kind of work, it's quite similar to Linux, I'm not afraid of command line).
Thank you for your help.

To find the drives, their partitions and device special file names on a Mac, you would run this in the Terminal:
diskutil list
Sample Output
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *3.0 TB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_CoreStorage Macintosh HD 3.0 TB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *121.3 GB disk1
1: EFI EFI 209.7 MB disk1s1
2: Apple_CoreStorage Macintosh HD 121.0 GB disk1s2
3: Apple_Boot Boot OS X 134.2 MB disk1s3
/dev/disk2 (internal, virtual):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_HFS Macintosh HD +3.1 TB disk2
Logical Volume on disk1s2, disk0s2
EF247607-3049-4EF0-8DFB-35B7ED84B7C0
Unencrypted Fusion Drive
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *12.0 TB disk4
1: EFI EFI 209.7 MB disk4s1
2: Apple_HFS SystemClone 3.0 TB disk4s2
3: Apple_Boot Recovery HD 650.0 MB disk4s3
4: Apple_HFS OldMachine 550.0 GB disk4s4
5: Apple_HFS Spare 1000.0 GB disk4s5
6: Apple_CoreStorage TimeMachine 7.4 TB disk4s6
7: Apple_Boot Boot OS X 134.2 MB disk4s7
8: Apple_HFS Untitled 251.5 MB disk4s8
/dev/disk5 (external, virtual):
#: TYPE NAME SIZE IDENTIFIER
0: Apple_HFS TimeMachine +7.4 TB disk5
Logical Volume TimeMachine on disk4s6
C7E53345-5059-45D8-826C-B10B6F16AD20
Locked Encrypted
Then very carefully select which ones have the right size and filesystem to match your SD card for input from and output to. Then use the entire disk name (rather than any slices which end in sN like /dev/disk5s2 ) to get the MBR:
sudo dd if=/dev/disk5000 of=/dev/disk5001 bs=65536
The <disk5000> above is a placeholder for the real name as I do not want to trash anyone's disk who is daft enough to copy/paste my example without checking it matches their system.

Related

Gem5 in full system running spec2006 runs out of memory

What I am trying to do is run a spec2006 benchmark (namely the 410.bwaves one) in full system mode.
I have made a .rcS script to pass to the fs.py script and the command I type to start the simulation is as follows:
build/X86/gem5.opt configs/example/fs.py --script="../run_bwaves.rcS" --disk-image=ubuntu-14.04.img --kernel=x86_64-vmlinux-2.6.22.9
The result after some time is:
Free swap: 0kB
131072 pages of RAM
3650 reserved pages
18 pages shared
0 pages swap cached
Out of memory: kill process 807 (bwaves) score 13154 or a child
Killed process 807 (bwaves)
/tmp/script: line 39: 807 Killed ./bwaves
Full linux output here
Gem5 output here
I am guessing it has something to do with this line: warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
but I am not sure.
I have tried adding a --mem-size=... flag but it brakes the simulation with a Memory size not divisible by page size error.
If anyone could help me I would be glad.
Edit: As suggested by comment, I used a large enough --mem-size flag divisible by the page size. The error now has turned into
bwaves[807]: segfault at 00007ffee647624c rip 0000000000410eb5 rsp 00007fff664761c0 error 4
/tmp/script: line 39: 807 Segmentation fault ./bwaves

How does Qemu locate its image file or How does Eclipse interact with Qemu?

for studying Qemu I got the 'QEMU Eclipse' plugin, built the 'blinky' project from https://gnu-mcu-eclipse.github.io/tutorials/blinky-arm/ and when I let it run, it produces the following output:
xPack 64-bit QEMU v2.8.0-9 (qemu-system-gnuarmeclipse).
Board: 'STM32F4-Discovery' (ST Discovery kit for STM32F407/417 lines).
Board picture: '/home/hgiese/Work/qemu-arm-dev/linux-x64/install/qemu-arm/share/qemu/graphics/STM32F4-Discovery.jpg'.
Device file: '/home/hgiese/Work/qemu-arm-dev/linux-x64/install/qemu-arm/share/qemu/devices/STM32F40x-qemu.json'.
Device: 'STM32F407VG' (Cortex-M4 r0p0, MPU, 4 NVIC prio bits, 82 IRQs), Flash: 1024 kB, RAM: 128 kB.
Command line: 'blinky' (6 bytes).
...
and when I let it run everything was fine.
Now, when I called Qemu directly (outside of Eclipse) with the exact command line the output was this:
xPack 64-bit QEMU v2.8.0-9 (qemu-system-gnuarmeclipse).
Board: 'STM32F4-Discovery' (ST Discovery kit for STM32F407/417 lines).
Board picture: '/home/hgiese/Work/qemu-arm-dev/linux-x64/install/qemu-arm/share/qemu/graphics/STM32F4-Discovery.jpg'.
Device file: '/home/hgiese/Work/qemu-arm-dev/linux-x64/install/qemu-arm/share/qemu/devices/STM32F40x-qemu.json'.
Device: 'STM32F407VG' (Cortex-M4 r0p0, MPU, 4 NVIC prio bits, 82 IRQs), Flash: 1024 kB, RAM: 128 kB.
Command line: 'blinky' (6 bytes).
qemu-system-gnuarmeclipse: Guest image must be specified (using --image)
no matter how I specified 'blinky':
being in the Debug directory
calling it as blinky.elf
calling it with its complete path
It got even stranger: In an attempt to produce an error message from Qemu (which might tell me something) I replaced 'blinky' with 'xyz' (in the command line field of the 'Debugger' pane in the 'Debug Configuration' dialog) - and it still worked. The only difference being the line
Command line: 'xyz' (3 bytes).
in Qemu's output, which showed me that Qemu had received this dummy parameter - and it didn't make the slightest difference for it: it still had the correct image file.
How do I have to communicate the image file to Qemu (or 'How does Eclipse does its magic?')
Any insight will be greatly appreciated.
Helmut

*Excruciatingly* slow (over ten seconds for `(+ 1 1)`) with language "How To Design Programs - Beginning Student"

I just installed DrRacket, and tried out the language "How To Design Programs - Beginning Student".
Racket - A programmable programming language
Racket - Getting Started
I run (+ 1 1), and it takes over ten seconds for this to show up:
Welcome to DrRacket, version 6.5 [3m].
Language: Beginning Student; memory limit: 128 MB.
2
>
As far as I can tell, my installation is pretty much "out of the box".
What I'm wondering is if my experience is unusual,
and if there's any obvious way to troubleshoot it if so
(I've looked around the settings and didn't find anything obvious to tweak),
or if maybe the whole HTDP language was quietly abandoned or something...?
EDIT 1
I have these files:
/usr/share/racket $
find -iname "*htdp*.zo"
./pkgs/htdp-lib/lang/private/compiled/create-htdp-executable_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-reader_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-beginner-abbr-reader_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-langs-save-file-prefix_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-advanced-reader_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-intermediate-lambda-reader_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-advanced_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-beginner-abbr_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-intermediate_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-intermediate-reader_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-langs_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-beginner_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-intermediate-lambda_rkt.zo
./pkgs/htdp-lib/lang/compiled/htdp-beginner-reader_rkt.zo
./pkgs/htdp-doc/scribblings/htdp-langs/compiled/htdp-langs_scrbl.zo
./pkgs/htdp-doc/scribblings/htdp-langs/compiled/htdp-ptr_scrbl.zo
./pkgs/htdp-doc/htdp/compiled/htdp_scrbl.zo
./pkgs/htdp-doc/htdp/compiled/htdp-lib_scrbl.zo
./pkgs/htdp-doc/teachpack/htdp/scribblings/compiled/htdp_scrbl.zo
./pkgs/htdp-doc/teachpack/2htdp/scribblings/compiled/2htdp_scrbl.zo
EDIT 2 - cpu and harddrive specs
CPU
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU N450 # 1.66GHz
stepping : 10
microcode : 0x107
cpu MHz : 1000.000
cache size : 512 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts nopl aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bugs :
bogomips : 3325.00
clflush size : 64
cache_alignment : 64
address sizes : 32 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 28
model name : Intel(R) Atom(TM) CPU N450 # 1.66GHz
stepping : 10
microcode : 0x107
cpu MHz : 1000.000
cache size : 512 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 1
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts nopl aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm movbe lahf_lm dtherm
bugs :
bogomips : 3325.00
clflush size : 64
cache_alignment : 64
address sizes : 32 bits physical, 48 bits virtual
power management:
HD
$ sudo hdparm -I /dev/sda
/dev/sda:
ATA device, with non-removable media
Model Number: Hitachi HTS545016B9A300
Serial Number: 100324PBPB06ECC0K6XL
Firmware Revision: PBBOC60F
Transport: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6; Revision: ATA8-AST T13 Project D1697 Revision 0b
Standards:
Used: unknown (minor revision code 0x0028)
Supported: 8 7 6 5
Likely used: 8
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
--
CHS current addressable sectors: 16514064
LBA user addressable sectors: 268435455
LBA48 user addressable sectors: 312581808
Logical/Physical Sector size: 512 bytes
device size with M = 1024*1024: 152627 MBytes
device size with M = 1000*1000: 160041 MBytes (160 GB)
cache/buffer size = 7208 KBytes (type=DualPortCache)
Form Factor: 2.5 inch
Nominal Media Rotation Rate: 5400
Capabilities:
LBA, IORDY(can be disabled)
Queue depth: 32
Standby timer values: spec'd by Vendor, no device specific minimum
R/W multiple sector transfer: Max = 16 Current = 16
Advanced power management level: 254
Recommended acoustic management value: 128, current value: 254
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=120ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
* SMART feature set
Security Mode feature set
* Power Management feature set
* Write cache
* Look-ahead
* Host Protected Area feature set
* WRITE_BUFFER command
* READ_BUFFER command
* NOP cmd
* DOWNLOAD_MICROCODE
* Advanced Power Management feature set
Power-Up In Standby feature set
* SET_FEATURES required to spinup after power up
SET_MAX security extension
Automatic Acoustic Management feature set
* 48-bit Address feature set
* Device Configuration Overlay feature set
* Mandatory FLUSH_CACHE
* FLUSH_CACHE_EXT
* SMART error logging
* SMART self-test
* General Purpose Logging feature set
* WRITE_{DMA|MULTIPLE}_FUA_EXT
* 64-bit World wide name
* IDLE_IMMEDIATE with UNLOAD
* WRITE_UNCORRECTABLE_EXT command
* {READ,WRITE}_DMA_EXT_GPL commands
* Segmented DOWNLOAD_MICROCODE
* Gen1 signaling speed (1.5Gb/s)
* Gen2 signaling speed (3.0Gb/s)
* Native Command Queueing (NCQ)
* Host-initiated interface power management
* Phy event counters
* NCQ priority information
Non-Zero buffer offsets in DMA Setup FIS
* DMA Setup Auto-Activate optimization
Device-initiated interface power management
In-order data delivery
* Software settings preservation
* SMART Command Transport (SCT) feature set
* SCT Write Same (AC2)
* SCT Error Recovery Control (AC3)
* SCT Features Control (AC4)
* SCT Data Tables (AC5)
Security:
Master password revision code = 65534
supported
not enabled
not locked
frozen
not expired: security count
supported: enhanced erase
64min for SECURITY ERASE UNIT. 66min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 5000cca5ffc040a7
NAA : 5
IEEE OUI : 000cca
Unique ID : 5ffc040a7
Checksum: correct
EDIT 3 command-line times
ran (+ 1 1) in HTDP-beginner 3 times -- Over 5 seconds.
$ time racket -t racket_HTDP_beginner.rkt
2
5.60user 1.04system 0:08.46elapsed 78%CPU (0avgtext+0avgdata 127968maxresident)k
5496inputs+0outputs (46major+40955minor)pagefaults 0swaps
$ time racket -t racket_HTDP_beginner.rkt
2
5.51user 0.67system 0:06.71elapsed 92%CPU (0avgtext+0avgdata 128124maxresident)k
24inputs+0outputs (0major+41790minor)pagefaults 0swaps
$ time racket -t racket_HTDP_beginner.rkt
2
5.41user 0.67system 0:06.55elapsed 92%CPU (0avgtext+0avgdata 128180maxresident)k
0inputs+0outputs (0major+36683minor)pagefaults 0swaps
ran (+ 1 1) in #lang racket 3 times -- A bit over 2 seconds.
$ time racket -t racket_lang_racket.rkt
2
2.13user 0.25system 0:02.71elapsed 87%CPU (0avgtext+0avgdata 64996maxresident)k
0inputs+0outputs (0major+12437minor)pagefaults 0swaps
$ time racket -t racket_lang_racket.rkt
2
2.15user 0.25system 0:02.63elapsed 91%CPU (0avgtext+0avgdata 61700maxresident)k
0inputs+0outputs (0major+15853minor)pagefaults 0swaps
$ time racket -t racket_lang_racket.rkt
2
2.28user 0.29system 0:02.89elapsed 89%CPU (0avgtext+0avgdata 61500maxresident)k
0inputs+0outputs (0major+15015minor)pagefaults 0swaps
EDIT 4
Running free -h every second while DrRacket is running (+ 1 1) in lang HTDP-beginner
(not running any other applications besides DrRacket and my basic system (ie window manager etc))
(this is fish shell, by the way):
http://pastebin.com/2RdZAuXj
At that point I had to kill DrRacket cuz everything was freezing up.
Anyway, yeah, it's leaking, obviously.
Everytime I re-ran the code in DrRacket, memory usage went up and stayed up.
I had only run it about twenty...two-ish (?) more times
(so maybe thirty-ish in total?)
by the point where it started getting near the limit
and I killed it to unfreeze the system.
I guess I should try this with normal #lang racket and see what happens...
EDIT 5
Yup, it leaks the same way:
http://pastebin.com/373PNnY7
I am 90% sure that the reason you had to wait was that your installation of Racket wasn't done properly.
During installation the program setup-plt needs to be run. It precompiles all racket files (.rkt) into so-called zo-files. If this step is omitted, then
DrRacket do the compilation for you the first time a file is needed.
In your case (I am guessing) it it your first time using the Beginner language, so all files relating to it needs to be compiled. And that takes a while.
The best solution is to use the official installers from http://download.racket-lang.org/ they all include precompiled zo-files.
If you happen to have used such an installer, then try again - and if the problem persist - do file a bug report (use the bug report in the Help menu in DrRacket).

Mongodb build/compile error: not enough memory on Ubuntu

Preface so this isn't marked as a duplicate: I've seen lots of mongodb memory issues posted on stack overflow, but none that have to do with errors on the compilation.
I just freshly downloaded and ran Ubuntu on Virtualbox (on a mac), so I feel like there should be enough memory. However, when I try to compile Mongodb from the source code I've gotten the following errors about an hour into the compilation (I have done this a few times now)
scons: *** [<whatever file it was working on>] No space left on device
scons: building terminated because of errors
and on a separate occasion
IOError: [Errno 28] No space left on device:
File "/usr/lib/scons/SCons/Script/Main.py", line 1359:
_exec_main(parser, values)
File "/usr/lib/scons/SCons/Script/Main.py", line 1323:
_main(parser)
File "/usr/lib/scons/SCons/Script/Main.py", line 1072:
nodes = _build_targets(fs, options, targets, target_top)
File "/usr/lib/scons/SCons/Script/Main.py", line 1281:
jobs.run(postfunc = jobs_postfunc)
File "/usr/lib/scons/SCons/Job.py", line 113:
postfunc()
File "/usr/lib/scons/SCons/Script/Main.py", line 1278:
SCons.SConsign.write()
File "/usr/lib/scons/SCons/SConsign.py", line 109:
syncmethod()
File "/usr/lib/scons/SCons/dblite.py", line 117:
self._pickle_dump(self._dict, f, 1)
Exception IOError: (28, 'No space left on device') in <bound method dblite.__del__ of <SCons.dblite.dblite object at 0x7fbe2a577dd0>> ignored
I've tried both of the following build commands:
scons all --dbg=on -j1
scons --dbg=on -j1
According to VirtualBox the virtual size is 8 GB and the Actual size is 4.09 GB. Also, if it makes the difference, the odds that the memory on my mac is actually full is slim to none.
Any help would be greatly appreciated, thanks in advance.
EDIT: I've tried creating more memory (24 GB) and resizing partitions but I still cannot complete a build.
Here is the output of the df -T command:
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext4 15345648 14304904 238184 99% /
none tmpfs 4 0 4 0% /sys/fs/cgroup
udev devtmpfs 1014316 12 1014304 1% /dev
tmpfs tempfs 205012 860 204152 1% /run
none tempfs 5120 0 5120 0% /run/lock
none tempfs 1025052 152 1024900 1% /run/shm
none tempfs 102400 40 102360 1% /run/user
When you say memory, I believe you mean disk space. Try running the command
df -T to see what % usage you really have. You will probably need to resize the amount of space virtualbox has assigned to your image, as well as resize your repartition. It may be simpler to just create a new virtualbox image with 16 or 24GB of disk space.
If you decide to go the resize partition route, here is a helpful resource: https://askubuntu.com/questions/126153/how-to-resize-partitions

Cloning a Bootable SD Card from Linux Using dd command

I have a Raspberry Pi with the default, store-bought operating systems on it. I want to wipe the SD card clean so that I can put in a new operating system, but I want to preserve the original OS in a backup disc image. I planned to store it in a .bin file. The SD card has two partitions.
I used the following command to figure out which drive is the SD card.
sudo dmesg | tail
--output--
[ 2954.642182] sd 3:0:0:0: [sdb] Attached SCSI removable disk _
[ 2955.149750] EXT4-fs (sdb2): mounted filesystem with ordered data mode. Opts: (null)
I believe this tells me that it is under dev/sdb2, but I also tried dev/sdb, ~/dev/sdb and ~/dev/sdb2. I used the following command to create the image:
dd if="dev/sdb2" of="~/Desktop/Pi Backup/Pi.bin"
But when I try to do this it returns the error message
dd: opening `dev/sdb2': No such file or directory
I'm running Linux Mint, Cinnamon.
Any help is appreciated.
Instead of doing:
sudo dd if="/dev/mmcblk0p1" of="Pi_1.bin"
sudo dd if="/dev/mmcblk0p2" of="Pi_2.bin"
try:
sudo dd if="/dev/mmcblk0" of="Pi.bin"
p1 and p2 are the partitions in that device and you want to make an image of the entire device.
All devices are under /dev
dev is looking for dev under the current directory and ~/dev is looking for dev under your home directory.
/dev/sdb2 if the second partition, I would expect use have /dev/sdb1 (the first partition) too.
sudo dmesg | tail -30
will give you the last 30 lines, then you should be able to see the sdb1 too.
I'm on Mint 14 and I did mount and the SDcard shows as 2 partitions like below
/dev/mmcblk0p1 on /media/nig/3312-932F type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)
/dev/mmcblk0p2 on /media/nig/b7b5ddff-ddb4-48dd-84d2-dd47bf00564a type ext4 (rw,nosuid,nodev,uhelper=udisks2)
so I then did
sudo dd if="/dev/mmcblk0p1" of="Pi_1.bin"
sudo dd if="/dev/mmcblk0p2" of="Pi_2.bin"
seemed to work, not sure about restoring, not tried that yet