Linux : How to put a disk or block device in offline mode and safely remove it
To put a disk or block device in offline mode and delete it from the system, follow the following steps.
This example will assume that we want to remove the 5th disk on the system (connected on controller 0, id 5 and seen as “sdf” and mounted as /mnt/disk5).
REMARK: If you were using this disk with LVM, make sure to delete everything first (lvremove, vgremove, pvremove).
1. Let’s first list all the disk seen by the system by using the “lsscsi” command – example :
2. Before going any further, let’s see if anything is accessing the disk you want to remove :
3. Unmount the drive :
4. Comment the corresponding entry in fstab :
5. Issue the offline command :
6. Remove the device :
7. Verify again the list of disk seen by the system :
The disk is no longer seen by the system and may be physically (or virtually!) removed.
About Kaven Gagnon
System & Network Architect
Unquoted Windows search path vulnerability in the Foxit Cloud Safe Update Service in the Cloud plugin in Foxit Reader 6.1 through 7.0.6.1126 allows local users to gain privileges via a Trojan horse program in the %SYSTEMDRIVE% folder. (CVSS:4.4) (Last Update:2016-12-03)
Foxit Reader, Enterprise Reader, and PhantomPDF before 7.1 allow remote attackers to cause a denial of service (memory corruption and crash) via a crafted (1) Ubyte Size in a DataSubBlock structure or (2) LZWMinimumCodeSize in a GIF image. (CVSS:4.3) (Last Update:2016-12-03)
Cross-site request forgery (CSRF) vulnerability in CS-Cart 4.2.4 allows remote attackers to hijack the authentication of users for requests that change a user password via a request to profiles-update/. (CVSS:6.8) (Last Update:2016-12-03)
How to create, add and remove block devices to the Raid device on Ubuntu 21.04
To Create, add and remove block devices to the Raid device on Ubuntu 21.04
Introduction:
The RAID device is a virtual device created from two or more real block devices that allows multiple devices to be combined into one and hold a single file system. A Linux Software RAID device is implemented using the MD device driver (Multiple Devices).
Step 1: Check the installed OS version by using the following command
[email protected]:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 21.04 Release: 21.04 Codename: hirsute
Step 2: Install mdadm package by using the following command
[email protected]:~# apt install mdadm Reading package lists. Done Building dependency tree. Done Reading state information. Done The following packages were automatically installed and are no longer required: libllvm11 net-tools Use 'apt autoremove' to remove them. The following additional packages will be installed: finalrd Suggested packages: default-mta | mail-transport-agent dracut-core The following NEW packages will be installed: finalrd mdadm 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 430 kB of archives. After this operation, 1,299 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 finalrd all 7 [6,860 B] Get:2 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 mdadm amd64 4.1-10ubuntu3 [423 kB] Fetched 430 kB in 1s (833 kB/s) Preconfiguring packages . Selecting previously unselected package finalrd. (Reading database . 209649 files and directories currently installed.) Preparing to unpack . /apt/archives/finalrd_7_all.deb . Unpacking finalrd (7) . Selecting previously unselected package mdadm. Preparing to unpack . /mdadm_4.1-10ubuntu3_amd64.deb . Unpacking mdadm (4.1-10ubuntu3) . Setting up finalrd (7) . Created symlink /etc/systemd/system/sysinit.target.wants/finalrd.service → /lib/systemd/system/finalrd.service. Setting up mdadm (4.1-10ubuntu3) . Generating mdadm.conf. done. update-initramfs: deferring update (trigger activated) Sourcing file `/etc/default/grub' Created symlink /etc/systemd/system/mdmonitor.service.wants/mdcheck_continue.timer → /lib/systemd/system/mdcheck_continu e.timer. Created symlink /etc/systemd/system/mdmonitor.service.wants/mdcheck_start.timer → /lib/systemd/system/mdcheck_start.time r. Created symlink /etc/systemd/system/mdmonitor.service.wants/mdmonitor-oneshot.timer → /lib/systemd/system/mdmonitor-ones hot.timer. Processing triggers for man-db (2.9.4-2) . Processing triggers for initramfs-tools (0.139ubuntu3) . update-initramfs: Generating /boot/initrd.img-5.11.0-40-generic
Step 3: Open fdisk to create partions on /dev/sdb disk
[email protected]:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.36.1). 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. Created a new DOS disklabel with disk identifier 0xec47ae17. Creating New Partition Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Using default partition number and using entire disk space partition by pressing enter for all Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +/-sectors or +/-size (2048-41943039, default 41943039): Created a new partition 1 of type 'Linux' and of size 20 GiB. Changing the partition type to Linux raid autodetect Command (m for help): t Selected partition 1 Hex code or alias (type L to list all): fd Changed type of partition 'Linux' to 'Linux raid autodetect'. Saving the all changes made to the disks Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Step 4: Open fdisk to create partions on /dev/sdc disk
[email protected]:~# fdisk /dev/sdc Welcome to fdisk (util-linux 2.36.1). 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. Created a new DOS disklabel with disk identifier 0xa183b98d. Creating New Partition Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Using default partition number and using entire disk space partition by pressing enter for all Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +/-sectors or +/-size (2048-41943039, default 41943039): Created a new partition 1 of type 'Linux' and of size 20 GiB. Change the partition type to Linux LVM Command (m for help): t Selected partition 1 Hex code or alias (type L to list all): fd Changed type of partition 'Linux' to 'Linux raid autodetect'. Save the all changes made to the disks Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Step 5: Create Raid device in Raid level 1 with two block devices
[email protected]:~# mdadm -C /dev/md0 -l 1 -n 2 /dev/sd[b-c]1 mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 Continue creating array? Continue creating array? (y/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started.
Step 6: View the details of Raid device
[email protected]:~# mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 29 19:19:08 2021 Raid Level : raid1 Array Size : 20953088 (19.98 GiB 21.46 GB) Used Dev Size : 20953088 (19.98 GiB 21.46 GB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Mon Nov 29 19:19:27 2021 State : clean, resyncing Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Consistency Policy : resync Resync Status : 20% complete Name : linuxhelp:0 (local to host linuxhelp) UUID : f925a91a:86f15757:d4721be4:5f6ccd45 Events : 3 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 33 1 active sync /dev/sdc1
Step 7: Format Raid partition to ext4 file system
[email protected]:~# mkfs.ext4 /dev/md0 mke2fs 1.45.7 (28-Jan-2021) Creating filesystem with 5238272 4k blocks and 1310720 inodes Filesystem UUID: 34ab81ad-6dd4-40fc-aba5-9c93acc37cb9 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Step 8: Create directory to mount Raid partition
Step 9: Mount Raid partition on /raid1 directory
Step 10: Create a file in Raid partition
[email protected]:~# vi /raid1/test Linuxhelp.com
Step 11: Make fstab entry for Raid partition
[email protected]:~# vi /etc/fstab /dev/md0 /raid1 ext4 defaults 0 0
Step 12: Make partition permanent
Step 13: Make one block device fault out of two then only able to remove it
[email protected]:~# mdadm -f /dev/md0 /dev/sdc1 mdadm: set /dev/sdc1 faulty in /dev/md0
Step 14: Remove one block device out of two
[email protected]:~# mdadm --remove /dev/md0 /dev/sdc1 mdadm: hot removed /dev/sdc1 from /dev/md0
Step 15: View the devices details
[email protected]:~# mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 29 19:19:08 2021 Raid Level : raid1 Array Size : 20953088 (19.98 GiB 21.46 GB) Used Dev Size : 20953088 (19.98 GiB 21.46 GB) Raid Devices : 2 Total Devices : 1 Persistence : Superblock is persistent Update Time : Mon Nov 29 19:23:18 2021 State : clean, degraded Active Devices : 1 Working Devices : 1 Failed Devices : 0 Spare Devices : 0 Consistency Policy : resync Name : linuxhelp:0 (local to host linuxhelp) UUID : f925a91a:86f15757:d4721be4:5f6ccd45 Events : 28 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 - 0 0 1 removed
Step 16: View the file created before removing one block device
[email protected]:~# cat /raid1/test Linuxhelp.com
By this to create, add and remove block devices to the Raid device on Ubuntu 21.04 comes to an end