*post note: do not use fdisk. It is limited to 2TB MBR systems. Use parted, instead*
Out of space again. The windows drive is 100 Gig or so, so replace it with a 1Tb drive and use the extra space with linux.
http://tlug.dnho.net/?q=node/91
looks promising.
The new drive is sdc, the old, sda. Copy the partition table:
$ sfdisk -d /dev/sda1 > sda1.out
where
$ cat sda.out
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start= 63, size=156344517, Id= 7, bootable
/dev/sda2 : start= 0, size= 0, Id= 0
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
Copy the partition table to sdc:
$ sfdisk /dev/sdc < sda.out
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdc: 121601 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdc: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdc1 * 63 156344579 156344517 7 HPFS/NTFS
/dev/sdc2 0 - 0 0 Empty
/dev/sdc3 0 - 0 0 Empty
/dev/sdc4 0 - 0 0 Empty
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
Shit. Complexities. Is it DOS? No, it's NTFS, isn't it? Leave as is, for now, and continue with the low level copy. If on drive swap there's a problem, try the zeroing mentioned above.
Low level copy: Note, dd_rescue is just as good and wont fail on bad sectors.
$ dd if=/dev/sda1 of=/dev/sdc1
After approx. an hour:
156344517+0 records in
156344517+0 records out
80048392704 bytes (80 GB) copied, 3404.66 s, 23.5 MB/s
Now, swap the drive with the original and reboot. Did it work?
Of course not. The system freezes at the DMI Table update (or whatever).
OK, zero the first 512 bytes and retry.
$ dd if=/dev/zero of=/dev/sdc1 bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000456196 s, 1.1 MB/s
And reboot. Joy? No. Maybe I should have copied the device, instead of the partition. Boot time shows this drive is the master, so the boot stuff is coming from it. OK, try:
------------------------------------ Start here ------------------------------
$ dd if=/dev/sda of=/dev/sdc
or
$dd_rescue /dev/sda /dev/sdc
It worked! The new drive can be plugged in, to replace the original. Now, to get to the extra space.
$ parted /dev/sda
GNU Parted 1.7.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 80.0GB 80.0GB primary ntfs boot, , , , , , , , , type=07, ,
(parted)
So, the windows partition is there. I want EXT2 / EXT3 on the remaining space. fdisk will partition the disk for me. From,
http://tldp.org/HOWTO/Partition/fdisk_partitioning.html
fdisk's units are the 'cylinder'. $ fdisk /dev/sda shows:
$ fdisk /dev/sda
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9732 78172258+ 7 HPFS/NTFS
Command (m for help):
So, I have a total of
121601 cylinders, of which 9732 are used for xp. Use the rest for ext2.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (9733-121601, default 9733):
Using default value 9733
Last cylinder or +size or +sizeM or +sizeK (9733-121601, default 121601):
Using default value 121601
Command (m for help): p
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 9732 78172258+ 7 HPFS/NTFS
/dev/sda2 9733 121601 898587742+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
------------------------------------------------------------------
Done. Now to format the new partition, and mount it at startup.
First, is the partition present?
$ ls /dev | grep sda
sda
sda1
sda2
Yes! sda2 is new. To format as ext3:
$ mke2fs -j /dev/sda2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
112328704 inodes, 224646935 blocks
11232346 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=226492416
6856 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
And finally, edit /etc/fstab to mount at startup.
I added the line
/dev/sda2 /home/me/projects/d2 ext3 acl,user_xattr 1 3
Now, create the directory /home/me/projects/d2 and reset to test.
It worked.
Footnote: testdisk was the program I used earlier, to recover lost partitions. It's an executable that needs to be downloaded (it's not a part of linux, afaik).
If /etc/fstab references drives by ID, it /dev/disk/by-id/scsi_SATA_etc_etc,
this process will fail. I found this ID approach was terminated by a part number, for each line. Changing this to /dev/sda6 (for example) fixed this.
-----------------------------------------------------------------
Adding a harddrive. First, partition it with fdisk, then format the partition with mke2fs, then
set mounting behaviour.
Work out which device the new drive is. In this case, it's /dev/sdb
$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6c929856.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
The number of cylinders for this disk is set to 243201.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdb: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x6c929856
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-243201, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-243201, default 243201):
Using default value 243201
Command (m for help): p
Disk /dev/sdb: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x6c929856
Device Boot Start End Blocks Id System
/dev/sdb1 1 243201 1953512001 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
--------------- Now format the new partition.
Is the new partition present?
$ ls /dev/sd*
/dev/sda /dev/sda2 /dev/sda4 /dev/sda6 /dev/sdb1
/dev/sda1 /dev/sda3 /dev/sda5 /dev/sdb
yes: sdb1 is new, and a result of the fdisk operation.
$ mke2fs -j /dev/sdb1
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122101760 inodes, 488378000 blocks
24418900 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
14905 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, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: count/14905
And finally, edit /etc/fstab to mount at startup.
I added the line
/dev/sdb1 /home/me/projects/d2 ext3 acl,user_xattr 1 3
No comments:
Post a Comment