首页 > 代码库 > centos 格式化硬盘并挂载,添加重启后生效

centos 格式化硬盘并挂载,添加重启后生效

[root@cloud /]# passwd更改用户 root 的密码 。新的 密码:重新输入新的 密码:passwd: 所有的身份验证令牌已经成功更新。[root@cloud /]# fdiskUsage: fdisk [options] <disk>    change partition table fdisk [options] -l <disk> list partition table(s) fdisk -s <partition>      give partition size(s) in blocksOptions: -b <size>                 sector size (512, 1024, 2048 or 4096) -c                        switch off DOS-compatible mode -h                        print help -u <size>                 give sizes in sectors instead of cylinders -v                        print version -C <number>               specify the number of cylinders -H <number>               specify the number of heads -S <number>               specify the number of sectors per track[root@cloud /]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00073ffb   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        1306     9972736   8e  Linux LVMDisk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_cloud-lv_root: 8095 MB, 8095006720 bytes255 heads, 63 sectors/track, 984 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_cloud-lv_swap: 2113 MB, 2113929216 bytes255 heads, 63 sectors/track, 257 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[root@cloud /]# df -h文件系统              容量  已用  可用 已用%% 挂载点/dev/mapper/vg_cloud-lv_root                      7.5G  3.5G  3.7G  49% /tmpfs                 503M   72K  503M   1% /dev/shm/dev/sda1             485M   32M  428M   7% /boot[root@cloud /]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x6f476ca3.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. Its strongly recommended to         switch off the mode (command c) and change display units to         sectors (command u).Command (m for help): mCommand 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 partitions 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): nCommand action   e   extended   p   primary partition (1-4)1Invalid partition number for type `1Command action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-6527, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): Using default value 6527Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@cloud /]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00073ffb   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        1306     9972736   8e  Linux LVMDisk /dev/sdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x6f476ca3   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1        6527    52428096   83  LinuxDisk /dev/mapper/vg_cloud-lv_root: 8095 MB, 8095006720 bytes255 heads, 63 sectors/track, 984 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/vg_cloud-lv_swap: 2113 MB, 2113929216 bytes255 heads, 63 sectors/track, 257 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[root@cloud /]# mkfs.ext3 /dev/sdb1mke2fs 1.41.12 (17-May-2010)文件系统标签=操作系统:Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks3276800 inodes, 13107024 blocks655351 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=0400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,         4096000, 7962624, 11239424正在写入inode表: 完成                            Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成This filesystem will be automatically checked every 26 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.[root@cloud /]# lsbin   dev  home  lost+found  media2  mnt  opt   root  selinux  sys  usrboot  etc  lib   media       misc    net  proc  sbin  srv      tmp  var[root@cloud /]# cd home[root@cloud home]# ls[root@cloud home]# ls -a.  ..[root@cloud home]# cd ..[root@cloud /]# mount /dev/sdb1 /home/[root@cloud /]# df -h文件系统              容量  已用  可用 已用%% 挂载点/dev/mapper/vg_cloud-lv_root                      7.5G  3.4G  3.7G  48% /tmpfs                 503M   72K  503M   1% /dev/shm/dev/sda1             485M   32M  428M   7% /boot/dev/sdb1              50G  180M   47G   1% /home[root@cloud /]# echo "/dev/sdb1 /home ext3 defaults 1 1" >> /etc/fstab[root@cloud /]# rebootBroadcast message from root@cloud        (/dev/pts/0) at 21:03 ...The system is going down for reboot NOW!

首先修改密码:passwd

查看磁盘信息:df -h

磁盘分区:fdisk

格式化硬盘:mkfs

挂载:mount

使挂载重启后生效:echo "/dev/sdb1 /home ext3 defaults 1 1" >> /etc/fstab

 

centos 格式化硬盘并挂载,添加重启后生效