How do I use a dd-created image, that's bigger than the original disk? - raspberry-pi

I created a backup of flash card, using: dd bs=4M if=/dev/mmcblk0 of=backup.img
Now, trying to restore that back to the same card with Etcher, I'm told the image is bigger than the card, and I need 300+Mb of more space.
Should I be creating the image a different way? Is there a work-around to restoring the image? If it matters, I'm trying to maintain all of the needed partitions for a RaspberryPi. I'm new at this, so any guidance would be great (including if there's a more appropriate Exchange to ask).

Since my question was focused in particular on a RPi .img file, there is a utility, PiShrink https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
for this very task.

Related

Saving screenshot to CoreData

I'm developing an app that I want the user to be able to take a screenshot with a button (this works, but it's stored to camera roll). I have a need to keep history of these screenshots along with site name, etc.
I've been reading that it's not recommended to save binary data in a sqlite db, so I've stumbled across core data. I'm still learning, but one question that comes to mind is this. Some recommend to save the filename to coredata and then save the image to document directory. I want to read the data back into a table view controller and have the image part of the cell. Will I need to resize the image to the size I want when reading in, or will it automatically size down to what it needs?
Also, when saving to document directory, are those files accessible from the camera roll? I don't want them to be and I'd like to give the user the ability to be able to delete them with the tableviewcontroller.
Please let me know if I need to expand on anything. I'm learning Swift, so I'm sure I missed something.
You should not save it to the Documents directory.
You should instead Allow External Storage of the attribute. Core Data will take care of storing it for you. This is explained in the answer by jansenmaarten to this question.

How can I shrink an image of an SD card to fit a smaller card?

I've been slowly building a home automation framework (Python and SQL) on a Raspberry Pi. I'm really happy with it and am trying to deploy it on a few other Pi's around the house.
I've used win32diskimager to create a .img archive of the SD card and have (on a few occasions when I stuffed things up) been able to restore to the same card.
The problem is that (illustrative numbers only) my current "8GB" SD card is 7.88GB, but the new SD cards I've purchased are 7.86GB. The image is 7.88, so it refuses to write to the 7.86GB card (even though about half of that image is just blank space).
Can I resize my image? Tried using "truncate" in nix but (for some reason) vital data is stored at the end, or there's a checksum, because lopping off a few hundred mb was enough to corrupt the file and prevent mounting / writing.
Happy to take alternate solutions for SD card cloning too. I have access to OSX / Ubuntu / W8.1, but Windows is preferred because that's where I've got the img at the moment.
Appreciate any tips!
Sam
A bit late but I found a setup that works:
Run the SD card inside a raspberry and use
sudo apt-get install -y gparted
sudo gparted
To edit its partitions. Look for the main partition, unmount it and resize it to the desired size. I haven't confirmed whether it matters but I made sure the relevant data is "on the left" and the unallocated data on the right.
There's a more detailed guide on how to do this here:
https://learn.adafruit.com/resizing-raspberry-pi-boot-partition/edit-partitions
If you can't do this for whatever reason, an alternative is setting up a fresh SD card with a new installation of say Raspbian lite and removing the option to expand into remaining space of the SD card from cmdline.txt (in my case this was the last option in the list) BEFORE running the new installation in a Raspberry pi. Then you can set up the Pi the way you like inside a smaller partition.
Once you have shrunk the needed partitions you can easily make a small image:
In Windows, you can use Win32DiskImager to make the image, while making sure "Read Only Allocated Partitions" is checked, giving you an image that - surprise surprise - omitted the unallocated data.

QGIS - Composer

My question concerns the general purpose of the composer in qgis. My first idea was that with the composer you can "save" different layer combinations with different style to gain the possibility the have different "views" on the same data. However I realized when I change the map in QGIS, the information in the composer is also refreshed. To clarify my intent I want to give a small example:
Assume you have the gas stations of different companies for a country and you want to produce a map with all companies and maps containing only the gas stations of a certain company. So in the beginning I though I just create different composers to gain different maps but I somehow fail.
If I understand your question, you can use the composer as you wish.
When you have finished a composer, click on the map and, in the object properties, just check "lock layers for this map."
It should no longer be updated, even if you hide or display layers.
Regards.
Vincent
For large projects with a large number of composers, it's better to use layer presets and the "Follow visibility preset" option within the composer.
This is because when using "lock layers" and "lock layer styles", it saves all of the layers and their styles and properties. When it does this for each composer, it can quickly balloon the size of the QGIS file. This can make it take an extremely long time to open a project, cause a lot of performance issues, and inevitably will corrupt your QGIS file. Following a visibility preset simply references the style for the layer rather than duplicates it.
E.g. I had an employee whose QGIS file got corrupted and I had him send it and the backup files to me. On review, the primary QGIS file was empty, and the backup file was an exceptional 65mb. The markup behind the QGIS file was nearly a million lines long. It was corrupted because it got cut off, so I'm not even sure how long it might have been in it's entirety. This was a result of him having about 30 layers and over 100 composers that each had the layers locked. It also explained why he was the only one who was constantly complaining about his laptop being too slow for the work :)
in answer to your statement “My question concerns the general purpose of the composer in qgis”
For me and as In understand the purpose of the print composer in qgis is more to provide an output for GIS project in a cartographic format .and it is very Cleary detailed in the qgis documentation “The Print Composer provides growing layout and printing capabilities. It allows you to add elements such as the QGIS map canvas, text labels, images, legends, scale bars, basic shapes, arrows, attribute tables and HTML frames “(see the link bellow)
If you need more information about how to use it please visit this link
https://docs.qgis.org/2.2/en/docs/user_manual/print_composer/print_composer.html?highlight=qgis%20composer
Best Regard,

Can one develop a program that can see and access the edits one makes to a file?

I know about key loggers and root kits. I know it is possible for these programs to know what keys a user is pressing and what programs a user has open at any given time but, is it possible for a program (or background process) to know what commands (functions) with in a program are being executed?
e.g. A user is in Photoshop and does the following:
Opens the file called mountain.jpg
Crops 103 pixels off the top
Increases the Contrast by a value of 50
Saves the file as mountain-EDIT_1.jpg
Can a background process (daemon) understand that a user ran Photoshop's Open, Crop, Contrast and Save functions?
To be more specific, can a background process:
gain access to those unsaved edits like Crop and Contrast
take that data and save it else where
Also how does one locate where a program like Microsoft Word, Photoshop or ProTools is saving each of the edits a user makes?
The more close you would get to this functionality would be by using the photoshop's built-in scripts. I do not have enough knowledge to talk about this more, and I also doubt its the place to discuss this functionality.
On a more programming oriented point of view, you would need to look at memory photoshop is allocating for this image file and reverse-engineer photoshop's code to understand what happens on every edits you mentionned. I doubt its humanly possible.
If the user is saving the image after each edits though, you could watch for changes in the image, and try to look for the what you want to understand.
You may create a Photoshop plugin or script. But a generic software in such detail I don't think is possible.

Where to cache remote image files in iOS?

I am planning to cache the images from a server and use show it as a sort slide show in my App. I would be asynchronously loading the images.
I have two options:
Either to cache the images as a File and use it whenever necessary.
Cache the images objects in memory and use it when ever necessary and write it in to files when Application quits.
Which one would be better?
Please let me know if you you have any kind of suggestions regarding caching images.
Your second approach has 2 major flaws:
If there's too many images then your application will get low memory warning and you'll have to dispose your images from memory anyway
It's also not a good idea to save all images to file on application quit - it is not guaranteed that your saving code will finish on application exit (e.g. if it takes too long system may just terminate your app and your images will be lost)
I'd suggest saving images to files right after you download them and keep in memory reasonable number of images you need to show without visible delay (loading extra images when required and disposing of unnecessary ones)
I would recommend you the first option. Leaves you more flexibility, e.g. when the data size increases the memory size.
I'd do it like this: Have a NSMutableDictionary with the cached images (as UIImage objects). If the image is not in the cache, look whether it's available as a file. If it's not available as a file, load it, put it into your dictionary and also write it to a file.
As for where to write the files to: you can either use the NSTemporaryDirectory() or create a directory inside your NSLibraryDirectory (use NSSearchPathForDirectoriesInDomains to locate it). The later has the advantage/disadvantage that it will be in the iTunes backup (whether that's an advantage or not depends on the use case). Using the Library directory is Apple's recommended way of storing data that is backed up but does not appear in the iTune's file exchange thingy (Documents directory).
I have started using EGOImageView to handle my caching; it's very versatile and handles the intricacies of caching for you.
It works very well for pulling images via http, you can find it on the EGO developer website here
http://developers.enormego.com/
For image caching solution on iOS platform, you might want to consider SDWebImage framework available at: https://github.com/rs/SDWebImage. It is very easy to integrate and takes care of all your image caching worries.: read more about the working here: https://github.com/rs/SDWebImage#readme
We recently picked this up for our app and it works great.