How can I safely remove a SATA disk from a running system?
I sometimes need to plug a disk into a disk bay. At other times, I have the very weird setup of connecting a SSD using a SATA-eSATA cable on my laptop while pulling power from a desktop.
How can I safely remove the SATA disk from the system? This Phoronix forum thread has some suggestions:
justsumdood wrote:
An(noymous)droid wrote:
What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
after unmounting the device, to "power off" (or sleep) the unit:
hdparm -Y /dev/sdX
(where X represents the device you wish to power off. for example: /dev/sdb)
this will power the drive down allowing for it's removal w/o risk of voltage surge.
Does this mean that the disk caches are properly flushed and powered off thereafter?
Another suggestion from the same thread:
chithanh wrote:
All SATA and eSATA hardware is physically able to be hotplugged (ie. not damaged if you insert/pull the plug).
How the chipset and driver handles this is another question. Some driver/chipset combinations do not properly handle hotplugging and need a warmplug command such as the following one:
echo 0 - 0 > /sys/class/scsi_host/hostX/scan
Replace X with the appropriate number for your SATA/eSATA port.
I doubt whether is the correct way to do so, but I cannot find some proof against it either.
So, what is the correct way to remove an attached disk from a system? Assume that I have already unmounted every partition on the disk and ran sync
. Please point to some official documentation if possible, I could not find anything in the Linux documentation tree, nor the Linux ATA wiki.
ssd sata hot-plug disk
add a comment |
I sometimes need to plug a disk into a disk bay. At other times, I have the very weird setup of connecting a SSD using a SATA-eSATA cable on my laptop while pulling power from a desktop.
How can I safely remove the SATA disk from the system? This Phoronix forum thread has some suggestions:
justsumdood wrote:
An(noymous)droid wrote:
What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
after unmounting the device, to "power off" (or sleep) the unit:
hdparm -Y /dev/sdX
(where X represents the device you wish to power off. for example: /dev/sdb)
this will power the drive down allowing for it's removal w/o risk of voltage surge.
Does this mean that the disk caches are properly flushed and powered off thereafter?
Another suggestion from the same thread:
chithanh wrote:
All SATA and eSATA hardware is physically able to be hotplugged (ie. not damaged if you insert/pull the plug).
How the chipset and driver handles this is another question. Some driver/chipset combinations do not properly handle hotplugging and need a warmplug command such as the following one:
echo 0 - 0 > /sys/class/scsi_host/hostX/scan
Replace X with the appropriate number for your SATA/eSATA port.
I doubt whether is the correct way to do so, but I cannot find some proof against it either.
So, what is the correct way to remove an attached disk from a system? Assume that I have already unmounted every partition on the disk and ran sync
. Please point to some official documentation if possible, I could not find anything in the Linux documentation tree, nor the Linux ATA wiki.
ssd sata hot-plug disk
add a comment |
I sometimes need to plug a disk into a disk bay. At other times, I have the very weird setup of connecting a SSD using a SATA-eSATA cable on my laptop while pulling power from a desktop.
How can I safely remove the SATA disk from the system? This Phoronix forum thread has some suggestions:
justsumdood wrote:
An(noymous)droid wrote:
What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
after unmounting the device, to "power off" (or sleep) the unit:
hdparm -Y /dev/sdX
(where X represents the device you wish to power off. for example: /dev/sdb)
this will power the drive down allowing for it's removal w/o risk of voltage surge.
Does this mean that the disk caches are properly flushed and powered off thereafter?
Another suggestion from the same thread:
chithanh wrote:
All SATA and eSATA hardware is physically able to be hotplugged (ie. not damaged if you insert/pull the plug).
How the chipset and driver handles this is another question. Some driver/chipset combinations do not properly handle hotplugging and need a warmplug command such as the following one:
echo 0 - 0 > /sys/class/scsi_host/hostX/scan
Replace X with the appropriate number for your SATA/eSATA port.
I doubt whether is the correct way to do so, but I cannot find some proof against it either.
So, what is the correct way to remove an attached disk from a system? Assume that I have already unmounted every partition on the disk and ran sync
. Please point to some official documentation if possible, I could not find anything in the Linux documentation tree, nor the Linux ATA wiki.
ssd sata hot-plug disk
I sometimes need to plug a disk into a disk bay. At other times, I have the very weird setup of connecting a SSD using a SATA-eSATA cable on my laptop while pulling power from a desktop.
How can I safely remove the SATA disk from the system? This Phoronix forum thread has some suggestions:
justsumdood wrote:
An(noymous)droid wrote:
What then do you do on the software side before unplugging? Is it a simple "umount /dev/sd"[drive letter]?
after unmounting the device, to "power off" (or sleep) the unit:
hdparm -Y /dev/sdX
(where X represents the device you wish to power off. for example: /dev/sdb)
this will power the drive down allowing for it's removal w/o risk of voltage surge.
Does this mean that the disk caches are properly flushed and powered off thereafter?
Another suggestion from the same thread:
chithanh wrote:
All SATA and eSATA hardware is physically able to be hotplugged (ie. not damaged if you insert/pull the plug).
How the chipset and driver handles this is another question. Some driver/chipset combinations do not properly handle hotplugging and need a warmplug command such as the following one:
echo 0 - 0 > /sys/class/scsi_host/hostX/scan
Replace X with the appropriate number for your SATA/eSATA port.
I doubt whether is the correct way to do so, but I cannot find some proof against it either.
So, what is the correct way to remove an attached disk from a system? Assume that I have already unmounted every partition on the disk and ran sync
. Please point to some official documentation if possible, I could not find anything in the Linux documentation tree, nor the Linux ATA wiki.
ssd sata hot-plug disk
ssd sata hot-plug disk
asked Jul 18 '12 at 20:04
LekensteynLekensteyn
9,993115288
9,993115288
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
- Unmount any filesystems on the disk. (
umount ...
) - Deactivate any LVM groups. (
vgchange -an
) - Make sure nothing is using the disk for anything.
- Once you've done that, it should be safe to unplug.
If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete
first. That'll unregister the device from the kernel, so you know nothing's using it when you unplug it. When I do that with a drive in an eSATA enclosure, I can hear the drive's heads park themselves, so the kernel apparently tells the drive to prepare for power-down.
If you're using an AHCI controller, it should cope with devices being unplugged. If you're using some other sort of SATA controller, the driver might be confused by hotplugging.
In my experience, SATA hotplugging (with AHCI) works pretty well in Linux. I've unplugged an optical drive, plugged in a hard drive, scanned it for errors, made a filesystem and copied data to it, unmounted and unplugged it, plugged in a differerent DVD drive, and burned a disc, all with the machine up and running.
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing1
todelete
made it disappear and I could hear the disk spinning down. Justhdparm -Y
was not enough because the/dev/
entries would still exist. Thanks!
– Lekensteyn
Aug 9 '12 at 9:25
12
I strongly advice to always issue theecho 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.
– drumfire
Feb 12 '14 at 21:21
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
Just one note worth mentioning,echo 1 > /sys/block/(whatever)/device/delete
will not work undersudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain oldsu
instead.
– TranslucentCloud
Mar 29 '15 at 10:59
10
@TranslucentCloud You can pipe it throughsudo tee
to emulate a redirect as root:echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
|
show 1 more comment
Those two sections are for different things.
The first is for unplugging. The second is for plugging.
For unplugging, the OS will sync the data during the unmount operation. Thus, if the disk is unmounted (assuming you in fact do have full hardware support) you can power off the disk then unplug it without risk of data loss or corruption.
For plugging, the device should be automatically recognized. If not, you can execute that command to trigger a bus scan. Once the device is recognized you can mount it.
And let me caveat this by saying I've only ever done this sort of thing with USB drives.
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
@Lekensteyn, thehdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.
– psusi
Jul 19 '12 at 13:16
add a comment |
what about eject /dev/sdX
? On my setup, this commands umounts, syncs and powers down the drive.
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports theioctl()
operation used by theeject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.
– peterh
Jul 31 '15 at 4:11
add a comment |
I have a pair of scripts that build upon the answer by Wyzard. The first, scsi-drop
, is to safely detach a single disk:
#!/bin/sh
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
if test -b "$disk"
then
echo 1 >/sys/block/$(basename "$disk")/device/delete
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Its main benefit is that you can pass it a symlink, such as found in /dev/disk/by-id/
and it will resolve that to the real device. It does require chase
to be installed; you might be able to get the same result using readlink -e
.
The second script, scsi-rescan
, is used after hotplugging a new device:
#!/bin/bash
exec tee /sys/class/scsi_host/host*/scan <<<'- - -' >/dev/null
This makes all adapters re-scan for devices. It was the only way I managed to get the new capacity and partition table to be read.
add a comment |
Actually, SATA drives automatically park the heads when power is lost. Pulling the drive while it is still spinning, should not result in issues. However, spinning disks are prone to dings if bumped. You can hear this when you have flaky power or solar flares.
Most damage is usually caused by, unflushed cache and uncommitted writes in buffers etc ... This is why you MUST unmount a drive, before removing it. The SCSI command is just good measure and works to the same end.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f43413%2fhow-can-i-safely-remove-a-sata-disk-from-a-running-system%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Unmount any filesystems on the disk. (
umount ...
) - Deactivate any LVM groups. (
vgchange -an
) - Make sure nothing is using the disk for anything.
- Once you've done that, it should be safe to unplug.
If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete
first. That'll unregister the device from the kernel, so you know nothing's using it when you unplug it. When I do that with a drive in an eSATA enclosure, I can hear the drive's heads park themselves, so the kernel apparently tells the drive to prepare for power-down.
If you're using an AHCI controller, it should cope with devices being unplugged. If you're using some other sort of SATA controller, the driver might be confused by hotplugging.
In my experience, SATA hotplugging (with AHCI) works pretty well in Linux. I've unplugged an optical drive, plugged in a hard drive, scanned it for errors, made a filesystem and copied data to it, unmounted and unplugged it, plugged in a differerent DVD drive, and burned a disc, all with the machine up and running.
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing1
todelete
made it disappear and I could hear the disk spinning down. Justhdparm -Y
was not enough because the/dev/
entries would still exist. Thanks!
– Lekensteyn
Aug 9 '12 at 9:25
12
I strongly advice to always issue theecho 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.
– drumfire
Feb 12 '14 at 21:21
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
Just one note worth mentioning,echo 1 > /sys/block/(whatever)/device/delete
will not work undersudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain oldsu
instead.
– TranslucentCloud
Mar 29 '15 at 10:59
10
@TranslucentCloud You can pipe it throughsudo tee
to emulate a redirect as root:echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
|
show 1 more comment
- Unmount any filesystems on the disk. (
umount ...
) - Deactivate any LVM groups. (
vgchange -an
) - Make sure nothing is using the disk for anything.
- Once you've done that, it should be safe to unplug.
If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete
first. That'll unregister the device from the kernel, so you know nothing's using it when you unplug it. When I do that with a drive in an eSATA enclosure, I can hear the drive's heads park themselves, so the kernel apparently tells the drive to prepare for power-down.
If you're using an AHCI controller, it should cope with devices being unplugged. If you're using some other sort of SATA controller, the driver might be confused by hotplugging.
In my experience, SATA hotplugging (with AHCI) works pretty well in Linux. I've unplugged an optical drive, plugged in a hard drive, scanned it for errors, made a filesystem and copied data to it, unmounted and unplugged it, plugged in a differerent DVD drive, and burned a disc, all with the machine up and running.
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing1
todelete
made it disappear and I could hear the disk spinning down. Justhdparm -Y
was not enough because the/dev/
entries would still exist. Thanks!
– Lekensteyn
Aug 9 '12 at 9:25
12
I strongly advice to always issue theecho 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.
– drumfire
Feb 12 '14 at 21:21
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
Just one note worth mentioning,echo 1 > /sys/block/(whatever)/device/delete
will not work undersudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain oldsu
instead.
– TranslucentCloud
Mar 29 '15 at 10:59
10
@TranslucentCloud You can pipe it throughsudo tee
to emulate a redirect as root:echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
|
show 1 more comment
- Unmount any filesystems on the disk. (
umount ...
) - Deactivate any LVM groups. (
vgchange -an
) - Make sure nothing is using the disk for anything.
- Once you've done that, it should be safe to unplug.
If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete
first. That'll unregister the device from the kernel, so you know nothing's using it when you unplug it. When I do that with a drive in an eSATA enclosure, I can hear the drive's heads park themselves, so the kernel apparently tells the drive to prepare for power-down.
If you're using an AHCI controller, it should cope with devices being unplugged. If you're using some other sort of SATA controller, the driver might be confused by hotplugging.
In my experience, SATA hotplugging (with AHCI) works pretty well in Linux. I've unplugged an optical drive, plugged in a hard drive, scanned it for errors, made a filesystem and copied data to it, unmounted and unplugged it, plugged in a differerent DVD drive, and burned a disc, all with the machine up and running.
- Unmount any filesystems on the disk. (
umount ...
) - Deactivate any LVM groups. (
vgchange -an
) - Make sure nothing is using the disk for anything.
- Once you've done that, it should be safe to unplug.
If you want to be extra cautious, do echo 1 > /sys/block/(whatever)/device/delete
first. That'll unregister the device from the kernel, so you know nothing's using it when you unplug it. When I do that with a drive in an eSATA enclosure, I can hear the drive's heads park themselves, so the kernel apparently tells the drive to prepare for power-down.
If you're using an AHCI controller, it should cope with devices being unplugged. If you're using some other sort of SATA controller, the driver might be confused by hotplugging.
In my experience, SATA hotplugging (with AHCI) works pretty well in Linux. I've unplugged an optical drive, plugged in a hard drive, scanned it for errors, made a filesystem and copied data to it, unmounted and unplugged it, plugged in a differerent DVD drive, and burned a disc, all with the machine up and running.
edited Jul 30 '18 at 14:48
Pro Backup
2,09363258
2,09363258
answered Jul 19 '12 at 3:25
WyzardWyzard
1,7611214
1,7611214
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing1
todelete
made it disappear and I could hear the disk spinning down. Justhdparm -Y
was not enough because the/dev/
entries would still exist. Thanks!
– Lekensteyn
Aug 9 '12 at 9:25
12
I strongly advice to always issue theecho 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.
– drumfire
Feb 12 '14 at 21:21
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
Just one note worth mentioning,echo 1 > /sys/block/(whatever)/device/delete
will not work undersudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain oldsu
instead.
– TranslucentCloud
Mar 29 '15 at 10:59
10
@TranslucentCloud You can pipe it throughsudo tee
to emulate a redirect as root:echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
|
show 1 more comment
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing1
todelete
made it disappear and I could hear the disk spinning down. Justhdparm -Y
was not enough because the/dev/
entries would still exist. Thanks!
– Lekensteyn
Aug 9 '12 at 9:25
12
I strongly advice to always issue theecho 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.
– drumfire
Feb 12 '14 at 21:21
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
Just one note worth mentioning,echo 1 > /sys/block/(whatever)/device/delete
will not work undersudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain oldsu
instead.
– TranslucentCloud
Mar 29 '15 at 10:59
10
@TranslucentCloud You can pipe it throughsudo tee
to emulate a redirect as root:echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing
1
to delete
made it disappear and I could hear the disk spinning down. Just hdparm -Y
was not enough because the /dev/
entries would still exist. Thanks!– Lekensteyn
Aug 9 '12 at 9:25
I had a need to unplug a HDD which I wanted to erase completely. After pulling the disk out of the bay, /dev/sdXY still showed up. Writing
1
to delete
made it disappear and I could hear the disk spinning down. Just hdparm -Y
was not enough because the /dev/
entries would still exist. Thanks!– Lekensteyn
Aug 9 '12 at 9:25
12
12
I strongly advice to always issue the
echo 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.– drumfire
Feb 12 '14 at 21:21
I strongly advice to always issue the
echo 1 > /sys/block/(whatever)/device/delete
command because the drive will park the heads, fully stop the disk and disable power on the bus. If a non-parked head touches a spinning plate the drive can be permanently destroyed.– drumfire
Feb 12 '14 at 21:21
2
2
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
Also - if smartd happens to be running, it's a good idea to issue a SIGHUP to the process so that it reloads the drive info. Especially important if you're replacing drives because smartd will reload the info for that drive and all others.
– drumfire
Feb 12 '14 at 21:23
1
1
Just one note worth mentioning,
echo 1 > /sys/block/(whatever)/device/delete
will not work under sudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain old su
instead.– TranslucentCloud
Mar 29 '15 at 10:59
Just one note worth mentioning,
echo 1 > /sys/block/(whatever)/device/delete
will not work under sudo
, the "Permission denied" error will be thrown. You'll need to become a real root, so use plain old su
instead.– TranslucentCloud
Mar 29 '15 at 10:59
10
10
@TranslucentCloud You can pipe it through
sudo tee
to emulate a redirect as root: echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
@TranslucentCloud You can pipe it through
sudo tee
to emulate a redirect as root: echo 1 | sudo tee /sys/block/(whatever)/device/delete
– Oli
Apr 15 '15 at 20:54
|
show 1 more comment
Those two sections are for different things.
The first is for unplugging. The second is for plugging.
For unplugging, the OS will sync the data during the unmount operation. Thus, if the disk is unmounted (assuming you in fact do have full hardware support) you can power off the disk then unplug it without risk of data loss or corruption.
For plugging, the device should be automatically recognized. If not, you can execute that command to trigger a bus scan. Once the device is recognized you can mount it.
And let me caveat this by saying I've only ever done this sort of thing with USB drives.
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
@Lekensteyn, thehdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.
– psusi
Jul 19 '12 at 13:16
add a comment |
Those two sections are for different things.
The first is for unplugging. The second is for plugging.
For unplugging, the OS will sync the data during the unmount operation. Thus, if the disk is unmounted (assuming you in fact do have full hardware support) you can power off the disk then unplug it without risk of data loss or corruption.
For plugging, the device should be automatically recognized. If not, you can execute that command to trigger a bus scan. Once the device is recognized you can mount it.
And let me caveat this by saying I've only ever done this sort of thing with USB drives.
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
@Lekensteyn, thehdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.
– psusi
Jul 19 '12 at 13:16
add a comment |
Those two sections are for different things.
The first is for unplugging. The second is for plugging.
For unplugging, the OS will sync the data during the unmount operation. Thus, if the disk is unmounted (assuming you in fact do have full hardware support) you can power off the disk then unplug it without risk of data loss or corruption.
For plugging, the device should be automatically recognized. If not, you can execute that command to trigger a bus scan. Once the device is recognized you can mount it.
And let me caveat this by saying I've only ever done this sort of thing with USB drives.
Those two sections are for different things.
The first is for unplugging. The second is for plugging.
For unplugging, the OS will sync the data during the unmount operation. Thus, if the disk is unmounted (assuming you in fact do have full hardware support) you can power off the disk then unplug it without risk of data loss or corruption.
For plugging, the device should be automatically recognized. If not, you can execute that command to trigger a bus scan. Once the device is recognized you can mount it.
And let me caveat this by saying I've only ever done this sort of thing with USB drives.
answered Jul 18 '12 at 21:37
bahamatbahamat
24.7k15090
24.7k15090
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
@Lekensteyn, thehdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.
– psusi
Jul 19 '12 at 13:16
add a comment |
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
@Lekensteyn, thehdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.
– psusi
Jul 19 '12 at 13:16
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
Thanks for your answer, but I am still not convinced what the correct action would be. SSDs have a "Unsafe Shutdown Count" S.M.A.R.T. field, just unplugging it without doing anything does not sound safe to me.
– Lekensteyn
Jul 18 '12 at 21:58
3
3
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
If it helps, I routinely hot-plug and hot-unplug SATA hard drives as part of my job, with no more than making sure it's unmounted first, and I've never run into a problem. That's anecdotal, so don't take it as gospel, but it's at least some evidence that it's likely safe. In any case, I'd consider it a kernel bug if the OS doesn't ensure that the data is fully written at the end of an unmount operation, especially in a hotplug world.
– Jander
Jul 19 '12 at 0:24
1
1
@Lekensteyn, the
hdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.– psusi
Jul 19 '12 at 13:16
@Lekensteyn, the
hdparm -Y
will take care of that. That is basically what the system does every time you suspend or shutdown.– psusi
Jul 19 '12 at 13:16
add a comment |
what about eject /dev/sdX
? On my setup, this commands umounts, syncs and powers down the drive.
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports theioctl()
operation used by theeject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.
– peterh
Jul 31 '15 at 4:11
add a comment |
what about eject /dev/sdX
? On my setup, this commands umounts, syncs and powers down the drive.
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports theioctl()
operation used by theeject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.
– peterh
Jul 31 '15 at 4:11
add a comment |
what about eject /dev/sdX
? On my setup, this commands umounts, syncs and powers down the drive.
what about eject /dev/sdX
? On my setup, this commands umounts, syncs and powers down the drive.
edited Aug 27 '13 at 22:19
Anthon
61k17104166
61k17104166
answered Aug 27 '13 at 21:58
bitvitezbitvitez
5111
5111
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports theioctl()
operation used by theeject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.
– peterh
Jul 31 '15 at 4:11
add a comment |
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports theioctl()
operation used by theeject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.
– peterh
Jul 31 '15 at 4:11
4
4
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
I tried this with a disk connected over eSATA but the command failed with "not hotpluggable" or something.
– Lekensteyn
Aug 30 '13 at 9:29
1
1
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports the
ioctl()
operation used by the eject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.– peterh
Jul 31 '15 at 4:11
Afaik eject plugs out the pluggable disk and not the device. It depends on that the block device driver supports the
ioctl()
operation used by the eject
tool. Esata hard disk drives don't support it, but optical devices, floppies and probably flash drives, yes.– peterh
Jul 31 '15 at 4:11
add a comment |
I have a pair of scripts that build upon the answer by Wyzard. The first, scsi-drop
, is to safely detach a single disk:
#!/bin/sh
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
if test -b "$disk"
then
echo 1 >/sys/block/$(basename "$disk")/device/delete
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Its main benefit is that you can pass it a symlink, such as found in /dev/disk/by-id/
and it will resolve that to the real device. It does require chase
to be installed; you might be able to get the same result using readlink -e
.
The second script, scsi-rescan
, is used after hotplugging a new device:
#!/bin/bash
exec tee /sys/class/scsi_host/host*/scan <<<'- - -' >/dev/null
This makes all adapters re-scan for devices. It was the only way I managed to get the new capacity and partition table to be read.
add a comment |
I have a pair of scripts that build upon the answer by Wyzard. The first, scsi-drop
, is to safely detach a single disk:
#!/bin/sh
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
if test -b "$disk"
then
echo 1 >/sys/block/$(basename "$disk")/device/delete
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Its main benefit is that you can pass it a symlink, such as found in /dev/disk/by-id/
and it will resolve that to the real device. It does require chase
to be installed; you might be able to get the same result using readlink -e
.
The second script, scsi-rescan
, is used after hotplugging a new device:
#!/bin/bash
exec tee /sys/class/scsi_host/host*/scan <<<'- - -' >/dev/null
This makes all adapters re-scan for devices. It was the only way I managed to get the new capacity and partition table to be read.
add a comment |
I have a pair of scripts that build upon the answer by Wyzard. The first, scsi-drop
, is to safely detach a single disk:
#!/bin/sh
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
if test -b "$disk"
then
echo 1 >/sys/block/$(basename "$disk")/device/delete
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Its main benefit is that you can pass it a symlink, such as found in /dev/disk/by-id/
and it will resolve that to the real device. It does require chase
to be installed; you might be able to get the same result using readlink -e
.
The second script, scsi-rescan
, is used after hotplugging a new device:
#!/bin/bash
exec tee /sys/class/scsi_host/host*/scan <<<'- - -' >/dev/null
This makes all adapters re-scan for devices. It was the only way I managed to get the new capacity and partition table to be read.
I have a pair of scripts that build upon the answer by Wyzard. The first, scsi-drop
, is to safely detach a single disk:
#!/bin/sh
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
if test -b "$disk"
then
echo 1 >/sys/block/$(basename "$disk")/device/delete
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Its main benefit is that you can pass it a symlink, such as found in /dev/disk/by-id/
and it will resolve that to the real device. It does require chase
to be installed; you might be able to get the same result using readlink -e
.
The second script, scsi-rescan
, is used after hotplugging a new device:
#!/bin/bash
exec tee /sys/class/scsi_host/host*/scan <<<'- - -' >/dev/null
This makes all adapters re-scan for devices. It was the only way I managed to get the new capacity and partition table to be read.
answered Apr 21 '16 at 11:01
Toby SpeightToby Speight
5,35011031
5,35011031
add a comment |
add a comment |
Actually, SATA drives automatically park the heads when power is lost. Pulling the drive while it is still spinning, should not result in issues. However, spinning disks are prone to dings if bumped. You can hear this when you have flaky power or solar flares.
Most damage is usually caused by, unflushed cache and uncommitted writes in buffers etc ... This is why you MUST unmount a drive, before removing it. The SCSI command is just good measure and works to the same end.
add a comment |
Actually, SATA drives automatically park the heads when power is lost. Pulling the drive while it is still spinning, should not result in issues. However, spinning disks are prone to dings if bumped. You can hear this when you have flaky power or solar flares.
Most damage is usually caused by, unflushed cache and uncommitted writes in buffers etc ... This is why you MUST unmount a drive, before removing it. The SCSI command is just good measure and works to the same end.
add a comment |
Actually, SATA drives automatically park the heads when power is lost. Pulling the drive while it is still spinning, should not result in issues. However, spinning disks are prone to dings if bumped. You can hear this when you have flaky power or solar flares.
Most damage is usually caused by, unflushed cache and uncommitted writes in buffers etc ... This is why you MUST unmount a drive, before removing it. The SCSI command is just good measure and works to the same end.
Actually, SATA drives automatically park the heads when power is lost. Pulling the drive while it is still spinning, should not result in issues. However, spinning disks are prone to dings if bumped. You can hear this when you have flaky power or solar flares.
Most damage is usually caused by, unflushed cache and uncommitted writes in buffers etc ... This is why you MUST unmount a drive, before removing it. The SCSI command is just good measure and works to the same end.
edited Feb 15 at 6:17
Michael Prokopec
1,532218
1,532218
answered Feb 15 at 3:21
spongebobspongebob
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f43413%2fhow-can-i-safely-remove-a-sata-disk-from-a-running-system%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown