
如何將分割區移到磁碟的開頭一點?由於某種原因,Parted 想要一個檔案系統(我不知道為什麼),我只想將所有磁區左移...
r@l:15:32:45:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: HGST HTS 541010A9E680 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 32.2GB 32.2GB primary fat32
2 32.2GB 37.6GB 5360MB primary
3 37.6GB 1000GB 963GB primary
(parted) move 3
WARNING: you are attempting to use parted to operate on (move) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Error: Could not detect file system.
答案1
sfdisk
,它的目的是成為一個可編寫腳本的 fdisk,從某個版本開始就有這個--move-data
選項。範例來自他們的手冊頁:
echo '+100M,' | sfdisk --move-data /dev/sdc -N 1
答案2
使用 dd 和 fdisk 的手動方式:
# fdisk -l /dev/sdb | grep sdb3
/dev/sdb3 73402368 1953525167 940061400 83 Linux
# fdisk /dev/sdb
Command (m for help): d
Partition number (1-4): 3
Command (m for help): n
Partition number (1-4, default 3): 3
First sector (73385984-1953525167, default 73385984):
Using default value 73385984
Last sector, +sectors or +size{K,M,G} (73385984-1953525167, default 1953525167):
Using default value 1953525167
Command (m for help): w
The partition table has been altered!
# fdisk -l /dev/sdb | grep sdb3
/dev/sdb3 73385984 1953525167 940069592 83 Linux
# dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 count=100 skip=$((73402368-73385984)) seek=0 2> /dev/null | file -s -
/dev/stdin: LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f
# dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((73402368-73385984)) seek=0 of=/dev/sdb3
# file -s /dev/sdb3
/dev/sdb3: sticky LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f
現在等待大約2小時。(越看越像18h...)
注意:這只會向後移動數據,而不是向前移動數據。
暫停:
# pidof dd
907
# kill -STOP 907
# cat /proc/907/fdinfo/1
pos: 586921398272
flags: 0100001
# kill -9 907
remember 586921398272/512 = 1146330856
恢復:
dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((1146330856+73402368-73385984)) seek=1146330856 of=/dev/sdb3
答案3
您可以隨時使用dd
.
- 從 liveCD 啟動(或確保分割區未安裝的任何其他方式)
dd if=/dev/sdc2 of=somefile bs=1M
在文件上建立分區的副本。- fdisk(或任何你喜歡的)刪除分割區
- fdisk(或任何您喜歡的東西)在您想要的位置建立分割區。
dd of=/dev/sdc2 if=somefile bs=1M
從文件中恢復內容。