Linux文件系统管理,重新扫描总线

 

一、文件系统构成

Centos 新扩张硬盘现在,系统不能够自动进行识别。

 

 

  /usr/bin、/bin:存放全体用户能够实践的吩咐

  1. 鉴于不明了新增添硬盘挂载的任务,能够先查看现存硬盘挂载的适配器。

    [root@localhost ~]# ls -l /sys/block/sda
    lrwxrwxrwx. 1 root root 0 Jun 15 11:47 /sys/block/sda -> ../devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda

 

 

  /usr/sbin、/sbin:存放唯有root能够实行的授命

  1. 发掘正在磁盘挂载到host32,能够尝尝接纳上边命令,重新扫描host3二音信

    echo “- – -” > /sys/class/scsi_host/host32/scan

 

 

  /home:用户缺省宿主目录  www.贰cto.com  

  1. 奉行到位后,dmesg能够查看到新增加硬盘新闻。

    [ 620.865767] scsi 32:0:1:0: Direct-Access VMware, VMware Virtual S 1.0 PQ: 0 ANSI: 2
    [ 620.865800] scsi target32:0:1: Beginning Domain Validation
    [ 620.866413] scsi target32:0:1: Domain Validation skipping write tests
    [ 620.866416] scsi target32:0:1: Ending Domain Validation
    [ 620.866450] scsi target32:0:1: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
    [ 620.870284] sd 32:0:1:0: Attached scsi generic sg2 type 0
    [ 620.870360] sd 32:0:1:0: [sdb] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
    [ 620.870408] sd 32:0:1:0: [sdb] Write Protect is off
    [ 620.870410] sd 32:0:1:0: [sdb] Mode Sense: 61 00 00 00
    [ 620.870734] sd 32:0:1:0: [sdb] Cache data unavailable
    [ 620.870736] sd 32:0:1:0: [sdb] Assuming drive cache: write through
    [ 620.874775] sd 32:0:1:0: [sdb] Cache data unavailable
    [ 620.874779] sd 32:0:1:0: [sdb] Assuming drive cache: write through
    [ 620.875859] sdb: unknown partition table
    [ 620.876069] sd 32:0:1:0: [sdb] Cache data unavailable
    [ 620.876071] sd 32:0:1:0: [sdb] Assuming drive cache: write through
    [ 620.876123] sd 32:0:1:0: [sdb] Attached SCSI disk

 

 

  /proc:虚拟文件系统,存放当前内部存储器镜像

  1. fdisk -l 能够窥见心中的/dev/sdb消息

    Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes

 

 

  /dev:存放设施文件

  1. 近年来就足以选拔fdisk -l 恐怕parted命令进行分区操作了。

 

 

  /lib:存放系统程序运转所需的共享库

 从总线删除/dev/sdb硬盘(删除后,不能够分辨/dev/sdb硬盘了)

 

echo 1 > /sys/block/sdb/device/delete

  /lost+found:存放一些系统出错的反省结果

 

 

  /tmp:存放一时文件

 

  /etc:系统布局文件

 

  /var:包括日常产生变动的公文,如邮件、日志文化、陈设职分等

 

  /usr:存放全体命令、库、手册页等  www.2cto.com  

 

  /mnt:暂且文件系统的安装点

 

  /boot:内核文件及自举程序文件保留地方

 

  1)常用命令

 

    查看分区意况:df

 

 

[[email protected]
~]# df

文件系统                 一K-块      已用      可用 已用% 挂载点

/dev/sda1              5039616    623020   4160596  14% /

tmpfs                   515396         0    515396   0% /dev/shm

/dev/sda5              1007896     44760    911936   5% /home

/dev/sda2              5039616   1737788   3045828  37% /usr

[[email protected]
~]# df -h

文件系统              体量  已用  可用 已用%% 挂载点

/dev/sda1             4.9G  609M  4.0G  14% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda5             985M   44M  891M   5% /home

/dev/sda2             4.9G  1.7G  3.0G  37% /usr

[[email protected]
~]# df -m

文件系统                 1M-块      已用      可用 已用% 挂载点

/dev/sda1                 4922       609      4064  14% /

tmpfs                      504         0       504   0% /dev/shm

/dev/sda5                  985        44       891   5% /home

/dev/sda2                 4922      1698      2975  37% /usr

[[email protected]
~]# 

 

    查看文件、目录大小:du

 

 

[[email protected]
~]# du -h /etc/services

628K    /etc/services

[[email protected]
~]# du -sh /etc

27M     /etc

[[email protected]
~]# 

 

    检验修复文件系统:fsck、e二fsck(单用户格局实行)

 

    判定文件类型:file

 

  贰)使用光驱

 

    挂载光驱

 

[[email protected]
~]# mount /dev/cdrom /mnt/cdrom

mount: block device /dev/sr0 is write-protected, mounting read-only

[[email protected]
~]#

    尽管未有/mnt/cdrom目录,先手工业创立该目录。

 

    查看挂载信息

 

 

[[email protected]
~]# df -h

文件系统              容积  已用  可用 已用%% 挂载点

/dev/sda1             4.9G  609M  4.0G  14% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda5             985M   44M  891M   5% /home

/dev/sda2             4.9G  1.7G  3.0G  37% /usr

/dev/sr0              3.5G  3.5G     0 100% /mnt/cdrom

[[email protected]
~]#

网赌十大信誉的平台, 

    卸载光驱

 

[[email protected]
~]# umount /mnt/cdrom

    或者

 

[[email protected]
~]# eject

  三)增加磁盘或分区

 

    以往用虚拟机增多了壹块硬盘sdb,重启系统后翻看新添长的硬盘是或不是被辨认:

 

 

[[email protected]
~]# dmesg | grep sdb

sd 2:0:1:0: [sdb] 10485760 512-byte logical blocks: (5.36 GB/5.00 GiB)

sd 2:0:1:0: [sdb] Write Protect is off

sd 2:0:1:0: [sdb] Mode Sense: 61 00 00 00

sd 2:0:1:0: [sdb] Cache data unavailable

sd 2:0:1:0: [sdb] Assuming drive cache: write through

sd 2:0:1:0: [sdb] Cache data unavailable

sd 2:0:1:0: [sdb] Assuming drive cache: write through

 sdb:

sd 2:0:1:0: [sdb] Cache data unavailable

sd 2:0:1:0: [sdb] Assuming drive cache: write through

sd 2:0:1:0: [sdb] Attached SCSI disk

[[email protected]
~]#

 

    3.1)分区:fdisk

 

      查看新加上的硬盘新闻

 

 

[[email protected]
~]# fdisk -l /dev/sdb

 

Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

 

[[email protected]
~]# 

 

      对硬盘举办分区

 

      fdisk  /dev/sdb

 

      常用命令:

 

      m  帮助

 

      p  呈现分区表

 

      n  增加新分区

 

      t  改变分区文件系统类型

 

      d  删除分区

 

      w  保存退出

 

      q  不保留退出

 

 

[[email protected]
~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF
disklabel

Building a new DOS disklabel with disk identifier 0x118c05b0.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won’t be recoverable.

 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by
w(rite)

 

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

         switch off the mode (command ‘c’) and change display units to

         sectors (command ‘u’).

 

Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition’s system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

 

Command (m for help): p

 

    三.二)创立文件系统(格式化):mkfs

 

 

[[email protected]
~]# mkfs.ext4 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=40玖陆 (log=二)

Stride=0 blocks, Stripe width=0 blocks

160960 inodes, 642592 blocks

32129 blocks (5.00%) reserved for the super user

首先个数据块=0

Maximum filesystem blocks=658505728

20 block groups

32768 blocks per group, 32768 fragments per group

8048 inodes per group

Superblock backups stored on blocks: 

        32768, 98304, 163840, 229376, 294912

 

正在写入inode表: 完毕                            

Creating journal (16384 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

 

This filesystem will be automatically checked every 31 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[[email protected]
~]# 

 

    叁.三)尝试挂载:mount

 

      把/dev/sdb1挂载到/web空目录

 

      先创建/web目录

 

[[email protected]
~]# mkdir /web

      挂载

 

[[email protected]
~]# mount /dev/sdb1 /web

      查看是或不是挂载成功

 

 

[[email protected]
~]# df -h

文件系统              体量  已用  可用 已用%% 挂载点

/dev/sda1             4.9G  609M  4.0G  14% /

tmpfs                 504M     0  504M   0% /dev/shm

/dev/sda5             985M   44M  891M   5% /home

/dev/sda2             4.9G  1.7G  3.0G  37% /usr

/dev/sdb1             2.5G   68M  2.3G   3% /web

[[email protected]
~]# 

 

     叁.肆)写入配置文件:/etc/fstab

 

 

[[email protected]
~]# more /etc/fstab

 

#

# /etc/fstab

# Created by anaconda on Wed Dec  5 04:36:40 2012

#

# Accessible filesystems, by reference, are maintained under
‘/dev/disk’

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more
info

#

UUID=1782302e-7804-4b32-9e59-04aac3651342 /                       ext4  
 defaul

ts        1 1

UUID=e5ec7966-8a82-438a-b929-962d375bb1e5 /home                   ext4  
 defaul

ts        1 2

UUID=926c0281-29b0-4ab0-9483-c1066462d508 /usr                    ext4  
 defaul

ts        1 2

UUID=ac208436-48b7-4bfa-b25d-758af1ea9019 swap                    swap  
 defaul

ts        0 0

tmpfs                   /dev/shm                tmpfs   defaults      
 0 0

devpts                  /dev/pts                devpts  gid=5,mode=620
 0 0

sysfs                   /sys                    sysfs   defaults      
 0 0

proc                    /proc                   proc    defaults      
 0 0

[[email protected]
~]#

 

    由以下一些组成

 

    物理分区名/卷标  挂载点  文件系统  缺省设置  是或不是检查评定  检查实验顺序

 

      proc      /proc   proc    defaults  1/0    0/1/2

 

    把我们刚新加的分区配置进去,让系统指导的时候自动加载 

 

 

[[email protected]
~]# vi /etc/fstab

 

 

#

# /etc/fstab

# Created by anaconda on Wed Dec  5 04:36:40 2012

#

# Accessible filesystems, by reference, are maintained under
‘/dev/disk’

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more
info

#

UUID=1782302e-7804-4b32-9e59-04aac3651342 /                       ext4  
 defaults        1 1

UUID=e5ec7966-8a82-438a-b929-962d375bb1e5 /home                   ext4  
 defaults        1 2

UUID=926c0281-29b0-4ab0-9483-c1066462d508 /usr                    ext4  
 defaults        1 2

UUID=ac208436-48b7-4bfa-b25d-758af1ea9019 swap                    swap  
 defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults      
 0 0

devpts                  /dev/pts                devpts  gid=5,mode=620
 0 0

sysfs                   /sys                    sysfs   defaults      
 0 0

proc                    /proc                   proc    defaults      
 0 0

/dev/sdb1               /web                    ext4    defaults      
 1 2

~

~

“/etc/fstab” 17L, 936C written

[[email protected]
~]#

 

 

 二、磁盘分配的定额

 

  一)开启分区分配的定额功效

 

    一.一)编辑/etc/fstab文件,在挂载属性上助长标记:usrquota(用户分配的定额)或grpquota(用户组分配的定额)

 

    假使/home那几个分区,限制每种用户只好选拔50M的空中:

 

    加载用户分配的定额设置

 

 

[[email protected]
~]# vi /etc/fstab

 

 

#

# /etc/fstab

# Created by anaconda on Wed Dec  5 04:36:40 2012

#

# Accessible filesystems, by reference, are maintained under
‘/dev/disk’

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more
info

#

UUID=1782302e-7804-4b32-9e59-04aac3651342 /                       ext4  
 defaults        1 1

UUID=e5ec7966-8a82-438a-b929-962d375bb1e5 /home                   ext4  
 defaults        1 2

UUID=926c0281-29b0-4ab0-9483-c1066462d508 /usr                    ext4  
 defaults        1 2

UUID=ac208436-48b7-4bfa-b25d-758af1ea9019 swap                    swap  
 defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults      
 0 0

devpts                  /dev/pts                devpts  gid=5,mode=620
 0 0

sysfs                   /sys                    sysfs   defaults      
 0 0

proc                    /proc                   proc    defaults      
 0 0

/dev/sdb1               /web                    ext4  
 defaults,usrquota       1 2

~

“/etc/fstab” 17L, 945C written

[[email protected]
~]#

 

    目前张开分区分配的定额功用

 

[[email protected]
~]# mount -o remount,usrquota /home

    一.2)创立分配的定额数据库:quotacheck -cvu /home

 

 

[[email protected]
~]# quotacheck -cvu /web

quotacheck: Mountpoint (or device) /web not found or has no quota
enabled.

quotacheck: Cannot find filesystem to check or filesystem not mounted
with quota option.

[[email protected]
~]# quotacheck -cvu /home

quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running
quotacheck after an unclean shutdown.

quotacheck: Scanning /dev/sda5 [/home] done

quotacheck: Cannot stat old user quota file: 未有分外文件或目录

quotacheck: Old group file not found. Usage will not be substracted.

quotacheck: Checked 387 directories and 1626 files

quotacheck: Old file not found.

[[email protected]
~]# 

 

    /home下已经有了aquota.user那个文件

 

 

[[email protected]
~]# ls /home

aquota.user  lixunxuan   luixaofeng  luxh01  luxh03  luxh05      yekai

cnblogs001   lost+found  luxh        luxh02  luxh04  luxiaofeng

[[email protected]
~]# 

 

    一.三)运营分配的定额作用

 

[[email protected]
~]# quotaon /home

[[email protected]
~]#

    假如要关闭分配的定额功用

 

[[email protected]
~]# quotaoff /home

[[email protected]
~]#

    壹.四)编辑用户分配的定额

 

      edquota 用户名

 

 

[[email protected]
~]# edquota luxh01

 

Disk quotas for user luxh01 (uid 1001):

  Filesystem                   blocks       soft       hard     inodes  
  soft     hard

  /dev/sda5                         8          0       51200          2
       0        0

~

 

    blocks soft  hard 限制用户能选用的长空大小

 

    inodes  soft  hard  限制用户能创立多少个公文

 

    查看luxh0一用户的分配的定额音信

 

 

[[email protected]
~]# quota luxh01

Disk quotas for user luxh01 (uid 1001): 

     Filesystem  blocks   quota   limit   grace   files   quota   limit
  grace

      /dev/sda5       8       0   51200               2       0       0
       

[[email protected]
~]# 

 

   查看全体用户的分配的定额音信

 

 

[[email protected]
~]# repquota /home

*** Report for user quotas on device /dev/sda5

Block grace time: 7days; Inode grace time: 7days

                        Block limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace


root      —   26936       0       0           1964     0     0       

luxh      —       8       0       0              2     0     0       

lihuai    —      36       0       0              9     0     0       

luixaofeng —      32       0       0              8     0     0       

lixunxuan —      32       0       0              8     0     0       

luxiaofeng —      32       0       0              8     0     0       

luxh01    —       8       0   51200              2     0     0       

luxh02    —       4       0       0              1     0     0       

luxh03    —       4       0       0              1     0     0       

luxh04    —       4       0       0              1     0     0       

luxh05    —       4       0       0              1     0     0       

cnblogs001 —      32       0       0              8     0     0       

 

 

[[email protected]
~]# 

 

 

 

    复制用户分配的定额音信:

 

    edquota -p 模板用户 复制用户壹 复制用户二

 

[[email protected]
~]# edquota -p luxh01 luxh02 luxh03

 

 

3、备份

 

  一)cp命令备份比如

 

    备份目录

 

    cp -景逸SUVpu 备份目录 目的目录

 

      -p  保持备份目录及文件属性

 

      -u  增量备份   

 

[[email protected]
~]# cp -p /etc/inittab /backup/inittab_20130103.bak

    远程备份能够用scp

 

  贰)tar命令打包备份

 

    备份/etc目录,能够而且备份三个目录

 

[[email protected]
~]# tar -zcf /backup/etc_20130103.tar.gz /etc

    还原/etc目录,暗中认可还原到打包文件源目录

 

[[email protected]
~]# tar -zxf /backup/etc_20130103.tar.gz

    只回复钦定的公文,如/etc/passwd,注意,在命令中要写成etc/passwd,解压到当前目录。

 

[[email protected]
~]# tar -zvf /backup/etc_20130103.tar.gz etc/passwd
 

/usr/bin、/bin:存放全数用户能够举行的通令
/usr/sbin、/sbin:存放唯有root能够推行的吩咐 /home:用户缺省宿主目录
www.贰cto…

Post Author: admin

发表评论

电子邮件地址不会被公开。 必填项已用*标注