Handy howto's for filesystem maintenance (SUN) ============================================== 2001,2007 frank4dd Howto redesign the /(root) filesystem with an additional harddisk on SUN ------------------------------------------------------------------------ # partition the second hardrive, create filesystem(s), and mount: format /dev/dsk/c1t1d0s0 newfs /dev/rdsk/c1t1d0s0 (s3) etc mount /dev/dsk/c1t1d0s0 /mnt # copy the contents of the current /(root) filesystem over to the secondary disk # using ufsdump/restore because it works across filesystems with different # sizes. dd is a byte copy and would work only with slices of the same size, # and tar would not properly copy /proc, /tmp and /dev device files. cp doesn't # work, either :) ufsdump 0f - /dev/rdsk/c1t0d0s0 | (cd /mnt; ufsrestore xf -) # run the installboot command on the target installboot /usr/platform//lib/fs/ufs /dev/rdsk/c1t1d0s0 # or installboot /usr/platform/`uname -i`/lib/fs/ufs /dev/rdsk/c1t1d0s0 # 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, boot from second disk (boot disk1), setup backup ddd scripts and # mirror configuration back to the primary boot disk Howto copy a harddisk over the network with ssh: ------------------------------------------------ # make sure the partition table is identical, check with format # copy the slices dd if=/dev/rdsk/c0t1d0s0 bs=8192k | ssh user@host "dd of=/dev/rdsk/c0t2d0s0 bs=8192k" ssh user@host # attention: copy a 7GB partition took 3:30h over the net instead of 0:30h locally, try different bs # and use ssh -c blowfish - its faster then DES and 3DES fsck -y /dev/rdsk/c0t2d0s0 # clean up any inconsistencies /usr/sbin/installboot /usr/platform/'SUNW,Ultra30'/lib/fs/ufsbootblk /dev/rdsk/c0t1d0s0 mount /dev/rdsk/c0t2d0s0 /mnt # mount and see if everything is fine vi /mnt/etc/vfstab # adjust slice to scsi ID if neccessary # try to boot # important when dd'ing /(root) filesystems to another machine # with slightly different hardware (i.e. different disks, etc) # delete and/or rebuild /etc/path_to_inst 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) ------------------------------------------------ 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 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 # some numbers derived: 100% of partition sectors = 4177920 75% of partition sectors (4177920/4*3) = 3133440 50% of partition sectors (4177920/2) = 2088960 # create new filesystem 50% of the partition size 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 # Mount and check the newly created filesystem bash-3.00# mount /dev/dsk/c0d1s2 /mnt bash-3.00# df -k | grep c0d1s2 /dev/dsk/c0d1s2 982511 1041 922520 1% /mnt # create a large file (i.e. 50MB) in the new filesystem (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 # hash the large file and verify the filesystem space 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 # Now lets resize the filesystem mounted in /mnt to 75% partition size 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 # check the new filesystem space, verify our testfile 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 # Lets increase the used space a bit 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 # Finally, lets grow the filesystem to full partition capacity 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 ash-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/testfile # Apparently, growfs is a script that uses mkfs_ufs with undocumented options -G and -M bash-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" ...