On 2024-02-01 04:16, bad sector wrote:
> On 1/31/24 21:23, Carlos E.R. wrote:
>> On 2024-02-01 03:02, bad sector wrote:
>>> How could I in such a case restore the laptop to as-it-was if I want
>>> to sell it for example?
>>
>> By doing a recovery imaging of the HD the first day to an external disk.
>
> I've already installed some drivers and bundleware but I think those can
> be taken out with a windows reset before the backup or before selling
Me, I would do a factory restore of the computer, and then create an
image on an external disk. I typically buy a rotating rust disk of at
least double size the internal disk, install a small linux on it (I use
plain Leap with xfce), and partition the rest of the disk as a huge data
partition, encrypted + compressed, with btrfs (because it is the only
one that has compression on the fly).
> For the 'recovery imaging' you mean load rescue, connect an external
> drive and either
>
> dd if=internal-1tb-ssd of=/path-to-1tb file
>
> or
>
> dd if=internal-1tb-ssd of=/dev/external-1tb-ssd?
Yes.
Actually, I do separate images per partition, and backp the partition
table. For the initial image, it can be the entire disk.
This is the script I use - warning: some lines have wrapped:
(sorry, some comments are in Spanish, ask for clarification if you need)
+++····································
#!/bin/bash
echo "Tiempo total estimado, 3 hora(s)"
THEDEVICE=sda
cd /backup/images/004
echo "=== Copiando las tablas"
dd if=/dev/$THEDEVICE of=MBR count=1
sgdisk --backup=gpt_table /dev/$THEDEVICE
parted --list > parted_list
echo
#restore: sgdisk --load-backup=gpt_table /dev/nvme0n1
#
http://www.tech-g.com/2014/11/28/backing-up-disk-with-dd-saving-space/
# restore, podría ser: pigz -dc /hds/www/vzhost.img.gz | dd of=/dev/sdd
status=progress
function hacer()
{
echo
echo "Haciendo la particion $1 ($2) en $3"
echo "copiando, comprimiendo, y calculando md5..."
mkfifo mdpipe
dd if=/dev/$1 status=progress bs=16M | tee mdpipe | pigz -3 > $3.gz &
md5sum -b mdpipe | tee -a md5checksum_expanded
wait
rm mdpipe
echo "$3" >> md5checksum_expanded
echo "Verificando..."
pigz --test $3.gz
echo
echo "·········"
}
echo "-----------" >> md5checksum_expanded
time hacer sda1 "8S" "sda1__SYSTEM_DRV"
time hacer sda2 "1S" "sda2__RESERVED"
time hacer sda5 "33S" "sda5__WINRE_DRV"
time hacer sda7 "34S" "sda7__LRS_ESP"
echo
echo "=== Ahora las particiones gordas (3, 4 y 6)"
echo
time hacer sda3 "161M" "sda3__Windows"
echo
time hacer sda4 "10M" "sda4__LENOVO"
echo
time hacer sda6 "11M" "sda6__LENOVO_PART"
echo
time hacer sda9 "10M" "sda9__Swap"
····································++-
This machine has evolved and now has more partitions, but you can get
the idea.
Another version of the script on another laptop:
+++····································
TIMESTAMPFILE=0_timestamp_dd
echo "==============================" >> $TIMESTAMPFILE
function hacer()
{
DATE=`date --rfc-3339=seconds`
echo
echo "Haciendo la particion $1 ($2) en $3 ($DATE)" | tee -a
$TIMESTAMPFILE
echo "copiando, comprimiendo, y calculando md5..."
mkfifo mdpipe
dd if=/dev/$1 status=progress bs=16M | tee mdpipe | zstd > $3.zst &
md5sum -b mdpipe | tee -a md5checksum_expanded
wait
rm mdpipe
echo "$3" >> md5checksum_expanded
#Study:
#
# --size-hint=#
# When handling input from a stream, zstd must guess how
large the source size will be when optimizing com
# parameters. If the stream size is relatively small, this
guess may be a poor one, resulting in a higher com
# ratio than expected. This feature allows for controlling
the guess when needed. Exact guesses result in bet
# pression ratios. Overestimates result in slightly
degraded compression ratios, while underestimates may re
# significant degradation.
#
# --adapt[=min=#,max=#]
# zstd will dynamically adapt compression level to
perceived I/O conditions. Compression level adaptatio
# observed live by using command -v. Adaptation can be
constrained between supplied min and max levels. The
# works when combined with multi-threading and --long
mode. It does not work with --single-thread. It set
# size to 8 MB by default (can be changed manually, see
wlog). Due to the chaotic nature of dynamic adaptatio
# pressed result is not reproducible. note : at the time
of this writing, --adapt can remain stuck at low sp
# combined with multiple worker threads (>=2).
echo "Verificando ($DATE)..." | tee -a $TIMESTAMPFILE
zstd --test $3.zst
echo
echo "Hecho ($DATE)" | tee -a $TIMESTAMPFILE
echo "·········" | tee -a $TIMESTAMPFILE
}
echo "Tarda aproximadamente cinco horas. A ver con 'pigz --fast - no,
mucho mejor con zstd'"
echo "El problema era que pigz alterna lectura y escritura. Encima, zstd
comprime más."
echo
echo "-----------" >> md5checksum_expanded
DATE=`date --rfc-3339=seconds`
echo "Start at $DATE" > $TIMESTAMPFILE
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda mbr" | tee -a $TIMESTAMPFILE
dd if=/dev/sda of=sda_mbr count=1
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 copiar tabla de particiones con sfdisk" | tee -a
$TIMESTAMPFILE
sfdisk -d /dev/sda > sda_partition_table_sfdisk.out
# recovery: % sfdisk /dev/hda < hda.out
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 copiar tabla de particiones con fdisk" | tee -a
$TIMESTAMPFILE
fdisk -l /dev/sda > sda_partition_table_fdisk.out
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda super_mbr" | tee -a $TIMESTAMPFILE
dd if=/dev/sda of=sda_super_mbr count=64
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda_1 WINBOOT" | tee -a $TIMESTAMPFILE
time hacer sda1 "5S" "sda1_WINBOOT"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda_2 WINDOWS" | tee -a $TIMESTAMPFILE
time hacer sda2 "250M" "sda2_WINDOWS"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda_3 Crypt" | tee -a $TIMESTAMPFILE
time hacer sda3 "21m" "sda3_Crypt"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda4_ext_grub" | tee -a $TIMESTAMPFILE
dd if=/dev/sda4 of=sda4_ext_grub
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda4_ext_grub_super" | tee -a $TIMESTAMPFILE
dd if=/dev/sda4 of=sda4_ext_grub_super count=64
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda_5_swap" | tee -a $TIMESTAMPFILE
time hacer sda5 "6m" "sda5_swap"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda6_boot" | tee -a $TIMESTAMPFILE
time hacer sda6 "8S" "sda6_boot"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda7_root" | tee -a $TIMESTAMPFILE
time hacer sda7 "37" "sda7_root"
echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Omitiendo sda_8_Home, muy grande, solo ficheros" | tee
-a $TIMESTAMPFILE
#echo "--- $DATE2 Haciendo sda_8_Home" | tee -a 0_timestamp_dd
#echo
DATE2=`date --rfc-3339=seconds`
echo "--- $DATE2 Haciendo sda_9_Other" | tee -a $TIMESTAMPFILE
dd_rhelp /dev/sda9 sda9_Other
time hacer sda9 "8M" "sda9_Other"
echo
echo "Finalizado!"
DATE3=`date --rfc-3339=seconds`
echo >> 0_timestamp_dd
echo "End at $DATE3" >> $TIMESTAMPFILE
····································++-
--
Cheers, Carlos.