<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://leo.leung.xyz/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=68.84.5.147</id>
	<title>Leo&#039;s Notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://leo.leung.xyz/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=68.84.5.147"/>
	<link rel="alternate" type="text/html" href="https://leo.leung.xyz/wiki/Special:Contributions/68.84.5.147"/>
	<updated>2026-10-12T00:26:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://leo.leung.xyz/wiki/index.php?title=How_to_hot-swap_SATA_disks_on_Linux&amp;diff=7373</id>
		<title>How to hot-swap SATA disks on Linux</title>
		<link rel="alternate" type="text/html" href="https://leo.leung.xyz/wiki/index.php?title=How_to_hot-swap_SATA_disks_on_Linux&amp;diff=7373"/>
		<updated>2023-10-09T17:58:30Z</updated>

		<summary type="html">&lt;p&gt;68.84.5.147: /* Rescanning SATA Bus */ correcting my very recent mis-paste&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;When running Linux on a server or NAS device, you might want to hot-swap disks without bringing the system down. For machines without a RAID controller, this might be a little bit tricker since you have to tell Linux to remove and add the device manually. This page will go over how to hot-swap SATA devices in Linux.&lt;br /&gt;
&lt;br /&gt;
==Removing a Drive==&lt;br /&gt;
If a device becomes unresponsive or if you simply just want to remove a SATA disk from a running system:&lt;br /&gt;
&lt;br /&gt;
#Ensure the disk is unmounted.&lt;br /&gt;
#Ensure the disk isn&#039;t used by swap or LVM groups.&lt;br /&gt;
#Remove the disk from the system by running {{code|echo 1 &amp;gt; /sys/block/sdX/device/delete}}. This should also power off the drive. If this doesn&#039;t work, try using [[hdparm]] to take the deivce to the lowest power setting with &amp;lt;code&amp;gt;hdparm -Y /dev/sdx&amp;lt;/code&amp;gt; and then try again.&lt;br /&gt;
&lt;br /&gt;
Once the drive spins down, you can disconnect the power and SATA connector. &lt;br /&gt;
&lt;br /&gt;
==Rescanning SATA Bus==&lt;br /&gt;
Depending on the chipset and SATA controller, when you connect a drive to the system, you may need to force a rescan of the bus before the drive shows up on the system. On Linux, you will need to trigger a rescan.&lt;br /&gt;
&lt;br /&gt;
Determine the controller the disk is attached to and trigger a rescan. Listing the scsi_host directory should give you a clue on what host is associated with which device:&lt;br /&gt;
{{highlight|lang=terminal|code=&lt;br /&gt;
# ls -al /sys/class/scsi_host&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host0 -&amp;gt; ../../devices/pci0000:00/0000:00:06.0/ata1/host0/scsi_host/host0/&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host1 -&amp;gt; ../../devices/pci0000:00/0000:00:06.0/ata2/host1/scsi_host/host1/&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host2 -&amp;gt; ../../devices/pci0000:00/0000:00:04.0/0000:01:06.0/ata3/host2/scsi_host/host2/&lt;br /&gt;
}}Trigger a rescan by writing 3 dashes (which denotes wildcards) to the scan command. Each of the 3 fields represents the channel, SCSI target ID, and LUN, respectively.&lt;br /&gt;
{{highlight|lang=terminal|code=&lt;br /&gt;
# echo &amp;quot;- - -&amp;quot; &amp;gt; /sys/class/scsi_host/host#/scan&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure which controller your disk is connected to, you may rescan all controllers with shell globbing.{{highlight&lt;br /&gt;
| lang = terminal&lt;br /&gt;
| code = # for arg in /sys/class/scsi_host/*/scan; do echo &amp;quot;- - -&amp;quot; &amp;gt; $arg; done&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Once the rescan is triggered, run &amp;lt;code&amp;gt;dmesg&amp;lt;/code&amp;gt; to see if a new disk was attached to the system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Navbox Linux}}&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>68.84.5.147</name></author>
	</entry>
	<entry>
		<id>https://leo.leung.xyz/wiki/index.php?title=How_to_hot-swap_SATA_disks_on_Linux&amp;diff=7372</id>
		<title>How to hot-swap SATA disks on Linux</title>
		<link rel="alternate" type="text/html" href="https://leo.leung.xyz/wiki/index.php?title=How_to_hot-swap_SATA_disks_on_Linux&amp;diff=7372"/>
		<updated>2023-10-09T17:53:46Z</updated>

		<summary type="html">&lt;p&gt;68.84.5.147: /* Rescanning SATA Bus */ the previous method here results in a bash error: &amp;quot;bash: /sys/class/scsi_host/host*/scan: ambiguous redirect&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;When running Linux on a server or NAS device, you might want to hot-swap disks without bringing the system down. For machines without a RAID controller, this might be a little bit tricker since you have to tell Linux to remove and add the device manually. This page will go over how to hot-swap SATA devices in Linux.&lt;br /&gt;
&lt;br /&gt;
==Removing a Drive==&lt;br /&gt;
If a device becomes unresponsive or if you simply just want to remove a SATA disk from a running system:&lt;br /&gt;
&lt;br /&gt;
#Ensure the disk is unmounted.&lt;br /&gt;
#Ensure the disk isn&#039;t used by swap or LVM groups.&lt;br /&gt;
#Remove the disk from the system by running {{code|echo 1 &amp;gt; /sys/block/sdX/device/delete}}. This should also power off the drive. If this doesn&#039;t work, try using [[hdparm]] to take the deivce to the lowest power setting with &amp;lt;code&amp;gt;hdparm -Y /dev/sdx&amp;lt;/code&amp;gt; and then try again.&lt;br /&gt;
&lt;br /&gt;
Once the drive spins down, you can disconnect the power and SATA connector. &lt;br /&gt;
&lt;br /&gt;
==Rescanning SATA Bus==&lt;br /&gt;
Depending on the chipset and SATA controller, when you connect a drive to the system, you may need to force a rescan of the bus before the drive shows up on the system. On Linux, you will need to trigger a rescan.&lt;br /&gt;
&lt;br /&gt;
Determine the controller the disk is attached to and trigger a rescan. Listing the scsi_host directory should give you a clue on what host is associated with which device:&lt;br /&gt;
{{highlight|lang=terminal|code=&lt;br /&gt;
# ls -al /sys/class/scsi_host&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host0 -&amp;gt; ../../devices/pci0000:00/0000:00:06.0/ata1/host0/scsi_host/host0/&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host1 -&amp;gt; ../../devices/pci0000:00/0000:00:06.0/ata2/host1/scsi_host/host1/&lt;br /&gt;
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host2 -&amp;gt; ../../devices/pci0000:00/0000:00:04.0/0000:01:06.0/ata3/host2/scsi_host/host2/&lt;br /&gt;
}}Trigger a rescan by writing 3 dashes (which denotes wildcards) to the scan command. Each of the 3 fields represents the channel, SCSI target ID, and LUN, respectively.&lt;br /&gt;
{{highlight|lang=terminal|code=&lt;br /&gt;
# echo &amp;quot;- - -&amp;quot; &amp;gt; /sys/class/scsi_host/host#/scan&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure which controller your disk is connected to, you may rescan all controllers with shell globbing.{{highlight|lang=terminal|code=&lt;br /&gt;
# for arg in /sys/bus/scsi/devices/*/*/*/scan; do echo &amp;quot;- - -&amp;quot; &amp;gt; $arg; done&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Once the rescan is triggered, run &amp;lt;code&amp;gt;dmesg&amp;lt;/code&amp;gt; to see if a new disk was attached to the system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Navbox Linux}}&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>68.84.5.147</name></author>
	</entry>
</feed>