Harddrive
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"
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 Knoppix
- partition the HD
- mount /dev/hdaX /mnt/hdaX
Make the computer accessible to backuppc as the computer to restore
- attribute the correct IP
- restore sshd keys on Knoppix ramdisk via tgz
- /etc/init.d/ssh start
- restore /root/.ssh/authorized_keys on Knoppix ramdisk
The big operation
- restore all / on /mnt/hdaX via backuppc
- 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])}'
Last steps: MBR and missing dirs if they were excluded from the backup:
- /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