Linux系统磁盘管理
fdisk -l ##真实存在的设备(不一定是系统识别的)
cat /proc/partitions ##系统识别的设备
blkid ##系统
linux系统中的磁盘管理 一.本地存储设备的识别
二.设备的挂载和卸载 1.设备名称 /dev/xdx ##/dev/hd0 /dev/hd1 /dex/sda /devsda1 /dev/sr0 ##光驱 /dev/mapper/* ##虚拟设备(用软件模拟出来的) 2.设备的挂载
3.解决设备正忙问题 [root@foundation14 kiosk]# umount /mnt umount: /mnt: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) 解决方法1: lsof /mnt [root@foundation14 kiosk]# lsof /mnt lsof: WARNING: can’t stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 6504 root cwd DIR 8,17 16384 1 /mnt kill -9 6504 umount /mnt 解决方法2: fuser -vm /mnt ##查看 fuser -kvm /mnt ##查看并结束 [root@foundation14 kiosk]# fuser -kvm /mnt USER PID ACCESS COMMAND /mnt: root kernel mount /mnt root 4742 …c… bash root 6504 …c… bash 3.磁盘分区 (1)fdisk -l (2)fdisk /dev/vdb m a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition ##删除 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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 ##修改分区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): n ##新建 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p ##主分区 Partition number (1-4, default 1): ##用户id默认 First sector (2048-20971519, default 2048): ##分区起始 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M ##分区大小 Partition 1 of type Linux and of size 500 MiB is set Command (m for help): p ##显示信息 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 Disk label type: dos Disk identifier: 0xbf29103c Device Boot Start End Blocks Id System /dev/vdb1 2048 1026047 512000 83 Linux ##当系统已经有三个主分区时 Command (m for help): n Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): Using default response e Selected partition 4 First sector (3074048-20971519, default 3074048): Using default value 3074048 Last sector, +sectors or +size{K,M,G} (3074048-20971519, default 20971519): Using default value 20971519 Partition 4 of type Extended and of size 8.5 GiB is set ##把所有剩余空间都给扩展分区 Command (m for help): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 Disk label type: dos Disk identifier: 0xbf29103c Device Boot Start End Blocks Id System /dev/vdb1 2048 1026047 512000 83 Linux /dev/vdb2 1026048 2050047 512000 83 Linux /dev/vdb3 2050048 3074047 512000 83 Linux /dev/vdb4 3074048 20971519 8948736 5 Extended 四.给设备安装文件系统 mkfs.xfs /dev/vdb1 mount /dev/vdb1 /mnt vim /etc/fstab 设备 挂载点 文件系统 挂载参数 是否备份 是否检测 /dev/vdb1 /mnt xfs defaults 0 0 mount -a 五.swap分区管理 1.swap分区建立 1.划分分区并设定分区标签为82 Command (m for help): n All primary partitions are in use Adding logical partition 5 First sector (3076096-20971519, default 3076096): Using default value 3076096 Last sector, +sectors or +size{K,M,G} (3076096-20971519, default 20971519): +500M Partition 5 of type Linux and of size 500 MiB is set Command (m for help): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 Disk label type: dos Disk identifier: 0xbf29103c Device Boot Start End Blocks Id System /dev/vdb1 2048 1026047 512000 83 Linux /dev/vdb2 1026048 2050047 512000 83 Linux /dev/vdb3 2050048 3074047 512000 83 Linux /dev/vdb4 3074048 20971519 8948736 5 Extended /dev/vdb5 3076096 4100095 512000 83 Linux Command (m for help): t Partition number (1-5, default 5): 5 Hex code (type L to list all codes): L … Command (m for help): p Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 Disk label type: dos Disk identifier: 0xbf29103c Device Boot Start End Blocks Id System /dev/vdb1 2048 1026047 512000 83 Linux /dev/vdb2 1026048 2050047 512000 83 Linux /dev/vdb3 2050048 3074047 512000 83 Linux /dev/vdb4 3074048 20971519 8948736 5 Extended /dev/vdb5 3076096 4100095 512000 82 Linux swap / Solaris 2.手动重新检测分区 partprobe 3.格式化 mkswap /dev/vdb6 [root@localhost ~]# mkswap /dev/vdb5 Setting up swapspace version 1, size = 511996 KiB no label, UUID=33ba8e90-4b6d-4007-96c6-36cdde144f8e 4.挂载 swapon -a /dev/vdb6 5.查看是否挂载成功 swapon -s 2.swap分区的删除 swapoff /dev/fstab swapon -s 六.配额 1.分区,格式化 2.建立挂载目录 mkdir /public 3.挂载 mount -o usrquota /dev/vdb6 /public 4.配额 edquota -u student 5.设为开机自动挂载 vim /etc/fstab 6.测试 dd if=/dev/zero of=/public/studentfile bs=1M count=500 六.磁盘加密 cryptsetup luksFormat /dev/vdb7 YES cryptsetup open /dev/vdb7 westos mkfs.xfs /dev/mapper/westos mount /dev/mapper/westos /mnt touch file{1…10} umount /mnt cryptsetup close westos cryptsetup open /dev/vdb7 linux mount /dev/mapper/linux /mnt (编辑:92站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |