Howto redesign the root filesystem with a additional disk
Prepare the second disk
First, we partition the second hardrive with the new, desired sizing and layout. Let's assume our original disk is c1t0d0 and our new disk is c1t1d0, we use the command format /dev/dsk/c1t1d0. Then we create the filesystem(s), for example on slice s0 with newfs /dev/rdsk/c1t1d0s0. Finally, we mount the new filesystem with mount /dev/dsk/c1t1d0s0 /mnt.
Copy root filesystem data to the new disk
Next, we copy the contents of the current /(root) filesystem over to the secondary disk using ufsdump/restore commands. These commands work across filesystems with different sizes. The 'dd' command we usually prefer is a byte copy and would work only with slices of the same size, and the 'tar' command would not properly copy /proc, /tmp and /dev device files. Of course, 'cp' doesn't work, either :) In our example, we use the command ufsdump 0f - /dev/rdsk/c1t0d0s0 | (cd /mnt; ufsrestore xf -).
Make the new disk bootable
Now we need to make our new disk c1t1d0 bootable by using the installboot command: 'installboot /usr/platform/
To do that, we edit /mnt/etc/vfstab on the secondary harddisk to reflect changes: vi /mnt/etc/vfstab and change /dev/(r)dsk/c1t0d0s0 to /dev/(r)/dsk/c1t1d0s0'.
Finally, we shut down and boot from the new disk (boot disk1). We need to remember to adjust backup scripts if they use 'dd' and refer to disk devices. If we use Solstice Disksuite to mirror disks, now we can rebuilt the root mirror from scratch by overwriting the old disk.
Before we start copying, make sure the partition size is identical, check with the partition table 'format' on both sides. Then, we copy the slices with this example command: dd if=/dev/rdsk/c0t1d0s0 bs=8192k | ssh user@host "dd of=/dev/rdsk/c0t2d0s0 bs=8192k". Depending on network and system speed, copying a 7GB partition took 3:30h over the net compared to 0:30h locally. We can speed up the transfer by explicitly using a faster encryption algorythm with ssh -c blowfish - its faster then DES and 3DES (default).
If we have been dd'ing the /(root) filesystems to another machine with slightly different hardware (i.e. different disks, etc), it is important to delete and/or rebuild the directory /etc/path_to_inst and reboot the system with ok>boot -ar.
The size of UFS filesystems can be increased on the fly with growfs (mkfs_ufs). In order to do that, the partition must have free cylinders, either by intentionally leaving free space, or by growing the volume/partition. UFS file systems cannot shrink.
In Example 1 I am using a 2 GB IDE disk with a Solaris partition table, create a 1 GB filesystem of half the 2 GB partition size and then grow it to its full capacity.
# get sector information from partition table
Set the boot device to the new disk
Re-boot into the new disk
Howto copy a harddisk over the network with ssh
Copy by using 'dd'
Afterwork
ok>boot -ar
Press enter to select default values for the questions asked during booting
and select yes to rebuild /etc/path_to_install
The /etc/path_to_inst on your system does not exist or is empty. Do you want to
rebuild this file [n]? y
system will continue booting after rebuilding the file.Howto grow a UFS filesystem on the fly (mounted)
Introduction
In order to demonstrate growth, I need to generate a filesystem that does not use up all partition space. I calcualte the filesystem size through sectors.
bash-3.00# prtvtoc /dev/rdsk/c0d1s2
* /dev/rdsk/c0d1s2 partition map
...
*
* First Sector Last
* Partition Tag Flags Sector Count Sector Mount Directory
2 5 01 0 4177920 4177919
8 1 01 0 4096 4095
9 9 00 4096 8192 12287
Now I can create a new filesystem that is 50% of the partition size:
Mount and check the newly created filesystem
bash-3.00# newfs -s 2088960 /dev/rdsk/c0d1s2
newfs: /dev/rdsk/c0d1s2 last mounted as /mnt
newfs: construct a new file system /dev/rdsk/c0d1s2: (y/n)? y
/dev/rdsk/c0d1s2: 2088960 sectors in 510 cylinders of 128 tracks, 32
sectors 1020.0MB in 32 cyl groups (16 c/g, 32.00MB/g, 15360 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 65600, 131168, 196736, 262304, 327872, 393440, 459008, 524576, 590144,
1442528, 1508096, 1573664, 1639232, 1704800, 1770368, 1835936, 1901504,
1967072, 2032640
Next, we create a large file (i.e. 50MB) in the new filesystem to use it as a demonstration for file data being untouched.
bash-3.00# mount /dev/dsk/c0d1s2 /mnt
bash-3.00# df -k | grep c0d1s2
/dev/dsk/c0d1s2 982511 1041 922520 1% /mnt
TO verify the file, we hash it with md5 and verify the filesystem space before growth. If md5sum is missing, it is part of the GNU coreutils available on the Solaris Companion CD, i.e. install bash-3.00# pkgadd -d /cdrom/s10_1106_software_companion/Solaris_Software_Companion/Solaris_i386/Packages SFWcoreu.
bash-3.00# dd if=/dev/random of=/mnt/testfile count=100000
100000+0 records in
100000+0 records out
bash-3.00# ls -l /mnt
total 100096
drwx------ 2 root root 8192 May 7 11:49 lost+found
-rw-r--r-- 1 root root 51200000 May 7 13:10 testfile
Now lets resize the filesystem mounted in /mnt to 75% partition size
bash-3.00# /opt/sfw/bin/md5sum /mnt/testfile
bf0c6b21ad6e3609be00bec7f0801f83 /mnt/testfile
bash-3.00# df -k /mnt
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d1s2 982511 51081 872480 6% /mnt
Check the new filesystem space, verify our testfile
bash-3.00# growfs -M /mnt -s 3133440 /dev/rdsk/c0d1s2
/dev/rdsk/c0d1s2: 3133440 sectors in 765 cylinders of 128 tracks, 32
sectors 1530.0MB in 48 cyl groups (16 c/g, 32.00MB/g, 15360 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 65600, 131168, 196736, 262304, 327872, 393440, 459008, 524576, 590144,
2491616, 2557184, 2622752, 2688320, 2753888, 2819456, 2885024, 2950592,
3016160, 3081728
Lets increase the used space a bit
bash-3.00# df -k /mnt
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d1s2 1473775 51593 1363232 4% /mnt
bash-3.00# ls -l /mnt/testfile
-rw-r--r-- 1 root root 51200000 May 7 13:10 /mnt/testfile
bash-3.00# /opt/sfw/bin/md5sum /mnt/testfile
bf0c6b21ad6e3609be00bec7f0801f83 /mnt/testfile
Finally, lets grow the filesystem to full partition capacity
bash-3.00# cp testfile testfile2; cp testfile testfile3;
cp testfile testfile4
bash-3.00# df -k /mnt
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d1s2 1473775 201713 1213112 15% /mnt
Apparently, growfs is a script that uses mkfs_ufs with undocumented options -G and -M
bash-3.00# growfs -M /mnt /dev/rdsk/c0d1s2
/dev/rdsk/c0d1s2: 4177920 sectors in 1020 cylinders of 128 tracks, 32
sectors 2040.0MB in 64 cyl groups (16 c/g, 32.00MB/g, 15360 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 65600, 131168, 196736, 262304, 327872, 393440, 459008, 524576, 590144,
3540704, 3606272, 3671840, 3737408, 3802976, 3868544, 3934112, 3999680,
4065248, 4130816
bash-3.00# df -k /mnt
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0d1s2 1965039 202217 1703872 11% /mnt
bash-3.00# ls -l /mnt/testfile
-rw-r--r-- 1 root root 51200000 May 7 13:10 /mnt/testfile
bash-3.00# /opt/sfw/bin/md5sum /mnt/testfile
bf0c6b21ad6e3609be00bec7f0801f83 /mnt/testfilebash-3.00# which growfs
/usr/sbin/growfs
bash-3.00# file /usr/sbin/growfs
/usr/sbin/growfs: executable shell script
bash-3.00# cat /usr/sbin/growfs
#!/bin/sh
#
#pragma ident "@(#)growfs.sh 2.3 03/09/19 SMI"
#
# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#exec newfs -G "$@"
myname=`basename $0`
USAGE="usage: $myname [ -M mount-point ] [ newfs-options ] raw-special-device"
if [ ! "$UFS_MKFS" ]; then
UFS_MKFS="/usr/lib/fs/ufs/mkfs"
fi
verbose=""
mkfs_opts="-G"
...