Linux添加磁盘、挂载 及 还原至裸设备状态
添加磁盘及挂载
·
磁盘划分区
[hadoop@hadoop03 ~]$ sudo fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000df169
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 8744959 4064256 82 Linux swap / Solaris
/dev/sda3 8744960 83886079 37570560 83 Linux
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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
[hadoop@hadoop03 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 12G 25G 32% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 9.2M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 152M 145M 52% /boot
tmpfs 378M 12K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/1000
tmpfs 378M 0 378M 0% /run/user/0
[hadoop@hadoop03 ~]$ fdisk /dev/sdb
fdisk: cannot open /dev/sdb: Permission denied
[hadoop@hadoop03 ~]$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x1a043559.
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x1a043559
Device Boot Start End Blocks Id System
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): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x1a043559
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux
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
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
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[hadoop@hadoop03 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 12G 25G 32% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 9.3M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 152M 145M 52% /boot
tmpfs 378M 16K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/1000
tmpfs 378M 0 378M 0% /run/user/0
### 在挂载之前需要先进行初始化 ###
[hadoop@hadoop03 ~]$ mkfs.ext3 /dev/sd
sda sda1 sda2 sda3 sdb sdb1
[hadoop@hadoop03 ~]$ sudo mkfs.ext3 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[hadoop@hadoop03 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 12G 25G 32% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 9.3M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 152M 145M 52% /boot
tmpfs 378M 16K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/1000
tmpfs 378M 0 378M 0% /run/user/0
[hadoop@hadoop03 ~]$ sudo mkdir /glusterfs-data
[hadoop@hadoop03 ~]$ mount /dev/sdb /glusterfs-data/
mount: only root can do that
[hadoop@hadoop03 ~]$ sudo mount /dev/sdb /glusterfs-data/
[hadoop@hadoop03 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 12G 25G 32% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 9.2M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 297M 152M 145M 52% /boot
tmpfs 378M 16K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/1000
tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb 4.8G 11M 4.6G 1% /glusterfs-data
[hadoop@hadoop03 ~]$
磁盘还原至裸设备状态(新添加磁盘未分配初始化状态)…
[root@hadoop03 kube-templates]# umount /dev/sdb
[root@hadoop03 kube-templates]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? yes
(parted) quit
Information: You may need to update /etc/fstab.
[root@hadoop03 kube-templates]# pvcreate /dev/sdb
/run/lvm/lvmetad.socket: connect failed: Connection refused
WARNING: Failed to connect to lvmetad. Falling back to device scanning.
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
[root@hadoop03 kube-templates]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000df169
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 8744959 4064256 82 Linux swap / Solaris
/dev/sda3 8744960 83886079 37570560 83 Linux
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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
[root@hadoop03 kube-templates]#
记录下
dmsetup status | grep xxxx
先删除 linear 的、
[root@k8s lib]# dmsetup remove --force vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db-tpool
device-mapper: remove ioctl on vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db-tpool failed: Device or resource busy
Command failed.
[root@k8s lib]# lsblk
lsblk: dm-41: failed to get device path
lsblk: dm-41: failed to get device path
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3.9G 0 lvm
└─centos-home 253:2 0 45.1G 0 lvm /home
sdb 8:16 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom
vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db-tpool
253:40 0 1G 0 lvm
[root@k8s lib]# dmsetup status | grep vg_4dc287441da484703f36d8bd3471d9d3
vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db-tpool: 0 2097152 error
vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db: 0 2097152 linear
[root@k8s lib]# dmsetup remove --force vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db
[root@k8s lib]# dmsetup remove --force vg_4dc287441da484703f36d8bd3471d9d3-tp_be1f05ddb033d4e3b10084719ce293db-tpool
[root@k8s lib]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3.9G 0 lvm
└─centos-home 253:2 0 45.1G 0 lvm /home
sdb 8:16 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom
#!/bin/bash
d1=`dmsetup deps | grep vg_ | grep "1 dependencies" | grep -v "tmeta" | grep -v "tdata"| awk '{sub(":",""); print $1}'`
for i in $d1;
do
dmsetup remove $i
done
sleep 5
###
d1=`dmsetup deps | grep vg_ | grep "2 dependencies" | awk '{sub(":",""); print $1}'`
for i in $d1;
do
dmsetup remove $i
done
sleep 5
d1=`dmsetup deps | grep vg_ | grep "1 dependencies" | awk '{sub(":",""); print $1}'`
for i in $d1;
do
dmsetup remove $i
done
更多推荐
已为社区贡献1条内容
所有评论(0)