Pages

Sunday, March 18, 2012

Migrating /usr to a new disk in NetBSD

Today I added another 18GB hard disk to my NetBSD machine. The goal is to migrate /usr on it. After I have connected the disk and booted the machine I ran fdisk to create a partition on the disk. I want to use the complete disk for /usr so I only created one partition. The -u option for the fdisk command runs fdisk in interactive mode which make things very easy: 

# fdisk -u /dev/rsd1
fdisk: primary partition table invalid, no magic in sector 0
Disk: /dev/rsd1d
NetBSD disklabel disk geometry:
cylinders: 14627, heads: 10, sectors/track: 243 (2430 sectors/cylinder)
total sectors: 35548320

BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 35548320

Do you want to change our idea of what BIOS thinks? [n]

Partition table:
0: <UNUSED>
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none] 0
The data for partition 0 is:
<UNUSED>
sysid: [0..255 default: 169]
start: [0..2213dcyl default: 63, 0dcyl, 0MB]
size: [0..2213dcyl default: 35548257, 2213dcyl, 17358MB]
bootmenu: []

Partition table:
0: NetBSD (sysid 169)
    start 63, size 35548257 (17358 MB, Cyls 0-2212/199/3)
        PBR is not bootable: All bytes are identical (0x00)
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none]

We haven't written the MBR back to disk yet.  This is your last chance.
Partition table:
0: NetBSD (sysid 169)
    start 63, size 35548257 (17358 MB, Cyls 0-2212/199/3)
        PBR is not bootable: All bytes are identical (0x00)
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
Bootselector disabled.
No active partition.
Should we write new partition table? [n] y

Next I needed to label the partition:

# disklabel -i -I /dev/rsd1
partition> a
Filesystem type [?] [unused]: ?
Supported file system types:
        4.1BSD          EFS             Linux Ext2      UDF
        4.2BSD          Eighth Edition  MSDOS           unknown
        4.4LFS          FILECORE        NTFS            unused
        ADOS            HFS             RAID            Version 6
        Apple UFS       HPFS            swap            Version 7
        boot            ISO9660         System V        vinum
        ccd             jfs             SysVBFS
Filesystem type [?] [unused]: 4.2BSD
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]:
Partition size ('$' for all remaining) [14628.9c, 35548320s, 17357.6M]: $
partition> W
Label disk [n]? y
Label written
partition> Q

The last step is to create a new filesystem on it, the -O 2 option will create a ffs2 file system:

# newfs -O 2 /dev/rsd1a
/dev/rsd1a: 17357.6MB (35548320 sectors) block size 16384, fragment size 2048
        using 94 cylinder groups of 184.66MB, 11818 blks, 22976 inodes.
super-block backups (for fsck_ffs -b #) at:
160, 378336, 756512, 1134688, 1512864, 1891040, 2269216, 2647392, 3025568, 3403744, 3781920, 4160096,
.............................................................................................................

So far that good, the disk is prepared. Next I mounted it on /temp (not /tmp):

# mkdir /temp
# mount /dev/sd1a /temp

Then I moved the content of /usr into /temp. Depending on your machine and disks that could take some time:

# cd /usr
# mv * /temp/

After all files were moved I unmounted the disk and removed the /temp directory:

# umount /temp
# rmdir /temp

Of course I had to mount /usr manually one more time:

# mount /dev/sd1a /usr

To mount the new /usr file system during booting I made an entry in /etc/fstab:

# vi /etc/fstab
...
/dev/sd1a               /usr    ffs     rw               1 1
...

To make sure that /usr gets mounted during booting I rebooted the machine:

# shutdown -r now
...

After the machine was available again I logged in and checked /usr with df:

# df -h
...
/dev/sd1a          16G       1.1G        14G   7% /usr
...

Perfect!

1 comment:

  1. It might be a good idea to note that this should only be done in single user mode. Bad things otherwise...

    ReplyDelete