OpenBSD Journal

User Stories: Changing the harddisk in my workstation.

Contributed by sean on from the getting things done the puffy way dept.

Andrei Gudiu found himself in a minor pickle and writes in with his solution:
This is my story of switching my 4.2 OpenBSD box from my old 15GB hard-disk to a new 160GB/7200/RPM one.

Lately I just frequently got "out of space" on my old 15GB hard-disk so I decided it's time to buy a new one. I got myself a 160GB IDE since my box only supports IDE hard-disks. So I started looking for a way to minimize my downtime and keep all my data and setup intact during and after the switch. I have to say that there was a single partition on my old 15GB hdd so this should be quite easy to dump and restore.

Read on for his solution.
Would you have solved this issue differently (how so)?
Andrei's submission as follows:
I browsed the OpenBSD FAQ and found that I could use dump(8) and restore(8) (http://www.openbsd.org/faq/faq14.html#Backup).

Note: I used a NFS mounted space for my system dump not a tape-drive. Throughout this story I will use /mnt/exported for my dump destination and source and /mnt/new for the new harddisk I mounted in.

1. First, the system dump. My single partition was wd0a so I started by dumping this partition into the NFS exported file-system.
/sbin/dump -0au -f /mnt/exported/systembackup /dev/rwd0a
This process took a long while (about an hour or so) since it all went through our LAN (which is a damn slow one).

2. Preparing the new hard-disk.
I got my new hard-disk in my box as primary slave. So now I have wd0 my old hdd and wd1 the new one. First I needed to initialize the new hdd for the use with OpenBSD (and only OpenBSD). For that I used:
$fdisk -e wd1
Enter 'help' for information
fdisk: 1> reinit
fdisk: 1> write
fdisk: 1> quit
At the prompt I initialized the new hdd with the "reinit" command, then "write" and then "quit". After that I had to create the disklabel. I only needed to create one UFS slice so I choose my / slice to have 30GB of space.

disklabel -E wd1
# Inside MBR partition 1: type A6 start ## size #######
Treating sectors ##-####### as the OpenBSD portion of the disk.
You can use the 'b' command to change this.

Initial label editor (enter '?' for help at any prompt)
> a a
size: 30G
FS type: [4.2BSD] 
> a f
size: 1G
FS type: [swap] 
> q
At the prompt I added the a 30GB slice and after that I created the swap space.

 ***********************************************
 *** DO NOT FORGET ABOUT THE SWAP PARTITION. ***
 ***********************************************
3. Next I got my new file system and mounted the new slice onto /mnt/new.

For that I used the newfs command to build a clean file-system in place.
  newfs /dev/rwd1a

after that:
  mount /dev/wd1a /mnt/new
Now I should have the new 30GB slice ready for the restore of my system backup.
  cd /mnt/new
  restore -rs 1 -f /mnt/exported/systembackup
This also will take a long while. Note that the restore command is pretty silent so if you would like to see which files are being restored you should add the -v flag but keep in mind that verbosity steals from your precious time :)

4. Next I wanted my new hard-disk to be able to boot :)

I used the following commands to write a new MBR for my drive and install boot blocks.
  fdisk -i wd1

  cp /usr/mdec/boot /mnt/new/boot
  /usr/mdec/installboot -v /mnt/new/boot /usr/mdec/biosboot wd1
5. Unmounted and halt.

After all this was done, with my heart beating like a locomotive I turned my box down, switched the IDE cables and...
VOILA ! My 4.2-current booted like a charm from my new hard-disk. I have to say it booted more than twice faster since my old hdd was a 4200 or 5400 RPM old runner.


6. I created 3 more slices for /var /home and /usr. You can do this the same
way as described above with the 30GB partition. I mounted /mnt/var, /mnt/home and /mnt/usr and copied my old /var, /home and /usr there using tar.
   cd /home
   tar cf - * | ( cd /mnt/home; tar xfp -)
   cd /var
   tar cf - * | ( cd /mnt/var; tar xfp -)
   cd /usr
   tar cf - * | ( cd /mnt/usr; tar xfp -)
Now change /etc/fstab to use your new slices and... reboot. At least that's
what I did. Everything works like a charm and about 3 times faster :)
What kinds of problems do you use OpenBSD to solve?

(Comments are closed)


Comments
  1. By Anonymous Coward (165.228.157.146) on

    Just do the dump | restore straight onto the other drive.

    Comments
    1. By Anonymous Coward (24.22.214.92) on

      > Just do the dump | restore straight onto the other drive.

      Suppose he wasn't in a scenario where it was possible (or simple) to have two hard disks in a machine at once. Many mini-desktops from big-name OEMs are like this.

      Comments
      1. By Lennie (82.75.29.106) on

        > > Just do the dump | restore straight onto the other drive.
        >
        > Suppose he wasn't in a scenario where it was possible (or simple) to have two hard disks in a machine at once. Many mini-desktops from big-name OEMs are like this.

        You mean to tell me it doesn't even allow for that when it's lying open ?

        It's not just a case problem ? Is it the power-spply ?

        Well, if you have an other machine, you could use the NFS method as shown above, but if you have enough memory, I could also suggest rsync.

        Comments
        1. By Anonymous Coward (68.148.116.122) on

          > You mean to tell me it doesn't even allow for that when it's lying open ?

          Yep. I've seen machines with just one ATA port and two molex connectors - just enough to run a disk and a CD/DVD. Not saying that's a good idea, but for some users, it's good enough.

          Comments
          1. By Marc Espie (213.41.185.88) espie@openbsd.org on

            > > You mean to tell me it doesn't even allow for that when it's lying open ?
            >
            > Yep. I've seen machines with just one ATA port and two molex connectors - just enough to run a disk and a CD/DVD. Not saying that's a good idea, but for some users, it's good enough.

            So you just disconnect the CD drive temporarily and plug-in both disks. Like wow, difficult idea.

  2. By Anonymous (82.204.30.143) on

    Your story is fascinating. Maybe some day I will tell you about the time I bought myself a new keyboard and the amazing story of how I migrated from the old keyboard to that one.. Or what about when I expanded my RAM? Haha that was great. Memories..

    Comments
    1. By Anonymous Coward (151.145.232.92) on

      > Your story is fascinating. Maybe some day I will tell you about the time I bought myself a new keyboard and the amazing story of how I migrated from the old keyboard to that one.. Or what about when I expanded my RAM? Haha that was great. Memories..

      Oh, Stewie, you're such a cutie.

    2. By Anonymous Coward (213.221.123.174) on

      > Your story is fascinating. Maybe some day I will tell you about the time I bought myself a new keyboard and the amazing story of how I migrated from the old keyboard to that one.. Or what about when I expanded my RAM? Haha that was great. Memories..

      Expanded your memory? To what? 4GB is the limit, isn't it?
      So what "expansion"? :-]]

  3. By Pierre Riteau (82.240.212.223) on

    For step 6, why do you use tar instead of a bare cp -Rp ?
    And you forget your hidden files in your home with the wildcard, at least on ksh.

    Comments
    1. By Andrei GUDIU (andreig) on http://www.openbsd-box.org

      > For step 6, why do you use tar instead of a bare cp -Rp ?
      > And you forget your hidden files in your home with the wildcard, at least on ksh.

      I'm using zsh and it worked OK for me.

      Comments
      1. By Anonymous Coward (192.61.201.164) on

        > > For step 6, why do you use tar instead of a bare cp -Rp ?
        > > And you forget your hidden files in your home with the wildcard, at least on ksh.
        >
        > I'm using zsh and it worked OK for me.

        You have hidden files in /home ?

        Comments
        1. By Andrei GUDIU (andreig) on http://www.openbsd-box.org

          > > > For step 6, why do you use tar instead of a bare cp -Rp ?
          > > > And you forget your hidden files in your home with the wildcard, at least on ksh.
          > >
          > > I'm using zsh and it worked OK for me.
          >
          > You have hidden files in /home ?

          of course I have, all my configs are in hidden files in my home and they are all there. Hidden files and hidden directories.

        2. By Pierre Riteau (82.65.36.204) on

          > > > For step 6, why do you use tar instead of a bare cp -Rp ?
          > > > And you forget your hidden files in your home with the wildcard, at least on ksh.
          > >
          > > I'm using zsh and it worked OK for me.
          >
          > You have hidden files in /home ?

          Sorry, it's /home but I thought /home/user... my mistake.

  4. By Anonymous Coward (24.37.242.64) on

    I thought this was a good story/example scenario.

  5. By Anonymous Coward (204.80.187.5) on

    What's the point of using dump/restore? tar (pax) does everything you need, including not jumping mount points.

    I would have just done the fdisk, disklabel, newfs, and then:

    (cwd is irrelevant here since absolute paths are specified):

    tar cXf - / | (cd /mnt; tar xpf -)
    tar cXf - /home | ( cd /mnt; tar xpf -)
    tar cXf - /var | ( cd /mnt; tar xpf -)
    tar cXf - /usr | ( cd /mnt; tar xpf -)
    /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1

    (where wd1 is the new disk)

    Comments
    1. By Andrei GUDIU (andreig) on http://www.openbsd-box.org

      > What's the point of using dump/restore? tar (pax) does everything you need, including not jumping mount points.
      >
      > I would have just done the fdisk, disklabel, newfs, and then:
      >
      > (cwd is irrelevant here since absolute paths are specified):
      >
      > tar cXf - / | (cd /mnt; tar xpf -)
      > tar cXf - /home | ( cd /mnt; tar xpf -)
      > tar cXf - /var | ( cd /mnt; tar xpf -)
      > tar cXf - /usr | ( cd /mnt; tar xpf -)
      > /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1
      >
      > (where wd1 is the new disk)

      I just found that soultion to be easiest to follow for me, and I guess I have also a good backup image (never had one before). Btw, my old hdd died yesterday evening. The box won't start with it plugged in anymore. Lucky me I got my new one 2 days ago.

      Comments
      1. By Anonymous Coward (204.80.187.5) on


        > I just found that soultion to be easiest to follow for me, and I guess I have also a good backup image (never had one before). Btw, my old hdd died yesterday evening. The box won't start with it plugged in anymore. Lucky me I got my new one 2 days ago.

        Well using the network with dump/restore and then using tar for the rest of it makes no sense, and is really a big waste of time. If you just use tar or dump/restore locally between the disks then you could have done the whole thing in like 10-15 minutes (with the write cache enabled on wd1)

        Comments
        1. By Andrei GUDIU (andreig) on http://www.openbsd-box.org

          >
          > > I just found that soultion to be easiest to follow for me, and I guess I have also a good backup image (never had one before). Btw, my old hdd died yesterday evening. The box won't start with it plugged in anymore. Lucky me I got my new one 2 days ago.
          >
          > Well using the network with dump/restore and then using tar for the rest of it makes no sense, and is really a big waste of time. If you just use tar or dump/restore locally between the disks then you could have done the whole thing in like 10-15 minutes (with the write cache enabled on wd1)
          >
          >

          I will keep that in mind for my next hdd switch (which will be in 10 years from now I guess :)). Thank you for your suggestions and good intentions (unlike some others around).

      2. By Anonymous Coward (24.37.242.64) on

        > > What's the point of using dump/restore? tar (pax) does everything you need, including not jumping mount points.
        > >
        > > I would have just done the fdisk, disklabel, newfs, and then:
        > >
        > > (cwd is irrelevant here since absolute paths are specified):
        > >
        > > tar cXf - / | (cd /mnt; tar xpf -)
        > > tar cXf - /home | ( cd /mnt; tar xpf -)
        > > tar cXf - /var | ( cd /mnt; tar xpf -)
        > > tar cXf - /usr | ( cd /mnt; tar xpf -)
        > > /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1
        > >
        > > (where wd1 is the new disk)
        >
        > I just found that soultion to be easiest to follow for me, and I guess I have also a good backup image (never had one before). Btw, my old hdd died yesterday evening. The box won't start with it plugged in anymore. Lucky me I got my new one 2 days ago.

        I think your posting was great and I always like to see new articles. It shows how you did it and even how others do it in different ways which means it's educational for many, one way or another. It shows how versatile things can be and gives people the 'choice' to do things how they like, and in a variety of ways.

        I'll be posting a few articles myself soon, just after 4.2 is out.

        Glad to see your effort, unlike some others... ;-)

    2. By Anonymous Coward (204.80.187.5) on

      Also I would end that with:

      cd /mnt/dev
      ./MAKEDEV all

      and, at this point, you could reboot and use the new drive as primary.....

    3. By Anonymous Coward (204.80.187.5) on


      > tar cXf - / | (cd /mnt; tar xpf -)
      > tar cXf - /home | ( cd /mnt; tar xpf -)
      > tar cXf - /var | ( cd /mnt; tar xpf -)
      > tar cXf - /usr | ( cd /mnt; tar xpf -)
      > /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1

      This assumes that wd1 is mounted to /mnt and that wd0 has 4 partitions: / /home /var /usr but your article says that your 15gb disk was only one partition so all you need to do is the first tar cXf - / | (cd /mnt; tar xpf -) between the disks and then run installboot.

    4. By tuyosi (210.253.226.156) on

      please sorry fo my poor english .
      i Changed the harddisk from 80GB(wd0) to 20GB(wd1) by following methods .
      i attach new 20GB harddisk drive

      1. boot with "OpenBSD CD"
      2. chose install
      3. select wd1 as "install hard disk"
      4.when formatting is done , press " ctrl+C ".
      ( this brings you shell prompt .)

      5. umount /mnt
      6. mkdir /m0
      mkdir /m1
      7. mount  /dev/wd0a /m0
      mount  /dev/wd1a /m1
      8. ( cd /m0 ; tar cf - . )|(cd /m1 ; tar xvpf - )

      9. fdisk -i wd1
      /usr/mdec/installboot -v /m1/boot /usr/mdec/biosboot wd1
      umount /m0
      umount /m1
      halt

      10. remove 80GB hard disk , and boot OpenBSD with 20GB hard disk .

      Comments
      1. By tuyosi (125.215.108.74) on

        sorry for garbled characters owing to japanese 2 byte character
        >7. mount  /dev/wd0a /m0
        > mount  /dev/wd1a /m1


        7. mount /dev/wd0a /m0
        mount /dev/wd1a /m1

  6. By Anonymous Coward (12.217.228.139) on

    I would have just dd'ed the old drive onto the new one, increased the slice size of your non swap partition, and then enlarged the filesystem with growfs(8). Shutdown, remove old drive, put new one in old one's place on the bus, and you're good to go.

    Comments
    1. By spikeysnack (12.45.63.191) spikeysnack@gmail.com on

      > I would have just dd'ed the old drive onto the new one, increased the slice size of your non swap partition, and then enlarged the filesystem with growfs(8).

      just for clarification --

      from growfs (8) :

      Before starting growfs, the partition must be set to a larger size using disklabel(8). 

      The growfs utility extends the size of the file system on the specified special file.

      Currently growfs can only enlarge unmounted file systems. Do not try enlarging a mounted file system - your system may panic and you will not be able to use the file system any longer. Most of the newfs(8) options cannot be changed by growfs. In fact, you can only increase the size of the file system. Use tunefs(8) for other changes.

      As always, Consult the man pages carefully before messing around with potentially destructive procedures -- (Duh!)

      [OpenBSD user since 2.1]

Latest Articles

Credits

Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]