Harddrive

From YobiWiki
Jump to navigation Jump to search

Converted with HTML::WikiConverter::MediaWiki from my old phpwiki site


S.M.A.R.T.

  • apt-get install smartmontools

If you have already smartsuite, it will be removed first.
On my system, there was a bug in the pre-removal script and I had to help a bit to remove this package:

  • /etc/init.d/smartsuite stop
  • echo "exit 0" > /etc/init.d/smartsuite
  • dpkg -r smartsuite

Turn SMART on (only once in HD's life):

  • smartctl --smart=on --offlineauto=on --saveauto=on /dev/hdX

Enable the daemon:

  • Edit /etc/default/smartmontools and uncomment start_smartd=yes
  • Edit /etc/smartd.conf:
    • DEVICESCAN -a -o on -S on -m root@teuwen.org -s (S/../.././02|L/../../6/03)

Selftests:

  • smartctl -t short /dev/hdX
  • smartctl -t long /dev/hdX

Interrupting self-test:

  • smartctl -X /dev/hdX

Read results:

  • smartctl -l selftest /dev/hdX

You can also run tests in captive mode:

  • smartctl -t long -C /dev/hdX

For SATA disks accessed with libata, use "-d ata /dev/sdX"

For disks behind a 3ware 800x RAID controller, see here

Repairing

Forcing sector reallocations:

  • badblocks -n -s -v /dev/hdXX
  • Destructive: badblocks -w -s -v /dev/hdXX

Rescuing

  • apt-get install ddrescue
  • If you have a knoppix, dd-rescue was probably installed.
    This is an older version packaged only for the knoppix.
    dpkg -r dd-rescue;apt-get install ddrescue
  • dd_rescue -A -a -v /dev/hdXX /rescue-hdXX
  • dd_rescue -h for other options

See also

Rebuilding filesystem

For ReiserFS:

  • apt-get install reiserfsprogs
  • losetup /dev/loop0 rescue-hdXX
  • reiserfsck --rebuild-sb /dev/loop0
  • reiserfsck --rebuild-tree --scan-whole-partition --logfile rebuild.log /dev/loop0

Restoring from backuppc

Prepare the HD

  • delay backups on backuppc interface
  • boot on LiveCD
    • Last time I used FCCU v12, supports cryptsetup but not XTS chaining mode, and needs rsync
  • partition the HD
  • Format & mount non-encrypted partitions (e.g. /boot)
mkfs.ext2 /dev/hda1
mount /dev/hda1 /mnt/hda1
  • For encrypted partitions: create, format & mount them as explained here
    • Note that cryptsetup is available on FCCU v12 but with a kernel 2.6.22 so no XTS support!
    • First restore / on a AES-CBC LUKS volume (cryptsetup luksFormat -s 256), then boot on it & format other data partitions with AES-XTS (cryptsetup luksFormat -c aes-xts-plain -s 256)

Make the computer accessible to backuppc as the computer to restore

  • attribute the correct IP
  • restore sshd keys into aufs from backuppc via tgz
  • /etc/init.d/ssh start
  • restore /root/.ssh/authorized_keys into aufs

The big operation

  • restore /boot on /mnt/hdaY via backuppc
  • restore / on /mnt/hdaX via backuppc
    • FCCU v12 does not contain rsync so I had to do "apt-get install rsync" on the aufs

Then fixing some details on /mnt/hdaX:

  • cd /mnt/hdaX
  • mkdir tmp; chmod go+w tmp; chmod +t tmp
  • mkdir nobackup
  • mkdir -p var/cache/apt/archives/partial
  • Restoring GRUB (/boot is in this example on /dev/sda1)
# grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Old notes

In the past, for older versions of backuppc, some special files were not properly restored and I had to do this:

  • check for errors (possibly failed restoration of some symlink and mknod...) and create them
    • gawk '/symlink/{match($0, /"(.*)".*"(.*)"/, a); system("ln -s " a[2] " " a[1])}'
  • /etc/init.d/libdevmapper1.00 start
  • cp -a /dev /mnt/hdaX/dev
  • chroot /mnt/hdaX
  • mkdir /tmp; chmod go+w /tmp; chmod +t /tmp
  • mkdir /proc
  • mkdir /mnt; cat /etc/fstab | gawk '/mnt/{system("mkdir " $2)}'
  • mkdir -p /var/cache/apt/archives/partial
  • mount /proc /proc -t proc
  • lilo/grub-install /dev/hda
  • exit
  • umount /mnt/hdaX
  • reboot

If you want to change the filesystem type, you are free to do so but pay attention:

  • change /etc/fstab accordingly
  • recreate the initrd image
    • mount /sys /sys -t sysfs
    • dpkg-reconfigure linux-image-XXXXX (look for initrd completion messages)

Managing the swap

Converted with HTML::WikiConverter::MediaWiki from my old phpwiki site

Check memory usage

cat /proc/meminfo
cat /proc/swaps

Swap partition

Here are the steps to create and enable a swap partition:


fdisk... (create the partition of the proper size, partition type 82)
mkswap -c /dev/hdXX
swapon /dev/hdXX

Swap file

Here are the steps for making a (256M) swap file:


dd if=/dev/zero of=/swapfile bs=1024 count=262144
mkswap /swapfile
sync
swapon /swapfile

To have the swap enabled automatically at bootup, you have to include the appropriate entry into the file /etc/fstab, for example:


/dev/hdXX swap swap defaults 0 0
or
/swapfile swap swap defaults 0 0

If you ever need to disable the swap, you can do it with (as root):


swapoff /dev/hdXX
or
swapoff /swapfile

You may also want to see the nice info written by Linus Torvalds himself:


man mkswap

Simulating RAID 0 (striping) for the swap

  • Simply give the same priority to both swap partitions:
  • /dev/hda2 swap swap defaults,pri=1 0 0
  • /dev/hdc2 swap swap defaults,pri=1 0 0