EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: Ed.Kloonk on October 27, 2022, 11:34:30 am

Title: Partial restore from ddrescue image to SSD
Post by: Ed.Kloonk on October 27, 2022, 11:34:30 am
Work laptop went wonky with rolling release update. Everything's fine. Don't panic. I had brought a towel.

I've got a full disk image (120gb, uncompressed) saved a few months ago for this kind of issue but was really saved in case of SDD failure.

In an attempt to roll back the system to discover how it went wayward, I'm trying to elegantly restore blocks of data that have been changed without blasting the whole 120gb SSD. If it were a magnetic drive, I'd just go dd..

Not worried too much about trampling the target drive data since laptop is not required for service currently. This is just an experiment.

Yes, I -could- mount the image and extract data from the FSs within. Not what I want.

Would like to explore some of the best ways to roll back the drive, with an emphasis on having as minimal SSD drive-wear as possible when blasting at the low level. Call me crazy.

How would you go about it?
Title: Re: Partial restore from ddrescue image to SSD
Post by: alm on October 27, 2022, 11:58:49 am
I wouldn't bother and just overwrite the SSD. But if given the challenge, I'd make an image of the target SSD, then generate a binary patch from the image of the target SSD to the source image using a tool like xdelta, and apply this patch to the SSD. I have no idea how this performs with a 120 GB image or patching a block device instead of a regular file, but it seems the simplest solution to me.

Second option would be doing a comparison using cmp to give all the different blocks, and have a script write just those blocks using dd.
Title: Re: Partial restore from ddrescue image to SSD
Post by: RoGeorge on October 27, 2022, 12:02:31 pm
No idea what OS you might have, what file system, or what errors do you see after upgrade.  :-//
My crystal globe is broken, and the Eye of Sauron is in maintenance shutdown until Halloween.  :-\
Title: Re: Partial restore from ddrescue image to SSD
Post by: Ed.Kloonk on October 27, 2022, 12:17:08 pm
No idea what OS you might have, what file system, or what errors do you see after upgrade.  :-//
Answer is many to all three of your no ideas.  ;D

Quote
My crystal globe is broken, and the Eye of Sauron is in maintenance shutdown until Halloween.  :-\

Mission is spelled out in the OP.
Title: Re: Partial restore from ddrescue image to SSD
Post by: DavidAlfa on October 27, 2022, 12:23:52 pm
Why? Another overthinking thread.
Just write the whole thing.
If the SSD is gone, nothing to do about it.
Title: Re: Partial restore from ddrescue image to SSD
Post by: RoGeorge on October 27, 2022, 12:58:48 pm
Mission is spelled out in the OP.

Spelled or misspelled?
SDD failure
:P

Just dd the whole damn thing from the backup, then if after upgrade it fails again, try to fix the already upgraded OS.

I don't know any ready made tool that can diff two images then dd only the changed blocks.  You can try to write some scripts to do that.  If you do so, beware some SSD have flash blocks different than 512B, mine is 4MiB IIRC, so physically it flushes 4MiB even if only one 512B sector has changed.
Title: Re: Partial restore from ddrescue image to SSD
Post by: Ed.Kloonk on October 27, 2022, 01:18:39 pm
I don't know any ready made tool that can diff two images then dd only the changed blocks.  You can try to write some scripts to do that.  If you do so, beware some SSD have flash blocks different than 512B, mine is 4kiB IIRC, so physically it flushes 4kiB even if only one 512B sector has changed.

Do you know how to make a drive cough up it's flush block size?
Title: Re: Partial restore from ddrescue image to SSD
Post by: RoGeorge on October 27, 2022, 01:34:03 pm
Depends on the SSD type.  For some models is top secret.  ;D
https://www.reddit.com/r/techsupport/comments/ai1qrz/nand_erase_block_size_for_samsung_970_pro_is_top/ (https://www.reddit.com/r/techsupport/comments/ai1qrz/nand_erase_block_size_for_samsung_970_pro_is_top/)

Found about about mine accidentally, from reading about that model before buying it.  Don't know if the info is correct.
Title: Re: Partial restore from ddrescue image to SSD
Post by: Ed.Kloonk on October 27, 2022, 01:40:21 pm
Depends on the SSD type.  For some models is top secret.  ;D
https://www.reddit.com/r/techsupport/comments/ai1qrz/nand_erase_block_size_for_samsung_970_pro_is_top/ (https://www.reddit.com/r/techsupport/comments/ai1qrz/nand_erase_block_size_for_samsung_970_pro_is_top/)

Found about about mine accidentally, from reading about that model before buying it.  Don't know if the info is correct.

Thanks.

 :-+
Title: Re: Partial restore from ddrescue image to SSD
Post by: ejeffrey on October 27, 2022, 01:59:43 pm
SSD wear is irrelevant.  Just write the whole thing.  The cost of those writes is at most about $.20 and much more likely $0.00.  If you are going to micromanage wear just go back to mechanical drives.  Your total system efficiency will be much higher when including the time you spend fing around with stuff that doesn't matter.

Mounting the disk image and doing a file restore would also be a fine way to go but since you have rejected that for being, I guess too obvious?
Title: Re: Partial restore from ddrescue image to SSD
Post by: RoGeorge on October 27, 2022, 02:09:12 pm
https://superuser.com/questions/728858/how-to-determine-ssds-nand-erase-block-size
Title: Re: Partial restore from ddrescue image to SSD
Post by: BradC on October 27, 2022, 02:15:24 pm
Mount the image loopback and just use rsync —delete

Title: Re: Partial restore from ddrescue image to SSD
Post by: Monkeh on October 27, 2022, 02:18:15 pm
Just do it. If you're writing the same data to the same place the SSD won't write - it's a no-op. At least on any properly implemented controller.
Title: Re: Partial restore from ddrescue image to SSD
Post by: rdl on October 27, 2022, 02:25:07 pm
I understand doing things "the hard way" just because, or out of curiosity, but keep in mind that 120 GB SSDs are less than $20.
Title: Re: Partial restore from ddrescue image to SSD
Post by: DavidAlfa on October 27, 2022, 02:59:15 pm
SSDs wear leveling algorithm is constantly remapping the actual sectors, when you write to sector 0, the flash area won't be the same the next time you write that same sector.
If your SSD is dead, nothing to do about it, try to image it, but solid drives are really bad at it when damaged.