1、ls -l /dev/disk/by-uuid
2、blkid /dev/sda5
如何在Linux 中获取硬盘分区或文件系统的UUID?
一、fdisk-l这个命令会列出当前分区和配置。
[root@cql ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000e3d27
Device Boot Start End Blocks Id System
/dev/sda1 1 914 7340032 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 914 1437 4194304 82 Linux swap / Solaris
/dev/sda3 * 1437 2611 9436160 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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
/dev/sdb就是我新添加的硬盘
二、格式化:
[root@cql ~]# mkfs -t ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
*** 作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
591008 inodes, 2361547 blocks
118077 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2420113408
73 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
三、挂载硬盘:
新建文件夹:mkdir /data2
将硬盘挂载到data2下
mount /dev/sdb /data2
四、加入开机自动
我是通过修改/etc/fstab文件,加入开机自动的,反正方法各种各样,都可以的,随自己的心情~
首先查看分区的UUID
[root@cql ~]# blkid
/dev/sda3: UUID="16046051-6a05-4e6b-b5d2-b64258f5e6d2" TYPE="ext4"
/dev/sda1: UUID="1573581f-e2d5-4f7c-a2de-da6e0eb94359" TYPE="ext4"
/dev/sda2: UUID="a0b44529-1476-4cd7-a009-51b879ba163a" TYPE="swap"
/dev/sdb1: UUID="f124b1f5-16df-4d68-bdc4-41aa08562111" TYPE="ext4"
编辑
[root@cql ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Sep 17 22:40:58 2017
#
# 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=16046051-6a05-4e6b-b5d2-b64258f5e6d2 / ext4 defaults 1 1
UUID=1573581f-e2d5-4f7c-a2de-da6e0eb94359 /u01 ext4 defaults 1 2
UUID=a0b44529-1476-4cd7-a009-51b879ba163a 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
UUID=f124b1f5-16df-4d68-bdc4-41aa08562111 /u01 ext4 defaults 1 2
~
"/etc/fstab" 16L, 899C written
[root@cql ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Sep 17 22:40:58 2017
#
# 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=16046051-6a05-4e6b-b5d2-b64258f5e6d2 / ext4 defaults 1 1
UUID=1573581f-e2d5-4f7c-a2de-da6e0eb94359 /u01 ext4 defaults 1 2
UUID=a0b44529-1476-4cd7-a009-51b879ba163a 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
UUID=f124b1f5-16df-4d68-bdc4-41aa08562111 /u01 ext4 defaults 1 2
重启,确认结果~
[root@cql ~]# reboot
Broadcast message from root@cql
(/dev/pts/3) at 21:50 ...
The system is going down for reboot NOW!
[root@cql ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 8.9G 4.0G 4.5G 48% /
tmpfs tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 ext3 8.9G 149M 8.3G 2% /u01
/dev/sdb1 ext3 8.9G 149M 8.3G 2% /u01
安装ubuntu特殊设备sda7不存在?这个是因为对原来已经挂载的磁盘分区进行了格式化或重新分区导致分区(磁盘)UUID改变而造成的。解决的方法:1.查看挂载脚本中的老的UUID。$ cat /etc/fstab查看当前挂载脚本中的dev设备及UUID。# /etc/fstab: static file system information.## Use 'blkid' to print the universally unique identifier for a# devicethis may be used with UUID= as a more robust way to name devices# that works even if disks are added and removed. See fstab(5).## <file system><mount point><type><options><dump><pass>proc /proc proc nodev,noexec,nosuid 0 0# / was on /dev/sda8 during installationUUID=0022e6f3-c3fa-44a0-8ec9-4ac91dc8edf4 / ext4 errors=remount-ro 0 1# /windows/C was on /dev/sda1 during installationUUID=00FJKDN09YW7JSX6 /windows/C ntfs defaults,umask=007,gid=46 0 0# /windows/D was on /dev/sda2 during installationUUID=0008E78D000E3B9C /windows/D ntfs defaults,umask=007,gid=46 0 0# /windows/E was on /dev/sda5 during installationUUID=00063C35000A63B9 /windows/E ntfs defaults,umask=007,gid=46 0 0# /windows/F was on /dev/sda6 during installationUUID=000F6F14000372B6 /windows/F ntfs defaults,umask=007,gid=46 0 0# swap was on /dev/sda7 during installationUUID=fefe7e3c-7001-451f-afa3-9dd773ede2d7 none swap sw 0 0大概记住/linux的UUID。2.查看当前磁盘(分区)的UUID。这里使用blkid命令查看当前计算机所有分区的UUID及文件系统类型。$ sudo blkid输出:/dev/sda1: UUID="C2E09EDAE09ED3CF" TYPE="ntfs"/dev/sda2: UUID="0008E78D000E3B9C" TYPE="ntfs"/dev/sda5: UUID="00063C35000A63B9" TYPE="ntfs"/dev/sda6: UUID="000F6F14000372B6" TYPE="ntfs"/dev/sda7: UUID="fefe7e3c-7001-451f-afa3-9dd773ede2d7" TYPE="swap"/dev/sda8: UUID="0022e6f3-c3fa-44a0-8ec9-4ac91dc8edf4" TYPE="ext4由此可见,当前的linux的UUID与原fstab挂载脚本中的UUID不符。3.修改fstab挂在脚本。提示:修改系统文件需要用root权限。$ sudo gedit /etc/fstab这里使用的是gedit文本编辑器。修改上述UUID项,改成一致的就行了。当然如果你习惯用vi(vim)的话也可以。$ sudo vi /etc/fstab或$ sudo vim /etc/fstab问题解决。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)