Solaris更改文件系统大小

来源:互联网 发布:jsp中使用javascript 编辑:程序博客网 时间:2024/05/16 20:27

        作为系统管理员的我们,经常遇到要增加或缩小某文件系统的需求。对于Unix上的主流OS以及linux来说,动态逻辑卷管理(LVM)能够很好的帮我们完成这个工作。但是对于不支持LVMSolaris系统,只能用笨办法实现了。

   假设一个工作场景,我需要在服务器硬盘上新增一个独立的文件系统,但是硬盘上已经没有可分配的自由空间。可选择的一种解决办法就是缩小已存在的某个文件系统,挤出一些自由空间。

 

硬盘现在已有三个文件系统(“/”,“/usr”,“/export/home”):

# df -h

Filesystem size used avail capacity Mounted on

/dev/dsk/c0d0s0 5.8G 3.8G 2.0G 66% /

/dev/dsk/c0d0s3 6G 4G 2.0G 66% /usr

/dev/dsk/c0d0s7 12G 12M 11G 1% /export/home

其中“/export/home”的容量最大,但已使用空间最少,选择缩小该文件系统以挤出自由空间。

 

以下是缩小文件系统步骤:

 

1、备份文件系统内容

# tar cvf /home.tar /export/home

 

2、卸载文件系统

# umount /export/home

 

3、修改/etc/vfstab,注释该文件系统项

# vi /etc/vfstab

#device device mount FS fsck mount mount

#to mount to fsck point type pass at boot options

#

#/dev/dsk/c0d0s7 /dev/rdsk/c0d0s7 /export/home ufs 2 yes -

 

4、用format缩小文件系统大小

format分区使用;
分区与格式化一定要熟练掌握format工具,现在以c0t11d0盘为例做一说明:执行format命令后结果显示如下:
Searching for disks...done
AVAILABLE DISK SELECTIONS:
       0. c0t10d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>  lzm
          /sbus@3,0/SUNW,fas@3,8800000/sd@a,0
       1. c0t11d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>
          /sbus@3,0/SUNW,fas@3,8800000/sd@b,0
       2. c0t12d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>
          /sbus@3,0/SUNW,fas@3,8800000/sd@c,0
       3. c0t13d0 <SUN18G cyl 7506 alt 2 hd 19 sec 248>
          /sbus@3,0/SUNW,fas@3,8800000/sd@d,0


 

Specify disk (enter its number):
选择1后敲回车,显示结果如下:
Specify disk (enter its number): 1
selecting c0t11d0
[disk formatted]
FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format>
我们可以先查看下目前的分区情况,输入“p”后回车,显示结果如下:
format> p
PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        !<cmd> - execute <cmd>, then return
        quit
partition>
在此处呈现的内容为可以选择的分区名称,选择0-7可以单个查看分区情况,另外还可以进行分区名称更改、命名、标记等操作,当输入“print”后可以查看整块盘的分区情况,如下:
partition> print 或者 p
Current partition table (original):
Total disk cylinders available: 7506 + 2 (reserved cylinders)
Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm       0 -   57      133.45MB    (58/0/0)     273296
  1       swap    wu      58 -  115      133.45MB    (58/0/0)     273296
  2     backup    wu       0 - 7505       16.86GB    (7506/0/0) 35368272
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6        usr    wm     116 - 4606       10.09GB    (4491/0/0) 21161592
  7 unassigned    wm    4607 - 7455        6.40GB    (2849/0/0) 13424488
partition>
该处呈现出来的是整块盘分区情况,需要注意的几点:1、tag在此处一般不能修改(怎么修改还没有研究出来);2、明确该块盘的大小,即size列;3、仔细研究下Cylinders列,该类呈现出的是该盘的柱面使用情况,其中2为整块盘的柱面区间数据,其他分区为本分区的占用情况,因此我们可以根据与之对应的关系来查看本块盘是否还有剩余空间可以使用;从以上的结果我们可以看出仍有7456-7505没有使用;
上面介绍的情况为确定磁盘信息,接下来着手进行分区操作,基于上面的呈现结果我们可以有两种操作:
1、扩大或缩小某一分区的大小;
在“partition> ”提示符下,输入分区号后回车,呈现结果如下:
partition> 6
Part      Tag    Flag     Cylinders        Size            Blocks
  6        usr    wm     116 - 4606       10.09GB    (4491/0/0) 21161592
Enter partition id tag[usr]:
该环节要求输入tag,可以直接回车,接下来分别要求输入的信息为:许可权限、起始柱面以及大小,输入所需大小后即可完成分区操作;在输入大小时分别以b、c、mb、gb为单位(注意:单位为小写);全部选择完毕后回车呈现结果如下:

partition> 6
Part      Tag    Flag     Cylinders        Size            Blocks
  6        usr    wm     116 - 4606       10.09GB    (4491/0/0) 21161592
Enter partition id tag[usr]:
Enter partition permission flags[wm]:
Enter new starting cyl[116]:
Enter partition size[21161592b, 4491c, 10332.81mb, 10.09gb]: 10.09gb

partition> modify 
partition>label 
partition>quit 
format>save 
到此分区操作尚未完成,需要在partition下命名,输入名称后仍然需要label下,之后输入“q”退出到“format”下执行“save”以便保存修改;到此位置扩大或缩小分区结束;

2、重新进行分区操作;
重新分区需要在“partition”下执行modify命令,结果如下:
partition> modify
Select partitioning base:
        0. Current partition table (s6)
        1. All Free Hog
Choose base (enter number) [0]?
此环节可以进行对s6进行重新分配,亦可以对整块盘重新划分;(现以s6为例)直接回车后显示如下:
Choose base (enter number) [0]?
Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm       0 -   57      133.45MB    (58/0/0)     273296
  1       swap    wu      58 -  115      133.45MB    (58/0/0)     273296
  2     backup    wu       0 - 7505       16.86GB    (7506/0/0) 35368272
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6        usr    wm     116 - 4606       10.09GB    (4491/0/0) 21161592
  7 unassigned    wm    4607 - 7455        6.40GB    (2849/0/0) 13424488
Do you wish to continue creating a new partition
table based on above table[yes]?
默认为yes,回车后提示从0-7(不包含分区6的提示)的所需大小,执行到此可以进行对每个分区的数据重新配置,按顺序执行后结果如下:
Do you wish to continue creating a new partition
table based on above table[yes]?
Free Hog partition[6]?
Enter size of partition '0' [273296b, 58c, 133.45mb, 0.13gb]: 0.15gb
Enter size of partition '1' [273296b, 58c, 133.45mb, 0.13gb]:
Enter size of partition '3' [0b, 0c, 0.00mb, 0.00gb]:
Enter size of partition '4' [0b, 0c, 0.00mb, 0.00gb]:
Enter size of partition '5' [0b, 0c, 0.00mb, 0.00gb]:
Enter size of partition '7' [13424488b, 2849c, 6554.93mb, 6.40gb]:
Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm       0 -   66      154.15MB    (67/0/0)     315704
  1       swap    wu      67 -  124      133.45MB    (58/0/0)     273296
  2     backup    wu       0 - 7505       16.86GB    (7506/0/0) 35368272
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6        usr    wm     125 - 4606       10.07GB    (4482/0/0) 21119184
  7 unassigned    wm    4607 - 7455        6.40GB    (2849/0/0) 13424488
Okay to make this the current partition table[yes]?
在提示符下回车,确认;输入“n”回车取消操作;注意标记与保存;
操作到此处分区已经完成;
3、逻辑格式化,也就是通常所说的高级格式化(High-Level Formatting,HLF或创建文件系统)
创建文件系统为比较简单的操作:可以直接执行命令:newfs  /dev/rdsk/c0t11d0s6即可(c0t11d0s6为新分区)
4、挂接文件系统:
执行命令mount:mount /dev/dsk/c0t11d0s6 /export/home/temp 此处要写绝对路径,并且要注意如果是做了镜像的磁盘一定要写/dev/md/dsk下面的设备,否则会造成镜像数据不同步;
以上描述为试验过的结果记录,如有需要可以按照说明步骤进行使用即可,到此为止分区与格式化均已描述完毕。
 

 

 

5、用newfs重新格式化文件系统

#cd /dev/dsk/

# newfs c0d0s7

newfs: construct a new file system /dev/rdsk/c0d0s7: (y/n)? y

Warning: 240 sector(s) in last cylinder unallocated

/dev/rdsk/c0d0s7: 12594960 sectors in 2050 cylinders of 48 tracks, 128 sectors

6149.9MB in 129 cyl groups (16 c/g, 48.00MB/g, 5824 i/g)

缩小后的文件系统是6G,释放了大约6G的自由空间。

 

6、恢复/etc/vfstab文件系统项

# vi /etc/vfstab

#device device mount FS fsck mount mount

#to mount to fsck point type pass at boot options

#

/dev/dsk/c0d0s7 /dev/rdsk/c0d0s7 /export/home ufs 2 yes -

将文件系统前的“#”注释符去掉

 

7、重新挂载文件系统

# mount     /export/home

 

8、将备份恢复到文件系统下

# tar   xvf /home.tar

 

9、既然有了6G的自由空间,剩下的事情就好办了,我就不赘述了。

 

 

增加文件系统大小的过程跟缩小基本相同,都遵循这个基本思路:

备份文件系统内容 -->卸载文件系统 -->更改文件系统大小 -->重新格式化文件系统  --> 重新挂载 -->恢复原来的备份到文件系统。

 

原创粉丝点击