September15
Here’s a slightly longer article than ususal on the subject of hard disks and partitions. This is always a subject that is occasionally tricky. Here’s the nutshell of how to find your hard disk name, the relevant partition and how to back it up and restore it.
Listing the disks and partitions
To list the hard disk devices on your system use..
sudo fdisk -l
You should get an output something similar to this…
Disk /dev/sda: 128.0 GB, 128035676160 bytes
255 Köpfe, 63 Sektoren/Spur, 15566 Zylinder, zusammen 250069680 Sektoren
Einheiten = Sektoren von 1 × 512 = 512 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Festplattenidentifikation: 0x00055cbf
Gerät boot. Anfang Ende Blöcke Id System
/dev/sda1 * 2048 495615 246784 83 Linux
/dev/sda2 497662 250068991 124785665 5 Erweiterte
/dev/sda5 497664 23932927 11717632 83 Linux
/dev/sda6 23934976 27838463 1951744 82 Linux Swap / Solaris
/dev/sda7 27840512 250068991 111114240 83 Linux
Disk /dev/mapper/sda5_crypt: 12.0 GB, 11996758016 bytes
255 Köpfe, 63 Sektoren/Spur, 1458 Zylinder, zusammen 23431168 Sektoren
Einheiten = Sektoren von 1 × 512 = 512 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Festplattenidentifikation: 0x00000000
Festplatte /dev/mapper/sda5_crypt enthält keine gültige Partitionstabelle
Platte /dev/mapper/cryptoswap: 1998 MByte, 1998585856 Byte
255 Köpfe, 63 Sektoren/Spur, 242 Zylinder, zusammen 3903488 Sektoren
Einheiten = Sektoren von 1 × 512 = 512 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Festplattenidentifikation: 0x67218b8c
Festplatte /dev/mapper/cryptoswap enthält keine gültige Partitionstabelle
Disk /dev/sdb: 32.0 GB, 32019316736 bytes
255 Köpfe, 63 Sektoren/Spur, 3892 Zylinder, zusammen 62537728 Sektoren
Einheiten = Sektoren von 1 × 512 = 512 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Festplattenidentifikation: 0xc3072e18
Gerät boot. Anfang Ende Blöcke Id System
/dev/sdb1 32 62537727 31268848 c W95 FAT32 (LBA)
As you can see, the first disk name is /dev/sda and this disk is 128GB in size. Listed further down are the details of how the disk, /dev/sda, is sliced up, namely the five partitions sda1, sda2, sda5, sda6 and sda7.
There’s also another disk, /dev/sdb which is 32GB. It has one partition, /dev/sdb1.
From this we can see that the disk is alsways called something like /dev/sda, /dev/sdb, /dev/sdc and so on. The partitions are always numbered sub items, so /dev/sdb1, /dev/sdb2, /dev/sdb3, /dev/sdb4 and so on as needed.
Back up the paritions or disks..
We back up the partition or disk using the dd command. Let’s backup the boot partition, /dev/sda1, on the disk /dev/sda to the partition /dev/sdb1 on the disk /dev/sdb. We know /dev/sda1 is the boot partition because it’s marked with an asterisk (*).
So, device /dev/sdb is a USB memory stick. To backup the boot parition, /dev/sda1, to the USB drive, /dev/sdb, let’s mount the USB drive first using the following commands.
First, make a target folder for the mount..
sudo mkdir -p /media/any/path/you/like
Now, we mount the partition /dev/sdb1 to the target location /media/any/path/you/like so that when we change directory to /media/any/path/you/like, the contents of the USB disk are visible.
For this, we use the mount command. The mount command syntax is effectively mount which_device where. We’ll use the following mount command.
sudo mount -t vfat -o rw,users /dev/sdb1 /media/any/path/you/like
The command above states that the filesystem of the USB disk is vfat and is read/write-able and can be dismounted by users.
Ready to backup
Now the disk is mounted, we can dd our data straight to it.
sudo dd if=/dev/sda1 of=/media/any/path/you/like/the_sda1_partition_backup
Once running, nothing appears to happen. Remain calm and wait. Losen any tight clothing if necessary and wait. Backup is happening. When it ends, you’ll get something like this…
493568+0 Datensätze ein
493568+0 Datensätze aus
252706816 Bytes (253 MB) kopiert, 6,09949 s, 41,4 MB/s
For style points, you can also backup the whole disk to another hard disk of the same size and dimensions..
sudo dd if=/dev/sda of=/dev/sdb
Or even back up a partition or disk to a compressed file to save space.
sudo dd if=/dev/sda1 | gzip > /media/any/path/you/like/the_sda1_partition_backup.gz
You will probably need to sudo su before running the command above, so first,
sudo su
and then use the dd command above.
That’s it. You’re a pro. Drinks all round.